UNPKG

14.3 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.debug7z = exports.debug = exports.archFromString = exports.getArchSuffix = exports.toLinuxArchString = exports.Arch = exports.prepareWindowsExecutableArgs = exports.execWine = exports.isMacOsSierra = exports.subTask = exports.task = exports.warn = exports.log = exports.TmpDir = undefined;
7
8var _tempFile;
9
10function _load_tempFile() {
11 return _tempFile = require("temp-file");
12}
13
14Object.defineProperty(exports, "TmpDir", {
15 enumerable: true,
16 get: function () {
17 return (_tempFile || _load_tempFile()).TmpDir;
18 }
19});
20
21var _log;
22
23function _load_log() {
24 return _log = require("./log");
25}
26
27Object.defineProperty(exports, "log", {
28 enumerable: true,
29 get: function () {
30 return (_log || _load_log()).log;
31 }
32});
33Object.defineProperty(exports, "warn", {
34 enumerable: true,
35 get: function () {
36 return (_log || _load_log()).warn;
37 }
38});
39Object.defineProperty(exports, "task", {
40 enumerable: true,
41 get: function () {
42 return (_log || _load_log()).task;
43 }
44});
45Object.defineProperty(exports, "subTask", {
46 enumerable: true,
47 get: function () {
48 return (_log || _load_log()).subTask;
49 }
50});
51
52var _macosVersion;
53
54function _load_macosVersion() {
55 return _macosVersion = require("./macosVersion");
56}
57
58Object.defineProperty(exports, "isMacOsSierra", {
59 enumerable: true,
60 get: function () {
61 return (_macosVersion || _load_macosVersion()).isMacOsSierra;
62 }
63});
64
65var _wine;
66
67function _load_wine() {
68 return _wine = require("./wine");
69}
70
71Object.defineProperty(exports, "execWine", {
72 enumerable: true,
73 get: function () {
74 return (_wine || _load_wine()).execWine;
75 }
76});
77Object.defineProperty(exports, "prepareWindowsExecutableArgs", {
78 enumerable: true,
79 get: function () {
80 return (_wine || _load_wine()).prepareWindowsExecutableArgs;
81 }
82});
83
84var _arch;
85
86function _load_arch() {
87 return _arch = require("./arch");
88}
89
90Object.defineProperty(exports, "Arch", {
91 enumerable: true,
92 get: function () {
93 return (_arch || _load_arch()).Arch;
94 }
95});
96Object.defineProperty(exports, "toLinuxArchString", {
97 enumerable: true,
98 get: function () {
99 return (_arch || _load_arch()).toLinuxArchString;
100 }
101});
102Object.defineProperty(exports, "getArchSuffix", {
103 enumerable: true,
104 get: function () {
105 return (_arch || _load_arch()).getArchSuffix;
106 }
107});
108Object.defineProperty(exports, "archFromString", {
109 enumerable: true,
110 get: function () {
111 return (_arch || _load_arch()).archFromString;
112 }
113});
114exports.removePassword = removePassword;
115exports.exec = exec;
116exports.doSpawn = doSpawn;
117exports.spawnAndWrite = spawnAndWrite;
118exports.spawn = spawn;
119exports.handleProcess = handleProcess;
120exports.use = use;
121exports.debug7zArgs = debug7zArgs;
122exports.isEmptyOrSpaces = isEmptyOrSpaces;
123exports.isTokenCharValid = isTokenCharValid;
124exports.asArray = asArray;
125exports.getCacheDirectory = getCacheDirectory;
126exports.smarten = smarten;
127exports.addValue = addValue;
128exports.replaceDefault = replaceDefault;
129exports.getPlatformIconFileName = getPlatformIconFileName;
130exports.isPullRequest = isPullRequest;
131exports.safeStringifyJson = safeStringifyJson;
132exports.isEnvTrue = isEnvTrue;
133
134var _bluebirdLst;
135
136function _load_bluebirdLst() {
137 return _bluebirdLst = _interopRequireDefault(require("bluebird-lst"));
138}
139
140var _chalk;
141
142function _load_chalk() {
143 return _chalk = require("chalk");
144}
145
146var _child_process;
147
148function _load_child_process() {
149 return _child_process = require("child_process");
150}
151
152var _crypto;
153
154function _load_crypto() {
155 return _crypto = require("crypto");
156}
157
158var _debug2;
159
160function _load_debug() {
161 return _debug2 = _interopRequireDefault(require("debug"));
162}
163
164var _os;
165
166function _load_os() {
167 return _os = require("os");
168}
169
170var _path = _interopRequireWildcard(require("path"));
171
172require("source-map-support/register");
173
174function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
175
176function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
177
178function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
179
180const debug = exports.debug = (0, (_debug2 || _load_debug()).default)("electron-builder");
181const debug7z = exports.debug7z = (0, (_debug2 || _load_debug()).default)("electron-builder:7z");
182function removePassword(input) {
183 return input.replace(/(-String |-P |pass:| \/p |-pass )([^ ]+)/g, (match, p1, p2) => {
184 return `${p1}${(0, (_crypto || _load_crypto()).createHash)("sha256").update(p2).digest("hex")} (sha256 hash)`;
185 });
186}
187function exec(file, args, options) {
188 let isLogOutIfDebug = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
189
190 if (debug.enabled) {
191 debug(`Executing ${file} ${args == null ? "" : removePassword(args.join(" "))}`);
192 if (options != null && options.env != null) {
193 const diffEnv = Object.assign({}, options.env);
194 for (const name of Object.keys(process.env)) {
195 if (process.env[name] === options.env[name]) {
196 delete diffEnv[name];
197 }
198 }
199 debug(`env: ${safeStringifyJson(diffEnv)}`);
200 }
201 if (options != null && options.cwd != null) {
202 debug(`cwd: ${options.cwd}`);
203 }
204 }
205 return new (_bluebirdLst || _load_bluebirdLst()).default((resolve, reject) => {
206 (0, (_child_process || _load_child_process()).execFile)(file, args, options, (error, stdout, stderr) => {
207 if (error == null) {
208 if (isLogOutIfDebug && debug.enabled) {
209 if (stderr.length !== 0) {
210 debug(stderr);
211 }
212 if (stdout.length !== 0) {
213 debug(stdout);
214 }
215 }
216 resolve(stdout.toString());
217 } else {
218 let message = (0, (_chalk || _load_chalk()).red)(removePassword(`Exit code: ${error.code}. ${error.message}`));
219 if (stdout.length !== 0) {
220 message += `\n${(0, (_chalk || _load_chalk()).yellow)(stdout.toString())}`;
221 }
222 if (stderr.length !== 0) {
223 message += `\n${(0, (_chalk || _load_chalk()).red)(stderr.toString())}`;
224 }
225 reject(new Error(message));
226 }
227 });
228 });
229}
230function doSpawn(command, args, options, extraOptions) {
231 if (options == null) {
232 options = {};
233 }
234 const isDebugEnabled = extraOptions == null || extraOptions.isDebugEnabled == null ? debug.enabled : extraOptions.isDebugEnabled;
235 if (options.stdio == null) {
236 // do not ignore stdout/stderr if not debug, because in this case we will read into buffer and print on error
237 options.stdio = [extraOptions != null && extraOptions.isPipeInput ? "pipe" : "ignore", isDebugEnabled ? "inherit" : "pipe", isDebugEnabled ? "inherit" : "pipe"];
238 }
239 // use general debug.enabled to log spawn, because it doesn't produce a lot of output (the only line), but important in any case
240 if (debug.enabled) {
241 const argsString = args.join(" ");
242 debug(`Spawning ${command} ${command === "docker" ? argsString : removePassword(argsString)}`);
243 if (options != null && options.cwd != null) {
244 debug(`cwd: ${options.cwd}`);
245 }
246 }
247 try {
248 return (0, (_child_process || _load_child_process()).spawn)(command, args, options);
249 } catch (e) {
250 throw new Error(`Cannot spawn ${command}: ${e.stack || e}`);
251 }
252}
253function spawnAndWrite(command, args, data, options) {
254 let isDebugEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
255
256 const childProcess = doSpawn(command, args, options, { isPipeInput: true, isDebugEnabled });
257 const timeout = setTimeout(() => childProcess.kill(), 4 * 60 * 1000);
258 return new (_bluebirdLst || _load_bluebirdLst()).default((resolve, reject) => {
259 handleProcess("close", childProcess, command, () => {
260 try {
261 clearTimeout(timeout);
262 } finally {
263 resolve();
264 }
265 }, error => {
266 try {
267 clearTimeout(timeout);
268 } finally {
269 reject(error.stack || error.toString());
270 }
271 });
272 childProcess.stdin.end(data);
273 });
274}
275function spawn(command, args, options, extraOptions) {
276 return new (_bluebirdLst || _load_bluebirdLst()).default((resolve, reject) => {
277 handleProcess("close", doSpawn(command, args || [], options, extraOptions), command, resolve, reject);
278 });
279}
280function handleProcess(event, childProcess, command, resolve, reject) {
281 childProcess.on("error", reject);
282 let out = "";
283 if (!debug.enabled && childProcess.stdout != null) {
284 childProcess.stdout.on("data", data => {
285 out += data;
286 });
287 }
288 let errorOut = "";
289 if (childProcess.stderr != null) {
290 childProcess.stderr.on("data", data => {
291 errorOut += data;
292 });
293 }
294 childProcess.once(event, code => {
295 if (code === 0 && debug.enabled) {
296 debug(`${command} (${childProcess.pid}) exited with exit code 0`);
297 }
298 if (code === 0) {
299 if (resolve != null) {
300 resolve();
301 }
302 } else {
303 function formatOut(text, title) {
304 return text.length === 0 ? "" : `\n${title}:\n${text}`;
305 }
306 reject(new Error(`${command} exited with code ${code}${formatOut(out, "Output")}${formatOut(errorOut, "Error output")}`));
307 }
308 });
309}
310function use(value, task) {
311 return value == null ? null : task(value);
312}
313function debug7zArgs(command) {
314 const args = [command, "-bd"];
315 if (debug7z.enabled) {
316 args.push("-bb3");
317 } else if (!debug.enabled) {
318 args.push("-bb0");
319 }
320 return args;
321}
322function isEmptyOrSpaces(s) {
323 return s == null || s.trim().length === 0;
324}
325function isTokenCharValid(token) {
326 return (/^[\w\/=+-]+$/.test(token)
327 );
328}
329function asArray(v) {
330 if (v == null) {
331 return [];
332 } else if (Array.isArray(v)) {
333 return v;
334 } else {
335 return [v];
336 }
337}
338function getCacheDirectory() {
339 const env = process.env.ELECTRON_BUILDER_CACHE;
340 if (!isEmptyOrSpaces(env)) {
341 return env;
342 }
343 if (process.platform === "darwin") {
344 return _path.join((0, (_os || _load_os()).homedir)(), "Library", "Caches", "electron-builder");
345 }
346 const localappdata = process.env.LOCALAPPDATA;
347 if (process.platform === "win32" && localappdata != null) {
348 // https://github.com/electron-userland/electron-builder/issues/1164
349 if (localappdata.toLowerCase().indexOf("\\windows\\system32\\") !== -1 || (process.env.USERNAME || "").toLowerCase() === "system") {
350 return _path.join((0, (_os || _load_os()).tmpdir)(), "electron-builder-cache");
351 }
352 return _path.join(localappdata, "electron-builder", "cache");
353 }
354 return _path.join((0, (_os || _load_os()).homedir)(), ".cache", "electron-builder");
355}
356// fpm bug - rpm build --description is not escaped, well... decided to replace quite to smart quote
357// http://leancrew.com/all-this/2010/11/smart-quotes-in-javascript/
358function smarten(s) {
359 // opening singles
360 s = s.replace(/(^|[-\u2014\s(\["])'/g, "$1\u2018");
361 // closing singles & apostrophes
362 s = s.replace(/'/g, "\u2019");
363 // opening doubles
364 s = s.replace(/(^|[-\u2014/\[(\u2018\s])"/g, "$1\u201c");
365 // closing doubles
366 s = s.replace(/"/g, "\u201d");
367 return s;
368}
369function addValue(map, key, value) {
370 const list = map.get(key);
371 if (list == null) {
372 map.set(key, [value]);
373 } else if (!(list.indexOf(value) !== -1)) {
374 list.push(value);
375 }
376}
377function replaceDefault(inList, defaultList) {
378 if (inList == null) {
379 return defaultList;
380 }
381 const index = inList.indexOf("default");
382 if (index >= 0) {
383 const list = inList.slice(0, index);
384 list.push.apply(list, _toConsumableArray(defaultList));
385 if (index !== inList.length - 1) {
386 list.push.apply(list, _toConsumableArray(inList.slice(index + 1)));
387 }
388 inList = list;
389 }
390 return inList;
391}
392function getPlatformIconFileName(value, isMac) {
393 if (value === undefined) {
394 return undefined;
395 }
396 if (value === null) {
397 return null;
398 }
399 if (!(value.indexOf(".") !== -1)) {
400 return `${value}.${isMac ? "icns" : "ico"}`;
401 }
402 return value.replace(isMac ? ".ico" : ".icns", isMac ? ".icns" : ".ico");
403}
404function isPullRequest() {
405 // TRAVIS_PULL_REQUEST is set to the pull request number if the current job is a pull request build, or false if it’s not.
406 function isSet(value) {
407 // value can be or null, or empty string
408 return value && value !== "false";
409 }
410 return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUESTS) || isSet(process.env.BITRISE_PULL_REQUEST) || isSet(process.env.APPVEYOR_PULL_REQUEST_NUMBER);
411}
412function safeStringifyJson(data, skippedNames) {
413 return JSON.stringify(data, (name, value) => {
414 if (name.endsWith("Password") || name.endsWith("PASSWORD") || name.endsWith("Token") || name.indexOf("password") !== -1 || name.indexOf("token") !== -1 || skippedNames != null && skippedNames.has(name)) {
415 return "<stripped sensitive data>";
416 }
417 return value;
418 }, 2);
419}
420function isEnvTrue(value) {
421 if (value != null) {
422 value = value.trim();
423 }
424 return value === "true" || value === "" || value === "1";
425}
426//# sourceMappingURL=util.js.map
\No newline at end of file