Skip to content

Commit

Permalink
run build when installing from git
Browse files Browse the repository at this point in the history
test v2

try cding into module folder??

try adding npmignore

test just yarn build

try in prepare script??

try prepack again

try changing prepare to postinstall

move to prepare again

add script to check if we're in a git repo

swap around test

update build script

test a few more things?

add scripts to npm included files (hopefully temporarily)

whoops include correct filename!

remove unnecessary files
  • Loading branch information
emma-sg committed Dec 4, 2023
1 parent 930f7d6 commit 3f42a68
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"release": "yarn run build && electron-builder",
"lint": "eslint ./",
"format": "prettier --write ./",
"prepare": "husky install"
"prepare": "husky install; node scripts/build-if-not-git-repo.js"
},
"build": {
"afterSign": "build/notarize.js",
Expand All @@ -102,7 +102,9 @@
"dist/*.js",
"dist/prebuilds/${platform}-${arch}/*",
"dist/build/*",
"*.js",
"index.js",
"ui.js",
"sw.js",
"*.html",
"ruffle",
"webmanifest.json",
Expand Down
45 changes: 45 additions & 0 deletions scripts/build-if-not-git-repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-env node */

// Runs a webpack build when not installed in a git repository (i.e. when installed from GitHub in node_modules)
// Largely pulled from https://github.com/typicode/husky/blob/9d3eb31cd14d3fbdb77225d23a0c5a11f71beb2c/src/index.ts#L23

const cp = require("child_process");

const webpack = require("webpack");
const config = require("../webpack.config.js");

/**
* Logger
* @param {string} msg
* @returns {void}
*/
const l = (msg) => console.log(`replaywebpage - ${msg}`);

/**
* Git command
* @param {string[]} args
* @returns {cp.SpawnSyncReturns<Buffer>}
*/
const git = (args) => cp.spawnSync("git", args, { stdio: "inherit" });

// Ensure that we're inside a Git repository
// If git command is not found, status is null and we should return
// That's why status value needs to be checked explicitly
if (git(["rev-parse"]).status !== 0) {
l(`git command not found, running build`);
const compiler = webpack(config.map((c) => c()));

compiler.run((err) => {
if (err) {
console.error(err);
process.exit(1);
}
compiler.close((err) => {
if (err) {
console.error(err);
process.exit(1);
}
});
});
}

0 comments on commit 3f42a68

Please sign in to comment.