-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup-npm-package.js
More file actions
52 lines (42 loc) · 1.76 KB
/
setup-npm-package.js
File metadata and controls
52 lines (42 loc) · 1.76 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require("fs");
const path = require("path");
const { execSync } = require("child_process");
const pkgPath = path.join(__dirname, "package.json");
const distPkgPath = path.join(__dirname, "dist", "package.json");
const source = fs.readFileSync(pkgPath, "utf-8");
const sourceObj = JSON.parse(source);
// Remove fields that block or are unnecessary for publishing
delete sourceObj.private;
sourceObj.scripts = {};
sourceObj.devDependencies = {};
// Only keep runtime deps needed by the CLI server (index.js)
const runtimeDeps = ["ws", "express", "tslib", "chalk"];
const cleanedDeps = {};
for (const dep of runtimeDeps) {
if (sourceObj.dependencies && sourceObj.dependencies[dep]) {
cleanedDeps[dep] = sourceObj.dependencies[dep];
}
}
sourceObj.dependencies = cleanedDeps;
if (sourceObj.exports && sourceObj.exports["."] && sourceObj.exports["."].startsWith("./dist")) {
sourceObj.exports["."] = "./" + sourceObj.exports["."].slice(7);
}
if (sourceObj.bin && sourceObj.bin["ngrx-devtool"] && sourceObj.bin["ngrx-devtool"].startsWith("./dist")) {
sourceObj.bin["ngrx-devtool"] = "./" + sourceObj.bin["ngrx-devtool"].slice(7);
}
fs.writeFileSync(distPkgPath, JSON.stringify(sourceObj, null, 2), "utf-8");
// Remove demo app from dist if present
const demoPath = path.join(__dirname, "dist", "ngrx-devtool-demo");
if (fs.existsSync(demoPath)) {
fs.rmSync(demoPath, { recursive: true, force: true });
}
const readmeSrc = path.join(__dirname, "npm-readme.md");
const readmeDest = path.join(__dirname, "dist", "README.md");
if (fs.existsSync(readmeSrc)) {
fs.copyFileSync(readmeSrc, readmeDest);
}
try {
execSync(`npx prettier --write "${distPkgPath}"`, { stdio: "inherit" });
} catch (e) {
console.warn("Prettier not found or failed to format dist/package.json");
}