Skip to content

Commit d031eea

Browse files
authored
fix: support option to override publish trigger (--policy) in publish command (#9228)
1 parent e9251f4 commit d031eea

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

.changeset/long-wasps-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"electron-builder": patch
3+
---
4+
5+
fix: support option to override `PublishPolicy` in publish command

packages/electron-builder/src/publish.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Publish } from "app-builder-lib/out/core"
55
import { computeSafeArtifactNameIfNeeded } from "app-builder-lib/out/platformPackager"
66
import { getConfig } from "app-builder-lib/out/util/config/config"
77
import { InvalidConfigurationError, archFromString, log, printErrorAndExit } from "builder-util"
8+
import { PublishPolicy } from "electron-publish"
89
import * as chalk from "chalk"
910
import * as path from "path"
1011
import * as yargs from "yargs"
@@ -37,29 +38,36 @@ export function configurePublishCommand(yargs: yargs.Argv): yargs.Argv {
3738
description:
3839
"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"),
3940
})
41+
.option("policy", {
42+
alias: ["p"],
43+
type: "string",
44+
description: `Publish trigger policy, see ${chalk.underline("https://www.electron.build/publish")}`,
45+
choices: ["onTag", "onTagOrDraft", "always", "never", undefined as any],
46+
})
4047
.demandOption("files")
4148
}
4249

43-
export async function publish(args: { files: string[]; version: string | undefined; configurationFilePath: string | undefined }) {
50+
export async function publish(args: { files: string[]; version: string | undefined; configurationFilePath: string | undefined; policy: PublishPolicy }) {
4451
const uploadTasks = args.files.map(f => {
4552
return {
4653
file: path.resolve(f),
4754
arch: null,
4855
}
4956
})
50-
return publishArtifactsWithOptions(uploadTasks, args.version, args.configurationFilePath)
57+
return publishArtifactsWithOptions(uploadTasks, args.version, args.configurationFilePath, undefined, { publish: args.policy })
5158
}
5259

5360
export async function publishArtifactsWithOptions(
5461
uploadOptions: { file: string; arch: string | null }[],
5562
buildVersion?: string,
5663
configurationFilePath?: string,
57-
publishConfiguration?: Publish
64+
publishConfiguration?: Publish,
65+
publishOptions?: PublishOptions
5866
) {
5967
const projectDir = process.cwd()
6068
const config = await getConfig(projectDir, configurationFilePath || null, { publish: publishConfiguration, detectUpdateChannel: false })
6169

62-
const buildOptions: BuildOptions = normalizeOptions({ config })
70+
const buildOptions: BuildOptions = normalizeOptions({ config, publish: publishOptions?.publish })
6371
checkBuildRequestOptions(buildOptions)
6472

6573
const uniqueUploads = Array.from(new Set(uploadOptions))

0 commit comments

Comments
 (0)