Files
replayweb.page/scripts/build-if-not-git-repo.js
T
Emma Segal-Grossman a63390f10c Update NPM packaging, linting, and a bunch of types (#275)
Preparation for
https://github.com/webrecorder/archiveweb.page/issues/198 /
https://github.com/webrecorder/archiveweb.page/pull/199.

## Changes

- Organizes published files more cleanly, using `dist/types` folder as
the target for type declarations and sourcemaps
- Configures type field in `package.json`
- Updates ESLint & its config
  - Sets up type-informed linting rules mirroring browsertrix
- Adds a bunch of other useful eslint and eslint-typescript rules, and
applies auto-fixes to the codebase
- Cleans up a bunch of types throughout the codebase, particularly parts
of the code used by ArchiveWebPage
- Changes `ItemIndex#_deleting` from `private` to `protected` so that a
part of AWP that extends it can do so properly
- Makes a bunch of previously-implied [non-null
assertions](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#non-null-assertion-operator-postfix-)
explicit
- Updates `URLResource` and `ItemType` types (and renames `Item` →
`ItemType` to disambiguate from the `Item` class)
- Removes `node-sass` and replaces it with `sass-embedded` for much
quicker installs and compilation
2024-02-06 18:50:12 -08:00

45 lines
1.2 KiB
JavaScript

/* 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 || process.argv.includes("--force")) {
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);
}
});
});
}