2017-11-20 16:07:36 +00:00
|
|
|
const electronBuilder = require('electron-builder');
|
|
|
|
const path = require('path');
|
|
|
|
const rimraf = require('rimraf');
|
|
|
|
const fs = require('fs');
|
2017-11-26 20:45:40 +00:00
|
|
|
const buildTask = require('./build');
|
2017-11-20 16:07:36 +00:00
|
|
|
|
|
|
|
const PLATFORM_MAP = {
|
|
|
|
darwin: 'mac',
|
|
|
|
linux: 'linux',
|
|
|
|
win32: 'win'
|
|
|
|
};
|
|
|
|
|
2017-11-26 20:45:40 +00:00
|
|
|
// Start package if ran from CLI
|
2017-11-26 23:04:47 +00:00
|
|
|
if (require.main === module) {
|
2017-11-26 20:45:40 +00:00
|
|
|
process.nextTick(async () => {
|
2018-02-13 17:04:39 +00:00
|
|
|
try {
|
|
|
|
await buildTask.start();
|
|
|
|
await module.exports.start();
|
|
|
|
} catch (err) {
|
|
|
|
console.warn('ERROR: ', err.stack);
|
|
|
|
}
|
2017-11-26 20:45:40 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
module.exports.start = async function() {
|
2017-11-20 16:07:36 +00:00
|
|
|
console.log('[package] Removing existing directories');
|
2018-04-20 22:31:57 +00:00
|
|
|
await emptyDir('../dist/*');
|
2017-11-20 16:07:36 +00:00
|
|
|
|
|
|
|
console.log('[package] Packaging app');
|
2017-11-26 20:45:40 +00:00
|
|
|
await pkg('../.electronbuilder');
|
2017-11-20 16:07:36 +00:00
|
|
|
|
|
|
|
console.log('[package] Complete!');
|
2017-11-26 20:45:40 +00:00
|
|
|
};
|
2017-11-20 16:07:36 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
async function pkg(relConfigPath) {
|
2017-11-20 16:07:36 +00:00
|
|
|
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();
|
2018-02-13 17:04:39 +00:00
|
|
|
} catch (err) {
|
2017-11-20 16:07:36 +00:00
|
|
|
console.log('[package] Failed: ' + err.stack);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
async function emptyDir(relPath) {
|
2017-11-20 16:07:36 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const dir = path.resolve(__dirname, relPath);
|
|
|
|
rimraf(dir, err => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|