mirror of
https://github.com/lutinglt/gitea-github-theme.git
synced 2026-10-28 09:44:55 +00:00
organize code
This commit is contained in:
5 files changed
+74
-36
No files matched your search
+19
-1
@@ -1,3 +1,21 @@
|
|||||||
# bunfig.toml
|
#
|
||||||
|
# Copyright (c) https://github.com/lutinglt
|
||||||
|
#
|
||||||
|
# See the NOTICE file distributed with this work for additional
|
||||||
|
# information regarding copyright ownership.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
[install]
|
[install]
|
||||||
registry = "https://registry.npmjs.org"
|
registry = "https://registry.npmjs.org"
|
||||||
+11
-8
@@ -1,5 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@lutinglt/gitea-github-theme",
|
"name": "@lutinglt/gitea-github-theme",
|
||||||
|
"version": "1.26.2",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"author": {
|
||||||
|
"name": "lutinglt",
|
||||||
|
"url": "https://github.com/lutinglt"
|
||||||
|
},
|
||||||
|
"type": "module",
|
||||||
|
"engines": {
|
||||||
|
"bun": ">=1.3.14"
|
||||||
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
"./theme.config.ts": "./theme.config.ts",
|
"./theme.config.ts": "./theme.config.ts",
|
||||||
"./core": "./src/index.ts",
|
"./core": "./src/index.ts",
|
||||||
@@ -9,17 +19,10 @@
|
|||||||
"./themes": "./themes/index.ts",
|
"./themes": "./themes/index.ts",
|
||||||
"./primer": "./primer/index.ts"
|
"./primer": "./primer/index.ts"
|
||||||
},
|
},
|
||||||
"version": "1.26.2",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"author": {
|
|
||||||
"name": "lutinglt",
|
|
||||||
"url": "https://github.com/lutinglt"
|
|
||||||
},
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "bun eslint .",
|
"lint": "bun eslint .",
|
||||||
"format": "bun prettier --write .",
|
"format": "bun prettier --write .",
|
||||||
"bundle": "tsgo -b -v && bunx --bun vite build",
|
"bundle": "tsgo -b && bunx --bun vite build",
|
||||||
"commit": "bun format && bun lint && bun test && bun bundle",
|
"commit": "bun format && bun lint && bun test && bun bundle",
|
||||||
"version": "bun scripts/version.ts",
|
"version": "bun scripts/version.ts",
|
||||||
"release": "bun bundle && bun update:locale",
|
"release": "bun bundle && bun update:locale",
|
||||||
|
|||||||
+24
-26
@@ -22,17 +22,19 @@ import fs from "node:fs";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import type { PluginOption } from "vite";
|
import type { PluginOption } from "vite";
|
||||||
import type { GiteaThemeMeta, Theme } from "../core";
|
import type { GiteaThemeMeta, Theme } from "../core";
|
||||||
import { createTheme, createThemeMetaInfo } from "../core";
|
import { createTheme, createThemeMetaInfo, flushCSS } from "../core";
|
||||||
import { flushCSS } from "../core/css";
|
|
||||||
import { compileCSS } from "../vanilla-extract";
|
import { compileCSS } from "../vanilla-extract";
|
||||||
import { buildFullDisplayName, buildFullThemeName } from "./utils";
|
import { buildFullDisplayName, buildFullThemeName } from "./utils";
|
||||||
|
|
||||||
type ThemeEntry = { themeName: string; meta: GiteaThemeMeta; theme: Theme };
|
type ThemeEntry = {
|
||||||
type AutoThemeEntry = { darkThemeName: string; lightThemeName: string };
|
themeName: string;
|
||||||
|
meta: GiteaThemeMeta;
|
||||||
|
theme?: Theme;
|
||||||
|
autoTheme?: { darkThemeName: string; lightThemeName: string };
|
||||||
|
};
|
||||||
|
|
||||||
export function giteaGitHubTheme(): PluginOption {
|
export function giteaGitHubTheme(): PluginOption {
|
||||||
const themeEntries = new Array<ThemeEntry>();
|
const themeEntries: ThemeEntry[] = [];
|
||||||
const autoThemeEntries = new Map<string, AutoThemeEntry>();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "lutinglt-gitea-github-theme",
|
name: "lutinglt-gitea-github-theme",
|
||||||
@@ -41,7 +43,7 @@ export function giteaGitHubTheme(): PluginOption {
|
|||||||
// 1. 动态导入 theme.config.ts(Bun 原生 TS + exports 自引用)
|
// 1. 动态导入 theme.config.ts(Bun 原生 TS + exports 自引用)
|
||||||
const themeConfig = (await import("@lutinglt/gitea-github-theme/theme.config.ts")).default;
|
const themeConfig = (await import("@lutinglt/gitea-github-theme/theme.config.ts")).default;
|
||||||
|
|
||||||
// 2. 解析主题条目
|
// 2. 解析主题条目 + 自动主题条目
|
||||||
for (const themeSeries of themeConfig) {
|
for (const themeSeries of themeConfig) {
|
||||||
for (const [themeKeyName, entry] of Object.entries(themeSeries.themes)) {
|
for (const [themeKeyName, entry] of Object.entries(themeSeries.themes)) {
|
||||||
const name = entry.themeName ?? themeKeyName;
|
const name = entry.themeName ?? themeKeyName;
|
||||||
@@ -57,25 +59,23 @@ export function giteaGitHubTheme(): PluginOption {
|
|||||||
theme: entry.theme,
|
theme: entry.theme,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 解析自动主题条目
|
|
||||||
for (const themeSeries of themeConfig) {
|
|
||||||
if (themeSeries.themes.dark && themeSeries.themes.light) {
|
if (themeSeries.themes.dark && themeSeries.themes.light) {
|
||||||
const themeName = buildFullThemeName(themeSeries, "auto");
|
const themeName = buildFullThemeName(themeSeries, "auto");
|
||||||
const meta: GiteaThemeMeta = {
|
themeEntries.push({
|
||||||
colorScheme: "auto",
|
themeName,
|
||||||
displayName: themeSeries.autoTheme?.displayName
|
meta: {
|
||||||
? `GitHub ${themeSeries.autoTheme.displayName}`
|
colorScheme: "auto",
|
||||||
: buildFullDisplayName(themeSeries, "auto"),
|
displayName: themeSeries.autoTheme?.displayName
|
||||||
colorblindType: themeSeries.autoTheme?.colorblindType,
|
? `GitHub ${themeSeries.autoTheme.displayName}`
|
||||||
};
|
: buildFullDisplayName(themeSeries, "auto"),
|
||||||
autoThemeEntries.set(themeName, {
|
colorblindType: themeSeries.autoTheme?.colorblindType,
|
||||||
darkThemeName: themeSeries.themes.dark.themeName!,
|
},
|
||||||
lightThemeName: themeSeries.themes.light.themeName!,
|
autoTheme: {
|
||||||
|
darkThemeName: themeSeries.themes.dark.themeName!,
|
||||||
|
lightThemeName: themeSeries.themes.light.themeName!,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
// 将自动主题也加入 themeEntries 以便编译 CSS
|
|
||||||
themeEntries.push({ themeName, meta, theme: null as unknown as Theme });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,14 +101,12 @@ export function giteaGitHubTheme(): PluginOption {
|
|||||||
|
|
||||||
// 编译每个主题的 CSS 并输出
|
// 编译每个主题的 CSS 并输出
|
||||||
for (const entry of themeEntries) {
|
for (const entry of themeEntries) {
|
||||||
const { themeName, meta } = entry;
|
const { themeName, meta, autoTheme } = entry;
|
||||||
const autoTheme = autoThemeEntries.get(themeName);
|
|
||||||
|
|
||||||
const rawThemeCSS = Buffer.from(
|
const rawThemeCSS = Buffer.from(
|
||||||
compileCSS(() => {
|
compileCSS(() => {
|
||||||
createThemeMetaInfo(meta);
|
createThemeMetaInfo(meta);
|
||||||
// 自动主题不需要颜色变量, 只有 metaInfo
|
if (entry.theme) createTheme(entry.theme);
|
||||||
if (!autoTheme) createTheme(entry.theme);
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const themeCSS = transform({ filename: themeName + ".css", code: rawThemeCSS, minify: true }).code.toString();
|
const themeCSS = transform({ filename: themeName + ".css", code: rawThemeCSS, minify: true }).code.toString();
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* Copyright (c) https://com/lutinglt
|
* Copyright (c) https://github.com/lutinglt
|
||||||
*
|
*
|
||||||
* See the NOTICE file distributed with this work for additional
|
* See the NOTICE file distributed with this work for additional
|
||||||
* information regarding copyright ownership.
|
* information regarding copyright ownership.
|
||||||
|
|||||||
@@ -1,3 +1,22 @@
|
|||||||
|
/*!
|
||||||
|
* Copyright (c) https://github.com/lutinglt
|
||||||
|
*
|
||||||
|
* See the NOTICE file distributed with this work for additional
|
||||||
|
* information regarding copyright ownership.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
import { defineConfig } from "vitest/config";
|
import { defineConfig } from "vitest/config";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
|||||||
Reference in new issue
Block a user