Skip to content

Commit

Permalink
(feat): dyanamic build paths (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
viralgupta authored Mar 19, 2024
1 parent 51faa88 commit 6555727
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions spec/build.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') &&
Expand All @@ -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'));
});
Expand All @@ -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'));
Expand Down
7 changes: 5 additions & 2 deletions src/commands/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const utils = require('../utils');
const bundler = require('../modules/bundler');
const config = require('../modules/config');

module.exports.register = (program) => {
program
Expand All @@ -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');
});
}
Expand Down
17 changes: 10 additions & 7 deletions src/modules/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down

0 comments on commit 6555727

Please sign in to comment.