Files
TUIkit/docs/scripts/generate-terminal-data.ts
T
phranck bdb6d0c3f9 Chore: Fourth-pass optimization — bug fix, auto test counts, ESLint clean, constant extraction
- Fix: parseTerminalFormatting used undefined 'key' instead of 'partKey' (TS error)
- Fix: ESLint setState-in-effect errors (4→0) via cleanup patterns and hydration-sync
- Feat: Auto test/suite counts from Swift project at build-time (prebuild script + env vars)
- Refactor: ArchHighlight sub-component eliminates 4× duplicated pattern in page.tsx
- Refactor: BTN_PRIMARY/BTN_SECONDARY constants replace duplicated button classes
- Refactor: CRT geometry object centralizes repeated calc() layer positions
- Refactor: 13 magic numbers → named constants in TerminalScreen (timings, delays)
- Refactor: Icon component extended with custom SVG support (copy icon)
- Refactor: cloudGradient() helper replaces 6× duplicated radial-gradient strings
- Refactor: HIGHLIGHT constants object for syntax highlighter colors
- Refactor: text-glow CSS utility replaces duplicated textShadow inline styles
2026-02-02 15:38:33 +01:00

60 lines
2.3 KiB
TypeScript

/**
* Prebuild script — runs before `next build` via the `prebuild` npm script.
*
* 1. Generates terminal-data.ts from terminal-script.md
* 2. Counts Swift @Test and @Suite annotations to produce project-stats.json
* (consumed by next.config.ts as environment variables)
*/
import { parseTerminalScript } from "../lib/terminal-parser";
import { execSync } from "child_process";
import fs from "fs";
import path from "path";
// ── Terminal Data ─────────────────────────────────────────────────────
const script = parseTerminalScript();
const terminalOutputPath = path.join(process.cwd(), "app", "components", "terminal-data.ts");
const tsContent = `/**
* Auto-generated from terminal-script.md
* DO NOT EDIT THIS FILE DIRECTLY - Edit terminal-script.md instead
*/
import type { TerminalScript } from "../../lib/terminal-parser";
export const TERMINAL_SCRIPT: TerminalScript = ${JSON.stringify(script, null, 2)};
`;
fs.writeFileSync(terminalOutputPath, tsContent);
console.log("✓ Generated terminal-data.ts from terminal-script.md");
// ── Project Stats ─────────────────────────────────────────────────────
const projectRoot = path.resolve(process.cwd(), "..");
const testsDir = path.join(projectRoot, "Tests");
/**
* Count occurrences of a pattern in all .swift files under a directory.
* Falls back to 0 if the directory doesn't exist (e.g. CI without Swift source).
*/
function countPattern(directory: string, pattern: string): number {
if (!fs.existsSync(directory)) return 0;
try {
const output = execSync(
`grep -r '${pattern}' --include='*.swift' "${directory}" | wc -l`,
{ encoding: "utf-8" }
);
return parseInt(output.trim(), 10) || 0;
} catch {
return 0;
}
}
const testCount = countPattern(testsDir, "@Test\\b");
const suiteCount = countPattern(testsDir, "@Suite\\b");
const statsPath = path.join(process.cwd(), "project-stats.json");
fs.writeFileSync(statsPath, JSON.stringify({ testCount, suiteCount }, null, 2));
console.log(`✓ Generated project-stats.json (${testCount} tests, ${suiteCount} suites)`);