Skip to content

Commit 734c758

Browse files
authored
Merge pull request #206 from otoyo/update-public-notion-copier
Update public-notion-copier
2 parents a73ab65 + 7ac20b8 commit 734c758

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
import fs from 'node:fs'
2-
import { execSync } from 'child_process'
2+
import path from 'path'
3+
import { fileURLToPath } from 'url'
34
import type { AstroIntegration } from 'astro'
45

6+
const copyFiles = (src: string, dest: string) => {
7+
const entries = fs.readdirSync(src, { withFileTypes: true })
8+
if (!fs.existsSync(dest)) {
9+
fs.mkdirSync(dest, { recursive: true })
10+
}
11+
12+
for (const entry of entries) {
13+
const srcPath = path.join(src, entry.name)
14+
const destPath = path.join(dest, entry.name)
15+
16+
if (entry.isDirectory()) {
17+
copyFiles(srcPath, destPath)
18+
} else {
19+
if (!fs.existsSync(destPath)) {
20+
fs.copyFileSync(srcPath, destPath)
21+
}
22+
}
23+
}
24+
}
25+
526
export default (): AstroIntegration => ({
627
name: 'public-notion-copier',
728
hooks: {
829
'astro:build:done': async ({ dir }) => {
9-
const outDir = new URL('notion', dir.href).pathname
30+
const dirPath = fileURLToPath(dir)
31+
const outDir = path.join(dirPath, 'notion')
1032
if (!fs.existsSync(outDir)) {
11-
fs.mkdirSync(outDir)
33+
fs.mkdirSync(outDir, { recursive: true })
1234
}
1335

14-
execSync(`cp -n -r public/notion/* ${outDir} || true`)
36+
copyFiles('public/notion', outDir)
37+
console.log('Finished copying notion files to root!')
1538
},
1639
},
1740
})

0 commit comments

Comments
 (0)