Repository navigation
Expand file tree
/
Copy pathbuild.ts
More file actions
130 lines (119 loc) · 3.89 KB
/
Copy pathbuild.ts
File metadata and controls
130 lines (119 loc) · 3.89 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
120
121
122
123
124
125
126
127
128
129
130
import {
copyFileSync,
existsSync,
mkdirSync,
readdirSync,
readFileSync,
rmSync,
writeFileSync,
} from "node:fs";
import { basename, extname, join } from "node:path";
import { build } from "esbuild";
const srcDir = "./src";
const distDir = "./dist";
rmSync(distDir, { recursive: true, force: true });
mkdirSync(distDir, { recursive: true });
const repo = Bun.env.GITHUB_REPOSITORY;
const branch = "static";
const builtPlugins: {
id: string;
name: string;
version: string;
description: string;
path: string;
readmePath?: string;
}[] = [];
for (const dirEntry of readdirSync(srcDir, { withFileTypes: true })) {
if (!dirEntry.isDirectory() || dirEntry.name === "utils") continue;
const folder = `${srcDir}/${dirEntry.name}`;
const outFolder = `${distDir}/${dirEntry.name}`;
mkdirSync(outFolder, { recursive: true });
const entryPoints = [
"isOnline.ts",
"getSuggestion.ts",
"search.ts",
"getList.ts",
"getMangas.ts",
"getMangaUpdates.ts",
"getDetailedManga.ts",
"getChapter.ts",
"getImage.ts",
]
.map((f) => `${folder}/${f}`)
.filter(existsSync);
for (const entryPoint of entryPoints) {
await build({
entryPoints: [entryPoint],
outdir: outFolder,
platform: "browser",
format: "esm",
bundle: true,
minify: true,
entryNames: "[name]",
});
}
console.log(`✅ Bundle created for ${dirEntry.name}`);
const metaPath = `${folder}/meta.json`;
const meta = JSON.parse(readFileSync(metaPath, "utf8"));
const id = meta.id;
const markdownFiles = readdirSync(folder, { withFileTypes: true }).filter(
(file) => file.isFile() && extname(file.name).toLowerCase() === ".md",
);
for (const file of markdownFiles) {
copyFileSync(join(folder, file.name), join(outFolder, file.name));
console.log(`✅ ${file.name} copied to ${outFolder}`);
}
const readme = markdownFiles.find(
(file) => file.name.toLowerCase() === "readme.md",
);
const scripts: Record<string, string> = {};
for (const entryPoint of entryPoints) {
const key = basename(entryPoint, ".ts");
scripts[key] = readFileSync(join(outFolder, `${key}.js`), "utf8");
console.log(`✅ ${key} added to ${id}.json`);
}
meta.scripts = scripts;
if (repo) {
const repoUrl = `https://github.com/${repo}`;
const updatesUrl = `https://raw.githubusercontent.com/${repo}/${branch}/${dirEntry.name}/${id}.json`;
if (!meta.repository) {
meta.repository = repoUrl;
console.log(`✅ Added repository to ${id}.json`);
}
if (!meta.updatesUrl) {
meta.updatesUrl = updatesUrl;
console.log(`✅ Added updatesUrl to ${id}.json`);
}
}
writeFileSync(`${outFolder}/${id}.json`, JSON.stringify(meta, null, 2));
console.log(`✅ ${id}.json created in ${outFolder}\n`);
builtPlugins.push({
id,
name: meta.name ?? id,
version: meta.version ?? "0.0.0",
description: meta.description ?? "",
path: `${dirEntry.name}/${id}.json`,
readmePath: readme ? `${dirEntry.name}/${readme.name}` : undefined,
});
}
if (repo && branch) {
console.log(`Create README.md for ${repo} on branch ${branch}`);
let readmeContent =
"# Built Plugins\n\n> This branch is auto-generated. Do not edit.\n\n";
for (const plugin of builtPlugins) {
const url = `https://raw.githubusercontent.com/${repo}/${branch}/${plugin.path}`;
readmeContent += `### ${plugin.name} v${plugin.version}\n`;
if (plugin.description) {
readmeContent += `${plugin.description}\n\n`;
}
if (plugin.readmePath) {
const readmeUrl = `https://github.com/${repo}/blob/${branch}/${plugin.readmePath}`;
readmeContent += `[Documentation](${readmeUrl})\n\n`;
}
readmeContent += `\`\`\`\n${url}\n\`\`\`\n\n`;
}
writeFileSync(`${distDir}/README.md`, readmeContent);
console.log(`✅ README.md created in ${distDir}`);
} else {
console.log("Skipping README generation (missing env vars)");
}