#! /usr/bin/env node
import { getElectronVersion } from "app-builder-lib/out/electron/electronVersion"
import { computeDefaultAppDirectory, getConfig } from "app-builder-lib/out/util/config/config"
import { orNullIfFileNotExist } from "app-builder-lib/out/util/config/load"
import { createLazyProductionDeps } from "app-builder-lib/out/util/packageDependencies"
import { installOrRebuild } from "app-builder-lib/out/util/yarn"
import { PACKAGE_VERSION } from "app-builder-lib/out/version"
import { getArchCliNames, log, printErrorAndExit, use } from "builder-util"
import { readJson } from "fs-extra"
import { Lazy } from "lazy-val"
import * as path from "path"
import * as yargs from "yargs"
export function configureInstallAppDepsCommand(yargs: yargs.Argv): yargs.Argv {
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",
})
}
export async function installAppDeps(args: any) {
try {
log.info({ version: PACKAGE_VERSION }, "electron-builder")
} catch (e: any) {
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 [appDir, version] = await Promise.all<string>([
computeDefaultAppDirectory(
projectDir,
use(config.directories, it => it.app)
),
getElectronVersion(projectDir, config),
])
await installOrRebuild(
config,
{
appDir,
projectDir,
},
{
frameworkInfo: { version, useCustomDist: true },
platform: args.platform,
arch: args.arch,
productionDeps: createLazyProductionDeps(appDir, null, false),
},
appDir !== projectDir
)
}
function main() {
return installAppDeps(configureInstallAppDepsCommand(yargs).argv)
}
if (require.main === module) {
log.warn("please use as subcommand: electron-builder install-app-deps")
main().catch(printErrorAndExit)
}