Skip to content

Commit d9ecfe5

Browse files
committed
feat: check that electron-builder version is not outdated for all subcommands
1 parent 2f3d7d8 commit d9ecfe5

File tree

4 files changed

+77
-57
lines changed

4 files changed

+77
-57
lines changed

packages/electron-builder/src/builder.ts

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import BluebirdPromise from "bluebird-lst"
2-
import { cyan, dim, green, reset, underline } from "chalk"
2+
import { underline } from "chalk"
33
import { Arch, archFromString, DIR_TARGET, Platform } from "electron-builder-core"
44
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
55
import { addValue, isEmptyOrSpaces } from "electron-builder-util"
66
import { warn } from "electron-builder-util/out/log"
7-
import { executeFinally, printErrorAndExit } from "electron-builder-util/out/promise"
7+
import { executeFinally } from "electron-builder-util/out/promise"
88
import { PublishOptions } from "electron-publish"
9-
import { readJson } from "fs-extra-p"
10-
import isCi from "is-ci"
11-
import * as path from "path"
12-
import updateNotifier from "update-notifier"
139
import { normalizePlatforms, Packager } from "./packager"
1410
import { PackagerOptions } from "./packagerApi"
1511
import { PublishManager } from "./publish/PublishManager"
@@ -229,116 +225,93 @@ export function configureBuildCommand(yargs: yargs.Yargs): yargs.Yargs {
229225
.option("mac", {
230226
group: buildGroup,
231227
alias: ["m", "o", "macos"],
232-
describe: `Build for macOS, accepts target list (see ${underline("https://goo.gl/HAnnq8")}).`,
228+
description: `Build for macOS, accepts target list (see ${underline("https://goo.gl/HAnnq8")}).`,
233229
type: "array",
234230
})
235231
.option("linux", {
236232
group: buildGroup,
237233
alias: "l",
238-
describe: `Build for Linux, accepts target list (see ${underline("https://goo.gl/O80IL2")})`,
234+
description: `Build for Linux, accepts target list (see ${underline("https://goo.gl/O80IL2")})`,
239235
type: "array",
240236
})
241237
.option("win", {
242238
group: buildGroup,
243239
alias: ["w", "windows"],
244-
describe: `Build for Windows, accepts target list (see ${underline("https://goo.gl/dL4i8i")})`,
240+
description: `Build for Windows, accepts target list (see ${underline("https://goo.gl/dL4i8i")})`,
245241
type: "array",
246242
})
247243
.option("x64", {
248244
group: buildGroup,
249-
describe: "Build for x64",
245+
description: "Build for x64",
250246
type: "boolean",
251247
})
252248
.option("ia32", {
253249
group: buildGroup,
254-
describe: "Build for ia32",
250+
description: "Build for ia32",
255251
type: "boolean",
256252
})
257253
.option("armv7l", {
258254
group: buildGroup,
259-
describe: "Build for armv7l",
255+
description: "Build for armv7l",
260256
type: "boolean",
261257
})
262258
.option("dir", {
263259
group: buildGroup,
264-
describe: "Build unpacked dir. Useful to test.",
260+
description: "Build unpacked dir. Useful to test.",
265261
type: "boolean",
266262
})
267263
.option("publish", {
268264
group: publishGroup,
269265
alias: "p",
270-
describe: `Publish artifacts (to GitHub Releases), see ${underline("https://goo.gl/WMlr4n")}`,
266+
description: `Publish artifacts (to GitHub Releases), see ${underline("https://goo.gl/WMlr4n")}`,
271267
choices: ["onTag", "onTagOrDraft", "always", "never", <any>undefined],
272268
})
273269
.option("draft", {
274270
group: publishGroup,
275-
describe: "Create a draft (unpublished) release",
271+
description: "Create a draft (unpublished) release",
276272
type: "boolean",
277273
default: undefined,
278274
})
279275
.option("prerelease", {
280276
group: publishGroup,
281-
describe: "Identify the release as a prerelease",
277+
description: "Identify the release as a prerelease",
282278
type: "boolean",
283279
default: undefined,
284280
})
285281
.option("platform", {
286282
group: deprecated,
287-
describe: "The target platform (preferred to use --mac, --win or --linux)",
283+
description: "The target platform (preferred to use --mac, --win or --linux)",
288284
choices: ["mac", "win", "linux", "darwin", "win32", "all", <any>undefined],
289285
})
290286
.option("arch", {
291287
group: deprecated,
292-
describe: "The target arch (preferred to use --x64 or --ia32)",
288+
description: "The target arch (preferred to use --x64 or --ia32)",
293289
choices: ["ia32", "x64", "all", <any>undefined],
294290
})
295291
.option("extraMetadata", {
296292
alias: ["em"],
297293
group: buildGroup,
298-
describe: "Inject properties to package.json (asar only)",
294+
description: "Inject properties to package.json (asar only)",
299295
})
300296
.option("prepackaged", {
301297
alias: ["pd"],
302298
group: buildGroup,
303-
describe: "The path to prepackaged app (to pack in a distributable format)",
299+
description: "The path to prepackaged app (to pack in a distributable format)",
304300
})
305301
.option("projectDir", {
306302
alias: ["project"],
307303
group: buildGroup,
308-
describe: "The path to project directory. Defaults to current working directory.",
304+
description: "The path to project directory. Defaults to current working directory.",
309305
})
310306
.option("config", {
311307
alias: ["c"],
312308
group: buildGroup,
313-
describe: "The path to an electron-builder config. Defaults to `electron-builder.yml` (or `json`, or `json5`), see " + underline("https://goo.gl/YFRJOM"),
309+
description: "The path to an electron-builder config. Defaults to `electron-builder.yml` (or `json`, or `json5`), see " + underline("https://goo.gl/YFRJOM"),
314310
})
315311
.group(["help", "version"], "Other:")
316312
.example("electron-builder -mwl", "build for macOS, Windows and Linux")
317313
.example("electron-builder --linux deb tar.xz", "build deb and tar.xz for Linux")
318314
.example("electron-builder --win --ia32", "build for Windows ia32")
319315
.example("electron-builder --em.foo=bar", "set package.json property `foo` to `bar`")
320316
.example("electron-builder --config.nsis.unicode=false", "configure unicode options for NSIS")
321-
}
322-
323-
/** @private */
324-
export function buildCommandHandler(args: CliOptions) {
325-
if (!isCi && process.env.NO_UPDATE_NOTIFIER == null) {
326-
readJson(path.join(__dirname, "..", "..", "package.json"))
327-
.then(it => {
328-
if (it.version === "0.0.0-semantic-release") {
329-
return
330-
}
331-
332-
const notifier = updateNotifier({pkg: it})
333-
if (notifier.update != null) {
334-
notifier.notify({
335-
message: `Update available ${dim(notifier.update.current)}${reset(" → ")}${green(notifier.update.latest)} \nRun ${cyan("npm i electron-builder --save-dev")} to update`
336-
})
337-
}
338-
})
339-
.catch(e => warn(`Cannot check updates: ${e}`))
340-
}
341-
342-
build(args)
343-
.catch(printErrorAndExit)
344317
}
Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,60 @@
11
#! /usr/bin/env node
22

