mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 11:20:50 +08:00
Compare commits
1 Commits
v0.1.4-dev
...
v0.1.5-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7de5280824 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -27,6 +27,8 @@ jobs:
|
|||||||
|
|
||||||
- name: Build all-in-one HTML
|
- name: Build all-in-one HTML
|
||||||
run: npm run build
|
run: npm run build
|
||||||
|
env:
|
||||||
|
VERSION: ${{ github.ref_name }}
|
||||||
|
|
||||||
- name: Prepare release assets
|
- name: Prepare release assets
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
34
build.js
34
build.js
@@ -49,6 +49,35 @@ function escapeForStyle(content) {
|
|||||||
return content.replace(/<\/(style)/gi, '<\\/$1');
|
return content.replace(/<\/(style)/gi, '<\\/$1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getVersion() {
|
||||||
|
// 1. 优先从环境变量获取(GitHub Actions 会设置)
|
||||||
|
if (process.env.VERSION) {
|
||||||
|
return process.env.VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 尝试从 git tag 获取
|
||||||
|
try {
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
const gitTag = execSync('git describe --tags --exact-match 2>/dev/null || git describe --tags 2>/dev/null || echo ""', { encoding: 'utf8' }).trim();
|
||||||
|
if (gitTag) {
|
||||||
|
return gitTag;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('无法从 git 获取版本号');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 回退到 package.json
|
||||||
|
try {
|
||||||
|
const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
||||||
|
return 'v' + packageJson.version;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('无法从 package.json 读取版本号');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 最后使用默认值
|
||||||
|
return 'v0.0.0-dev';
|
||||||
|
}
|
||||||
|
|
||||||
function ensureDistDir() {
|
function ensureDistDir() {
|
||||||
if (fs.existsSync(distDir)) {
|
if (fs.existsSync(distDir)) {
|
||||||
fs.rmSync(distDir, { recursive: true, force: true });
|
fs.rmSync(distDir, { recursive: true, force: true });
|
||||||
@@ -83,6 +112,11 @@ function build() {
|
|||||||
const i18n = escapeForScript(readFile(sourceFiles.i18n));
|
const i18n = escapeForScript(readFile(sourceFiles.i18n));
|
||||||
const app = escapeForScript(readFile(sourceFiles.app));
|
const app = escapeForScript(readFile(sourceFiles.app));
|
||||||
|
|
||||||
|
// 获取版本号并替换
|
||||||
|
const version = getVersion();
|
||||||
|
console.log(`使用版本号: ${version}`);
|
||||||
|
html = html.replace(/__VERSION__/g, version);
|
||||||
|
|
||||||
html = html.replace(
|
html = html.replace(
|
||||||
'<link rel="stylesheet" href="styles.css">',
|
'<link rel="stylesheet" href="styles.css">',
|
||||||
`<style>
|
`<style>
|
||||||
|
|||||||
@@ -785,7 +785,7 @@
|
|||||||
<!-- 版本信息 -->
|
<!-- 版本信息 -->
|
||||||
<footer class="version-footer">
|
<footer class="version-footer">
|
||||||
<div class="version-info">
|
<div class="version-info">
|
||||||
<span data-i18n="footer.version">版本</span>: v0.1.3
|
<span data-i18n="footer.version">版本</span>: __VERSION__
|
||||||
<span class="separator">•</span>
|
<span class="separator">•</span>
|
||||||
<span data-i18n="footer.author">作者</span>: CLI Proxy API Team
|
<span data-i18n="footer.author">作者</span>: CLI Proxy API Team
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user