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

Commit

Permalink
Add support for building with NPM
Browse files Browse the repository at this point in the history
Yarn is used unless a `package-lock.json` file is found
  • Loading branch information
samuelmeuli committed Nov 15, 2019
1 parent 4af633a commit 009c7a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ Suggestions and contributions are always welcome! Please discuss larger changes

This project is still WIP. The following needs to be implemented before `v1.0`:

- [ ] Add support for NPM (besides Yarn)
- [ ] Make the `build` NPM script optional
- [ ] Make the `yarn build` script optional
- [ ] In the sample workflow, add tag detection, which should decide whether to release after the build
- [ ] Add support for publishing to Snapcraft
- [ ] Add support for Windows code signing
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { execSync } = require("child_process");
const { existsSync } = require("fs");

/**
* Logs to the console
Expand All @@ -18,6 +19,11 @@ const exit = msg => {
*/
const run = cmd => execSync(cmd, { encoding: "utf8", stdio: "inherit" });

/**
* Returns whether NPM should be used to run commands (instead of Yarn, which is the default)
*/
const useNpm = existsSync("./package-lock.json");

/**
* Determines the current operating system (one of ["mac", "windows", "linux"])
*/
Expand Down Expand Up @@ -61,15 +67,19 @@ const runAction = () => {
process.env.CSC_KEY_PASSWORD = getEnvVariable("mac_certs_password", true);
}

log("Installing dependencies…");
run("yarn");
log(`Installing dependencies using ${useNpm ? "NPM" : "Yarn"}…`);
run(useNpm ? "npm install" : "yarn");

// TODO: Only run build script if it exists
// TODO: Only run Yarn build script if it exists
log("Building app…");
run("yarn build");
run(useNpm ? "npm run build --if-present" : "yarn build");

log(`${release ? "Releasing" : "Building"} the Electron app…`);
run(`yarn run electron-builder --${platform} ${release ? "--publish always" : ""}`);
run(
`${useNpm ? "npx --no-install" : "yarn run"} electron-builder --${platform} ${
release ? "--publish always" : ""
}`,
);
};

runAction();

0 comments on commit 009c7a3

Please sign in to comment.