This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
bundle.ts
72 lines (59 loc) · 1.78 KB
/
bundle.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
67
68
69
70
71
72
/// <reference path="../index.d.ts" />
import { file, write } from "bun";
import { mkdirSync } from "fs";
import { join, resolve } from "path";
import { getDotTsFiles } from "./utils/getDotTsFiles";
// Combine all the .d.ts files into a single .d.ts file
// so that your editor loads the types faster
const BUN_VERSION = (
process.env.BUN_VERSION ||
Bun.version ||
process.versions.bun
).replace(/^v/, "");
const folder = resolve(process.argv.at(-1)!);
if (folder.endsWith("bundle.ts")) {
throw new Error("Pass a folder");
}
try {
mkdirSync(folder, { recursive: true });
} catch {}
const header = await file(join(import.meta.dir, "..", "header.txt")).text();
const filesToCat = (await getDotTsFiles("./")).filter(
(f) => !["./index.d.ts"].some((tf) => f === tf)
);
const fileContents: string[] = [];
for (let i = 0; i < filesToCat.length; i++) {
const name = filesToCat[i];
fileContents.push(
"// " +
name +
"\n\n" +
(await file(resolve(import.meta.dir, "..", name)).text()) +
"\n"
);
}
const text = header.replace("{version}", BUN_VERSION) + fileContents.join("\n");
const destination = resolve(folder, "types.d.ts");
await write(destination, text);
const packageJSON = {
name: process.env.PACKAGE_NAME || "bun-types",
version: BUN_VERSION,
description:
"Type definitions for Bun, an incredibly fast JavaScript runtime",
types: "types.d.ts",
files: ["types.d.ts", "README.md"],
private: false,
keywords: ["bun", "bun.js", "types"],
repository: "https://github.com/oven-sh/bun-types",
homepage: "https://bun.sh",
};
await write(
resolve(folder, "package.json"),
JSON.stringify(packageJSON, null, 2) + "\n"
);
await write(
resolve(folder, "README.md"),
file(resolve(import.meta.dir, "..", "README.md"))
);
export {};
import "../index";