@@ -2,9 +2,6 @@ const { execSync } = require("child_process");
22const { existsSync, readFileSync } = require ( "fs" ) ;
33const { join } = require ( "path" ) ;
44
5- const NPM_LOCKFILE_PATH = "./package-lock.json" ;
6- const PACKAGE_JSON_PATH = "./package.json" ;
7-
85/**
96 * Logs to the console
107 */
@@ -23,15 +20,6 @@ const exit = msg => {
2320 */
2421const run = ( cmd , cwd ) => execSync ( cmd , { encoding : "utf8" , stdio : "inherit" , cwd } ) ;
2522
26- /**
27- * Exits if the `package.json` file is missing
28- */
29- const verifyPackageJson = cwd => {
30- if ( ! existsSync ( join ( cwd , PACKAGE_JSON_PATH ) ) ) {
31- exit ( "Missing `package.json` file" ) ;
32- }
33- } ;
34-
3523/**
3624 * Determines the current operating system (one of ["mac", "windows", "linux"])
3725 */
@@ -78,18 +66,23 @@ const getInput = (name, required) => {
7866const runAction = ( ) => {
7967 const platform = getPlatform ( ) ;
8068 const release = getInput ( "release" , true ) === "true" ;
81- const appRoot = getInput ( "app_root" , true ) ;
8269 const pkgRoot = getInput ( "package_root" , true ) ;
8370
84- // Determine whether NPM should be used to run commands (instead of Yarn, which is the default)
85- const useNpm = existsSync ( join ( pkgRoot , NPM_LOCKFILE_PATH ) ) ;
71+ // TODO: Deprecated option, remove in v2.0. `electron-builder` always requires a `package.json` in
72+ // the same directory as the Electron app, so the `package_root` option should be used instead
73+ const appRoot = getInput ( "app_root" ) || pkgRoot ;
74+
75+ const pkgJsonPath = join ( pkgRoot , "package.json" ) ;
76+ const pkgLockPath = join ( pkgRoot , "package-lock.json" ) ;
8677
87- // Log information about working directories
78+ // Determine whether NPM should be used to run commands (instead of Yarn, which is the default)
79+ const useNpm = existsSync ( pkgLockPath ) ;
8880 log ( `Will run ${ useNpm ? "NPM" : "Yarn" } commands in directory "${ pkgRoot } "` ) ;
89- log ( `Will run \`electron-builder\` commands in directory "${ appRoot } "` ) ;
9081
9182 // Make sure `package.json` file exists
92- verifyPackageJson ( pkgRoot ) ;
83+ if ( ! existsSync ( pkgJsonPath ) ) {
84+ exit ( `\`package.json\` file not found at path "${ pkgJsonPath } "` ) ;
85+ }
9386
9487 // Copy "github_token" input variable to "GH_TOKEN" env variable (required by `electron-builder`)
9588 setEnv ( "GH_TOKEN" , getInput ( "github_token" , true ) ) ;
@@ -116,14 +109,14 @@ const runAction = () => {
116109 run ( "npm run build --if-present" , pkgRoot ) ;
117110 } else {
118111 // TODO: Use `yarn run build --if-present` once supported
119- // ( https://github.com/yarnpkg/yarn/issues/6894)
120- const packageJson = JSON . parse ( readFileSync ( PACKAGE_JSON_PATH , "utf8" ) ) ;
121- if ( packageJson . scripts && packageJson . scripts . build ) {
112+ // https://github.com/yarnpkg/yarn/issues/6894
113+ const pkgJson = JSON . parse ( readFileSync ( pkgJsonPath , "utf8" ) ) ;
114+ if ( pkgJson . scripts && pkgJson . scripts . build ) {
122115 run ( "yarn build" , pkgRoot ) ;
123116 }
124117 }
125118
126- log ( `${ release ? "Releasing " : "Building " } the Electron app…` ) ;
119+ log ( `Building ${ release ? " and releasing " : "" } the Electron app…` ) ;
127120 run (
128121 `${ useNpm ? "npx --no-install" : "yarn run" } electron-builder --${ platform } ${
129122 release ? "--publish always" : ""
0 commit comments