UNPKG

2.73 kBJavaScriptView Raw
1"use strict";
2const child_process_1 = require("child_process");
3const bluebird_1 = require("bluebird");
4require("source-map-support/register");
5exports.log = console.log;
6bluebird_1.Promise.config({
7 longStackTraces: true,
8 cancellation: true
9});
10exports.DEFAULT_APP_DIR_NAME = "app";
11exports.commonArgs = [{
12 name: "appDir",
13 type: String,
14 description: "Relative (to the working directory) path to the folder containing the application package.json. Working directory or app/ by default."
15 }];
16const execFileAsync = bluebird_1.Promise.promisify(child_process_1.execFile, { multiArgs: true });
17function installDependencies(appDir, arch, electronVersion) {
18 exports.log("Installing app dependencies for arch %s to %s", arch || process.arch, appDir);
19 const env = Object.assign({}, process.env, {
20 npm_config_disturl: "https://atom.io/download/atom-shell",
21 npm_config_target: electronVersion,
22 npm_config_runtime: "electron",
23 HOME: require("os").homedir() + "/.electron-gyp",
24 });
25 if (arch != null) {
26 env.npm_config_arch = arch;
27 }
28 let npmExecPath = process.env.npm_execpath || process.env.NPM_CLI_JS;
29 const npmExecArgs = ["install"];
30 if (npmExecPath == null) {
31 npmExecPath = "npm";
32 }
33 else {
34 npmExecArgs.unshift(npmExecPath);
35 npmExecPath = process.env.npm_node_execpath || process.env.NODE_EXE || "node";
36 }
37 return spawn(npmExecPath, npmExecArgs, {
38 cwd: appDir,
39 stdio: "inherit",
40 env: env
41 });
42}
43exports.installDependencies = installDependencies;
44function exec(file, args, options) {
45 return execFileAsync(file, args, options);
46}
47exports.exec = exec;
48function spawn(command, args, options) {
49 return new bluebird_1.Promise((resolve, reject) => {
50 const p = child_process_1.spawn(command, args, options);
51 p.on("close", (code) => code === 0 ? resolve() : reject(new Error(command + " exited with code " + code)));
52 });
53}
54exports.spawn = spawn;
55function getElectronVersion(packageData, filePath) {
56 const devDependencies = packageData.devDependencies;
57 let electronPrebuiltDep = devDependencies == null ? null : devDependencies["electron-prebuilt"];
58 if (electronPrebuiltDep == null) {
59 const dependencies = packageData.dependencies;
60 electronPrebuiltDep = dependencies == null ? null : dependencies["electron-prebuilt"];
61 }
62 if (electronPrebuiltDep == null) {
63 throw new Error("Cannot find electron-prebuilt dependency to get electron version in the '" + filePath + "'");
64 }
65 return electronPrebuiltDep.substring(1);
66}
67exports.getElectronVersion = getElectronVersion;
68//# sourceMappingURL=util.js.map
\No newline at end of file