Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion web/scripts/extract-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ function titleFromMarkdown(content: string, fallback: string): string {
return titleMatch ? titleMatch[1] : fallback;
}

/**
* Recursively copy a directory tree.
*
* Avoids `fs.cpSync`: on Windows with Node 22 it terminates the process with
* STATUS_STACK_BUFFER_OVERRUN (exit code 0xC0000409) and no JS-level error,
* which silently breaks `npm run dev` because this script backs its `predev` step.
*/
function copyDirRecursive(srcDir: string, dstDir: string): void {
fs.mkdirSync(dstDir, { recursive: true });
for (const entry of fs.readdirSync(srcDir, { withFileTypes: true })) {
const srcPath = path.join(srcDir, entry.name);
const dstPath = path.join(dstDir, entry.name);
if (entry.isDirectory()) {
copyDirRecursive(srcPath, dstPath);
} else if (entry.isFile()) {
fs.copyFileSync(srcPath, dstPath);
}
}
}

function cleanCourseAssets() {
fs.rmSync(COURSE_ASSETS_DIR, { recursive: true, force: true });
fs.mkdirSync(COURSE_ASSETS_DIR, { recursive: true });
Expand All @@ -215,7 +235,7 @@ function copyChapterAssets(chapter: ChapterSource): ChapterImage[] {

const outDir = path.join(COURSE_ASSETS_DIR, chapter.dirName);
fs.mkdirSync(outDir, { recursive: true });
fs.cpSync(imagesDir, outDir, { recursive: true });
copyDirRecursive(imagesDir, outDir);

return fs
.readdirSync(imagesDir)
Expand Down