refactor: 템플릿에서 기본적으로 제공하고 있는 워크 플로우에 디자인과 라우팅 흡수

This commit is contained in:
donghyeon-ka
2026-09-23 12:42:10 +09:00
parent afde2b1da1
commit aaa384c145
181 changed files with 12553 additions and 5280 deletions
+7 -2
View File
@@ -82,11 +82,16 @@ async function listSourceFiles(directory: string): Promise<string[]> {
for (const entry of await readdir(directory, { withFileTypes: true })) {
const target = path.join(directory, entry.name);
if (entry.isDirectory()) result.push(...(await listSourceFiles(target)));
else if (/\.(?:ts|tsx|mts|cts)$/.test(entry.name)) result.push(target);
else if (/\.(?:ts|tsx|mts|cts|css)$/.test(entry.name)) result.push(target);
}
return result;
}
const rawPaletteSourceFiles = new Set([
...Object.values(tokenFiles),
"src/features/tech-log/presentation/styles/tech-log-theme.css",
]);
const sources = fixtureMode
? await listSourceFiles("tests/fixtures/design-system/forbidden")
: await listSourceFiles("src");
@@ -109,7 +114,7 @@ for (const file of sources) {
failures.push(`design-system deep import in ${file}`);
}
if (
!file.includes("src/presentation/design-system/tokens/") &&
!rawPaletteSourceFiles.has(file) &&
containsRawPaletteValue(source)
) {
failures.push(`raw palette value in ${file}`);
+23 -2
View File
@@ -2,6 +2,7 @@ import { mkdir, readFile, readdir } from "node:fs/promises";
import { i18nReportArtifactSchema } from "./contracts/release-artifacts.ts";
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
import { findTechLogBehavioralLiteralViolations } from "./lib/tech-log-i18n-policy.ts";
import path from "node:path";
import { EN_MESSAGES, KO_MESSAGES, MESSAGE_CATALOGS } from "../src/presentation/i18n/catalog.ts";
@@ -61,13 +62,17 @@ const commonDirectories = [
"src/presentation/routes",
"src/presentation/templates",
];
const sources = fixtureMode
const commonSources = fixtureMode
? await listSourceFiles("tests/fixtures/i18n/forbidden")
: (
await Promise.all(commonDirectories.map((directory) => listSourceFiles(directory)))
).flat();
const techLogSources = fixtureMode
? []
: await listSourceFiles("src/features/tech-log/presentation");
const sources = [...commonSources, ...techLogSources];
for (const file of sources) {
for (const file of commonSources) {
const source = await readFile(file, "utf8");
if (koreanLiteral.test(source)) {
failures.push(`hardcoded common user-facing locale literal in ${file}`);
@@ -80,6 +85,22 @@ for (const file of sources) {
}
}
for (const file of techLogSources) {
const source = await readFile(file, "utf8");
for (const violation of findTechLogBehavioralLiteralViolations(source)) {
failures.push(
`hardcoded TechLog behavioral locale literal in ${file}:${violation.kind}:${violation.text}`,
);
}
if (rawFailureRender.test(source)) {
failures.push(`raw backend/error message rendered in ${file}`);
}
if (source.includes("dangerouslySetInnerHTML")) {
failures.push(`untrusted HTML interpolation boundary in ${file}`);
}
}
const report = i18nReportArtifactSchema.parse({
schemaVersion: 1,
mode: fixtureMode ? "negative-fixture" : "source",
+65
View File
@@ -0,0 +1,65 @@
import fs from "node:fs";
import path from "node:path";
import { TECH_LOG_ROUTE_REGISTRY } from "../src/features/tech-log/contracts/tech-log-route-contract.ts";
const ROOT = path.resolve("src/features/tech-log/presentation");
const EXTENSIONS = new Set([".ts", ".tsx"]);
const TECH_LOG_ROUTE_ROOTS = new Set(
Object.values(TECH_LOG_ROUTE_REGISTRY)
.map(({ path: routePath }) => /^\/([^/:*]+)/.exec(routePath)?.[1])
.filter((segment): segment is string => Boolean(segment)),
);
type RouteLiteralViolation = Readonly<{
file: string;
line: number;
value: string;
}>;
const violations: RouteLiteralViolation[] = [];
function visitFile(filePath: string): void {
const source = fs.readFileSync(filePath, "utf8");
const withoutComments = source
.replace(/\/\*[\s\S]*?\*\//g, "")
.replace(/\/\/.*$/gm, "");
// Only strings beginning with a real TechLog route family are forbidden.
// Media paths (/media/...), Markdown command examples (/problem, /context),
// generated metadata paths, etc. are slash-prefixed strings too, but they
// are not navigation URLs and must not be classified as route duplication.
const pattern = /(["'`])(\/([A-Za-z0-9-]+))(?=[/?#"'`])/g;
for (const match of withoutComments.matchAll(pattern)) {
const routeRoot = match[3];
if (!routeRoot || !TECH_LOG_ROUTE_ROOTS.has(routeRoot)) continue;
const before = withoutComments.slice(0, match.index ?? 0);
const line = before.split("\n").length;
violations.push({
file: path.relative(process.cwd(), filePath),
line,
value: match[2] ?? match[0],
});
}
}
function walk(directory: string): void {
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
const filePath = path.join(directory, entry.name);
if (entry.isDirectory()) walk(filePath);
else if (EXTENSIONS.has(path.extname(entry.name))) visitFile(filePath);
}
}
walk(ROOT);
if (violations.length > 0) {
console.error("TechLog route source-of-truth check failed.");
console.error("Build internal TechLog URLs through publicRoutes/studioRoutes instead of presentation literals.");
for (const violation of violations) {
console.error(`- ${violation.file}:${violation.line} ${JSON.stringify(violation.value)}`);
}
process.exit(1);
}
console.log("TechLog route source-of-truth: PASS");
+75
View File
@@ -0,0 +1,75 @@
export type TechLogBehavioralLiteralViolation = Readonly<{
kind: string;
index: number;
text: string;
}>;
const korean = /[가-힣]/;
const behavioralState =
/(다시 시도|찾을 수 없|불러오지 못|못했습니다|만들지 못|없습니다|저장했습니다|삭제했습니다|게시했습니다|보관했습니다|저장 중|처리 중|불러오는 중|검증 중|생성 중|업로드 중|준비하고 있습니다)/;
function add(
violations: TechLogBehavioralLiteralViolation[],
kind: string,
index: number,
text: string,
): void {
const normalized = text.trim();
if (!korean.test(normalized)) return;
violations.push(Object.freeze({ kind, index, text: normalized }));
}
function literalBody(match: RegExpMatchArray, bodyIndex: number): string {
return match[bodyIndex] ?? "";
}
export function findTechLogBehavioralLiteralViolations(
source: string,
): readonly TechLogBehavioralLiteralViolation[] {
const violations: TechLogBehavioralLiteralViolation[] = [];
for (const match of source.matchAll(
/(?:\b[A-Za-z_$][\w$]*\.)?(?:setRequestAnnouncement|setNotice|setSuccess)\(\s*(["'`])([\s\S]*?)\1\s*\)/g,
)) {
const body = literalBody(match, 2);
add(violations, "announcement", match.index ?? 0, body);
}
for (const match of source.matchAll(
/\b(?:pendingLabel|closeLabel|resetLabel|clearLabel|actionLabel|confirmLabel)\s*=\s*(["'`])([\s\S]*?)\1/g,
)) {
const body = literalBody(match, 2);
add(violations, "action-prop", match.index ?? 0, body);
}
for (const match of source.matchAll(/<(Button|Link)\b[^>]*>\s*([^<{][^<{}]*?)\s*<\/\1>/g)) {
add(violations, "action-text", match.index ?? 0, match[2] ?? "");
}
for (const match of source.matchAll(
/(?:studioFailureMessage|managementFailureMessage)\([\s\S]{0,600}?,\s*(["'`])([\s\S]*?)\1\s*\)/g,
)) {
const body = literalBody(match, 2);
add(violations, "failure-fallback", match.index ?? 0, body);
}
for (const match of source.matchAll(
/<(h1|h2|h3|p|span)\b[^>]*>\s*([^<{][^<{}]*[가-힣][^<{}]*)\s*<\/\1>/g,
)) {
const body = (match[2] ?? "").trim();
if (behavioralState.test(body)) {
add(violations, "behavioral-surface", match.index ?? 0, body);
}
}
for (const match of source.matchAll(
/\b(?:title|description|message|empty|emptyLabel|error|errorLabel|loading|loadingLabel)\s*=\s*(["'`])([^"'`\n]*[가-힣][^"'`\n]*)\1/g,
)) {
const body = match[2] ?? "";
if (behavioralState.test(body)) {
add(violations, "behavioral-prop", match.index ?? 0, body);
}
}
return Object.freeze(violations);
}