feat: support build and runtime ENV configuration
This commit is contained in:
5 files changed
+62
-3
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { escapeHtml, pickPublicEnv, resolveSiteConfig } from '../src/site-config.js'
|
||||
import { escapeHtml, pickBuildEnv, pickPublicEnv, resolveSiteConfig } from '../src/site-config.js'
|
||||
|
||||
test('defaults preserve the original site and hide unconfigured registrations', () => {
|
||||
const config = resolveSiteConfig({}, {}, 2026)
|
||||
@@ -23,6 +23,28 @@ test('runtime overrides build values while keeping unspecified build settings',
|
||||
assert.equal(config.copyright, '© 2026 运行项目')
|
||||
})
|
||||
|
||||
test('Rainbond BUILD_VITE variables override build defaults and preserve empty values', () => {
|
||||
const config = pickBuildEnv({
|
||||
VITE_PROJECT_NAME: '本地默认名称',
|
||||
VITE_ICP_NUMBER: '本地备案号',
|
||||
BUILD_VITE_PROJECT_NAME: 'Rainbond 项目',
|
||||
BUILD_VITE_ICP_NUMBER: '',
|
||||
BUILD_VITE_OTHER_SECRET: 'not-public',
|
||||
})
|
||||
assert.deepEqual(config, { VITE_PROJECT_NAME: 'Rainbond 项目', VITE_ICP_NUMBER: '' })
|
||||
assert.equal(resolveSiteConfig(config).title, 'Rainbond 项目 · 美好的事,即将发生')
|
||||
assert.equal(resolveSiteConfig(config).icpNumber, '')
|
||||
})
|
||||
|
||||
test('Rainbond build values do not override runtime VITE settings', () => {
|
||||
const buildEnv = pickBuildEnv({ BUILD_VITE_PROJECT_NAME: '构建名称' })
|
||||
const config = resolveSiteConfig(buildEnv, {
|
||||
VITE_PROJECT_NAME: '运行名称',
|
||||
BUILD_VITE_PROJECT_NAME: '旧构建名称',
|
||||
})
|
||||
assert.equal(config.projectName, '运行名称')
|
||||
})
|
||||
|
||||
test('empty runtime values hide optional build content and fall back for required text', () => {
|
||||
const config = resolveSiteConfig({
|
||||
VITE_PROJECT_NAME: '构建项目',
|
||||
|
||||
Reference in new issue
Block a user