1 | #! /usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | const builder_util_1 = require("builder-util");
|
5 | const chalk = require("chalk");
|
6 | const electronVersion_1 = require("app-builder-lib/out/electron/electronVersion");
|
7 | const fs_extra_1 = require("fs-extra");
|
8 | const isCi = require("is-ci");
|
9 | const path = require("path");
|
10 | const read_config_file_1 = require("read-config-file");
|
11 | const updateNotifier = require("update-notifier");
|
12 | const util_1 = require("builder-util/out/util");
|
13 | const builder_1 = require("../builder");
|
14 | const create_self_signed_cert_1 = require("./create-self-signed-cert");
|
15 | const install_app_deps_1 = require("./install-app-deps");
|
16 | const start_1 = require("./start");
|
17 | const yarn_1 = require("app-builder-lib/out/util/yarn");
|
18 |
|
19 | void 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 , 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;
|
36 | function 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 |
|
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 | }
|
54 | function 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 | }
|
73 | async function rebuildAppNativeCode(args) {
|
74 | const projectDir = process.cwd();
|
75 |
|
76 | return yarn_1.nodeGypRebuild(args.platform, args.arch, { version: await electronVersion_1.getElectronVersion(projectDir), useCustomDist: true });
|
77 | }
|
78 |
|
\ | No newline at end of file |