diff --git a/src/integrations/public-notion-copier.ts b/src/integrations/public-notion-copier.ts index 2fcf2d3ec..7401d0a41 100644 --- a/src/integrations/public-notion-copier.ts +++ b/src/integrations/public-notion-copier.ts @@ -1,17 +1,40 @@ import fs from 'node:fs' -import { execSync } from 'child_process' +import path from 'path' +import { fileURLToPath } from 'url' import type { AstroIntegration } from 'astro' +const copyFiles = (src: string, dest: string) => { + const entries = fs.readdirSync(src, { withFileTypes: true }) + if (!fs.existsSync(dest)) { + fs.mkdirSync(dest, { recursive: true }) + } + + for (const entry of entries) { + const srcPath = path.join(src, entry.name) + const destPath = path.join(dest, entry.name) + + if (entry.isDirectory()) { + copyFiles(srcPath, destPath) + } else { + if (!fs.existsSync(destPath)) { + fs.copyFileSync(srcPath, destPath) + } + } + } +} + export default (): AstroIntegration => ({ name: 'public-notion-copier', hooks: { 'astro:build:done': async ({ dir }) => { - const outDir = new URL('notion', dir.href).pathname + const dirPath = fileURLToPath(dir) + const outDir = path.join(dirPath, 'notion') if (!fs.existsSync(outDir)) { - fs.mkdirSync(outDir) + fs.mkdirSync(outDir, { recursive: true }) } - execSync(`cp -n -r public/notion/* ${outDir} || true`) + copyFiles('public/notion', outDir) + console.log('Finished copying notion files to root!') }, }, })