|
20 | 20 |
|
21 | 21 | import { execSync } from 'node:child_process'; |
22 | 22 | import { existsSync, readdirSync, statSync } from 'node:fs'; |
23 | | -import { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises'; |
24 | | -import { dirname, join } from 'node:path'; |
| 23 | +import { copyFile, cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'; |
| 24 | +import { dirname, join, relative } from 'node:path'; |
25 | 25 | import { fileURLToPath } from 'node:url'; |
26 | 26 | import { parseArgs } from 'node:util'; |
27 | 27 |
|
@@ -402,12 +402,17 @@ async function copyBundledDocs() { |
402 | 402 | return; |
403 | 403 | } |
404 | 404 |
|
405 | | - // Clean and recreate target directory |
| 405 | + const skipPrefixes = ['node_modules', '.vitepress/cache', '.vitepress/dist']; |
406 | 406 | await rm(docsTargetDir, { recursive: true, force: true }); |
407 | | - await mkdir(docsTargetDir, { recursive: true }); |
| 407 | + await cp(docsSourceDir, docsTargetDir, { |
| 408 | + recursive: true, |
| 409 | + filter: (src) => { |
| 410 | + const rel = relative(docsSourceDir, src).replaceAll('\\', '/'); |
| 411 | + return !skipPrefixes.some((prefix) => rel === prefix || rel.startsWith(`${prefix}/`)); |
| 412 | + }, |
| 413 | + }); |
408 | 414 |
|
409 | | - const copied = await copyDocsTree(docsSourceDir, docsTargetDir); |
410 | | - console.log(` Copied ${copied} docs files to docs/ (with paths preserved)`); |
| 415 | + console.log(' Copied docs to docs/ (with paths preserved)'); |
411 | 416 | } |
412 | 417 |
|
413 | 418 | async function syncReadmeFromRoot() { |
@@ -445,49 +450,6 @@ function splitReadme(content: string, label: string) { |
445 | 450 | }; |
446 | 451 | } |
447 | 452 |
|
448 | | -async function copyDocsTree( |
449 | | - docsSourceDir: string, |
450 | | - docsTargetDir: string, |
451 | | - relativePath = '', |
452 | | -): Promise<number> { |
453 | | - let copied = 0; |
454 | | - const currentDir = join(docsSourceDir, relativePath); |
455 | | - |
456 | | - for (const entry of readdirSync(currentDir, { withFileTypes: true })) { |
457 | | - const entryRelPath = relativePath ? join(relativePath, entry.name) : entry.name; |
458 | | - const normalizedPath = entryRelPath.replaceAll('\\', '/'); |
459 | | - |
460 | | - if (shouldSkipDocsPath(normalizedPath)) { |
461 | | - continue; |
462 | | - } |
463 | | - |
464 | | - const sourcePath = join(docsSourceDir, entryRelPath); |
465 | | - const targetPath = join(docsTargetDir, entryRelPath); |
466 | | - |
467 | | - if (entry.isDirectory()) { |
468 | | - await mkdir(targetPath, { recursive: true }); |
469 | | - copied += await copyDocsTree(docsSourceDir, docsTargetDir, entryRelPath); |
470 | | - continue; |
471 | | - } |
472 | | - |
473 | | - if (!entry.isFile()) { |
474 | | - continue; |
475 | | - } |
476 | | - |
477 | | - await mkdir(dirname(targetPath), { recursive: true }); |
478 | | - await copyFile(sourcePath, targetPath); |
479 | | - copied++; |
480 | | - } |
481 | | - |
482 | | - return copied; |
483 | | -} |
484 | | - |
485 | | -function shouldSkipDocsPath(relativePath: string) { |
486 | | - return ['node_modules', '.vitepress/cache', '.vitepress/dist'].some( |
487 | | - (prefix) => relativePath === prefix || relativePath.startsWith(`${prefix}/`), |
488 | | - ); |
489 | | -} |
490 | | - |
491 | 453 | type ExportValue = |
492 | 454 | | string |
493 | 455 | | { |
|
0 commit comments