From 499f2dac20658ae963d2594059c12e9afd882e8d Mon Sep 17 00:00:00 2001 From: viralgupta Date: Sat, 10 Aug 2024 18:27:06 +0530 Subject: [PATCH 1/5] feat: Add support for projectRunner --- src/commands/run.js | 12 +++++++++ src/modules/bundler.js | 28 ++++++++++++++++++++ src/modules/creator.js | 5 ++++ src/modules/frontendlib.js | 2 +- src/modules/projectRunner.js | 50 ++++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/modules/projectRunner.js 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 5848746..5f38692 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,12 +59,19 @@ 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...'); @@ -91,6 +100,25 @@ module.exports.bundleApp = async (isRelease, copyStorage) => { } } + if(projectRunner.containsRunnerApp() && projectRunnerConfig && projectRunnerConfig.buildPath){ + utils.log('Copying Project Runner build...'); + + if(fse.existsSync(projectRunnerConfig.buildPath)){ + // copy contents from builddir/appname -> buildDir/appname/bin + 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 }); + }); + + // copy projectRunner buildPath -> buildDir/appname + 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...'); let output = fs.createWriteStream(`${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..90419f2 --- /dev/null +++ b/src/modules/projectRunner.js @@ -0,0 +1,50 @@ +const process = require('process'); +const spawnCommand = require('spawn-command'); +const config = require('./config'); +const utils = require('../utils'); + +module.exports.containsRunnerApp = async () => { + 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[commandKey]) { + + return new Promise((resolve, _reject) => { + let cmd = projectRunner[commandKey]; + + utils.log(`Running ${commandKey}: ${cmd}...`); + + const proc = spawnCommand(cmd, { stdio: 'inherit'}); + 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.devCommand) { + return new Promise((resolve, _reject) => { + let cmd = projectRunner.devCommand; + + utils.log(`Running Project Runner: ${cmd} ...`); + const proc = spawnCommand(cmd, { stdio: 'inherit'}); + 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 From 3a7a4ba02b786abd0addedbd3fbf9a214ef68cd8 Mon Sep 17 00:00:00 2001 From: viralgupta Date: Sat, 10 Aug 2024 20:05:58 +0530 Subject: [PATCH 2/5] fix: passed test cases --- spec/.gitignore | 2 ++ src/modules/projectRunner.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/.gitignore b/spec/.gitignore index d572211..f95a667 100644 --- a/spec/.gitignore +++ b/spec/.gitignore @@ -133,3 +133,5 @@ dist .svelte-kit # End of https://www.toptal.com/developers/gitignore/api/node + +test-app \ No newline at end of file diff --git a/src/modules/projectRunner.js b/src/modules/projectRunner.js index 90419f2..b5f82f5 100644 --- a/src/modules/projectRunner.js +++ b/src/modules/projectRunner.js @@ -3,7 +3,7 @@ const spawnCommand = require('spawn-command'); const config = require('./config'); const utils = require('../utils'); -module.exports.containsRunnerApp = async () => { +module.exports.containsRunnerApp = () => { let configObj = config.get(); return !!(configObj.cli && configObj.cli.projectRunner); } From 5d931573cbe34ef1bc9f5b42ae23b4a00fa12b44 Mon Sep 17 00:00:00 2001 From: viralgupta Date: Tue, 13 Aug 2024 01:38:20 +0530 Subject: [PATCH 3/5] refactor: Improve bundler.js logic for handling projectRunner apps --- src/modules/bundler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/bundler.js b/src/modules/bundler.js index 5f38692..1dfcd9f 100644 --- a/src/modules/bundler.js +++ b/src/modules/bundler.js @@ -78,7 +78,7 @@ module.exports.bundleApp = async (isRelease, copyStorage) => { 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}`); } From 329dd4f139b204443d3110038416881e80f6cee5 Mon Sep 17 00:00:00 2001 From: viralgupta Date: Tue, 13 Aug 2024 01:51:56 +0530 Subject: [PATCH 4/5] feat: support projectPath Config in projectRunner --- src/modules/projectRunner.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/projectRunner.js b/src/modules/projectRunner.js index b5f82f5..6621e48 100644 --- a/src/modules/projectRunner.js +++ b/src/modules/projectRunner.js @@ -12,14 +12,15 @@ module.exports.runCommand = async (commandKey) => { let configObj = config.get(); let projectRunner = configObj.cli ? configObj.cli.projectRunner : undefined; - if (projectRunner && projectRunner[commandKey]) { + 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'}); + const proc = spawnCommand(cmd, { stdio: 'inherit', cwd: projectPath}); proc.on('exit', (code) => { utils.log(`Project Runner: ${commandKey} completed with exit code: ${code}`); resolve(); @@ -32,12 +33,13 @@ module.exports.runApp = async () => { let configObj = config.get(); let projectRunner = configObj.cli ? configObj.cli.projectRunner : undefined; - if (projectRunner && projectRunner.devCommand) { + 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'}); + const proc = spawnCommand(cmd, { stdio: 'inherit', cwd: projectPath}); proc.on('exit', (code) => { utils.log(`Project stopped with exit code: ${code}`); resolve(); From 05eb133538b0ad1b2b9cf938cac463bfb7edc045 Mon Sep 17 00:00:00 2001 From: Shalitha Suranga Date: Mon, 19 Aug 2024 15:37:03 +0530 Subject: [PATCH 5/5] Update .gitignore --- spec/.gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/.gitignore b/spec/.gitignore index f95a667..d572211 100644 --- a/spec/.gitignore +++ b/spec/.gitignore @@ -133,5 +133,3 @@ dist .svelte-kit # End of https://www.toptal.com/developers/gitignore/api/node - -test-app \ No newline at end of file