-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvite.config.js
More file actions
148 lines (139 loc) · 5.19 KB
/
Copy pathvite.config.js
File metadata and controls
148 lines (139 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vuetify from 'vite-plugin-vuetify'
import { viteSingleFile } from 'vite-plugin-singlefile'
import { execSync } from 'node:child_process'
// Read package version
import pkg from './package.json'
export default defineConfig(({ mode }) => {
const isVitest =
mode === 'test' ||
String(process.env.NODE_ENV || '').toLowerCase() === 'test' ||
String(process.env.VITEST || '').toLowerCase() === 'true' ||
String(process.env.npm_lifecycle_event || '').toLowerCase() === 'test' ||
process.argv.some(a => String(a || '').toLowerCase().includes('vitest'))
const isProdBuild = mode === 'production' && !isVitest
const env = loadEnv(mode, process.cwd(), '')
const gitlabTarget = String(env.VITE_GITLAB_PROXY_TARGET || '').trim()
const svnTarget = String(env.VITE_SVN_PROXY_TARGET || '').trim()
const proxy = {}
if (svnTarget) {
proxy['/svn'] = {
target: svnTarget,
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/svn/, '')
}
}
if (gitlabTarget) {
proxy['/gitlab'] = {
target: gitlabTarget,
changeOrigin: true,
secure: false,
rewrite: (path) => path.replace(/^\/gitlab/, '')
}
}
const safeExec = (cmd) => {
try {
return execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim()
} catch {
return ''
}
}
const gitCommit = safeExec('git rev-parse --short HEAD')
const gitBranch = safeExec('git rev-parse --abbrev-ref HEAD')
const gitRepo = safeExec('git config --get remote.origin.url')
const gitDirty = !!safeExec('git status --porcelain')
// GitHub Actions metadata (only present on runners)
const isGitHubActions = String(process.env.GITHUB_ACTIONS || '').toLowerCase() === 'true'
const ghRepo = String(process.env.GITHUB_REPOSITORY || '').trim()
const ghServerUrl = String(process.env.GITHUB_SERVER_URL || '').trim()
const ghRunId = String(process.env.GITHUB_RUN_ID || '').trim()
const ghRunNumber = String(process.env.GITHUB_RUN_NUMBER || '').trim()
const ghRunAttempt = String(process.env.GITHUB_RUN_ATTEMPT || '').trim()
const ghWorkflow = String(process.env.GITHUB_WORKFLOW || '').trim()
const ghRefName = String(process.env.GITHUB_REF_NAME || '').trim()
const ghSha = String(process.env.GITHUB_SHA || '').trim()
const buildTime = new Date().toISOString()
const versionInfo = {
version: pkg.version,
buildTime
}
const currentVersionPlugin = () => ({
name: 'gitlabviz-current-version',
transformIndexHtml(html) {
return html
.replaceAll('%APP_VERSION%', String(versionInfo.version || ''))
.replaceAll('%BUILD_TIME%', String(versionInfo.buildTime || ''))
.replaceAll('%IS_PROD_BUILD%', isProdBuild ? 'true' : 'false')
},
generateBundle() {
this.emitFile({
type: 'asset',
fileName: 'current_version.json',
source: JSON.stringify(versionInfo, null, 2) + '\n'
})
}
})
return {
base: './',
plugins: [
vue(),
// Tests run in Node; Vuetify auto-import injects component imports that pull in CSS (e.g. VIcon.css),
// which Node can't load. For unit tests we don't need Vuetify, so skip the plugin.
...(isVitest ? [] : [vuetify({ autoImport: true })]),
viteSingleFile(),
currentVersionPlugin()
],
define: {
'__APP_VERSION__': JSON.stringify(pkg.version),
'__BUILD_TIME__': JSON.stringify(buildTime),
'__GIT_COMMIT__': JSON.stringify(gitCommit || ''),
'__GIT_BRANCH__': JSON.stringify(gitBranch || ''),
'__GIT_REPO__': JSON.stringify(gitRepo || ''),
'__GIT_DIRTY__': JSON.stringify(gitDirty),
'__CI_PROVIDER__': JSON.stringify(isGitHubActions ? 'github' : ''),
'__GITHUB_REPOSITORY__': JSON.stringify(ghRepo),
'__GITHUB_SERVER_URL__': JSON.stringify(ghServerUrl),
'__GITHUB_RUN_ID__': JSON.stringify(ghRunId),
'__GITHUB_RUN_NUMBER__': JSON.stringify(ghRunNumber),
'__GITHUB_RUN_ATTEMPT__': JSON.stringify(ghRunAttempt),
'__GITHUB_WORKFLOW__': JSON.stringify(ghWorkflow),
'__GITHUB_REF_NAME__': JSON.stringify(ghRefName),
'__GITHUB_SHA__': JSON.stringify(ghSha)
},
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['src/vitest.setup.js'],
// Ensure jsdom has an origin so localStorage is available (localforage fallback driver).
environmentOptions: {
jsdom: {
url: 'http://localhost/'
}
},
coverage: {
provider: 'v8',
reporter: ['text', 'html'],
// Keep noise down: these are runtime/bootstrap files, not business logic.
exclude: [
'**/dist/**',
'**/electron/**',
'**/node_modules/**',
'src/main.js',
'src/vitest.setup.js',
// Large UI pages/components (not currently unit-tested)
'src/components/ConfigPage.vue',
'src/components/ChatToolsPage.vue',
'src/components/SvnLogDialog.vue',
'src/components/SidebarFilterControls.vue',
'src/components/sidebar/**',
'src/components/chatTools/**'
]
}
},
server: {
proxy
}
}
})