mirror of
https://github.com/lutinglt/gitea-github-theme.git
synced 2026-10-28 09:44:55 +00:00
refactor code
This commit is contained in:
14 files changed
+79
-61
No files matched your search
@@ -4,5 +4,3 @@
|
||||
.github/** linguist-vendored
|
||||
.vscode/** linguist-generated
|
||||
gitea/** linguist-generated
|
||||
screenshots/** linguist-vendored
|
||||
scripts/** linguist-vendored
|
||||
Vendored
+8
-5
@@ -5,12 +5,15 @@ on:
|
||||
branches:
|
||||
- main
|
||||
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: dorny/paths-filter@v3
|
||||
- uses: actions/checkout@v6
|
||||
- uses: dorny/paths-filter@v4
|
||||
id: changes
|
||||
with:
|
||||
filters: |
|
||||
@@ -32,14 +35,14 @@ jobs:
|
||||
|
||||
- name: Upload css assets
|
||||
if: steps.build.outcome == 'success'
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: themes
|
||||
path: dist/*.css
|
||||
|
||||
- name: Upload templates assets
|
||||
if: steps.build.outcome == 'success'
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: templates
|
||||
path: templates
|
||||
@@ -52,7 +55,7 @@ jobs:
|
||||
|
||||
- name: Upload locales assets
|
||||
if: steps.locales.outcome =='success'
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: locales
|
||||
path: dist/options/locale
|
||||
Vendored
+4
-1
@@ -6,11 +6,14 @@ on:
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
- name: Build theme
|
||||
run: |
|
||||
npm install
|
||||
|
||||
+2
-2
@@ -24,12 +24,12 @@ import tseslint from "typescript-eslint";
|
||||
|
||||
export default defineConfig([
|
||||
{
|
||||
files: ["**/*.{js,mjs,cjs,ts,mts,cts}"],
|
||||
files: ["**/*.ts"],
|
||||
plugins: { js },
|
||||
extends: ["js/recommended"],
|
||||
languageOptions: {
|
||||
ecmaVersion: "latest",
|
||||
globals: globals.browser,
|
||||
globals: globals.node,
|
||||
},
|
||||
rules: {
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gitea-github-theme",
|
||||
"version": "1.26.2",
|
||||
"version": "1.26.1",
|
||||
"license": "Apache-2.0",
|
||||
"author": {
|
||||
"name": "lutinglt",
|
||||
@@ -12,9 +12,9 @@
|
||||
"lint": "eslint .",
|
||||
"format": "prettier --write .",
|
||||
"commit": "npm run lint && npm run format && npm run build",
|
||||
"version": "node scripts/version.cjs",
|
||||
"tr": "node scripts/translate.cjs",
|
||||
"update:gitea": "node scripts/update_gitea.cjs",
|
||||
"version": "node scripts/version.ts",
|
||||
"tr": "node scripts/translate.ts",
|
||||
"update:gitea": "node scripts/update_gitea.ts",
|
||||
"release": "npm run build && npm run tr",
|
||||
"install:clean": "npm cache clean --force && rm -rf node_modules package-lock.json && npm install"
|
||||
},
|
||||
|
||||
@@ -17,22 +17,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const child_process = require("child_process");
|
||||
import dotenv from "dotenv";
|
||||
import child_process from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { pkg, rootDir, setGlobalProxy } from "./utils.ts";
|
||||
|
||||
const { ProxyAgent, setGlobalDispatcher } = require("undici");
|
||||
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || process.env.ALL_PROXY;
|
||||
if (proxyUrl) {
|
||||
setGlobalDispatcher(new ProxyAgent(proxyUrl));
|
||||
}
|
||||
|
||||
const dotenv = require("dotenv");
|
||||
dotenv.config({ quiet: true });
|
||||
|
||||
const rootDir = path.join(__dirname, "..");
|
||||
const pkgPath = path.join(rootDir, "package.json");
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath));
|
||||
setGlobalProxy();
|
||||
|
||||
const githubSite = "https://raw.githubusercontent.com";
|
||||
const giteaRepo = "go-gitea/gitea";
|
||||
@@ -41,14 +33,12 @@ const githubTagPath = "refs/tags";
|
||||
const localePath = "options/locale";
|
||||
|
||||
const [major, minor, patch, tag = ""] = pkg.version.split(".");
|
||||
|
||||
console.log("Version:", pkg.version);
|
||||
let versionPath = "";
|
||||
if (tag.includes("rc") || patch.includes("latest")) {
|
||||
versionPath = `${githubBranchPath}/v${major}.${minor}`;
|
||||
} else {
|
||||
versionPath = `${githubTagPath}/v${major}.${minor}.${patch}`;
|
||||
}
|
||||
|
||||
const versionPath =
|
||||
tag.includes("rc") || patch.includes("latest")
|
||||
? `${githubBranchPath}/v${major}.${minor}`
|
||||
: `${githubTagPath}/v${major}.${minor}.${patch}`;
|
||||
|
||||
const githubUrl = `${githubSite}/${giteaRepo}/${versionPath}/${localePath}`;
|
||||
const locales = fs.readdirSync(path.join(rootDir, localePath)).filter(file => file.endsWith(".json"));
|
||||
@@ -63,7 +53,7 @@ const locales = fs.readdirSync(path.join(rootDir, localePath)).filter(file => fi
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
let content = await response.json();
|
||||
const content = (await response.json()) as Record<string, string>;
|
||||
if (locale.includes("zh-CN")) {
|
||||
for (const key of Object.keys(content)) {
|
||||
if (typeof content[key] === "string") {
|
||||
@@ -17,18 +17,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { pkg, rootDir, setGlobalProxy } from "./utils.ts";
|
||||
|
||||
const { ProxyAgent, setGlobalDispatcher } = require("undici");
|
||||
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || process.env.ALL_PROXY;
|
||||
if (proxyUrl) {
|
||||
setGlobalDispatcher(new ProxyAgent(proxyUrl));
|
||||
}
|
||||
|
||||
const rootDir = path.join(__dirname, "..");
|
||||
const pkgPath = path.join(rootDir, "package.json");
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath));
|
||||
setGlobalProxy();
|
||||
|
||||
const githubSite = "https://raw.githubusercontent.com";
|
||||
const giteaRepo = "go-gitea/gitea";
|
||||
@@ -40,8 +33,8 @@ const versionPath = `${githubTagPath}/v${major}.${minor}.${patch}`;
|
||||
const githubBaseUrl = `${githubSite}/${giteaRepo}/${versionPath}`;
|
||||
|
||||
// 递归读取所有子目录中的文件
|
||||
function readFilesRecursively(dir) {
|
||||
const results = [];
|
||||
function readFilesRecursively(dir: string) {
|
||||
const results: string[] = [];
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
for (const file of files) {
|
||||
@@ -72,7 +65,7 @@ const files = readFilesRecursively(localGiteaPath);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
let content = await response.text();
|
||||
const content = await response.text();
|
||||
fs.writeFileSync(path.join(localGiteaPath, file), content);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,34 @@
|
||||
/*!
|
||||
* 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 path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { ProxyAgent, setGlobalDispatcher } from "undici";
|
||||
import pkg from "../package.json" with { type: "json" };
|
||||
|
||||
export function setGlobalProxy() {
|
||||
const proxyUrl = process.env.HTTPS_PROXY || process.env.HTTP_PROXY || process.env.ALL_PROXY;
|
||||
if (proxyUrl) {
|
||||
setGlobalDispatcher(new ProxyAgent(proxyUrl));
|
||||
}
|
||||
}
|
||||
|
||||
export { pkg };
|
||||
export const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
export const rootDir = path.join(__dirname, "..");
|
||||
@@ -17,10 +17,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const pkgPath = path.join(__dirname, "..", "package.json");
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath));
|
||||
import { pkg } from "./utils.ts";
|
||||
|
||||
console.log(pkg.version);
|
||||
+1
-1
@@ -156,7 +156,7 @@ export function github2ThemeColor(githubColor: GitHubColor): ThemeColor {
|
||||
input: {
|
||||
text: themeVars.color.text.self,
|
||||
background: githubColor.bgColor.muted,
|
||||
toggleBackgound: githubColor.bgColor.inset,
|
||||
toggleBackground: githubColor.bgColor.inset,
|
||||
border: themeVars.color.light.border,
|
||||
},
|
||||
light: { self: themeVars.color.body, border: githubColor.borderColor.default },
|
||||
|
||||
@@ -27,6 +27,6 @@ type CSSVarName = `--${string}`;
|
||||
*/
|
||||
export function extractVarName(cssvar: CSSVarFunction): CSSVarName {
|
||||
assertVarName(cssvar);
|
||||
const var_name = cssvar.replace("var(--", "").replace(")", "");
|
||||
return `--${var_name}`;
|
||||
const varName = cssvar.replace("var(--", "").replace(")", "");
|
||||
return `--${varName}`;
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export const other = {
|
||||
/** 滑块按钮的背景色, 不能与背景色一致
|
||||
* @example 管理设置中启用/禁用头像
|
||||
*/
|
||||
toggleBackgound: "color-input-toggle-background",
|
||||
toggleBackground: "color-input-toggle-background",
|
||||
border: null,
|
||||
},
|
||||
light: {
|
||||
|
||||
@@ -128,7 +128,8 @@ export const clone = css`
|
||||
&:active {
|
||||
background: ${themeVars.github.control.transparent.bgColor.active};
|
||||
}
|
||||
}}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,5 +37,5 @@
|
||||
"themes": ["./themes"]
|
||||
}
|
||||
},
|
||||
"include": ["src", "styles", "themes", "vite.config.ts", "theme.config.ts", "eslint.config.ts"]
|
||||
"include": ["src", "styles", "themes", "scripts", "vite.config.ts", "theme.config.ts", "eslint.config.ts"]
|
||||
}
|
||||
Reference in new issue
Block a user