- 지역 이야기(가요·인물·연표·엽서·퀴즈) 생성 경로: story_service · grounding/story · section_prompts. 지금까지 만들 자리가 없어 시안에만 손으로 넣은 3만 자였다 - 발행본 섹션: ItinerarySection · Carousel 레일 자동재생(use-rail-autoplay) · Festival · LocalGuide · Weather · Gallery · Header/Footer - 목업 payload 를 payloads-mockup/ 으로 분리 — 발행 대상과 섞이지 않게 - DB 새 구조 후속: site_payload · local_content_crud 조인 정리 · 테스트 - 마이그레이션 주석 축약: 9개 파일 합계 주석 비율 48% → 25%. 실측과 밟은 함정만 남기고 논증은 커밋 메시지로 옮겼다 검증: site·frontend 빌드 통과 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
72 lines
3.3 KiB
JavaScript
72 lines
3.3 KiB
JavaScript
/**
|
|
* 지역 이야기 프롬프트를 백엔드가 읽을 JSON 으로 뽑는다.
|
|
*
|
|
* npm run export:prompts (레포 루트에서)
|
|
*
|
|
* ★ 왜 산출물을 커밋하나
|
|
* 백엔드 컨테이너에는 node 도 워크스페이스도 없다. 빌드 때 뽑게 하면 파이썬 이미지에
|
|
* node 를 넣어야 하고, 그러면 두 런타임의 버전을 같이 맞춰야 한다. 산출물을 커밋해 두면
|
|
* 백엔드는 파일 하나만 읽으면 된다 — `scripts/export_openapi.py` 가 반대 방향으로 하는 것과 같다.
|
|
*
|
|
* ★ 산출물(`services/prompts/section_prompts.json`)은 손으로 고치지 않는다.
|
|
* 고칠 자리는 `shared/src/lib/section-prompts.ts` 하나다. 어긋나면 사장님이 복사해 가는
|
|
* 프롬프트와 서버가 도는 프롬프트가 갈린다.
|
|
*/
|
|
import {mkdirSync, writeFileSync} from 'node:fs';
|
|
import {dirname, resolve} from 'node:path';
|
|
import {fileURLToPath} from 'node:url';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const OUT = resolve(here, '../../backend/services/prompts/section_prompts.json');
|
|
|
|
// TS 를 그대로 읽을 수 없으므로 원문에서 값을 떼어 낸다 — 이 파일은 순수 상수 선언이라
|
|
// 파서를 세울 이유가 없다. 모양이 바뀌면 아래 검사에서 즉시 터진다.
|
|
const src = await import('node:fs').then((fs) =>
|
|
fs.readFileSync(resolve(here, '../src/lib/section-prompts.ts'), 'utf8'),
|
|
);
|
|
|
|
function block(name) {
|
|
const m = src.match(new RegExp(`export const ${name} = \`([\\s\\S]*?)\`;`));
|
|
if (!m) throw new Error(`${name} 를 찾지 못했다 — section-prompts.ts 의 모양이 바뀌었다`);
|
|
return m[1];
|
|
}
|
|
|
|
const rules = block('SECTION_PROMPT_RULES');
|
|
|
|
// ★ 목록을 여기 손으로 적지 않는다. 예전엔 배열 하나를 더 두었는데, `STORY_KINDS` 에
|
|
// 종류를 하나 늘려도 이 배열을 잊으면 **뽑히지 않는다** — 프론트는 아는데 서버만 모르는
|
|
// 상태가 되고, 그 종류의 탭은 영원히 빈칸이다(실측 2026-09-10, `daily`).
|
|
const kinds = (() => {
|
|
const m = src.match(/export const STORY_KINDS: StoryKind\[\] = \[([\s\S]*?)\];/);
|
|
if (!m) throw new Error('STORY_KINDS 를 찾지 못했다 — section-prompts.ts 의 모양이 바뀌었다');
|
|
return [...m[1].matchAll(/'([^']+)'/g)].map((hit) => hit[1]);
|
|
})();
|
|
const specs = {};
|
|
for (const kind of kinds) {
|
|
const body = src.match(new RegExp(`\\n ${kind}: \\{([\\s\\S]*?)\\n \\},`));
|
|
if (!body) throw new Error(`${kind} 항목을 찾지 못했다`);
|
|
const take = (field) => {
|
|
const m = body[1].match(new RegExp(`${field}: \`([\\s\\S]*?)\`,`));
|
|
if (!m) throw new Error(`${kind}.${field} 를 찾지 못했다`);
|
|
return m[1];
|
|
};
|
|
const label = body[1].match(/label: '([^']*)'/);
|
|
const maxItems = body[1].match(/maxItems: (\d+)/);
|
|
if (!label || !maxItems) throw new Error(`${kind} 의 label/maxItems 를 찾지 못했다`);
|
|
specs[kind] = {
|
|
kind,
|
|
label: label[1],
|
|
maxItems: Number(maxItems[1]),
|
|
task: take('task'),
|
|
rules: take('rules'),
|
|
};
|
|
}
|
|
|
|
mkdirSync(dirname(OUT), {recursive: true});
|
|
writeFileSync(
|
|
OUT,
|
|
`${JSON.stringify({_generated: 'npm run export:prompts — 손으로 고치지 않는다', rules, specs}, null, 2)}\n`,
|
|
'utf8',
|
|
);
|
|
console.log(`프롬프트 ${kinds.length}종 → ${OUT}`);
|