3-
import { underline } from "chalk"
3+
import { cyan, dim, green, reset, underline } from "chalk"
4+
import { warn } from "electron-builder-util/out/log"
45
import { printErrorAndExit } from "electron-builder-util/out/promise"
6+
import { readJson } from "fs-extra-p"
7+
import isCi from "is-ci"
8+
import * as path from "path"
9+
import updateNotifier from "update-notifier"
510
import yargs from "yargs"
6-
import { buildCommandHandler, configureBuildCommand } from "../builder"
11+
import { build, configureBuildCommand } from "../builder"
712
import { createSelfSignedCert } from "./create-self-signed-cert"
813
import { configureInstallAppDepsCommand, installAppDeps } from "./install-app-deps"
914

1015
yargs
11-
.command(<any>["build", "*"], "Build", configureBuildCommand, buildCommandHandler)
12-
.command("install-app-deps", "Install app deps", configureInstallAppDepsCommand, argv => {
13-
installAppDeps(argv)
14-
.catch(printErrorAndExit)
15-
})
16+
.command(<any>["build", "*"], "Build", configureBuildCommand, wrap(build))
17+
.command("install-app-deps", "Install app deps", configureInstallAppDepsCommand, wrap(installAppDeps))
1618
.command("create-self-signed-cert", "Create self-signed code signing cert for Windows apps",
1719
yargs => yargs
1820
.option("publisher", {
1921
alias: ["p"],
2022
type: "string",
2123
requiresArg: true,
24+
description: "The publisher name",
2225
})
2326
.demandOption("publisher"),
24-
argv => {
25-
createSelfSignedCert(argv.publisher)
26-
.catch(printErrorAndExit)
27-
})
27+
wrap(argv => createSelfSignedCert(argv.publisher)))
2828
.help()
2929
.epilog(`See the Wiki (${underline("https://github.com/electron-userland/electron-builder/wiki")}) for more documentation.`)
3030
.strict()
3131
.argv
32+
33+
function wrap(task: (args: any) => Promise<any>) {
34+
return (args: any) => {
35+
checkIsOutdated()
36+
task(args)
37+
.catch(printErrorAndExit)
38+
}
39+
}
40+
41+
function checkIsOutdated() {
42+
if (isCi || process.env.NO_UPDATE_NOTIFIER != null) {
43+
return
44+
}
45+
46+
readJson(path.join(__dirname, "..", "..", "package.json"))
47+
.then(it => {
48+
if (it.version === "0.0.0-semantic-release") {
49+
return
50+
}
51+
52+
const notifier = updateNotifier({pkg: it})
53+
if (notifier.update != null) {
54+
notifier.notify({
55+
message: `Update available ${dim(notifier.update.current)}${reset(" → ")}${green(notifier.update.latest)} \nRun ${cyan("yarn upgrade electron-builder")} to update`
56+
})
57+
}
58+
})
59+
.catch(e => warn(`Cannot check updates: ${e}`))
60+
}

