diff --git a/src/commands/run.js b/src/commands/run.js index e2b1ab3..8e441b1 100644 --- a/src/commands/run.js +++ b/src/commands/run.js @@ -4,6 +4,7 @@ const runner = require('../modules/runner'); const utils = require('../utils'); const config = require('../modules/config'); const frontendlib = require('../modules/frontendlib'); +const projectRunner = require('../modules/projectRunner'); module.exports.register = (program) => { program @@ -14,6 +15,17 @@ module.exports.register = (program) => { .action(async (command) => { utils.checkCurrentProject(); let configObj = config.get(); + + if(configObj.cli && configObj.cli.projectRunner) { + try { + await projectRunner.runApp(); + process.exit(0); + } catch (error) { + utils.log(error); + process.exit(1); + } + } + let containsFrontendLibApp = frontendlib.containsFrontendLibApp(); let argsOpt = ""; diff --git a/src/modules/bundler.js b/src/modules/bundler.js index ea9e2bc..c950ac3 100644 --- a/src/modules/bundler.js +++ b/src/modules/bundler.js @@ -5,7 +5,9 @@ const asar = require('@electron/asar'); const config = require('./config'); const constants = require('../constants'); const frontendlib = require('./frontendlib'); +const projectRunner = require('./projectRunner'); const utils = require('../utils'); +const path = require('path'); async function createAsarFile() { utils.log(`Generating ${constants.files.resourceFile}...`); @@ -57,19 +59,26 @@ module.exports.bundleApp = async (isRelease, copyStorage) => { let configObj = config.get(); let binaryName = configObj.cli.binaryName; const buildDir = configObj.cli.distributionPath ? utils.trimPath(configObj.cli.distributionPath) : 'dist'; + const projectRunnerConfig = configObj.cli ? configObj.cli.projectRunner : undefined; try { if (frontendlib.containsFrontendLibApp()) { await frontendlib.runCommand('buildCommand'); } + if(projectRunner.containsRunnerApp()) { + if(projectRunnerConfig.buildCommand){ + await projectRunner.runCommand('buildCommand', true); + } + } + await createAsarFile(); utils.log('Copying binaries...'); for (let platform in constants.files.binaries) { for (let arch in constants.files.binaries[platform]) { let originalBinaryFile = constants.files.binaries[platform][arch]; - let destinationBinaryFile = originalBinaryFile.replace('neutralino', binaryName); + let destinationBinaryFile = projectRunner.containsRunnerApp() ? originalBinaryFile : originalBinaryFile.replace('neutralino', binaryName); if (fse.existsSync(`bin/${originalBinaryFile}`)) { fse.copySync(`bin/${originalBinaryFile}`, `${buildDir}/${binaryName}/${destinationBinaryFile}`); } @@ -90,6 +99,24 @@ module.exports.bundleApp = async (isRelease, copyStorage) => { process.exit(1); } } + + if(projectRunner.containsRunnerApp() && projectRunnerConfig && projectRunnerConfig.buildPath){ + utils.log('Copying Project Runner build...'); + + if(fse.existsSync(projectRunnerConfig.buildPath)){ + fse.mkdirSync(`${buildDir}/${binaryName}/bin`, { recursive: true }); + fse.readdirSync(`${buildDir}/${binaryName}`, { withFileTypes: true, recursive: true }).forEach(file => { + if(file.isDirectory() && file.name == "bin") return; + const sourcePath = path.join(`${buildDir}/${binaryName}`, file.name); + fse.moveSync(sourcePath, `${buildDir}/${binaryName}/bin/${file.name}`, { overwrite: true }); + }); + + fse.copySync(projectRunnerConfig.buildPath, `${buildDir}/${binaryName}/`); + } else { + utils.error('Unable to copy projectRunner data from the build directory. Please check if the directory exists'); + } + } + if (isRelease) { utils.log('Making app bundle ZIP file...'); await zl.archiveFolder(`${buildDir}/${binaryName}`, `${buildDir}/${binaryName}-release.zip`); diff --git a/src/modules/creator.js b/src/modules/creator.js index bcad3de..e4eaa3a 100644 --- a/src/modules/creator.js +++ b/src/modules/creator.js @@ -4,6 +4,7 @@ const fse = require('fs-extra'); const config = require('../modules/config'); const downloader = require('./downloader'); const frontendlib = require('../modules/frontendlib'); +const projectRunner = require('../modules/projectRunner'); const utils = require('../utils'); module.exports.createApp = async (binaryName, template) => { @@ -47,6 +48,10 @@ module.exports.createApp = async (binaryName, template) => { await frontendlib.runCommand('initCommand'); } + if(projectRunner.containsRunnerApp()) { + await projectRunner.runCommand('initCommand'); + } + console.log('-------'); utils.log(`Enter 'cd ${binaryName} && neu run' to run your application.`); } diff --git a/src/modules/frontendlib.js b/src/modules/frontendlib.js index 40d3432..a516c5b 100644 --- a/src/modules/frontendlib.js +++ b/src/modules/frontendlib.js @@ -99,7 +99,7 @@ module.exports.runCommand = (commandKey) => { utils.log(`Running ${commandKey}: ${cmd}...`); const proc = spawnCommand(cmd, { stdio: 'inherit', cwd: projectPath }); proc.on('exit', (code) => { - utils.log(`${commandKey} completed with exit code: ${code}`); + utils.log(`FrontendLib: ${commandKey} completed with exit code: ${code}`); resolve(); }); }); diff --git a/src/modules/projectRunner.js b/src/modules/projectRunner.js new file mode 100644 index 0000000..6621e48 --- /dev/null +++ b/src/modules/projectRunner.js @@ -0,0 +1,52 @@ +const process = require('process'); +const spawnCommand = require('spawn-command'); +const config = require('./config'); +const utils = require('../utils'); + +module.exports.containsRunnerApp = () => { + let configObj = config.get(); + return !!(configObj.cli && configObj.cli.projectRunner); +} + +module.exports.runCommand = async (commandKey) => { + let configObj = config.get(); + let projectRunner = configObj.cli ? configObj.cli.projectRunner : undefined; + + if (projectRunner && projectRunner.projectPath && projectRunner[commandKey]) { + + return new Promise((resolve, _reject) => { + let projectPath = utils.trimPath(projectRunner.projectPath); + let cmd = projectRunner[commandKey]; + + utils.log(`Running ${commandKey}: ${cmd}...`); + + const proc = spawnCommand(cmd, { stdio: 'inherit', cwd: projectPath}); + proc.on('exit', (code) => { + utils.log(`Project Runner: ${commandKey} completed with exit code: ${code}`); + resolve(); + }); + }); + } +} + +module.exports.runApp = async () => { + let configObj = config.get(); + let projectRunner = configObj.cli ? configObj.cli.projectRunner : undefined; + + if (projectRunner && projectRunner.projectPath && projectRunner.devCommand) { + return new Promise((resolve, _reject) => { + let projectPath = utils.trimPath(projectRunner.projectPath); + let cmd = projectRunner.devCommand; + + utils.log(`Running Project Runner: ${cmd} ...`); + const proc = spawnCommand(cmd, { stdio: 'inherit', cwd: projectPath}); + proc.on('exit', (code) => { + utils.log(`Project stopped with exit code: ${code}`); + resolve(); + }); + }); + } else { + utils.error("Config file does not contain projectRunner.devCommand to run the project!!!"); + process.exit(1); + } +} \ No newline at end of file