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');
|
|
|
|
const mkdirp = require('mkdirp');
|
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 () => {
|
|
|
|
await buildTask.start();
|
|
|
|
await module.exports.start();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.start = async function () {
|
2017-11-20 16:07:36 +00:00
|
|
|
console.log('[package] Removing existing directories');
|
|
|
|
await emptyDir('../dist');
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-11-26 20:45:40 +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 20:45:40 +00:00
|
|
|
return packager.start();
|
2017-11-20 16:07:36 +00:00
|
|
|
} catch
|
|
|
|
(err) {
|
|
|
|
console.log('[package] Failed: ' + err.stack);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function emptyDir (relPath) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const dir = path.resolve(__dirname, relPath);
|
|
|
|
rimraf(dir, err => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
mkdirp.sync(dir);
|
|
|
|
resolve();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|