|
| 1 | +import { access, cp, mkdir, readdir, rm, writeFile } from 'node:fs/promises'; |
| 2 | +import path from 'node:path'; |
| 3 | +import { fileURLToPath } from 'node:url'; |
| 4 | + |
| 5 | +const __filename = fileURLToPath(import.meta.url); |
| 6 | +const __dirname = path.dirname(__filename); |
| 7 | + |
| 8 | +const docsRoot = path.resolve(__dirname, '..'); |
| 9 | +const repoRoot = path.resolve(docsRoot, '..', '..'); |
| 10 | + |
| 11 | +const docsDistPath = path.join(docsRoot, 'app', '.vitepress', 'dist'); |
| 12 | +const newDocsOutPath = path.join(repoRoot, 'packages', 'newdocs', 'out'); |
| 13 | +const newDocsOutWithBasePath = path.join(newDocsOutPath, 'new'); |
| 14 | +const sitePath = path.join(repoRoot, 'site'); |
| 15 | + |
| 16 | +const exists = async (targetPath) => { |
| 17 | + try { |
| 18 | + await access(targetPath); |
| 19 | + return true; |
| 20 | + } catch { |
| 21 | + return false; |
| 22 | + } |
| 23 | +}; |
| 24 | + |
| 25 | +const copyDirectoryContents = async (sourceDir, targetDir) => { |
| 26 | + await mkdir(targetDir, { recursive: true }); |
| 27 | + |
| 28 | + const entries = await readdir(sourceDir, { withFileTypes: true }); |
| 29 | + for (const entry of entries) { |
| 30 | + const from = path.join(sourceDir, entry.name); |
| 31 | + const to = path.join(targetDir, entry.name); |
| 32 | + await cp(from, to, { recursive: true }); |
| 33 | + } |
| 34 | +}; |
| 35 | + |
| 36 | +await rm(sitePath, { recursive: true, force: true }); |
| 37 | +await copyDirectoryContents(docsDistPath, sitePath); |
| 38 | + |
| 39 | +if (await exists(newDocsOutWithBasePath)) { |
| 40 | + await copyDirectoryContents(newDocsOutPath, sitePath); |
| 41 | +} else { |
| 42 | + const siteNewPath = path.join(sitePath, 'new'); |
| 43 | + await copyDirectoryContents(newDocsOutPath, siteNewPath); |
| 44 | +} |
| 45 | + |
| 46 | +await writeFile(path.join(sitePath, '.nojekyll'), ''); |
0 commit comments