mirror of
https://github.com/lutinglt/gitea-github-theme.git
synced 2025-10-26 21:20:31 +00:00
版本号自动生成
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import { createGlobalTheme, globalStyle } from "@vanilla-extract/css";
|
import { createGlobalTheme, globalStyle } from "@vanilla-extract/css";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
import { otherThemeVars, themeInfoVars, themeVars } from "src/types/vars";
|
import { otherThemeVars, themeInfoVars, themeVars } from "src/types/vars";
|
||||||
import type { MapLeafNodes, WithOptionalLayer } from "./types";
|
import type { MapLeafNodes, WithOptionalLayer } from "./types";
|
||||||
|
|
||||||
@@ -32,9 +34,19 @@ const emoji = `
|
|||||||
.emoji[aria-label="musical notes"]
|
.emoji[aria-label="musical notes"]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// 版本号: 版本号.YYMMDD
|
||||||
|
const now = new Date();
|
||||||
|
const year = now.getFullYear().toString().slice(-2);
|
||||||
|
const month = (now.getMonth() + 1).toString().padStart(2, "0");
|
||||||
|
const day = now.getDate().toString().padStart(2, "0");
|
||||||
|
|
||||||
|
const pkgPath = path.join(__dirname, "../..", "package.json");
|
||||||
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
||||||
|
const version = `"${pkg.version}.${year}${month}${day}"`;
|
||||||
|
|
||||||
export function createTheme(theme: Theme): void {
|
export function createTheme(theme: Theme): void {
|
||||||
const isDarkTheme: boolean = JSON.parse(theme.isDarkTheme);
|
const isDarkTheme: boolean = JSON.parse(theme.isDarkTheme);
|
||||||
createGlobalTheme(":root", themeInfoVars, { version: "1.24.6.250909" });
|
createGlobalTheme(":root", themeInfoVars, { version });
|
||||||
createGlobalTheme(":root", themeVars, theme);
|
createGlobalTheme(":root", themeVars, theme);
|
||||||
createGlobalTheme(":root", otherThemeVars, {
|
createGlobalTheme(":root", otherThemeVars, {
|
||||||
border: { radius: "6px" },
|
border: { radius: "6px" },
|
||||||
|
|||||||
@@ -50,9 +50,9 @@ export function themeInput(outDir: string, themeDir: string, mode: string): { [k
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAutoThemeInfo(nameGroup: string[]): string {
|
function giteaThemeMetaInfo(nameGroup: string[]): string {
|
||||||
const displayName = nameGroup.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
const displayName = nameGroup.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
||||||
return `gitea-theme-meta-info { --theme-display-name: GitHub ${displayName};}`; // 不要省略分号, 也不要追加任何变量, 否则 Gitea 不识别
|
return `gitea-theme-meta-info{--theme-display-name:"GitHub ${displayName}";}`; // 不要省略分号, 也不要追加任何变量, 否则 Gitea 不识别
|
||||||
}
|
}
|
||||||
|
|
||||||
const prefix = "theme-github-";
|
const prefix = "theme-github-";
|
||||||
@@ -88,23 +88,22 @@ export function themePlugin(): Plugin {
|
|||||||
const originalFileName = value.originalFileNames.pop();
|
const originalFileName = value.originalFileNames.pop();
|
||||||
const type = value.type;
|
const type = value.type;
|
||||||
// 合并样式文件和主题信息
|
// 合并样式文件和主题信息
|
||||||
const meta = getAutoThemeInfo(key.split(".")[0].split("-"));
|
const meta = giteaThemeMetaInfo(key.split(".")[0].split("-"));
|
||||||
const source = `${meta}\n${value.source.toString()}${styles}`;
|
const source = `${meta}${value.source.toString()}${styles}`;
|
||||||
// 添加主题到输出
|
// 添加主题到输出
|
||||||
this.emitFile({ name, fileName, source, type, originalFileName });
|
this.emitFile({ name, fileName, source, type, originalFileName });
|
||||||
// 自动颜色主题
|
// 自动颜色主题
|
||||||
const nameGroup = key.split(".")[0].split("-");
|
const isDark = key.endsWith("dark.css");
|
||||||
const isDark = nameGroup.at(-1) === "dark";
|
|
||||||
const darkName = key.replace("light", "dark");
|
const darkName = key.replace("light", "dark");
|
||||||
const lightName = darkName.replace("dark", "light");
|
const lightName = darkName.replace("dark", "light");
|
||||||
const autoName = `${prefix}${darkName.replace("dark", "auto")}`;
|
|
||||||
const findTheme = isDark ? lightName : darkName;
|
const findTheme = isDark ? lightName : darkName;
|
||||||
if (findTheme in bundle) {
|
if (findTheme in bundle) {
|
||||||
|
const autoName = `${prefix}${darkName.replace("dark", "auto")}`;
|
||||||
const lightContent = `@import "./${prefix}${lightName}" (prefers-color-scheme: light);`;
|
const lightContent = `@import "./${prefix}${lightName}" (prefers-color-scheme: light);`;
|
||||||
const darkContent = `@import "./${prefix}${darkName}" (prefers-color-scheme: dark);`;
|
const darkContent = `@import "./${prefix}${darkName}" (prefers-color-scheme: dark);`;
|
||||||
const autoNameGroup = nameGroup.slice(0, -1);
|
const nameGroup = key.split(".")[0].split("-").slice(0, -1);
|
||||||
autoNameGroup.push("auto");
|
nameGroup.push("auto");
|
||||||
const metaInfo = getAutoThemeInfo(autoNameGroup);
|
const metaInfo = giteaThemeMetaInfo(nameGroup);
|
||||||
this.emitFile({
|
this.emitFile({
|
||||||
name: autoName,
|
name: autoName,
|
||||||
fileName: autoName,
|
fileName: autoName,
|
||||||
|
|||||||
Reference in New Issue
Block a user