2020-04-26 20:33:39 +00:00
|
|
|
const { appConfig, electronBuilderConfig } = require('../config');
|
2017-11-20 16:07:36 +00:00
|
|
|
const electronBuilder = require('electron-builder');
|
|
|
|
const path = require('path');
|
|
|
|
const rimraf = require('rimraf');
|
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');
|
2020-04-26 20:33:39 +00:00
|
|
|
await pkg(electronBuilderConfig());
|
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
|
|
|
|
2020-04-26 20:33:39 +00:00
|
|
|
async function pkg(electronBuilderConfig) {
|
|
|
|
const app = appConfig();
|
2019-09-18 00:02:42 +00:00
|
|
|
|
|
|
|
// Replace some things
|
2020-04-26 20:33:39 +00:00
|
|
|
const rawConfig = JSON.stringify(electronBuilderConfig, null, 2)
|
|
|
|
.replace(/__APP_ID__/g, app.appId)
|
|
|
|
.replace(/__BINARY_PREFIX__/g, app.binaryPrefix)
|
|
|
|
.replace(/__EXECUTABLE_NAME__/g, app.executableName)
|
|
|
|
.replace(/__GITHUB_OWNER__/g, app.githubOrg)
|
|
|
|
.replace(/__GITHUB_REPO__/g, app.githubRepo)
|
|
|
|
.replace(/__ICON_URL__/g, app.icon)
|
|
|
|
.replace(/__SYNOPSIS__/g, app.synopsis);
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|