Defining vite env vars with git info

This commit is contained in:
Eric van der Vlist 2023-03-07 20:04:06 +01:00
parent da76e30fc4
commit 7997138c5e
2 changed files with 97 additions and 80 deletions

View File

@ -157,6 +157,7 @@ const Map: Component = () => {
params: {
...params,
},
lastCommit: import.meta.env.VITE_GIT_COMMIT_HASH,
});
setState({
provider: params.provider,
@ -290,7 +291,7 @@ const Map: Component = () => {
moveTolerance: 10,
interactions: new Collection<Interaction>([
new DragRotate(),
// new DoubleClickZoom(),
// new DoubleClickZoom(),
new DragPan(),
new PinchRotate(),
new PinchZoom(),

View File

@ -5,6 +5,7 @@ import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';
import suidPlugin from '@suid/vite-plugin';
import solidSvg from 'vite-plugin-solid-svg';
import { execSync } from 'child_process';
// yarn add --dev @esbuild-plugins/node-globals-polyfill
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
@ -13,7 +14,21 @@ import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfil
// You don't need to add this to deps, it's included by @esbuild-plugins/node-modules-polyfill
import rollupNodePolyFill from 'rollup-plugin-node-polyfills';
export default defineConfig(({ command, mode, ssrBuild }) => ({
export default defineConfig(({ command, mode, ssrBuild }) => {
const commitDate = execSync('git log -1 --format=%cI').toString().trimEnd();
const branchName = execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trimEnd();
const commitHash = execSync('git rev-parse HEAD').toString().trimEnd();
const lastCommitMessage = execSync('git show -s --format=%s')
.toString()
.trimEnd();
process.env.VITE_GIT_COMMIT_DATE = commitDate;
process.env.VITE_GIT_BRANCH_NAME = branchName;
process.env.VITE_GIT_COMMIT_HASH = commitHash;
process.env.VITE_GIT_LAST_COMMIT_MESSAGE = lastCommitMessage;
return {
plugins: [
suidPlugin(),
solidPlugin(),
@ -94,4 +109,5 @@ export default defineConfig(({ command, mode, ssrBuild }) => ({
global: {},
}
: {},
}));
};
});