insomnia/packages/insomnia-app/scripts/package.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

const electronBuilder = require('electron-builder');
const path = require('path');
const rimraf = require('rimraf');
const fs = require('fs');
const buildTask = require('./build');
const PLATFORM_MAP = {
darwin: 'mac',
linux: 'linux',
win32: 'win'
};
// Start package if ran from CLI
if (require.main === module) {
process.nextTick(async () => {
try {
await buildTask.start();
await module.exports.start();
} catch (err) {
console.warn('ERROR: ', err.stack);
}
});
}
2018-06-25 17:42:50 +00:00
module.exports.start = async function() {
console.log('[package] Removing existing directories');
await emptyDir('../dist/*');
console.log('[package] Packaging app');
await pkg('../.electronbuilder');
console.log('[package] Complete!');
};
2018-06-25 17:42:50 +00:00
async function pkg(relConfigPath) {
try {
const configPath = path.resolve(__dirname, relConfigPath);
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
const targetPlatform = PLATFORM_MAP[process.platform];
const packager = new electronBuilder.Packager({
config,
cscLink: process.env.CSC_LINK,
cscKeyPassword: process.env.CSC_KEY_PASSWORD,
[targetPlatform]: config[targetPlatform].target
});
2017-11-26 23:05:44 +00:00
return packager.build();
} catch (err) {
console.log('[package] Failed: ' + err.stack);
throw err;
}
}
2018-06-25 17:42:50 +00:00
async function emptyDir(relPath) {
return new Promise((resolve, reject) => {
const dir = path.resolve(__dirname, relPath);
rimraf(dir, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}