-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
60 lines (54 loc) · 1.31 KB
/
build.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as esbuild from "esbuild";
import { copyFileSync, readFileSync, writeFileSync } from "node:fs";
const BUILD_DIR = "dist";
const buildAll = async (minify) => {
const ext = minify ? ".min.js" : ".js";
for (let [entry, out] of [
["src/index.ts", "genart"],
["src/adapters/urlparams.ts", "adapter-urlparams"],
]) {
const outFile = `${BUILD_DIR}/${out}${ext}`;
console.log("building", outFile);
await esbuild.build({
entryPoints: [entry],
outfile: outFile,
platform: "browser",
target: "es2022",
bundle: true,
minify,
});
if (out === "genart") {
const pkg = JSON.parse(readFileSync("package.json"));
console.log("injecting version:", pkg.version, outFile);
writeFileSync(
outFile,
readFileSync(outFile, "utf-8").replace(
"__VERSION__",
pkg.version
)
);
}
}
};
await buildAll(false);
await buildAll(true);
const PKG = JSON.parse(readFileSync("package.json"));
writeFileSync(
`${BUILD_DIR}/package.json`,
JSON.stringify(
{
name: PKG.name,
version: PKG.version,
description: PKG.description,
repository: PKG.repository,
author: PKG.author,
license: PKG.license,
typings: "./genart.d.ts",
sideEffects: false,
},
null,
4
)
);
copyFileSync("README.md", `${BUILD_DIR}/README.md`);
copyFileSync("LICENSE", `${BUILD_DIR}/LICENSE`);