-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepublish.ts
40 lines (34 loc) · 1003 Bytes
/
prepublish.ts
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
import { buildSync } from "esbuild";
import * as fs from "fs";
import * as path from "path";
import rimraf from "rimraf";
import originalPkg from "./package.json";
const SRC_FILE = path.resolve(__dirname, "src", "index.ts");
const DEST_FILE = path.resolve(__dirname, "dist", "index.js");
const DEST_PKG_JSON = path.resolve(__dirname, "dist", "package.json");
// clean the dist folder
rimraf.sync("dist");
// build the dist file
buildSync({
entryPoints: [SRC_FILE],
outfile: DEST_FILE,
platform: "node",
bundle: true,
minify: true,
legalComments: "none",
});
// create the package.json to be published
const pkgJson = {
...originalPkg,
main: "index.js",
bin: "index.js",
scripts: {
start: "node index.js",
},
// remove all deps since esbuild already bundles everything
dependencies: {},
devDependencies: {},
};
fs.writeFileSync(DEST_PKG_JSON, JSON.stringify(pkgJson, null, 2));
// copy essential files like the readme
fs.copyFileSync("README.md", "dist/README.md");