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