Skip to content
This repository was archived by the owner on Oct 13, 2024. It is now read-only.

Commit 6a20bbf

Browse files
committed
Deprecate app_root option, use package_root as default
1 parent 9375f4c commit 6a20bbf

File tree

3 files changed

+21
-28
lines changed

3 files changed

+21
-28
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ After building successfully, the action will publish your release artifacts. By
7171

7272
You can configure the action further with the following options:
7373

74-
- `app_root`: Directory where `electron-builder` commands should be run (default: repository root)
75-
- `package_root`: Directory where NPM/Yarn commands should be run (default: repository root)
74+
- `package_root`: Directory where NPM/Yarn commands should be run (default: `"."`)
7675

7776
See [`action.yml`](./action.yml) for a list of all possible input variables.
7877

action.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ inputs:
2222
windows_certs_password:
2323
description: Password for decrypting `windows_certs`
2424
required: false
25-
app_root:
26-
description: Directory where `electron-builder` commands should be run
27-
required: false
28-
default: "."
2925
package_root:
3026
description: Directory where NPM/Yarn commands should be run
3127
required: false
3228
default: "."
3329

30+
# Deprecated
31+
app_root:
32+
description: Directory where `electron-builder` commands should be run
33+
required: false
34+
3435
runs:
3536
using: node12
3637
main: index.js

index.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ const { execSync } = require("child_process");
22
const { existsSync, readFileSync } = require("fs");
33
const { 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
*/
2421
const 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) => {
7866
const 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

Comments
 (0)