This repository was archived by the owner on Oct 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage.js
More file actions
92 lines (75 loc) · 2.24 KB
/
Copy pathpackage.js
File metadata and controls
92 lines (75 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"use strict";
var packager = require('electron-packager');
const pkg = require('./package.json');
const argv = require('minimist')(process.argv.slice(1));
const appName = argv.name || pkg.productName || pkg.name;
const buildVersion = pkg.version || '1.0';
const shouldUseAsar = argv.asar || false;
const shouldBuildAll = argv.all || false;
const arch = argv.arch || 'all';
const platform = argv.platform || 'darwin';
const fs = require('fs'), readdirSync = fs.readdirSync, unlinkSync = fs.unlinkSync;
const renameSync = fs.renameSync;
const rimraf = require('rimraf');
const DEFAULT_OPTS = {
dir: './dist',
name: appName,
asar: shouldUseAsar,
buildVersion: buildVersion
};
pack(platform, arch, function done(err, appPath) {
if (err) {
console.log(err);
} else {
var newPath = postPack(platform, appPath);
console.log('Application packaged successfuly!', newPath);
}
});
function pack(plat, arch, cb) {
// there is no darwin ia32 electron
if (plat === 'darwin' && arch === 'ia32') return;
let icon = 'src/resources/icon';
if (icon) {
DEFAULT_OPTS.icon = icon + (() => {
let extension = '.png';
if (plat === 'darwin') {
extension = '.icns';
} else if (plat === 'win32') {
extension = '.ico';
}
return extension;
})();
}
const opts = Object.assign({}, DEFAULT_OPTS, {
platform: plat,
arch,
prune: true,
overwrite: true,
all: shouldBuildAll,
out: `app-builds`
});
//console.log(opts)
packager(opts, cb);
}
function postPack(platform, appPaths) {
var appPath = appPaths.toString();
var dir = appPath.split('/').slice(-1);
var binDir = appPath.split('/').slice(0,-1).join('/');
if( platform === 'darwin' ) {
platform = 'macos';
}
if ( platform === 'win32' ) {
platform = 'win';
}
unlinkSync(appPath + '/LICENSE');
unlinkSync(appPath + '/LICENSES.chromium.html');
unlinkSync(appPath + '/version');
var newName = binDir + '/' + pkg.productName + '-' + platform + '-' + pkg.version;
rimraf(newName, function(err){
if (err) {
throw err;
}
renameSync(appPath, newName);
});
return newName;
}