2019-09-18 00:02:42 +00:00
|
|
|
const packageJson = require('../package.json');
|
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',
|
2018-12-12 17:36:11 +00:00
|
|
|
win32: 'win',
|
2017-11-20 16:07:36 +00:00
|
|
|
};
|
|
|
|
|
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) {
|
2019-04-19 22:56:50 +00:00
|
|
|
console.log('[package] ERROR:', err);
|
2018-10-20 02:11:58 +00:00
|
|
|
process.exit(1);
|
2018-02-13 17:04:39 +00:00
|
|
|
}
|
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-11-06 17:27:38 +00:00
|
|
|
|
|
|
|
if (process.env.KEEP_DIST_FOLDER !== 'yes') {
|
|
|
|
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) {
|
2018-10-20 02:11:58 +00:00
|
|
|
const configPath = path.resolve(__dirname, relConfigPath);
|
2019-09-18 00:02:42 +00:00
|
|
|
|
|
|
|
// Replace some things
|
|
|
|
const rawConfig = fs
|
|
|
|
.readFileSync(configPath, 'utf8')
|
|
|
|
.replace('__APP_ID__', packageJson.app.appId)
|
|
|
|
.replace('__ICON_URL__', packageJson.app.icon)
|
|
|
|
.replace('__EXECUTABLE_NAME__', packageJson.app.executableName)
|
|
|
|
.replace('__SYNOPSIS__', packageJson.app.synopsis);
|
|
|
|
|
2019-10-02 15:19:23 +00:00
|
|
|
// console.log(`[package] Using electron-builder config\n${rawConfig}`);
|
2019-09-18 00:02:42 +00:00
|
|
|
|
|
|
|
const config = JSON.parse(rawConfig);
|
2018-10-20 02:11:58 +00:00
|
|
|
const targetPlatform = PLATFORM_MAP[process.platform];
|
2018-11-06 17:27:38 +00:00
|
|
|
|
|
|
|
const target = process.env.BUILD_TARGETS
|
|
|
|
? process.env.BUILD_TARGETS.split(',')
|
|
|
|
: config[targetPlatform].target;
|
|
|
|
|
2018-10-20 02:11:58 +00:00
|
|
|
return electronBuilder.build({
|
|
|
|
config,
|
2018-12-12 17:36:11 +00:00
|
|
|
[targetPlatform]: target,
|
2018-10-20 02:11:58 +00:00
|
|
|
});
|
2017-11-20 16:07:36 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|