Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
26 lines
635 B
JavaScript
26 lines
635 B
JavaScript
import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
import { dirname } from "node:path";
|
|
|
|
const capturePath = process.argv[2];
|
|
const filePath = process.argv.at(-1);
|
|
if (!capturePath || !filePath) {
|
|
process.exit(1);
|
|
}
|
|
|
|
const directory = dirname(filePath);
|
|
writeFileSync(
|
|
capturePath,
|
|
JSON.stringify({
|
|
filePath,
|
|
content: readFileSync(filePath, "utf-8"),
|
|
entries: readdirSync(directory),
|
|
directoryMode: statSync(directory).mode & 0o777,
|
|
}),
|
|
"utf-8",
|
|
);
|
|
|
|
if (process.argv.includes("--fail")) {
|
|
process.exit(1);
|
|
}
|
|
writeFileSync(filePath, process.argv.includes("--empty") ? "" : "edited\n", "utf-8");
|