-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
install-app-deps.ts
74 lines (66 loc) · 2.51 KB
/
install-app-deps.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env node
import { log, use, getArchCliNames } from "builder-util"
import { printErrorAndExit } from "builder-util/out/promise"
import { computeDefaultAppDirectory, getConfig } from "app-builder-lib/out/util/config"
import { getElectronVersion } from "app-builder-lib/out/electron/electronVersion"
import { createLazyProductionDeps } from "app-builder-lib/out/util/packageDependencies"
import { installOrRebuild } from "app-builder-lib/out/util/yarn"
import { readJson } from "fs-extra"
import { Lazy } from "lazy-val"
import * as path from "path"
import { orNullIfFileNotExist } from "read-config-file"
import yargs from "yargs"
declare const PACKAGE_VERSION: string
/** @internal */
export function configureInstallAppDepsCommand(yargs: yargs.Argv): yargs.Argv {
// https://github.com/yargs/yargs/issues/760
// demandOption is required to be set
return yargs
.parserConfiguration({
"camel-case-expansion": false,
})
.option("platform", {
choices: ["linux", "darwin", "win32"],
default: process.platform,
description: "The target platform",
})
.option("arch", {
choices: getArchCliNames().concat("all"),
default: process.arch === "arm" ? "armv7l" : process.arch,
description: "The target arch",
})
}
/** @internal */
export async function installAppDeps(args: any) {
try {
log.info({version: PACKAGE_VERSION}, "electron-builder")
}
catch (e) {
// error in dev mode without babel
if (!(e instanceof ReferenceError)) {
throw e
}
}
const projectDir = process.cwd()
const packageMetadata = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))
const config = await getConfig(projectDir, null, null, packageMetadata)
const results = await Promise.all<string>([
computeDefaultAppDirectory(projectDir, use(config.directories, it => it!.app)),
getElectronVersion(projectDir, config, packageMetadata),
])
// if two package.json — force full install (user wants to install/update app deps in addition to dev)
await installOrRebuild(config, results[0], {
frameworkInfo: {version: results[1], useCustomDist: true},
platform: args.platform,
arch: args.arch,
productionDeps: createLazyProductionDeps(results[0], null),
}, results[0] !== projectDir)
}
function main() {
return installAppDeps(configureInstallAppDepsCommand(yargs).argv)
}
if (process.mainModule === module) {
log.warn("please use as subcommand: electron-builder install-app-deps")
main()
.catch(printErrorAndExit)
}