-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from otoyo/update-public-notion-copier
Update public-notion-copier
- Loading branch information
Showing
1 changed file
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!') | ||
}, | ||
}, | ||
}) |