mirror of
https://github.com/HeyPuter/browser.js.git
synced 2026-11-13 20:12:38 -10:00
50 lines
1.0 KiB
JavaScript
50 lines
1.0 KiB
JavaScript
import { spawnSync } from "node:child_process";
|
|
|
|
function run(command, args) {
|
|
const result = spawnSync(command, args, {
|
|
stdio: "inherit",
|
|
});
|
|
|
|
if (result.error) throw result.error;
|
|
|
|
return result.status ?? 1;
|
|
}
|
|
|
|
function getDefaultTargets() {
|
|
const result = spawnSync(
|
|
"git",
|
|
[
|
|
"ls-files",
|
|
"-z",
|
|
"--cached",
|
|
"--others",
|
|
"--exclude-standard",
|
|
"--",
|
|
"*.js",
|
|
"*.mjs",
|
|
"*.cjs",
|
|
"*.ts",
|
|
":(exclude)external/**",
|
|
],
|
|
{
|
|
encoding: "utf8",
|
|
}
|
|
);
|
|
|
|
if (result.error) throw result.error;
|
|
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
|
|
return result.stdout.split("\0").filter(Boolean);
|
|
}
|
|
|
|
const cliArgs = process.argv.slice(2);
|
|
const needsGitAwareTargets =
|
|
cliArgs.length === 0 || cliArgs.includes(".") || cliArgs.includes("./");
|
|
|
|
const passthroughArgs = cliArgs.filter((arg) => arg !== "." && arg !== "./");
|
|
const eslintArgs = needsGitAwareTargets
|
|
? [...passthroughArgs, ...getDefaultTargets()]
|
|
: cliArgs;
|
|
|
|
process.exit(run("pnpm", ["exec", "eslint", ...eslintArgs]));
|