UNPKG

3.9 kBJavaScriptView Raw
1#! /usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4const builder_util_1 = require("builder-util");
5const chalk = require("chalk");
6const electronVersion_1 = require("app-builder-lib/out/electron/electronVersion");
7const fs_extra_1 = require("fs-extra");
8const isCi = require("is-ci");
9const path = require("path");
10const read_config_file_1 = require("read-config-file");
11const updateNotifier = require("update-notifier");
12const util_1 = require("builder-util/out/util");
13const builder_1 = require("../builder");
14const create_self_signed_cert_1 = require("./create-self-signed-cert");
15const install_app_deps_1 = require("./install-app-deps");
16const start_1 = require("./start");
17const yarn_1 = require("app-builder-lib/out/util/yarn");
18// tslint:disable:no-unused-expression
19void builder_1.createYargs()
20 .command(["build", "*"], "Build", builder_1.configureBuildCommand, wrap(builder_1.build))
21 .command("install-app-deps", "Install app deps", install_app_deps_1.configureInstallAppDepsCommand, wrap(install_app_deps_1.installAppDeps))
22 .command("node-gyp-rebuild", "Rebuild own native code", install_app_deps_1.configureInstallAppDepsCommand /* yes, args the same as for install app deps */, wrap(rebuildAppNativeCode))
23 .command("create-self-signed-cert", "Create self-signed code signing cert for Windows apps", yargs => yargs
24 .option("publisher", {
25 alias: ["p"],
26 type: "string",
27 requiresArg: true,
28 description: "The publisher name",
29})
30 .demandOption("publisher"), wrap(argv => create_self_signed_cert_1.createSelfSignedCert(argv.publisher)))
31 .command("start", "Run application in a development mode using electron-webpack", yargs => yargs, wrap(() => start_1.start()))
32 .help()
33 .epilog(`See ${chalk.underline("https://electron.build")} for more documentation.`)
34 .strict()
35 .recommendCommands().argv;
36function wrap(task) {
37 return (args) => {
38 checkIsOutdated();
39 read_config_file_1.loadEnv(path.join(process.cwd(), "electron-builder.env"))
40 .then(() => task(args))
41 .catch(error => {
42 process.exitCode = 1;
43 // https://github.com/electron-userland/electron-builder/issues/2940
44 process.on("exit", () => (process.exitCode = 1));
45 if (error instanceof builder_util_1.InvalidConfigurationError) {
46 builder_util_1.log.error(null, error.message);
47 }
48 else if (!(error instanceof util_1.ExecError) || !error.alreadyLogged) {
49 builder_util_1.log.error({ failedTask: task.name, stackTrace: error.stack }, error.message);
50 }
51 });
52 };
53}
54function checkIsOutdated() {
55 if (isCi || process.env.NO_UPDATE_NOTIFIER != null) {
56 return;
57 }
58 fs_extra_1.readJson(path.join(__dirname, "..", "..", "package.json"))
59 .then(async (it) => {
60 if (it.version === "0.0.0-semantic-release") {
61 return;
62 }
63 const packageManager = (await fs_extra_1.pathExists(path.join(__dirname, "..", "..", "package-lock.json"))) ? "npm" : "yarn";
64 const notifier = updateNotifier({ pkg: it });
65 if (notifier.update != null) {
66 notifier.notify({
67 message: `Update available ${chalk.dim(notifier.update.current)}${chalk.reset(" → ")}${chalk.green(notifier.update.latest)} \nRun ${chalk.cyan(`${packageManager} upgrade electron-builder`)} to update`,
68 });
69 }
70 })
71 .catch(e => builder_util_1.log.warn({ error: e }, "cannot check updates"));
72}
73async function rebuildAppNativeCode(args) {
74 const projectDir = process.cwd();
75 // this script must be used only for electron
76 return yarn_1.nodeGypRebuild(args.platform, args.arch, { version: await electronVersion_1.getElectronVersion(projectDir), useCustomDist: true });
77}
78//# sourceMappingURL=cli.js.map
\No newline at end of file