diff --git a/apps/web/src/App.vue b/apps/web/src/App.vue index 040fbbe..59d091f 100644 --- a/apps/web/src/App.vue +++ b/apps/web/src/App.vue @@ -1,28 +1,37 @@ diff --git a/apps/web/src/assets/main.css b/apps/web/src/assets/main.css index 6e2bc0a..d71e2d2 100644 --- a/apps/web/src/assets/main.css +++ b/apps/web/src/assets/main.css @@ -1,33 +1,34 @@ @import './base.css'; #app { - max-width: 640px; - margin: 0 auto; - padding: 1em; - font-weight: normal; - text-wrap: normal; + max-width: 640px; + margin: 0 auto; + padding: 1em; + font-weight: normal; + text-wrap: normal; } a, .green { - text-decoration: none; - color: hsla(160, 100%, 37%, 1); - transition: 0.4s; - padding: 3px; + text-decoration: none; + color: hsla(160, 100%, 37%, 1); + transition: 0.4s; + padding: 3px; } @media (hover: hover) { - a:hover { - background-color: hsla(160, 100%, 37%, 0.2); - } + a:hover { + background-color: hsla(160, 100%, 37%, 0.2); + } } -@media (min-width: 1024px) { - body { +body { display: flex; - } +} + +@media (min-width: 1024px) { - #app { - width: 640px; - } + #app { + width: 640px; + } } diff --git a/apps/web/src/components/BuildInfo.vue b/apps/web/src/components/BuildInfo.vue new file mode 100644 index 0000000..fc6e340 --- /dev/null +++ b/apps/web/src/components/BuildInfo.vue @@ -0,0 +1,38 @@ + + + + + \ No newline at end of file diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index c193ca2..33d4936 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -1,12 +1,15 @@ import { fileURLToPath, URL } from 'node:url' -import { defineConfig } from 'vite' +import { ConfigEnv, defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import vueJsx from '@vitejs/plugin-vue-jsx' import nightwatchPlugin from 'vite-plugin-nightwatch' // import { ViteFaviconsPlugin } from 'vite-plugin-favicon2' import checker from 'vite-plugin-checker' import { VitePWA, VitePWAOptions } from 'vite-plugin-pwa' +import { execSync } from 'child_process' + +import packageJson from './package.json' const PWAOptions: Partial = { registerType: 'autoUpdate', @@ -65,20 +68,56 @@ const PWAOptions: Partial = { } } +interface BuildInfo { + commitHash: string + isoDate: string + version: string + refName: string +} +function getBuildInfo(): BuildInfo | null { + const parts: string[] = execSync("git show --no-patch --no-notes --pretty='%h;%cI;%D' HEAD") + .toString() + .trim() + .split(';') + + if (parts.length == 3) { + const [commitHash, isoDate, ref_name] = parts + return { + commitHash, + isoDate, + version: packageJson.version, + refName: ref_name.match('HEAD ->.+origin/(.+)')?.[1] || ref_name + } + } + return null +} + // https://vitejs.dev/config/ -export default defineConfig({ - plugins: [ - vue(), - vueJsx(), - nightwatchPlugin(), - checker({ typescript: true }), - // ViteFaviconsPlugin('./public/food_recipe_calculator_icon.png'), - VitePWA(PWAOptions) - ], - base: './', - resolve: { - alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)) +export default defineConfig(({ mode }: ConfigEnv) => { + process.env = { ...process.env, ...loadEnv(mode, process.cwd()) } + + const buildInfo = getBuildInfo() + if (buildInfo) { + process.env.VITE_GIT_COMMIT_DATE = buildInfo.isoDate + process.env.VITE_GIT_BRANCH_NAME = buildInfo.refName + process.env.VITE_GIT_COMMIT_HASH = buildInfo.commitHash + process.env.VITE_PACKAGE_VERSION = buildInfo.version + } + + return { + plugins: [ + vue(), + vueJsx(), + nightwatchPlugin(), + checker({ typescript: true }), + // ViteFaviconsPlugin('./public/food_recipe_calculator_icon.png'), + VitePWA(PWAOptions) + ], + base: './', + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } } } }) diff --git a/apps/web/vitest.config.ts b/apps/web/vitest.config.ts index 10067d5..1aaf478 100644 --- a/apps/web/vitest.config.ts +++ b/apps/web/vitest.config.ts @@ -2,13 +2,15 @@ import { fileURLToPath } from 'node:url' import { mergeConfig, defineConfig, configDefaults } from 'vitest/config' import viteConfig from './vite.config' -export default mergeConfig( - viteConfig, - defineConfig({ - test: { - environment: 'jsdom', - exclude: [...configDefaults.exclude, 'e2e/*'], - root: fileURLToPath(new URL('./', import.meta.url)) - } - }) +export default defineConfig((env) => + mergeConfig( + viteConfig(env), + defineConfig({ + test: { + environment: 'jsdom', + exclude: [...configDefaults.exclude, 'e2e/*'], + root: fileURLToPath(new URL('./', import.meta.url)) + } + }) + ) )