-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
48 lines (40 loc) · 1.37 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
import * as esbuild from "esbuild";
import * as fs from "fs/promises";
type Browser = "chrome" | "firefox" | "edge";
class Builder {
private watch: boolean;
private dev: boolean;
private browser: Browser;
private buildFile: string;
private staticFiles: File[];
private staticDirs: string[];
constructor(browser: Browser, watch: boolean, dev: boolean, buildFile: string) {
this.browser = browser;
this.watch = watch;
this.dev = dev;
this.buildFile = buildFile;
this.staticFiles = [];
this.staticDirs = [];
}
getOutDir(): string {
return `./dist-${this.browser}`;
}
build() {
fs.mkdir(this.getOutDir(), { recursive: true });
fs.copyFile("./manifest.json", `${this.getOutDir()}/manifest.json`);
const buildOptions: esbuild.BuildOptions = {
entryPoints: [this.buildFile],
bundle: true,
outdir: this.getOutDir(),
};
esbuild.build(buildOptions);
}
}
const watchFlag = process.argv.includes("--watch");
const devFlag = process.argv.includes("--dev");
const chromeFlag = process.argv.includes("--chrome");
const firefoxFlag = process.argv.includes("--firefox");
const edgeFlag = process.argv.includes("--edge");
const browser: Browser = chromeFlag ? "chrome" : firefoxFlag ? "firefox" : edgeFlag ? "edge" : "chrome";
const builder = new Builder(browser, watchFlag, devFlag, "./extension/main.ts");
builder.build();