-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupPackage.js
More file actions
40 lines (33 loc) · 1.25 KB
/
Copy pathsetupPackage.js
File metadata and controls
40 lines (33 loc) · 1.25 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
const fs = require("fs");
const path = require("path");
function main() {
const packageJsonPath = path.join(__dirname, "package.json");
const distPath = path.join(__dirname, "dist");
const readmePath = path.join(__dirname, "README.md");
if (!fs.existsSync(distPath)) {
fs.mkdirSync(distPath);
}
const source = fs.readFileSync(packageJsonPath).toString("utf-8");
const sourceObj = JSON.parse(source);
sourceObj.scripts = {};
sourceObj.devDependencies = {};
if (sourceObj.main && sourceObj.main.startsWith("/dist/")) {
sourceObj.main = sourceObj.main.slice(5);
}
const distPackageJsonPath = path.join(distPath, "package.json");
const versionFilePath = path.join(distPath, "version.txt");
const npmignorePath = path.join(distPath, ".npmignore");
const distReadmePath = path.join(distPath, "README.md");
fs.writeFileSync(
distPackageJsonPath,
Buffer.from(JSON.stringify(sourceObj, null, 2), "utf-8")
);
fs.writeFileSync(versionFilePath, Buffer.from(sourceObj.version, "utf-8"));
if (fs.existsSync(npmignorePath)) {
fs.copyFileSync(npmignorePath, path.join(distPath, ".npmignore"));
}
if (fs.existsSync(readmePath)) {
fs.copyFileSync(readmePath, distReadmePath);
}
}
main();