|
7 | 7 | * 3. syncCorePackageExports() - Creates shim files to re-export from @voidzero-dev/vite-plus-core |
8 | 8 | * 4. syncTestPackageExports() - Creates shim files to re-export from @voidzero-dev/vite-plus-test |
9 | 9 | * 5. syncVersionsExport() - Generates ./versions module with bundled tool versions |
10 | | - * 6. copySkillDocs() - Copies docs into skills/vite-plus/docs for runtime MCP access |
| 10 | + * 6. copyBundledDocs() - Copies docs into docs/ for bundled package access |
11 | 11 | * 7. syncReadmeFromRoot() - Keeps package README in sync |
12 | 12 | * |
13 | 13 | * The sync functions allow this package to be a drop-in replacement for 'vite' by |
|
19 | 19 | */ |
20 | 20 |
|
21 | 21 | import { execSync } from 'node:child_process'; |
22 | | -import { existsSync, globSync, readdirSync, statSync } from 'node:fs'; |
| 22 | +import { existsSync, readdirSync, statSync } from 'node:fs'; |
23 | 23 | import { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises'; |
24 | 24 | import { dirname, join } from 'node:path'; |
25 | 25 | import { fileURLToPath } from 'node:url'; |
@@ -74,7 +74,7 @@ if (!skipTs) { |
74 | 74 | await syncTestPackageExports(); |
75 | 75 | await syncVersionsExport(); |
76 | 76 | } |
77 | | -await copySkillDocs(); |
| 77 | +await copyBundledDocs(); |
78 | 78 | await syncReadmeFromRoot(); |
79 | 79 |
|
80 | 80 | async function buildNapiBinding() { |
@@ -387,42 +387,27 @@ async function syncVersionsExport() { |
387 | 387 | } |
388 | 388 |
|
389 | 389 | /** |
390 | | - * Copy markdown doc files from the monorepo docs/ directory into skills/vite-plus/docs/, |
391 | | - * preserving the relative directory structure. This keeps stable file paths for |
392 | | - * skills routing and MCP page slugs. |
| 390 | + * Copy the docs source tree into docs/, preserving relative paths. |
| 391 | + * Generated VitePress output and installed dependencies are excluded so the package |
| 392 | + * only ships authoring sources and referenced assets. |
393 | 393 | */ |
394 | | -async function copySkillDocs() { |
395 | | - console.log('\nCopying skill docs...'); |
| 394 | +async function copyBundledDocs() { |
| 395 | + console.log('\nCopying bundled docs...'); |
396 | 396 |
|
397 | 397 | const docsSourceDir = join(projectDir, '..', '..', 'docs'); |
398 | | - const docsTargetDir = join(projectDir, 'skills', 'vite-plus', 'docs'); |
| 398 | + const docsTargetDir = join(projectDir, 'docs'); |
399 | 399 |
|
400 | 400 | if (!existsSync(docsSourceDir)) { |
401 | | - console.log(' Docs source directory not found, skipping skill docs copy'); |
| 401 | + console.log(' Docs source directory not found, skipping docs copy'); |
402 | 402 | return; |
403 | 403 | } |
404 | 404 |
|
405 | 405 | // Clean and recreate target directory |
406 | 406 | await rm(docsTargetDir, { recursive: true, force: true }); |
407 | 407 | await mkdir(docsTargetDir, { recursive: true }); |
408 | 408 |
|
409 | | - // Find all markdown files recursively and copy them with their relative paths. |
410 | | - const mdFiles = globSync('**/*.md', { cwd: docsSourceDir }).filter( |
411 | | - (f) => !f.includes('node_modules') && f !== 'index.md', |
412 | | - ); |
413 | | - // eslint-disable-next-line unicorn/no-array-sort -- sorted traversal keeps output deterministic |
414 | | - mdFiles.sort(); |
415 | | - |
416 | | - let copied = 0; |
417 | | - for (const relPath of mdFiles) { |
418 | | - const sourcePath = join(docsSourceDir, relPath); |
419 | | - const targetPath = join(docsTargetDir, relPath); |
420 | | - await mkdir(dirname(targetPath), { recursive: true }); |
421 | | - await copyFile(sourcePath, targetPath); |
422 | | - copied++; |
423 | | - } |
424 | | - |
425 | | - console.log(` Copied ${copied} doc files to skills/vite-plus/docs/ (with paths preserved)`); |
| 409 | + const copied = await copyDocsTree(docsSourceDir, docsTargetDir); |
| 410 | + console.log(` Copied ${copied} docs files to docs/ (with paths preserved)`); |
426 | 411 | } |
427 | 412 |
|
428 | 413 | async function syncReadmeFromRoot() { |
@@ -460,6 +445,49 @@ function splitReadme(content: string, label: string) { |
460 | 445 | }; |
461 | 446 | } |
462 | 447 |
|
| 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 | + |
463 | 491 | type ExportValue = |
464 | 492 | | string |
465 | 493 | | { |
|
0 commit comments