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
+67
-29
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]
|
||||
registry = "https://registry.npmjs.org"
|
||||
+11
-8
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"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": {
|
||||
"./theme.config.ts": "./theme.config.ts",
|
||||
"./core": "./src/index.ts",
|
||||
@@ -9,17 +19,10 @@
|
||||
"./themes": "./themes/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": {
|
||||
"lint": "bun eslint .",
|
||||
"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",
|
||||
"version": "bun scripts/version.ts",
|
||||
"release": "bun bundle && bun update:locale",
|
||||
|
||||
+17
-19
@@ -22,17 +22,19 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { PluginOption } from "vite";
|
||||
import type { GiteaThemeMeta, Theme } from "../core";
|
||||
import { createTheme, createThemeMetaInfo } from "../core";
|
||||
import { flushCSS } from "../core/css";
|
||||
import { createTheme, createThemeMetaInfo, flushCSS } from "../core";
|
||||
import { compileCSS } from "../vanilla-extract";
|
||||
import { buildFullDisplayName, buildFullThemeName } from "./utils";
|
||||
|
||||
type ThemeEntry = { themeName: string; meta: GiteaThemeMeta; theme: Theme };
|
||||
type AutoThemeEntry = { darkThemeName: string; lightThemeName: string };
|
||||
type ThemeEntry = {
|
||||
themeName: string;
|
||||
meta: GiteaThemeMeta;
|
||||
theme?: Theme;
|
||||
autoTheme?: { darkThemeName: string; lightThemeName: string };
|
||||
};
|
||||
|
||||
export function giteaGitHubTheme(): PluginOption {
|
||||
const themeEntries = new Array<ThemeEntry>();
|
||||
const autoThemeEntries = new Map<string, AutoThemeEntry>();
|
||||
const themeEntries: ThemeEntry[] = [];
|
||||
|
||||
return {
|
||||
name: "lutinglt-gitea-github-theme",
|
||||
@@ -41,7 +43,7 @@ export function giteaGitHubTheme(): PluginOption {
|
||||
// 1. 动态导入 theme.config.ts(Bun 原生 TS + exports 自引用)
|
||||
const themeConfig = (await import("@lutinglt/gitea-github-theme/theme.config.ts")).default;
|
||||
|
||||
// 2. 解析主题条目
|
||||
// 2. 解析主题条目 + 自动主题条目
|
||||
for (const themeSeries of themeConfig) {
|
||||
for (const [themeKeyName, entry] of Object.entries(themeSeries.themes)) {
|
||||
const name = entry.themeName ?? themeKeyName;
|
||||
@@ -57,25 +59,23 @@ export function giteaGitHubTheme(): PluginOption {
|
||||
theme: entry.theme,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 解析自动主题条目
|
||||
for (const themeSeries of themeConfig) {
|
||||
if (themeSeries.themes.dark && themeSeries.themes.light) {
|
||||
const themeName = buildFullThemeName(themeSeries, "auto");
|
||||
const meta: GiteaThemeMeta = {
|
||||
themeEntries.push({
|
||||
themeName,
|
||||
meta: {
|
||||
colorScheme: "auto",
|
||||
displayName: themeSeries.autoTheme?.displayName
|
||||
? `GitHub ${themeSeries.autoTheme.displayName}`
|
||||
: buildFullDisplayName(themeSeries, "auto"),
|
||||
colorblindType: themeSeries.autoTheme?.colorblindType,
|
||||
};
|
||||
autoThemeEntries.set(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 并输出
|
||||
for (const entry of themeEntries) {
|
||||
const { themeName, meta } = entry;
|
||||
const autoTheme = autoThemeEntries.get(themeName);
|
||||
const { themeName, meta, autoTheme } = entry;
|
||||
|
||||
const rawThemeCSS = Buffer.from(
|
||||
compileCSS(() => {
|
||||
createThemeMetaInfo(meta);
|
||||
// 自动主题不需要颜色变量, 只有 metaInfo
|
||||
if (!autoTheme) createTheme(entry.theme);
|
||||
if (entry.theme) createTheme(entry.theme);
|
||||
})
|
||||
);
|
||||
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
|
||||
* 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";
|
||||
|
||||
export default defineConfig({
|
||||
|
||||
Reference in new issue
Block a user