1 | #! /usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.configurePublishCommand = configurePublishCommand;
|
5 | exports.publish = publish;
|
6 | exports.publishArtifactsWithOptions = publishArtifactsWithOptions;
|
7 | const app_builder_lib_1 = require("app-builder-lib");
|
8 | const platformPackager_1 = require("app-builder-lib/out/platformPackager");
|
9 | const config_1 = require("app-builder-lib/out/util/config/config");
|
10 | const builder_util_1 = require("builder-util");
|
11 | const builder_util_2 = require("builder-util");
|
12 | const chalk = require("chalk");
|
13 | const path = require("path");
|
14 | const yargs = require("yargs");
|
15 | const builder_1 = require("./builder");
|
16 |
|
17 | function configurePublishCommand(yargs) {
|
18 |
|
19 |
|
20 | return yargs
|
21 | .parserConfiguration({
|
22 | "camel-case-expansion": false,
|
23 | })
|
24 | .option("files", {
|
25 | alias: "f",
|
26 | string: true,
|
27 | type: "array",
|
28 | requiresArg: true,
|
29 | description: "The file(s) to upload to your publisher",
|
30 | })
|
31 | .option("version", {
|
32 | alias: ["v"],
|
33 | type: "string",
|
34 | description: "The app/build version used when searching for an upload release (used by some Publishers)",
|
35 | })
|
36 | .option("config", {
|
37 | alias: ["c"],
|
38 | type: "string",
|
39 | description: "The path to an electron-builder config. Defaults to `electron-builder.yml` (or `json`, or `json5`, or `js`, or `ts`), see " + chalk.underline("https://goo.gl/YFRJOM"),
|
40 | })
|
41 | .demandOption("files");
|
42 | }
|
43 | async function publish(args) {
|
44 | const uploadTasks = args.files.map(f => {
|
45 | return {
|
46 | file: path.resolve(f),
|
47 | arch: null,
|
48 | };
|
49 | });
|
50 | return publishArtifactsWithOptions(uploadTasks, args.version, args.config);
|
51 | }
|
52 | async function publishArtifactsWithOptions(uploadOptions, buildVersion, configurationFilePath, publishConfiguration) {
|
53 | const projectDir = process.cwd();
|
54 | const config = await (0, config_1.getConfig)(projectDir, configurationFilePath || null, { publish: publishConfiguration, detectUpdateChannel: false });
|
55 | const buildOptions = (0, builder_1.normalizeOptions)({ config });
|
56 | (0, app_builder_lib_1.checkBuildRequestOptions)(buildOptions);
|
57 | const uniqueUploads = Array.from(new Set(uploadOptions));
|
58 | const tasks = uniqueUploads.map(({ file, arch }) => {
|
59 | const filename = path.basename(file);
|
60 | return { file, arch: arch ? (0, builder_util_1.archFromString)(arch) : null, safeArtifactName: (0, platformPackager_1.computeSafeArtifactNameIfNeeded)(filename, () => filename) };
|
61 | });
|
62 | return publishPackageWithTasks(buildOptions, tasks, buildVersion);
|
63 | }
|
64 | async function publishPackageWithTasks(options, uploadTasks, buildVersion, cancellationToken = new app_builder_lib_1.CancellationToken(), packager = new app_builder_lib_1.Packager(options, cancellationToken)) {
|
65 | await packager.validateConfig();
|
66 | const appInfo = new app_builder_lib_1.AppInfo(packager, buildVersion);
|
67 | const publishManager = new app_builder_lib_1.PublishManager(packager, options, cancellationToken);
|
68 | const sigIntHandler = () => {
|
69 | builder_util_1.log.warn("cancelled by SIGINT");
|
70 | packager.cancellationToken.cancel();
|
71 | publishManager.cancelTasks();
|
72 | };
|
73 | process.once("SIGINT", sigIntHandler);
|
74 | try {
|
75 | const publishConfigurations = await publishManager.getGlobalPublishConfigurations();
|
76 | if (publishConfigurations == null || publishConfigurations.length === 0) {
|
77 | throw new builder_util_1.InvalidConfigurationError("unable to find any publish configuration");
|
78 | }
|
79 | for (const newArtifact of uploadTasks) {
|
80 | for (const publishConfiguration of publishConfigurations) {
|
81 | publishManager.scheduleUpload(publishConfiguration, newArtifact, appInfo);
|
82 | }
|
83 | }
|
84 | await publishManager.awaitTasks();
|
85 | return uploadTasks;
|
86 | }
|
87 | catch (error) {
|
88 | packager.cancellationToken.cancel();
|
89 | publishManager.cancelTasks();
|
90 | process.removeListener("SIGINT", sigIntHandler);
|
91 | builder_util_1.log.error({ message: (error.stack || error.message || error).toString() }, "error publishing");
|
92 | }
|
93 | return null;
|
94 | }
|
95 | function main() {
|
96 | return publish(configurePublishCommand(yargs).argv);
|
97 | }
|
98 | if (require.main === module) {
|
99 | builder_util_1.log.warn("please use as subcommand: electron-builder publish");
|
100 | main().catch(builder_util_2.printErrorAndExit);
|
101 | }
|
102 |
|
\ | No newline at end of file |