UNPKG

9.3 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.createYargs = createYargs;
4exports.normalizeOptions = normalizeOptions;
5exports.coerceTypes = coerceTypes;
6exports.createTargets = createTargets;
7exports.build = build;
8exports.configureBuildCommand = configureBuildCommand;
9const builder_util_1 = require("builder-util");
10const chalk = require("chalk");
11const app_builder_lib_1 = require("app-builder-lib");
12const yargs = require("yargs");
13function createYargs() {
14 return yargs.parserConfiguration({
15 "camel-case-expansion": false,
16 });
17}
18/** @private */
19function normalizeOptions(args) {
20 if (args.targets != null) {
21 return args;
22 }
23 const targets = new Map();
24 function processTargets(platform, types) {
25 function commonArch(currentIfNotSpecified) {
26 const result = Array();
27 if (args.x64) {
28 result.push(builder_util_1.Arch.x64);
29 }
30 if (args.armv7l) {
31 result.push(builder_util_1.Arch.armv7l);
32 }
33 if (args.arm64) {
34 result.push(builder_util_1.Arch.arm64);
35 }
36 if (args.ia32) {
37 result.push(builder_util_1.Arch.ia32);
38 }
39 if (args.universal) {
40 result.push(builder_util_1.Arch.universal);
41 }
42 return result.length === 0 && currentIfNotSpecified ? [(0, builder_util_1.archFromString)(process.arch)] : result;
43 }
44 let archToType = targets.get(platform);
45 if (archToType == null) {
46 archToType = new Map();
47 targets.set(platform, archToType);
48 }
49 if (types.length === 0) {
50 const defaultTargetValue = args.dir ? [app_builder_lib_1.DIR_TARGET] : [];
51 for (const arch of commonArch(args.dir === true)) {
52 archToType.set(arch, defaultTargetValue);
53 }
54 return;
55 }
56 for (const type of types) {
57 const suffixPos = type.lastIndexOf(":");
58 if (suffixPos > 0) {
59 (0, builder_util_1.addValue)(archToType, (0, builder_util_1.archFromString)(type.substring(suffixPos + 1)), type.substring(0, suffixPos));
60 }
61 else {
62 for (const arch of commonArch(true)) {
63 (0, builder_util_1.addValue)(archToType, arch, type);
64 }
65 }
66 }
67 }
68 if (args.mac != null) {
69 processTargets(app_builder_lib_1.Platform.MAC, args.mac);
70 }
71 if (args.linux != null) {
72 processTargets(app_builder_lib_1.Platform.LINUX, args.linux);
73 }
74 if (args.win != null) {
75 processTargets(app_builder_lib_1.Platform.WINDOWS, args.win);
76 }
77 if (targets.size === 0) {
78 processTargets(app_builder_lib_1.Platform.current(), []);
79 }
80 const result = { ...args };
81 result.targets = targets;
82 delete result.dir;
83 delete result.mac;
84 delete result.linux;
85 delete result.win;
86 const r = result;
87 delete r.m;
88 delete r.o;
89 delete r.l;
90 delete r.w;
91 delete r.windows;
92 delete r.macos;
93 delete r.$0;
94 delete r._;
95 delete r.version;
96 delete r.help;
97 delete r.c;
98 delete r.p;
99 delete r.pd;
100 delete result.ia32;
101 delete result.x64;
102 delete result.armv7l;
103 delete result.arm64;
104 delete result.universal;
105 let config = result.config;
106 // config is array when combining dot-notation values with a config file value
107 // https://github.com/electron-userland/electron-builder/issues/2016
108 if (Array.isArray(config)) {
109 const newConfig = {};
110 for (const configItem of config) {
111 if (typeof configItem === "object") {
112 (0, builder_util_1.deepAssign)(newConfig, configItem);
113 }
114 else if (typeof configItem === "string") {
115 newConfig.extends = configItem;
116 }
117 }
118 config = newConfig;
119 result.config = newConfig;
120 }
121 // AJV cannot coerce "null" string to null if string is also allowed (because null string is a valid value)
122 if (config != null && typeof config !== "string") {
123 if (config.extraMetadata != null) {
124 coerceTypes(config.extraMetadata);
125 }
126 // ability to disable code sign using -c.mac.identity=null
127 if (config.mac != null) {
128 coerceValue(config.mac, "identity");
129 }
130 // fix Boolean type by coerceTypes
131 if (config.nsis != null) {
132 coerceTypes(config.nsis);
133 }
134 if (config.nsisWeb != null) {
135 coerceTypes(config.nsisWeb);
136 }
137 }
138 if ("project" in r && !("projectDir" in result)) {
139 result.projectDir = r.project;
140 }
141 delete r.project;
142 return result;
143}
144function coerceValue(host, key) {
145 const value = host[key];
146 if (value === "true") {
147 host[key] = true;
148 }
149 else if (value === "false") {
150 host[key] = false;
151 }
152 else if (value === "null") {
153 host[key] = null;
154 }
155 else if (key === "version" && typeof value === "number") {
156 host[key] = value.toString();
157 }
158 else if (value != null && typeof value === "object") {
159 coerceTypes(value);
160 }
161}
162/** @private */
163function coerceTypes(host) {
164 for (const key of Object.getOwnPropertyNames(host)) {
165 coerceValue(host, key);
166 }
167 return host;
168}
169function createTargets(platforms, type, arch) {
170 const targets = new Map();
171 for (const platform of platforms) {
172 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]) : [(0, builder_util_1.archFromString)(arch == null ? process.arch : arch)];
173 const archToType = new Map();
174 targets.set(platform, archToType);
175 for (const arch of archs) {
176 archToType.set(arch, type == null ? [] : [type]);
177 }
178 }
179 return targets;
180}
181function build(rawOptions) {
182 const buildOptions = normalizeOptions(rawOptions || {});
183 return (0, app_builder_lib_1.build)(buildOptions, new app_builder_lib_1.Packager(buildOptions));
184}
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`, or `js`, or `ts`), 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}
268//# sourceMappingURL=builder.js.map
\No newline at end of file