mirror of
https://github.com/HananoshikaYomaru/openfreebooks.git
synced 2026-11-13 04:55:51 +00:00
Update build scripts and enhance development workflow: Revise package.json to streamline build commands, replacing deprecated scripts with new chapter-specific build commands. Update CONTRIBUTING.md to clarify local development instructions and improve chapter sync processes. Enhance README.md with updated serving and build commands for better user guidance. Add new types for Bun in devDependencies and update the feed and sitemap to reflect recent content changes.
This commit is contained in:
parent
61963350e7
commit
5ac8e330ca
19 changed files with 501 additions and 125 deletions
|
|
@ -123,6 +123,13 @@ async function copyDir(srcDir: string, destDir: string) {
|
|||
}
|
||||
}
|
||||
|
||||
async function writeIfChanged(path: string, content: string) {
|
||||
const current = existsSync(path) ? await readFile(path, "utf8") : null;
|
||||
if (current === content) return;
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, content);
|
||||
}
|
||||
|
||||
async function compileChapterScss(
|
||||
subject: string,
|
||||
slug: string,
|
||||
|
|
@ -361,18 +368,14 @@ function buildWidgetRegistry(
|
|||
const lines: string[] = [
|
||||
"// Auto-generated by scripts/sync-chapters.ts — do not edit.",
|
||||
"",
|
||||
"import type { Component } from \"solid-js\";",
|
||||
"",
|
||||
"export type ChapterWidgetModule = { default: Component };",
|
||||
"",
|
||||
"export const chapterWidgetLoaders: Record<string, () => Promise<ChapterWidgetModule>> = {",
|
||||
"export const chapterWidgetUrls: Record<string, string> = {",
|
||||
];
|
||||
|
||||
for (const { key, widgets, dir } of entries) {
|
||||
const relFromGenerated = relative(dirname(GENERATED_WIDGETS), dir).replace(/\\/g, "/");
|
||||
for (const { key, widgets } of entries) {
|
||||
const [subject, slug] = key.split("/");
|
||||
for (const widget of widgets) {
|
||||
const importPath = `${relFromGenerated}/widgets/${widget}`;
|
||||
lines.push(` "${key}/${widget}": () => import("${importPath}"),`);
|
||||
const importPath = `/js/chapter-widgets/${subject}/${slug}/${widget}.js`;
|
||||
lines.push(` "${key}/${widget}": "${importPath}",`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -411,14 +414,11 @@ async function main() {
|
|||
widgetEntries.push({ key, widgets, dir: chapter.dir });
|
||||
}
|
||||
|
||||
await mkdir(dirname(GENERATED_META), { recursive: true });
|
||||
await writeFile(GENERATED_META, `${JSON.stringify(metaFile, null, 2)}\n`);
|
||||
|
||||
await mkdir(dirname(GENERATED_WIDGETS), { recursive: true });
|
||||
await writeFile(GENERATED_WIDGETS, buildWidgetRegistry(widgetEntries));
|
||||
await writeIfChanged(GENERATED_META, `${JSON.stringify(metaFile, null, 2)}\n`);
|
||||
await writeIfChanged(GENERATED_WIDGETS, buildWidgetRegistry(widgetEntries));
|
||||
|
||||
const chapterNav = await buildChapterNav(chapters);
|
||||
await writeFile(GENERATED_NAV, `${JSON.stringify(chapterNav, null, 2)}\n`);
|
||||
await writeIfChanged(GENERATED_NAV, `${JSON.stringify(chapterNav, null, 2)}\n`);
|
||||
|
||||
const subjectEntries: Array<{ id: string; dir: string; hasJs: boolean }> = [];
|
||||
const subjectsMeta: SubjectsMetaFile = { subjects: {} };
|
||||
|
|
@ -446,9 +446,8 @@ async function main() {
|
|||
subjectsMeta.subjects[subject.id] = meta;
|
||||
subjectEntries.push({ id: subject.id, dir: subject.dir, hasJs: meta.hasJs });
|
||||
}
|
||||
await writeFile(GENERATED_SUBJECTS_META, `${JSON.stringify(subjectsMeta, null, 2)}\n`);
|
||||
await mkdir(dirname(GENERATED_SUBJECT_MODULES), { recursive: true });
|
||||
await writeFile(GENERATED_SUBJECT_MODULES, buildSubjectModuleRegistry(subjectEntries));
|
||||
await writeIfChanged(GENERATED_SUBJECTS_META, `${JSON.stringify(subjectsMeta, null, 2)}\n`);
|
||||
await writeIfChanged(GENERATED_SUBJECT_MODULES, buildSubjectModuleRegistry(subjectEntries));
|
||||
await mkdir(dirname(SYNC_CACHE_PATH), { recursive: true });
|
||||
await writeFile(SYNC_CACHE_PATH, `${JSON.stringify(nextCache, null, 2)}\n`);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue