-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.js
executable file
·178 lines (167 loc) · 4.95 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env node
"use strict";
/*
* Copyright (C) 2017-2021 UBports Foundation <[email protected]>
* Copyright (C) 2023 Erik Inkinen <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const builder = require("electron-builder");
const cli = require("commander");
const PLATFORMS = ["darwin", "win32", "linux"];
const PACKAGES = ["deb", "snap", "AppImage", "dmg", "portable", "dir"];
const ARCH = ["armv7l", "x64", "ia32", "arm64"];
cli
.version(require("./package.json").version)
.name("./build.js")
.usage("-o <os> -p <package> -a <arch> [options]") // remember the cant
.option(
"-o, --os <os>",
`Target operating system (${PLATFORMS.join(", ")})`,
p => (PLATFORMS.includes(p) ? p : process.platform),
process.platform
)
.option(
"-p, --package <package>",
`Target package (${PACKAGES.join(", ")})`,
p => (PACKAGES.includes(p) ? p : "dir"),
"dir"
)
.option(
"-a, --arch <architecture>",
`Target architecture (${ARCH.join(", ")})`,
a => (ARCH.includes(a) ? a : "x64"),
"x64"
)
.option(
"-e, --extra-metadata [JSON]",
"extra data for package.json",
JSON.parse,
"{}"
)
.parse(process.argv);
const opts = cli.opts();
var targetOs;
var buildConfig = {
appId: "org.droidian.installer",
productName: "droidian-installer",
copyright: `Copyright © 2017-${new Date().getFullYear()} UBports Foundation, Erik Inkinen`,
artifactName: "${name}_${version}_${os}_${arch}.${ext}",
publish: [],
files: [
"src/**/*",
"public/**/*",
"node_modules/**/*",
"build/icons/icon.*",
// exclude binaries for other operating systems
...PLATFORMS.filter(p => p !== opts.os).map(
p => `!node_modules/android-tools-bin/dist/${p}`
),
// exclude binaries for other architectures
`!node_modules/android-tools-bin/dist/**/${
opts.arch.includes("arm") ? "x86" : "arm"
}/**`
],
asarUnpack: [
// Unpack dependencies of pakcages containing binaries
"node_modules/7zip-min/*", // for 7zip-bin
"node_modules/jsonfile/**/*", // for fs-extra
"node_modules/at-least-node/**/*", // for fs-extra
"node_modules/graceful-fs/**/*", // for fs-extra
"node_modules/universalify/**/*", // for fs-extra
"node_modules/fs-extra/**/*", // for promise-android-tools
"node_modules/cancelable-promise/**/*", // for promise-android-tools
"node_modules/promise-android-tools/**/*", // for android-tools-bin
"node_modules/@babel/runtime/**/*" // for android-tools-bin
],
extraMetadata: {
package: opts.package === "portable" ? "exe" : opts.package,
...opts.extraMetadata
}
};
const target = {
target: opts.package,
arch: opts.arch
};
// Validate and configure operating system
switch (opts.os) {
case "linux":
targetOs = builder.Platform.LINUX;
buildConfig = Object.assign(buildConfig, {
linux: {
target,
icon: "build/icons",
synopsis: "Install Droidian on supported devices",
category: "Utility"
},
deb: {
depends: [
"gconf2",
"gconf-service",
"libnotify4",
"libappindicator1",
"libxtst6",
"libnss3",
"android-tools-adb",
"android-tools-fastboot",
"heimdall-flash"
]
},
afterPack: "./afterPack.js"
});
break;
case "win32":
targetOs = builder.Platform.WINDOWS;
buildConfig = Object.assign(buildConfig, {
win: {
target,
icon: "build/icons/icon.ico"
}
});
break;
case "darwin":
targetOs = builder.Platform.MAC;
buildConfig = Object.assign(buildConfig, {
mac: {
target,
icon: "build/icons/icon.icns",
category: "public.app-category.utilities"
}
});
break;
default:
break;
}
const build = () =>
builder
.build({
targets: builder.createTargets([targetOs]),
config: buildConfig
})
.then(() => console.log("build complete"))
.catch(e => {
if (e.message.indexOf("GitHub Personal Access Token is not set") !== -1) {
console.log("build complete");
} else {
throw new Error(`Build error: ${e}`);
}
});
// actual work happens here
console.log("build", opts.package, "for", opts.arch, opts.os, "or die trying");
build()
.then(() => console.log("all done!"))
.catch(e => {
console.error(e);
process.exit(1);
});