|
1
|
import { promises as fs } from "fs" |
|
2
|
import path from "path" |
|
3
|
|
|
4
|
type Options = { |
|
5
|
srcDir: string |
|
6
|
destDir: string |
|
7
|
} |
|
8
|
|
|
9
|
async function copyDir(src: string, dest: string): Promise<void> { |
|
10
|
const entries = await fs.readdir(src, { withFileTypes: true }) |
|
11
|
|
|
12
|
await fs.mkdir(dest, { recursive: true }) |
|
13
|
|
|
14
|
for (const entry of entries) { |
|
15
|
const srcPath = path.join(src, entry.name) |
|
16
|
const destPath = path.join(dest, entry.name) |
|
17
|
|
|
18
|
if (entry.isDirectory()) { |
|
19
|
await copyDir(srcPath, destPath) |
|
20
|
} else if ( |
|
21
|
entry.isFile() && |
|
22
|
(entry.name === "page.mdx" || entry.name === "_md-content.mdx") |
|
23
|
) { |
|
24
|
await fs.copyFile(srcPath, destPath) |
|
25
|
} |
|
26
|
} |
|
27
|
} |
|
28
|
|
|
29
|
export async function copyMdxToPublic({ |
|
30
|
srcDir, |
|
31
|
destDir, |
|
32
|
}: Options): Promise<void> { |
|
33
|
await copyDir(srcDir, destDir) |
|
34
|
} |