Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df0d7a4fe3 | ||
|
|
d7aa0f171d |
@@ -31,10 +31,7 @@ jobs:
|
||||
run: npm ci
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
AppVersion: ${{ github.ref_name }}
|
||||
SimApiVersion: ${{ github.ref_name }}
|
||||
run: npm run build
|
||||
run: npm run build -- --define SimApiVersion="'${{github.ref_name}}'"
|
||||
|
||||
- name: Publish to npm
|
||||
run: npm publish --access public
|
||||
+7
-3
@@ -108,17 +108,21 @@ npm run build
|
||||
|
||||
**版本号注入:**
|
||||
|
||||
版本号通过 `vite.core.config.ts` 的 `define` 配置注入,从环境变量读取:
|
||||
版本号通过 `vite.core.config.ts` 的 `define` 配置注入,从 npm config 读取:
|
||||
|
||||
```typescript
|
||||
define: {
|
||||
'AppVersion': JSON.stringify(process.env.AppVersion || process.env.npm_config_AppVersion || '0.0.0-develop'),
|
||||
'SimApiVersion': JSON.stringify(process.env.SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
||||
'AppVersion': JSON.stringify(process.env.npm_config_AppVersion || '0.0.0-develop'),
|
||||
'SimApiVersion': JSON.stringify(process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
||||
}
|
||||
```
|
||||
|
||||
**本地构建示例:**
|
||||
```bash
|
||||
# 通过 npm config 传递(推荐)
|
||||
npm run build -- --AppVersion=1.0.0 --SimApiVersion=1.0.0
|
||||
|
||||
# 或通过环境变量
|
||||
# Windows PowerShell
|
||||
$env:AppVersion="1.0.0"; $env:SimApiVersion="1.0.0"; npm run build
|
||||
|
||||
|
||||
@@ -338,6 +338,10 @@ npm link # 本地调试
|
||||
|
||||
**本地构建:**
|
||||
```bash
|
||||
# 通过 npm config 传递
|
||||
npm run build -- --AppVersion=1.0.0 --SimApiVersion=1.0.0
|
||||
|
||||
# 或设置环境变量后构建
|
||||
# Windows PowerShell
|
||||
$env:AppVersion="1.0.0"; $env:SimApiVersion="1.0.0"; npm run build
|
||||
|
||||
@@ -348,8 +352,8 @@ AppVersion=1.0.0 SimApiVersion=1.0.0 npm run build
|
||||
**CI/CD 构建版本号:**
|
||||
```bash
|
||||
env:
|
||||
AppVersion: ${VERSION}
|
||||
SimApiVersion: ${VERSION}
|
||||
AppVersion: ${{ github.ref_name }}
|
||||
SimApiVersion: ${{ github.ref_name }}
|
||||
```
|
||||
|
||||
如果未指定环境变量,版本号默认为 `0.0.0-develop`。
|
||||
|
||||
+4
-6
@@ -77,8 +77,6 @@ async function fetchPost<T = any>(
|
||||
|
||||
export class SimApiCore {
|
||||
debug: boolean = true
|
||||
uiAppVersion?: string
|
||||
|
||||
auth: SimApiAuthConfig = {
|
||||
token_name: 'simapi-auth-token',
|
||||
check_url: '/auth/check',
|
||||
@@ -210,8 +208,8 @@ export class SimApiCore {
|
||||
if (resp?.data) {
|
||||
const d = resp.data
|
||||
const versions: SimApiVersions = {
|
||||
uiApp: this.uiAppVersion ?? AppVersion,
|
||||
uiSimApi: SimApiVersion,
|
||||
uiApp: AppVersion ?? "0.0.0-develop",
|
||||
uiSimApi: SimApiVersion ?? "0.0.0-develop",
|
||||
apiApp: d.App?.split('+')[0] ?? '0.0.0',
|
||||
apiSimApi: d.SimApi?.split('+')[0] ?? '0.0.0',
|
||||
apiAppFull: d.App ?? '0.0.0',
|
||||
@@ -226,8 +224,8 @@ export class SimApiCore {
|
||||
// 版本获取失败返回默认值
|
||||
}
|
||||
return {
|
||||
uiApp: AppVersion,
|
||||
uiSimApi: SimApiVersion,
|
||||
uiApp: "0.0.0-develop",
|
||||
uiSimApi: "0.0.0-develop",
|
||||
apiApp: '0.0.0',
|
||||
apiSimApi: '0.0.0',
|
||||
apiAppFull: '0.0.0',
|
||||
|
||||
+5
-8
@@ -1,6 +1,6 @@
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
export default defineConfig(({ mode }) => ({
|
||||
export default defineConfig({
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
emptyOutDir: true,
|
||||
@@ -15,11 +15,8 @@ export default defineConfig(({ mode }) => ({
|
||||
}
|
||||
},
|
||||
define: {
|
||||
// 版本号从环境变量读取,构建时传入:
|
||||
// npm run build:core -- --AppVersion=1.2.3 --SimApiVersion=2.3.4
|
||||
// 或:
|
||||
// AppVersion=1.2.3 SimApiVersion=2.3.4 npm run build:core
|
||||
'AppVersion': JSON.stringify(process.env.AppVersion || process.env.npm_config_AppVersion || '0.0.0-develop'),
|
||||
'SimApiVersion': JSON.stringify(process.env.SimApiVersion || process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
||||
// SimApiVersion 由构建注入,AppVersion 留给调用方 APP 注入
|
||||
// 使用方式: npm run build -- --SimApiVersion=1.0.0
|
||||
'SimApiVersion': JSON.stringify(process.env.npm_config_SimApiVersion || '0.0.0-develop'),
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user