-
-
Notifications
You must be signed in to change notification settings - Fork 670
/
Copy pathprepublish.js
32 lines (29 loc) · 874 Bytes
/
prepublish.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import fs from "fs";
import path from "path";
import { createRequire } from "module";
import { fileURLToPath } from "url";
const require = createRequire(import.meta.url);
const dirname = path.dirname(fileURLToPath(import.meta.url));
const reset = process.argv[2] === "--reset";
if (reset) {
fs.copyFileSync(
path.join(dirname, "..", "package.json.backup"),
path.join(dirname, "..", "package.json")
);
fs.unlinkSync(
path.join(dirname, "..", "package.json.backup")
);
} else {
const pkg = require("../package.json");
if (!pkg.scripts) throw Error("already modified");
delete pkg.scripts;
delete pkg.devDependencies;
fs.copyFileSync(
path.join(dirname, "..", "package.json"),
path.join(dirname, "..", "package.json.backup")
);
fs.writeFileSync(
path.join(dirname, "..", "package.json"),
JSON.stringify(pkg, null, 2)
);
}