diff --git a/spec/build.spec.js b/spec/build.spec.js index deec469..c3631cf 100644 --- a/spec/build.spec.js +++ b/spec/build.spec.js @@ -24,7 +24,7 @@ describe('Run neu build command and its options', () => { assert.equal(output.error, null); assert.equal(output.status, 0); assert.ok(typeof output.data == 'string'); - assert.ok(output.data.includes('Application package was generated at the ./dist directory!')); + assert.ok(output.data.includes('Application package was generated at the dist directory!')); assert.ok(binaries.includes('resources.neu') && binaries.includes('test-app-linux_arm64') && binaries.includes('test-app-linux_armhf') && @@ -41,7 +41,7 @@ describe('Run neu build command and its options', () => { assert.equal(output.error, null); assert.equal(output.status, 0); assert.ok(typeof output.data == 'string'); - assert.ok(output.data.includes('Application package was generated at the ./dist directory!') && + assert.ok(output.data.includes('Application package was generated at the dist directory!') && output.data.includes('Making app bundle ZIP file')); assert.ok(applicationBundle.includes('test-app-release.zip')); }); @@ -53,7 +53,7 @@ describe('Run neu build command and its options', () => { assert.equal(output.error, null); assert.equal(output.status, 0); assert.ok(typeof output.data == 'string'); - assert.ok(output.data.includes('Application package was generated at the ./dist directory!') && + assert.ok(output.data.includes('Application package was generated at the dist directory!') && output.data.includes('Copying binaries') && output.data.includes('Copying storage data')); assert.ok(storageSnapshot.includes('.storage')); diff --git a/src/commands/build.js b/src/commands/build.js index 22f871f..6e51668 100644 --- a/src/commands/build.js +++ b/src/commands/build.js @@ -1,5 +1,6 @@ const utils = require('../utils'); const bundler = require('../modules/bundler'); +const config = require('../modules/config'); module.exports.register = (program) => { program @@ -9,12 +10,14 @@ module.exports.register = (program) => { .option('--copy-storage') .action(async (command) => { utils.checkCurrentProject(); + const configObj = config.get() utils.log('Removing current build...'); - utils.clearDirectory('dist'); + const buildDir = configObj.distributionPath ? utils.trimPath(configObj.distributionPath) : 'dist'; + utils.clearDirectory(buildDir); utils.log('Bundling app...'); await bundler.bundleApp(command.release, command.copyStorage); utils.showArt(); - utils.log('Application package was generated at the ./dist directory!'); + utils.log(`Application package was generated at the ${buildDir} directory!`); utils.log('Distribution guide: https://neutralino.js.org/docs/distribution/overview'); }); } diff --git a/src/modules/bundler.js b/src/modules/bundler.js index f364d72..795c778 100644 --- a/src/modules/bundler.js +++ b/src/modules/bundler.js @@ -16,12 +16,13 @@ async function createAsarFile() { : null; const icon = utils.trimPath(configObj.modes.window.icon); const binaryName = configObj.cli.binaryName; + const buildDir = configObj.distributionPath ? utils.trimPath(configObj.distributionPath) : 'dist'; fs.mkdirSync(`.tmp`, { recursive: true }); await fse.copy(`./${resourcesDir}`, `.tmp/${resourcesDir}`, {overwrite: true}); if(extensionsDir && fs.existsSync(extensionsDir)) { - await fse.copy(`./${extensionsDir}`, `dist/${binaryName}/${extensionsDir}`, {overwrite: true}); + await fse.copy(`./${extensionsDir}`, `${buildDir}/${binaryName}/${extensionsDir}`, {overwrite: true}); } await fse.copy(`${constants.files.configFile}`, `.tmp/${constants.files.configFile}`, {overwrite: true}); @@ -34,12 +35,14 @@ async function createAsarFile() { } await fse.copy(`./${icon}`, `.tmp/${icon}`, {overwrite: true}); - await asar.createPackage('.tmp', `dist/${binaryName}/${constants.files.resourceFile}`); + await asar.createPackage('.tmp', `${buildDir}/${binaryName}/${constants.files.resourceFile}`); } module.exports.bundleApp = async (isRelease, copyStorage) => { let configObj = config.get(); let binaryName = configObj.cli.binaryName; + const buildDir = configObj.distributionPath ? utils.trimPath(configObj.distributionPath) : 'dist'; + try { if(frontendlib.containsFrontendLibApp()) { await frontendlib.runCommand('buildCommand'); @@ -53,19 +56,19 @@ module.exports.bundleApp = async (isRelease, copyStorage) => { let originalBinaryFile = constants.files.binaries[platform][arch]; let destinationBinaryFile = originalBinaryFile.replace('neutralino', binaryName); if(fse.existsSync(`bin/${originalBinaryFile}`)) { - fse.copySync(`bin/${originalBinaryFile}`, `dist/${binaryName}/${destinationBinaryFile}`); + fse.copySync(`bin/${originalBinaryFile}`, `${buildDir}/${binaryName}/${destinationBinaryFile}`); } } } for(let dependency of constants.files.dependencies) { - fse.copySync(`bin/${dependency}`,`dist/${binaryName}/${dependency}`); + fse.copySync(`bin/${dependency}`,`${buildDir}/${binaryName}/${dependency}`); } if(copyStorage) { utils.log('Copying storage data...'); try { - fse.copySync('.storage',`dist/${binaryName}/.storage`); + fse.copySync('.storage',`${buildDir}/${binaryName}/.storage`); } catch(err) { utils.error('Unable to copy storage data from the .storage directory. Please check if the directory exists'); @@ -75,10 +78,10 @@ module.exports.bundleApp = async (isRelease, copyStorage) => { if (isRelease) { utils.log('Making app bundle ZIP file...'); - let output = fs.createWriteStream(`dist/${binaryName}-release.zip`); + let output = fs.createWriteStream(`${buildDir}/${binaryName}-release.zip`); let archive = archiver('zip', { zlib: { level: 9 } }); archive.pipe(output); - archive.directory(`dist/${binaryName}`, false); + archive.directory(`${buildDir}/${binaryName}`, false); await archive.finalize(); } utils.clearDirectory('.tmp');