UNPKG

11.7 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.tmpDirCounter = exports.debug7z = exports.debug = exports.Lazy = exports.subTask = exports.task = exports.warn = exports.log = exports.TmpDir = undefined;
7
8var _tmp;
9
10function _load_tmp() {
11 return _tmp = require("./tmp");
12}
13
14Object.defineProperty(exports, "TmpDir", {
15 enumerable: true,
16 get: function () {
17 return (_tmp || _load_tmp()).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 _electronBuilderHttp;
53
54function _load_electronBuilderHttp() {
55 return _electronBuilderHttp = require("electron-builder-http");
56}
57
58Object.defineProperty(exports, "Lazy", {
59 enumerable: true,
60 get: function () {
61 return (_electronBuilderHttp || _load_electronBuilderHttp()).Lazy;
62 }
63});
64exports.removePassword = removePassword;
65exports.exec = exec;
66exports.doSpawn = doSpawn;
67exports.spawn = spawn;
68exports.handleProcess = handleProcess;
69exports.use = use;
70exports.debug7zArgs = debug7zArgs;
71exports.getTempName = getTempName;
72exports.isEmptyOrSpaces = isEmptyOrSpaces;
73exports.isTokenCharValid = isTokenCharValid;
74exports.asArray = asArray;
75exports.getCacheDirectory = getCacheDirectory;
76exports.smarten = smarten;
77exports.addValue = addValue;
78exports.replaceDefault = replaceDefault;
79exports.getPlatformIconFileName = getPlatformIconFileName;
80exports.isPullRequest = isPullRequest;
81exports.safeStringifyJson = safeStringifyJson;
82
83var _bluebirdLst;
84
85function _load_bluebirdLst() {
86 return _bluebirdLst = _interopRequireDefault(require("bluebird-lst"));
87}
88
89var _chalk;
90
91function _load_chalk() {
92 return _chalk = require("chalk");
93}
94
95var _child_process;
96
97function _load_child_process() {
98 return _child_process = require("child_process");
99}
100
101var _crypto;
102
103function _load_crypto() {
104 return _crypto = require("crypto");
105}
106
107var _debug2;
108
109function _load_debug() {
110 return _debug2 = _interopRequireDefault(require("debug"));
111}
112
113var _os;
114
115function _load_os() {
116 return _os = require("os");
117}
118
119var _path = _interopRequireWildcard(require("path"));
120
121require("source-map-support/register");
122
123function _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; } }
124
125function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
126
127function _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); } }
128
129const debug = exports.debug = (0, (_debug2 || _load_debug()).default)("electron-builder");
130const debug7z = exports.debug7z = (0, (_debug2 || _load_debug()).default)("electron-builder:7z");
131function removePassword(input) {
132 return input.replace(/(-String |-P |pass:| \/p |-pass )([^ ]+)/g, (match, p1, p2) => {
133 return `${p1}${(0, (_crypto || _load_crypto()).createHash)("sha256").update(p2).digest("hex")} (sha256 hash)`;
134 });
135}
136function exec(file, args, options) {
137 let isLogOutIfDebug = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
138
139 if (debug.enabled) {
140 debug(`Executing ${file} ${args == null ? "" : removePassword(args.join(" "))}`);
141 }
142 return new (_bluebirdLst || _load_bluebirdLst()).default((resolve, reject) => {
143 (0, (_child_process || _load_child_process()).execFile)(file, args, options, (error, stdout, stderr) => {
144 if (error == null) {
145 if (isLogOutIfDebug && debug.enabled) {
146 if (stderr.length !== 0) {
147 debug(stderr);
148 }
149 if (stdout.length !== 0) {
150 debug(stdout);
151 }
152 }
153 resolve(stdout);
154 } else {
155 let message = (0, (_chalk || _load_chalk()).red)(removePassword(`Exit code: ${error.code}. ${error.message}`));
156 if (stdout.length !== 0) {
157 message += `\n${(0, (_chalk || _load_chalk()).yellow)(stdout)}`;
158 }
159 if (stderr.length !== 0) {
160 message += `\n${(0, (_chalk || _load_chalk()).red)(stderr)}`;
161 }
162 reject(new Error(message));
163 }
164 });
165 });
166}
167function doSpawn(command, args, options, extraOptions) {
168 if (options == null) {
169 options = {};
170 }
171 const isDebugEnabled = extraOptions == null || extraOptions.isDebugEnabled == null ? debug.enabled : extraOptions.isDebugEnabled;
172 if (options.stdio == null) {
173 // do not ignore stdout/stderr if not debug, because in this case we will read into buffer and print on error
174 options.stdio = [extraOptions != null && extraOptions.isPipeInput ? "pipe" : "ignore", isDebugEnabled ? "inherit" : "pipe", isDebugEnabled ? "inherit" : "pipe"];
175 }
176 // use general debug.enabled to log spawn, because it doesn't produce a lot of output (the only line), but important in any case
177 if (debug.enabled) {
178 const argsString = args.join(" ");
179 debug(`Spawning ${command} ${command === "docker" ? argsString : removePassword(argsString)}`);
180 }
181 try {
182 return (0, (_child_process || _load_child_process()).spawn)(command, args, options);
183 } catch (e) {
184 throw new Error(`Cannot spawn ${command}: ${e.stack || e}`);
185 }
186}
187function spawn(command, args, options, extraOptions) {
188 return new (_bluebirdLst || _load_bluebirdLst()).default((resolve, reject) => {
189 handleProcess("close", doSpawn(command, args || [], options, extraOptions), command, resolve, reject);
190 });
191}
192function handleProcess(event, childProcess, command, resolve, reject) {
193 childProcess.on("error", reject);
194 let out = "";
195 if (!debug.enabled && childProcess.stdout != null) {
196 childProcess.stdout.on("data", data => {
197 out += data;
198 });
199 }
200 let errorOut = "";
201 if (childProcess.stderr != null) {
202 childProcess.stderr.on("data", data => {
203 errorOut += data;
204 });
205 }
206 childProcess.once(event, code => {
207 if (code === 0 && debug.enabled) {
208 debug(`${command} (${childProcess.pid}) exited with exit code 0`);
209 }
210 if (code === 0) {
211 if (resolve != null) {
212 resolve();
213 }
214 } else {
215 function formatOut(text, title) {
216 return text.length === 0 ? "" : `\n${title}:\n${text}`;
217 }
218 reject(new Error(`${command} exited with code ${code}${formatOut(out, "Output")}${formatOut(errorOut, "Error output")}`));
219 }
220 });
221}
222function use(value, task) {
223 return value == null ? null : task(value);
224}
225function debug7zArgs(command) {
226 const args = [command, "-bd"];
227 if (debug7z.enabled) {
228 args.push("-bb3");
229 } else if (!debug.enabled) {
230 args.push("-bb0");
231 }
232 return args;
233}
234let tmpDirCounter = exports.tmpDirCounter = 0;
235// add date to avoid use stale temp dir
236const tempDirPrefix = `${process.pid.toString(16)}-${Date.now().toString(16)}`;
237function getTempName(prefix) {
238 return `${prefix == null ? "" : `${prefix}-`}${tempDirPrefix}-${(exports.tmpDirCounter = tmpDirCounter += 1, tmpDirCounter - 1).toString(16)}`;
239}
240function isEmptyOrSpaces(s) {
241 return s == null || s.trim().length === 0;
242}
243function isTokenCharValid(token) {
244 return (/^[\w\/=+-]+$/.test(token)
245 );
246}
247function asArray(v) {
248 if (v == null) {
249 return [];
250 } else if (Array.isArray(v)) {
251 return v;
252 } else {
253 return [v];
254 }
255}
256function getCacheDirectory() {
257 const env = process.env.ELECTRON_BUILDER_CACHE;
258 if (!isEmptyOrSpaces(env)) {
259 return env;
260 }
261 if (process.platform === "darwin") {
262 return _path.join((0, (_os || _load_os()).homedir)(), "Library", "Caches", "electron-builder");
263 }
264 const localappdata = process.env.LOCALAPPDATA;
265 if (process.platform === "win32" && localappdata != null) {
266 // https://github.com/electron-userland/electron-builder/issues/1164
267 if (localappdata.toLowerCase().indexOf("\\windows\\system32\\") !== -1 || (process.env.USERNAME || "").toLowerCase() === "system") {
268 return _path.join((0, (_os || _load_os()).tmpdir)(), "electron-builder-cache");
269 }
270 return _path.join(localappdata, "electron-builder", "cache");
271 }
272 return _path.join((0, (_os || _load_os()).homedir)(), ".cache", "electron-builder");
273}
274// fpm bug - rpm build --description is not escaped, well... decided to replace quite to smart quote
275// http://leancrew.com/all-this/2010/11/smart-quotes-in-javascript/
276function smarten(s) {
277 // opening singles
278 s = s.replace(/(^|[-\u2014\s(\["])'/g, "$1\u2018");
279 // closing singles & apostrophes
280 s = s.replace(/'/g, "\u2019");
281 // opening doubles
282 s = s.replace(/(^|[-\u2014/\[(\u2018\s])"/g, "$1\u201c");
283 // closing doubles
284 s = s.replace(/"/g, "\u201d");
285 return s;
286}
287function addValue(map, key, value) {
288 const list = map.get(key);
289 if (list == null) {
290 map.set(key, [value]);
291 } else if (!(list.indexOf(value) !== -1)) {
292 list.push(value);
293 }
294}
295function replaceDefault(inList, defaultList) {
296 if (inList == null) {
297 return defaultList;
298 }
299 const index = inList.indexOf("default");
300 if (index >= 0) {
301 const list = inList.slice(0, index);
302 list.push.apply(list, _toConsumableArray(defaultList));
303 if (index !== inList.length - 1) {
304 list.push.apply(list, _toConsumableArray(inList.slice(index + 1)));
305 }
306 inList = list;
307 }
308 return inList;
309}
310function getPlatformIconFileName(value, isMac) {
311 if (value === undefined) {
312 return undefined;
313 }
314 if (value === null) {
315 return null;
316 }
317 if (!(value.indexOf(".") !== -1)) {
318 return `${value}.${isMac ? "icns" : "ico"}`;
319 }
320 return value.replace(isMac ? ".ico" : ".icns", isMac ? ".icns" : ".ico");
321}
322function isPullRequest() {
323 // 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.
324 function isSet(value) {
325 // value can be or null, or empty string
326 return value && value !== "false";
327 }
328 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);
329}
330function safeStringifyJson(data, skippedNames) {
331 return JSON.stringify(data, (name, value) => {
332 if (name.endsWith("Password") || name.endsWith("Token") || name.indexOf("password") !== -1 || name.indexOf("token") !== -1 || skippedNames != null && skippedNames.has(name)) {
333 return "<stripped sensitive data>";
334 }
335 return value;
336 }, 2);
337}
338//# sourceMappingURL=util.js.map
\No newline at end of file