-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
119 lines (98 loc) · 2.85 KB
/
build.ts
File metadata and controls
119 lines (98 loc) · 2.85 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { copyFile, mkdir, rm, cp } from "fs/promises";
import { existsSync } from "fs";
import path from "path";
const DIST_DIR = "dist";
async function clean() {
if (existsSync(DIST_DIR)) {
await rm(DIST_DIR, { recursive: true });
}
await mkdir(DIST_DIR);
await mkdir(path.join(DIST_DIR, "popup"));
await mkdir(path.join(DIST_DIR, "popup", "styles"));
await mkdir(path.join(DIST_DIR, "content"));
await mkdir(path.join(DIST_DIR, "background"));
await mkdir(path.join(DIST_DIR, "icons"));
}
async function buildContentScript() {
const result = await Bun.build({
entrypoints: ["src/content/index.ts"],
outdir: path.join(DIST_DIR, "content"),
naming: "[name].js",
});
if (!result.success) {
console.error("Content script build failed:", result.logs);
process.exit(1);
}
}
async function buildBackground() {
const result = await Bun.build({
entrypoints: ["src/background/index.ts"],
outdir: path.join(DIST_DIR, "background"),
naming: "[name].js",
});
if (!result.success) {
console.error("Background script build failed:", result.logs);
process.exit(1);
}
}
async function buildPopup() {
// Build JS
const result = await Bun.build({
entrypoints: ["src/popup/index.tsx"],
outdir: path.join(DIST_DIR, "popup"),
naming: "[name].js",
});
if (!result.success) {
console.error("Popup build failed:", result.logs);
process.exit(1);
}
// Copy HTML
await copyFile("src/popup/index.html", path.join(DIST_DIR, "popup", "index.html"));
}
async function buildCSS() {
const proc = Bun.spawn(
[
"bunx",
"tailwindcss",
"-i",
"src/popup/styles/index.css",
"-o",
path.join(DIST_DIR, "popup", "styles", "index.css"),
"--minify",
],
{ stdout: "inherit", stderr: "inherit" }
);
const exitCode = await proc.exited;
if (exitCode !== 0) {
console.error("CSS build failed");
process.exit(1);
}
}
async function copyPublicFiles() {
// Copy manifest
await copyFile("public/manifest.json", path.join(DIST_DIR, "manifest.json"));
// Copy icons folder
if (existsSync("public/icons")) {
await cp("public/icons", path.join(DIST_DIR, "icons"), { recursive: true });
}
// Copy _locales for i18n
if (existsSync("public/_locales")) {
await cp("public/_locales", path.join(DIST_DIR, "_locales"), { recursive: true });
}
}
async function build() {
console.log("Building Threads Logger...");
await clean();
console.log("Cleaned dist directory");
await Promise.all([buildContentScript(), buildPopup(), buildBackground()]);
console.log("Built scripts");
await buildCSS();
console.log("Built CSS");
await copyPublicFiles();
console.log("Copied public files");
console.log("Build complete! Load the extension from:", DIST_DIR);
}
build().catch((err) => {
console.error("Build failed:", err);
process.exit(1);
});