-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
51 lines (44 loc) · 1.3 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
import { exec } from "child_process";
import { promisify } from "util";
import { rmSync, writeFileSync } from "fs";
const execAsync = promisify(exec);
async function buildProject() {
try {
// Clean the dist directory
rmSync("dist", { recursive: true, force: true });
// Run the TypeScript compiler to generate type definitions and JavaScript files
await execAsync("tsc");
// Run Bun's build process
const result = await Bun.build({
entrypoints: ["src/index.ts"],
outdir: "dist",
target: "node",
minify: true,
sourcemap: "inline",
});
if (result.success) {
console.log("Build successful!");
// Create custom package.json in the dist folder
const packageJsonContent = {
name: "transform_json_keys",
version: "1.0.0",
main: "index.js",
types: "index.d.ts",
type: "module",
};
writeFileSync(
"dist/package.json",
JSON.stringify(packageJsonContent, null, 2)
);
console.log("Custom package.json created in dist folder.");
} else {
console.error("Build failed with errors:");
console.error(result.logs);
}
} catch (error) {
console.error("Build failed with errors:");
console.error(error);
}
}
// Call the async function
buildProject();