`semantic.css`가 팔레트를 거치지 않은 날 `oklch()` 36개를 정의한다(밝은 테마의 focus와 info·success·warning·danger 세 쌍 13개, 어두운 테마 23개). `PRODUCT.md`와 `docs/styling/design-tokens.md`는 토큰이 primitive → semantic → component로 파생되고 팔레트는 `primitive.css`에 있다고 적는다. 그래서 팔레트만 바꿔 리브랜드하면 status 색, focus, 어두운 테마 대부분이 그대로다. 고른 방법: 36개 값을 그대로 `primitive.css` 팔레트로 옮기고 semantic은 `var()`로 읽는다. 색상 이름 무리(slate·night·blue·sky·green·amber·red)마다 밝기 순서로 단계 이름을 붙였다. 값은 바꾸지 않아 화면은 같다. 그리고 `check:design-system`에 UI-07을 더한다: semantic 선언값이 날 색(#hex, oklch·oklab·lch·lab·rgb·hsl·hwb·color 함수)이면 실패하고, 토큰과 위치를 말한다. 버린 대안: 문서에 "semantic은 역할 전용 값을 가질 수 있다"와 예외 목록을 적는 것(리브랜드 약속이 그대로 깨진다). 위험·한계: 다운스트림이 `semantic.css`에 날 색을 더해 두었으면 다음 동기화에서 UI-07이 그 줄을 이름과 함께 알린다. 팔레트로 옮기면 된다. UI-01 대비 계산은 var 사슬을 따라가므로 그대로 돈다. 검증: 규칙 단위 시험(거절 다섯·통과 셋·저장소 파일)과 check-design-system 연결 시험의 RED·GREEN, 시각 골든 불변은 desktop에서 돌려 PR 본문에 적는다. Refs: 1112/04-13
188 lines
6.2 KiB
TypeScript
188 lines
6.2 KiB
TypeScript
import { mkdir, readFile, readdir } from "node:fs/promises";
|
|
|
|
import { designSystemReportArtifactSchema } from "./contracts/release-artifacts.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
import path from "node:path";
|
|
|
|
import {
|
|
PRODUCT_LOADED_FONT_FAMILIES,
|
|
REQUIRED_COMPONENT_TOKENS,
|
|
REQUIRED_PRIMITIVE_TOKENS,
|
|
REQUIRED_SEMANTIC_TOKENS,
|
|
} from "../src/presentation/design-system/tokens/token-contract.ts";
|
|
import {
|
|
firstFontFamilyFailures,
|
|
focusContrastFailures,
|
|
hueMixFailures,
|
|
rawSemanticColourFailures,
|
|
unreadTokenFailures,
|
|
} from "./lib/design-system-rules.ts";
|
|
import { readCustomProperties } from "./lib/oklch-contrast.ts";
|
|
|
|
const fixtureMode = process.argv.includes("--fixture");
|
|
const failures: string[] = [];
|
|
const tokenFiles = {
|
|
primitive: "src/presentation/design-system/tokens/primitive.css",
|
|
semantic: "src/presentation/design-system/tokens/semantic.css",
|
|
component: "src/presentation/design-system/tokens/component.css",
|
|
};
|
|
const tokenLayers: Array<readonly [string, string, readonly string[]]> = [
|
|
["primitive", tokenFiles.primitive, REQUIRED_PRIMITIVE_TOKENS],
|
|
["semantic", tokenFiles.semantic, REQUIRED_SEMANTIC_TOKENS],
|
|
["component", tokenFiles.component, REQUIRED_COMPONENT_TOKENS],
|
|
];
|
|
|
|
for (const [layer, file, tokens] of tokenLayers) {
|
|
const source = await readFile(file, "utf8");
|
|
for (const token of tokens) {
|
|
if (!source.includes(`${token}:`)) {
|
|
failures.push(`${layer} token is missing: ${token}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// theme.css only imports the files under styles/theme/, so check them all.
|
|
const styleFiles = (
|
|
await readdir("src/presentation/styles", { recursive: true })
|
|
)
|
|
.filter((file) => file.endsWith(".css"))
|
|
.map((file) => path.join("src/presentation/styles", file));
|
|
const cssSources = await Promise.all(
|
|
[...Object.values(tokenFiles), ...styleFiles].map(
|
|
async (file) => ({ file, source: await readFile(file, "utf8") }),
|
|
),
|
|
);
|
|
const definitions = new Set(
|
|
cssSources.flatMap(({ source }) =>
|
|
[...source.matchAll(/(--[a-z0-9-]+)\s*:/g)].map((match) => match[1]),
|
|
),
|
|
);
|
|
for (const { file, source } of cssSources) {
|
|
for (const match of source.matchAll(/var\((--[a-z0-9-]+)/g)) {
|
|
if (!definitions.has(match[1])) {
|
|
failures.push(`${file} uses undefined token ${match[1]}`);
|
|
}
|
|
}
|
|
failures.push(...hueMixFailures({ file, source }));
|
|
}
|
|
|
|
const semanticSource = await readFile(tokenFiles.semantic, "utf8");
|
|
failures.push(
|
|
...rawSemanticColourFailures({ file: tokenFiles.semantic, source: semanticSource }),
|
|
);
|
|
const darkSource =
|
|
semanticSource.match(/:root\[data-theme="dark"\]\s*\{([\s\S]*?)\n\}/)?.[1] ??
|
|
"";
|
|
for (const token of [
|
|
"--color-surface",
|
|
"--color-surface-muted",
|
|
"--color-surface-elevated",
|
|
"--color-content",
|
|
"--color-content-muted",
|
|
"--color-content-inverse",
|
|
"--color-border",
|
|
"--color-border-strong",
|
|
"--color-action",
|
|
"--color-action-hover",
|
|
"--color-action-pressed",
|
|
"--color-danger",
|
|
"--color-focus",
|
|
"--color-disabled-content",
|
|
"--color-disabled-surface",
|
|
]) {
|
|
if (!darkSource.includes(`${token}:`)) {
|
|
failures.push(`dark theme token is missing: ${token}`);
|
|
}
|
|
}
|
|
const lightProperties = new Map([
|
|
...readCustomProperties(await readFile(tokenFiles.primitive, "utf8")),
|
|
...readCustomProperties(semanticSource.split(':root[data-theme="dark"]')[0]),
|
|
]);
|
|
const darkProperties = new Map([
|
|
...lightProperties,
|
|
...readCustomProperties(darkSource),
|
|
]);
|
|
// Rule texts and reasons: scripts/lib/design-system-rules.ts.
|
|
failures.push(
|
|
...focusContrastFailures("light", lightProperties),
|
|
...focusContrastFailures("dark", darkProperties),
|
|
...unreadTokenFailures(
|
|
REQUIRED_COMPONENT_TOKENS,
|
|
cssSources.filter(({ file }) => file !== tokenFiles.component),
|
|
),
|
|
...firstFontFamilyFailures(
|
|
lightProperties.get("--font-sans") ?? "",
|
|
cssSources,
|
|
PRODUCT_LOADED_FONT_FAMILIES,
|
|
),
|
|
);
|
|
|
|
const componentSource = await readFile(tokenFiles.component, "utf8");
|
|
if (!componentSource.includes("@media (forced-colors: active)")) {
|
|
failures.push("forced-colors token fallback is missing");
|
|
}
|
|
|
|
async function listSourceFiles(directory: string): Promise<string[]> {
|
|
const result: 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);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const sources = fixtureMode
|
|
? await listSourceFiles("tests/fixtures/design-system/forbidden")
|
|
: await listSourceFiles("src");
|
|
for (const file of sources) {
|
|
const source = await readFile(file, "utf8");
|
|
// Icon vendor and design-system deep imports are graph rules in
|
|
// .dependency-cruiser.json (check:architecture), which also sees relative,
|
|
// dynamic and type imports (12-08, 12-10).
|
|
if (
|
|
/from\s+["'](?:react-aria-components|@radix-ui\/[^"']+)["']/.test(source)
|
|
) {
|
|
failures.push(`direct headless vendor import in ${file}`);
|
|
}
|
|
if (
|
|
!file.includes("src/presentation/design-system/tokens/") &&
|
|
/(?:#[0-9a-f]{3,8}\b|oklch\(|rgba?\()/i.test(source)
|
|
) {
|
|
failures.push(`raw palette value in ${file}`);
|
|
}
|
|
if (
|
|
file.includes("tests/fixtures/design-system/forbidden") &&
|
|
source.includes("TOOLTIP_ONLY_REQUIRED_INFORMATION")
|
|
) {
|
|
failures.push(`tooltip-only required information in ${file}`);
|
|
}
|
|
}
|
|
|
|
const report = designSystemReportArtifactSchema.parse({
|
|
schemaVersion: 1,
|
|
mode: fixtureMode ? "negative-fixture" : "source",
|
|
checkedTokenCount:
|
|
REQUIRED_PRIMITIVE_TOKENS.length +
|
|
REQUIRED_SEMANTIC_TOKENS.length +
|
|
REQUIRED_COMPONENT_TOKENS.length,
|
|
failures,
|
|
passed: failures.length === 0,
|
|
});
|
|
await mkdir("artifacts/quality", { recursive: true });
|
|
await writeValidatedJsonArtifact({
|
|
path: fixtureMode
|
|
? "artifacts/quality/design-system-fixture.json"
|
|
: "artifacts/quality/design-system.json",
|
|
schema: designSystemReportArtifactSchema,
|
|
value: report,
|
|
});
|
|
|
|
if (failures.length > 0) {
|
|
process.stderr.write(`Design system contract failed:\n${failures.join("\n")}\n`);
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Design system contract: ${report.checkedTokenCount} tokens and headless vendor boundary PASS\n`,
|
|
);
|