// supporters/(뷰성형외과 샘플) → templates/supporters-astro/ 내보내기. // 병원 고유 데이터(글·데이터 JSON·이미지·home_text·구조 기준선)를 빼고 빈 데이터 세트(scripts/template/data)를 넣는다. // 멱등: 대상 폴더를 지우고 다시 만든다. // node scripts/export_template.mjs [--dest ../templates/supporters-astro] import { cpSync, rmSync, mkdirSync, readdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs'; import { join, relative, sep } from 'node:path'; import { fileURLToPath } from 'node:url'; const SRC = fileURLToPath(new URL('../', import.meta.url)).replace(/\/$/, ''); const argDest = process.argv.indexOf('--dest'); const DEST = argDest > -1 ? process.argv[argDest + 1] : join(SRC, '..', 'templates', 'supporters-astro'); const TPL = join(SRC, 'scripts', 'template'); // 복사에서 뺄 경로 (SRC 기준 상대). 디렉터리는 하위 전부. const EXCLUDE = [ 'node_modules', 'dist', '.astro', '.vercel', 'docs', 'src/content/posts', 'public/img', 'scripts/home_text.txt', 'scripts/gate/layout-baseline.json', 'scripts/template', 'README.md', 'src/data/recoveryNotes.cache.json', // 시술 후 관리 안내 번역 캐시(병원별 산출물) ]; const excluded = (abs) => { const rel = relative(SRC, abs).split(sep).join('/'); return EXCLUDE.some((e) => rel === e || rel.startsWith(e + '/')); }; rmSync(DEST, { recursive: true, force: true }); mkdirSync(DEST, { recursive: true }); cpSync(SRC, DEST, { recursive: true, filter: (s) => !excluded(s) }); // 빈 데이터 세트 for (const f of readdirSync(join(TPL, 'data'))) cpSync(join(TPL, 'data', f), join(DEST, 'src', 'data', f)); mkdirSync(join(DEST, 'src', 'content', 'posts'), { recursive: true }); writeFileSync(join(DEST, 'src', 'content', 'posts', '.gitkeep'), ''); mkdirSync(join(DEST, 'public', 'img'), { recursive: true }); writeFileSync(join(DEST, 'public', 'img', '.gitkeep'), ''); writeFileSync(join(DEST, 'scripts', 'home_text.txt'), ''); cpSync(join(TPL, 'README.template.md'), join(DEST, 'README.md')); // 배포 주소 자리표시자 const sub = (rel, from, to) => { const p = join(DEST, rel); const s = readFileSync(p, 'utf8'); if (!s.includes(from)) throw new Error(`${rel}: "${from}" 없음`); writeFileSync(p, s.split(from).join(to)); }; sub('astro.config.mjs', 'https://view-supporters-sample.vercel.app', 'https://supporters-__CLINIC_ID__.vercel.app'); sub('vercel.json', 'https://view-supporters-sample.vercel.app', 'https://supporters-__CLINIC_ID__.vercel.app'); const pkgPath = join(DEST, 'package.json'); const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')); pkg.name = 'supporters-template'; writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); // 남은 병원 고유 문자열 검사 // 상호뿐 아니라 지명·건물 같은 병원 고유 사실도 잡는다. 상호만 찾으면 // "Sinnonhyeon Station Exit 3" 처럼 지명으로 적힌 사실이 그대로 템플릿에 남는다. const CLINIC_RE = /뷰성형외과|viewclinic|ViewclinicKR|안성민|o2oteam|View Plastic|Sinnonhyeon|Bongeunsa|Gimpo|신논현|봉은사|19-storey/; const leaks = []; const walk = (d) => { for (const f of readdirSync(d, { withFileTypes: true })) { const p = join(d, f.name); if (f.isDirectory()) { if (f.name !== 'node_modules') walk(p); } else if (/\.(astro|ts|mjs|json|css)$/.test(f.name) && !p.endsWith('export_template.mjs') && !p.includes('/scripts/gate/fixtures/') && CLINIC_RE.test(readFileSync(p, 'utf8'))) leaks.push(relative(DEST, p)); } }; walk(DEST); // 문장을 그리는 코드에 병원 고유 사실이 박히면 다른 병원 화면에 틀린 말이 나가므로 내보내기를 멈춘다. // 데이터(src/data)는 워커가 병원마다 갈아끼우고 빌드 도구(scripts)는 고객이 보지 않으므로 알림만 한다. const RENDER_RE = /^src\/(pages|layouts|components|lib)\//; const blocking = leaks.filter((f) => RENDER_RE.test(f)); const notes = leaks.filter((f) => !RENDER_RE.test(f)); if (notes.length) console.log('참고 · 병원 이름이 남은 파일(고객 화면 아님):\n ' + notes.join('\n ')); if (blocking.length) { console.error('고객 화면 코드에 병원 고유 사실이 남았습니다. 데이터에서 읽도록 고치세요:\n ' + blocking.join('\n ')); process.exit(1); } console.log(`템플릿 내보내기 완료: ${DEST}${existsSync(join(DEST, 'node_modules')) ? '' : ' (npm ci 필요)'}`);