-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ts
66 lines (56 loc) · 1.32 KB
/
build.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { build } from "esbuild";
import { copy } from "esbuild-plugin-copy";
import fs from "fs";
import path from "path";
const buildDir = "build";
/**
* @param file relative to __dirname
*/
function getJsonFromFile(file: string) {
const data = fs.readFileSync(path.resolve(__dirname, file), "utf-8");
return JSON.parse(data);
}
function syncVersions() {
const { version } = getJsonFromFile("package.json");
const manifest = getJsonFromFile("manifest.json");
manifest.version = version;
fs.writeFileSync(
path.resolve(__dirname, "manifest.json"),
JSON.stringify(manifest)
);
}
(async () => {
if (fs.existsSync(buildDir)) {
fs.rmSync(buildDir, { recursive: true });
}
try {
syncVersions();
} catch (error) {
console.log(
"unable to sync `version` value of package.json and manifest.json"
);
}
const res = await build({
entryPoints: ["./src/projects/**/index.ts"],
outdir: buildDir,
bundle: true,
minify: true,
sourcemap: true,
plugins: [
copy({
resolveFrom: "cwd",
assets: [
{
from: ["./manifest.json"],
to: ["./build/manifest.json"],
},
{
from: ["./icons/*.png"],
to: ["./build/icons"],
},
],
}),
],
});
console.log(res);
})();