packages/electron-builder/src/cli/install-app-deps.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,41 @@
22

33
import BluebirdPromise from "bluebird-lst"
44
import { computeDefaultAppDirectory, use } from "electron-builder-util"
5+
import { log, warn } from "electron-builder-util/out/log"
56
import { printErrorAndExit } from "electron-builder-util/out/promise"
67
import yargs from "yargs"
78
import { getElectronVersion, loadConfig } from "../util/readPackageJson"
89
import { installOrRebuild } from "../yarn"
910

11+
declare const PACKAGE_VERSION: string
12+
13+
// https://github.com/yargs/yargs/issues/760
14+
// demandOption is required to be set
1015
export function configureInstallAppDepsCommand(yargs: yargs.Yargs): yargs.Yargs {
1116
return yargs
1217
.option("platform", {
1318
choices: ["linux", "darwin", "win32"],
1419
default: process.platform,
20+
description: "The target platform",
1521
})
1622
.option("arch", {
1723
choices: ["ia32", "x64", "all"],
1824
default: process.arch,
25+
description: "The target arch",
1926
})
2027
}
2128

2229
export async function installAppDeps(args: any) {
30+
try {
31+
log("electron-builder " + PACKAGE_VERSION)
32+
}
33+
catch (e) {
34+
// error in dev mode without babel
35+
if (!(e instanceof ReferenceError)) {
36+
throw e
37+
}
38+
}
39+
2340
const projectDir = process.cwd()
2441
const config = (await loadConfig(projectDir)) || {}
2542
const muonVersion = config.muonVersion
@@ -37,6 +54,7 @@ function main() {
3754
}
3855

3956
if (process.mainModule === module) {
57+
warn("Please use as subcommand: electron-builder install-app-deps")
4058
main()
4159
.catch(printErrorAndExit)
4260
}

packages/electron-builder/src/windowsCodeSign.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async function spawnSign(options: SignOptions, inputPath: string, outputPath: st
135135
args.push(inputPath)
136136
}
137137

138-
return await exec(await getToolPath(), args)
138+
return await exec(await getToolPath(), args, {timeout: 120 * 1000})
139139
}
140140

141141
function getOutputPath(inputPath: string, hash: string) {

0 commit comments

Comments
 (0)