-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostbuild.js
More file actions
44 lines (37 loc) · 1.27 KB
/
postbuild.js
File metadata and controls
44 lines (37 loc) · 1.27 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
/* eslint-disable no-console */
const { resolve, join, basename } = require("path");
const { readFile, writeFile, copy } = require("fs-extra");
const packagePath = process.cwd();
const distPath = join(packagePath, "./dist");
const writeJson = (targetPath, obj) => writeFile(targetPath, JSON.stringify(obj, null, 2), "utf8");
async function createPackageFile() {
const packageData = await readFile(resolve(packagePath, "./package.json"), "utf8");
const { scripts, devDependencies, ...packageOthers } = JSON.parse(packageData);
const newPackageData = {
...packageOthers,
private: false,
typings: "./index.d.ts",
main: "./cjs/index.js",
module: "./index.js",
};
const targetPath = resolve(distPath, "./package.json");
await writeJson(targetPath, newPackageData);
console.log(`Created package.json in ${targetPath}`);
}
async function includeFileInBuild(file) {
const sourcePath = resolve(packagePath, file);
const targetPath = resolve(distPath, basename(file));
await copy(sourcePath, targetPath);
console.log(`Copied ${sourcePath} to ${targetPath}`);
}
async function run() {
try {
await createPackageFile();
//await includeFileInBuild("./README.md");
// await includeFileInBuild('../../LICENSE');
} catch (err) {
console.error(err);
process.exit(1);
}
}
run();