import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const targetDir = path.resolve(__dirname, "../shared"); const sourceDir = path.resolve(__dirname, "../../shared"); if (!fs.existsSync(sourceDir)) { console.log( "[sync-shared] skip: repo shared/ not found, keep downLoadServer/shared as deployed copy", ); process.exit(0); } fs.mkdirSync(targetDir, { recursive: true }); const sourceFiles = fs .readdirSync(sourceDir) .filter((name) => !name.startsWith(".") && fs.statSync(path.join(sourceDir, name)).isFile()); sourceFiles.forEach((name) => { fs.copyFileSync(path.join(sourceDir, name), path.join(targetDir, name)); }); const stale = fs .readdirSync(targetDir) .filter((name) => !name.startsWith(".") && !sourceFiles.includes(name)); stale.forEach((name) => { fs.unlinkSync(path.join(targetDir, name)); }); console.log( `[sync-shared] copied ${sourceFiles.length} files to downLoadServer/shared${ stale.length ? `, removed ${stale.length} stale` : "" }`, ); sourceFiles.forEach((name) => console.log(` - ${name}`));