99 lines
3.2 KiB
TypeScript
99 lines
3.2 KiB
TypeScript
import { access, readFile, readdir } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
|
|
const root = process.cwd();
|
|
const generatedPath = join(root, "dist", "theme-github-dev.css");
|
|
const generatedDarkPath = join(root, "dist", "theme-github-dev-dark.css");
|
|
const themeSourceDir = join(root, "themes", "github-light");
|
|
const darkThemeSourceDir = join(root, "themes", "github-dark");
|
|
const tokenSourceDir = join(root, "styles", "tokens");
|
|
const packageJson = JSON.parse(await readFile(join(root, "package.json"), "utf8")) as { version?: string };
|
|
const githubThemePackageJson = JSON.parse(
|
|
await readFile(join(root, ".github-theme", "package.json"), "utf8"),
|
|
) as { version?: string };
|
|
const generated = await readFile(generatedPath, "utf8");
|
|
const generatedDark = await readFile(generatedDarkPath, "utf8");
|
|
|
|
const requiredSnippets = [
|
|
"--theme-display-name: GitHub Light",
|
|
'--theme-version: "1.26.1',
|
|
"--color-primary: #0969da",
|
|
"--github-bgColor-accent-emphasis: #0969da",
|
|
".ui.primary.button",
|
|
".repository.file.list #repo-files-table",
|
|
".page-content.user.signin",
|
|
".gitea-github-theme-templates",
|
|
];
|
|
|
|
const requiredDarkSnippets = [
|
|
'--theme-display-name: "GitHub Dark"',
|
|
'--theme-color-scheme: "dark"',
|
|
"--is-dark-theme: true",
|
|
"--color-body: #0d1117",
|
|
"--color-text: #e6edf3",
|
|
"--github-bgColor-accent-emphasis: #1f6feb",
|
|
".ui.primary.button",
|
|
];
|
|
|
|
if (packageJson.version !== "1.26.1") {
|
|
throw new Error(`project version must be 1.26.1, got ${packageJson.version}`);
|
|
}
|
|
|
|
if (githubThemePackageJson.version !== "1.26.1") {
|
|
throw new Error(`.github-theme version must be 1.26.1, got ${githubThemePackageJson.version}`);
|
|
}
|
|
|
|
await access(join(root, "themes", "index.ts"));
|
|
await access(join(themeSourceDir, "index.ts"));
|
|
await access(join(darkThemeSourceDir, "index.ts"));
|
|
|
|
const tokenFiles = await readdir(tokenSourceDir);
|
|
const themeFiles = await readdir(themeSourceDir);
|
|
const darkThemeFiles = await readdir(darkThemeSourceDir);
|
|
const allowedTokenFiles = new Set(["derived.ts", "index.ts", "render-theme.ts", "required.ts"]);
|
|
|
|
const unexpectedTokenFiles = tokenFiles.filter((file) => !allowedTokenFiles.has(file));
|
|
|
|
if (unexpectedTokenFiles.length > 0) {
|
|
throw new Error(
|
|
`styles/tokens must only contain theme rendering helpers, got: ${unexpectedTokenFiles.join(", ")}`,
|
|
);
|
|
}
|
|
|
|
for (const file of [
|
|
"theme-meta.ts",
|
|
"core.ts",
|
|
"console.ts",
|
|
"named-colors.ts",
|
|
"ansi-colors.ts",
|
|
"diff-colors.ts",
|
|
"semantic-colors.ts",
|
|
"github-colors.ts",
|
|
"syntax-colors.ts",
|
|
"target-colors.ts",
|
|
]) {
|
|
if (!themeFiles.includes(file)) {
|
|
throw new Error(`themes/github-light is missing theme source file: ${file}`);
|
|
}
|
|
}
|
|
|
|
for (const file of ["theme-meta.ts", "core.ts", "github-colors.ts", "target-colors.ts", "index.ts"]) {
|
|
if (!darkThemeFiles.includes(file)) {
|
|
throw new Error(`themes/github-dark is missing theme source file: ${file}`);
|
|
}
|
|
}
|
|
|
|
for (const snippet of requiredSnippets) {
|
|
if (!generated.includes(snippet)) {
|
|
throw new Error(`generated theme is missing migrated GitHub theme snippet: ${snippet}`);
|
|
}
|
|
}
|
|
|
|
for (const snippet of requiredDarkSnippets) {
|
|
if (!generatedDark.includes(snippet)) {
|
|
throw new Error(`generated dark theme is missing snippet: ${snippet}`);
|
|
}
|
|
}
|
|
|
|
console.log("generated GitHub theme migration verified");
|