-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbuild.js
61 lines (56 loc) · 1.59 KB
/
build.js
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
const builder = require("electron-builder");
const yaml = require("js-yaml");
const fs = require("fs-extra");
const path = require("path");
const config = yaml.load(fs.readFileSync("./electron-builder.yml"));
const Platform = builder.Platform;
const program = require("commander");
async function copyFiles() {
const files = [
"package.json",
"loading.html",
"settings.html",
"images",
"locales",
"src/renderer/desktop.css",
"node_modules"
];
for (let file of files) {
await fs.copy(file, path.join(__dirname, config.directories.app, file.replace("src/", "")));
}
return files;
}
async function patchFiles() {
await fs.copy('patch/underscore-package.json', path.join(__dirname, "node_modules/nomnom/node_modules/underscore/package.json"));
return ['nomnom/*/underscore/package.json'];
}
async function build() {
const platform = (process.platform === "darwin") ? Platform.MAC : Platform.WINDOWS;
return await builder.build({
targets: platform.createTarget(),
config
});
}
async function main() {
program
.option("-s --setup")
.option("-b --build")
.parse(process.argv);
const opts = program.opts();
const noopts = !(opts.setup || opts.build)
try {
if (noopts || opts.setup) {
const patched = await patchFiles();
console.log(`Patched ${patched}.`);
const copied = await copyFiles();
console.log(`Copy ${copied} to dist/*`);
}
if (noopts || opts.build) {
const res = await build();
console.log(res);
}
}catch(err) {
console.error(err);
}
}
main().then(() => {console.log(`Done.`)});