UNPKG

9.4 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.configureBuildCommand = exports.build = exports.createTargets = exports.coerceTypes = exports.normalizeOptions = exports.createYargs = void 0;
4const builder_util_1 = require("builder-util");
5const chalk = require("chalk");
6const app_builder_lib_1 = require("app-builder-lib");
7const yargs = require("yargs");
8function createYargs() {
9 return yargs.parserConfiguration({
10 "camel-case-expansion": false,
11 });
12}
13exports.createYargs = createYargs;
14/** @private */
15function normalizeOptions(args) {
16 if (args.targets != null) {
17 return args;
18 }
19 const targets = new Map();
20 function processTargets(platform, types) {
21 function commonArch(currentIfNotSpecified) {
22 const result = Array();
23 if (args.x64) {
24 result.push(builder_util_1.Arch.x64);
25 }
26 if (args.armv7l) {
27 result.push(builder_util_1.Arch.armv7l);
28 }
29 if (args.arm64) {
30 result.push(builder_util_1.Arch.arm64);
31 }
32 if (args.ia32) {
33 result.push(builder_util_1.Arch.ia32);
34 }
35 if (args.universal) {
36 result.push(builder_util_1.Arch.universal);
37 }
38 return result.length === 0 && currentIfNotSpecified ? [builder_util_1.archFromString(process.arch)] : result;
39 }
40 let archToType = targets.get(platform);
41 if (archToType == null) {
42 archToType = new Map();
43 targets.set(platform, archToType);
44 }
45 if (types.length === 0) {
46 const defaultTargetValue = args.dir ? [app_builder_lib_1.DIR_TARGET] : [];
47 for (const arch of commonArch(args.dir === true)) {
48 archToType.set(arch, defaultTargetValue);
49 }
50 return;
51 }
52 for (const type of types) {
53 const suffixPos = type.lastIndexOf(":");
54 if (suffixPos > 0) {
55 builder_util_1.addValue(archToType, builder_util_1.archFromString(type.substring(suffixPos + 1)), type.substring(0, suffixPos));
56 }
57 else {
58 for (const arch of commonArch(true)) {
59 builder_util_1.addValue(archToType, arch, type);
60 }
61 }
62 }
63 }
64 if (args.mac != null) {
65 processTargets(app_builder_lib_1.Platform.MAC, args.mac);
66 }
67 if (args.linux != null) {
68 processTargets(app_builder_lib_1.Platform.LINUX, args.linux);
69 }
70 if (args.win != null) {
71 processTargets(app_builder_lib_1.Platform.WINDOWS, args.win);
72 }
73 if (targets.size === 0) {
74 processTargets(app_builder_lib_1.Platform.current(), []);
75 }
76 const result = { ...args };
77 result.targets = targets;
78 delete result.dir;
79 delete result.mac;
80 delete result.linux;
81 delete result.win;
82 const r = result;
83 delete r.m;
84 delete r.o;
85 delete r.l;
86 delete r.w;
87 delete r.windows;
88 delete r.macos;
89 delete r.$0;
90 delete r._;
91 delete r.version;
92 delete r.help;
93 delete r.c;
94 delete r.p;
95 delete r.pd;
96 delete result.ia32;
97 delete result.x64;
98 delete result.armv7l;
99 delete result.arm64;
100 delete result.universal;
101 let config = result.config;
102 // config is array when combining dot-notation values with a config file value
103 // https://github.com/electron-userland/electron-builder/issues/2016
104 if (Array.isArray(config)) {
105 const newConfig = {};
106 for (const configItem of config) {
107 if (typeof configItem === "object") {
108 builder_util_1.deepAssign(newConfig, configItem);
109 }
110 else if (typeof configItem === "string") {
111 newConfig.extends = configItem;
112 }
113 }
114 config = newConfig;
115 result.config = newConfig;
116 }
117 // AJV cannot coerce "null" string to null if string is also allowed (because null string is a valid value)
118 if (config != null && typeof config !== "string") {
119 if (config.extraMetadata != null) {
120 coerceTypes(config.extraMetadata);
121 }
122 // ability to disable code sign using -c.mac.identity=null
123 if (config.mac != null) {
124 coerceValue(config.mac, "identity");
125 }
126 // fix Boolean type by coerceTypes
127 if (config.nsis != null) {
128 coerceTypes(config.nsis);
129 }
130 if (config.nsisWeb != null) {
131 coerceTypes(config.nsisWeb);
132 }
133 }
134 if ("project" in r && !("projectDir" in result)) {
135 result.projectDir = r.project;
136 }
137 delete r.project;
138 return result;
139}
140exports.normalizeOptions = normalizeOptions;
141function coerceValue(host, key) {
142 const value = host[key];
143 if (value === "true") {
144 host[key] = true;
145 }
146 else if (value === "false") {
147 host[key] = false;
148 }
149 else if (value === "null") {
150 host[key] = null;
151 }
152 else if (key === "version" && typeof value === "number") {
153 host[key] = value.toString();
154 }
155 else if (value != null && typeof value === "object") {
156 coerceTypes(value);
157 }
158}
159/** @private */
160function coerceTypes(host) {
161 for (const key of Object.getOwnPropertyNames(host)) {
162 coerceValue(host, key);
163 }
164 return host;
165}
166exports.coerceTypes = coerceTypes;
167function createTargets(platforms, type, arch) {
168 const targets = new Map();
169 for (const platform of platforms) {
170 const archs = arch === "all" ? (platform === app_builder_lib_1.Platform.MAC ? [builder_util_1.Arch.x64, builder_util_1.Arch.arm64, builder_util_1.Arch.universal] : [builder_util_1.Arch.x64, builder_util_1.Arch.ia32]) : [builder_util_1.archFromString(arch == null ? process.arch : arch)];
171 const archToType = new Map();
172 targets.set(platform, archToType);
173 for (const arch of archs) {
174 archToType.set(arch, type == null ? [] : [type]);
175 }
176 }
177 return targets;
178}
179exports.createTargets = createTargets;
180function build(rawOptions) {
181 const buildOptions = normalizeOptions(rawOptions || {});
182 return app_builder_lib_1.build(buildOptions, new app_builder_lib_1.Packager(buildOptions));
183}
184exports.build = build;
185/**
186 * @private
187 */
188function configureBuildCommand(yargs) {
189 const publishGroup = "Publishing:";
190 const buildGroup = "Building:";
191 return yargs
192 .option("mac", {
193 group: buildGroup,
194 alias: ["m", "o", "macos"],
195 description: `Build for macOS, accepts target list (see ${chalk.underline("https://goo.gl/5uHuzj")}).`,
196 type: "array",
197 })
198 .option("linux", {
199 group: buildGroup,
200 alias: "l",
201 description: `Build for Linux, accepts target list (see ${chalk.underline("https://goo.gl/4vwQad")})`,
202 type: "array",
203 })
204 .option("win", {
205 group: buildGroup,
206 alias: ["w", "windows"],
207 description: `Build for Windows, accepts target list (see ${chalk.underline("https://goo.gl/jYsTEJ")})`,
208 type: "array",
209 })
210 .option("x64", {
211 group: buildGroup,
212 description: "Build for x64",
213 type: "boolean",
214 })
215 .option("ia32", {
216 group: buildGroup,
217 description: "Build for ia32",
218 type: "boolean",
219 })
220 .option("armv7l", {
221 group: buildGroup,
222 description: "Build for armv7l",
223 type: "boolean",
224 })
225 .option("arm64", {
226 group: buildGroup,
227 description: "Build for arm64",
228 type: "boolean",
229 })
230 .option("universal", {
231 group: buildGroup,
232 description: "Build for universal",
233 type: "boolean",
234 })
235 .option("dir", {
236 group: buildGroup,
237 description: "Build unpacked dir. Useful to test.",
238 type: "boolean",
239 })
240 .option("publish", {
241 group: publishGroup,
242 alias: "p",
243 description: `Publish artifacts, see ${chalk.underline("https://goo.gl/tSFycD")}`,
244 choices: ["onTag", "onTagOrDraft", "always", "never", undefined],
245 })
246 .option("prepackaged", {
247 alias: ["pd"],
248 group: buildGroup,
249 description: "The path to prepackaged app (to pack in a distributable format)",
250 })
251 .option("projectDir", {
252 alias: ["project"],
253 group: buildGroup,
254 description: "The path to project directory. Defaults to current working directory.",
255 })
256 .option("config", {
257 alias: ["c"],
258 group: buildGroup,
259 description: "The path to an electron-builder config. Defaults to `electron-builder.yml` (or `json`, or `json5`), see " + chalk.underline("https://goo.gl/YFRJOM"),
260 })
261 .group(["help", "version"], "Other:")
262 .example("electron-builder -mwl", "build for macOS, Windows and Linux")
263 .example("electron-builder --linux deb tar.xz", "build deb and tar.xz for Linux")
264 .example("electron-builder --win --ia32", "build for Windows ia32")
265 .example("electron-builder -c.extraMetadata.foo=bar", "set package.json property `foo` to `bar`")
266 .example("electron-builder --config.nsis.unicode=false", "configure unicode options for NSIS");
267}
268exports.configureBuildCommand = configureBuildCommand;
269//# sourceMappingURL=builder.js.map
\No newline at end of file