Skip to content

Commit

Permalink
Merge pull request #4 from mauvehed/add-build-ver
Browse files Browse the repository at this point in the history
feat(app.vue, nuxt.config.ts, package.json): display build version in UI and automate version generation
  • Loading branch information
mauvehed authored Dec 7, 2024
2 parents 0f2d909 + d6d6aed commit 214efa1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
16 changes: 16 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<p v-if="ip">{{ ip }}</p>
<p v-else>Loading...</p>
</div>
<div id="app">
<NuxtPage />
<div class="build-version">
Build Version: {{ buildVersion }}
</div>
</div>
</template>

<script setup>
Expand All @@ -20,6 +26,8 @@ onMounted(async () => {
console.error("Failed to fetch IP:", error);
}
});
const buildVersion = useRuntimeConfig().public.buildVersion;
</script>

<style>
Expand All @@ -32,6 +40,14 @@ onMounted(async () => {
font-family: Arial, sans-serif;
}
.build-version {
position: fixed;
bottom: 10px;
right: 10px;
font-size: 12px;
color: #aaa;
}
h1 {
font-size: 2rem;
margin-bottom: 1rem;
Expand Down
3 changes: 3 additions & 0 deletions build-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2024-12-07T19:44:53.790Z"
}
16 changes: 14 additions & 2 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
import { readFileSync } from 'fs';
import { resolve } from 'path';

const buildVersion = JSON.parse(
readFileSync(resolve(__dirname, 'build-version.json'), 'utf-8')
).version;

export default defineNuxtConfig({
compatibilityDate: '2024-11-01',
devtools: { enabled: true }
})
devtools: { enabled: true },
runtimeConfig: {
public: {
buildVersion,
},
},
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"private": true,
"type": "module",
"scripts": {
"build": "nuxt build",
"generate-version": "node scripts/generate-build-version.js",
"build": "yarn generate-version && nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
Expand Down
13 changes: 13 additions & 0 deletions scripts/generate-build-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { writeFileSync } from "fs";
import { resolve } from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = resolve(__filename, "..");

const version = new Date().toISOString();
const outputPath = resolve(__dirname, "../build-version.json");

writeFileSync(outputPath, JSON.stringify({ version }, null, 2));

console.log(`Build version generated: ${version}`);

1 comment on commit 214efa1

@vercel
Copy link

@vercel vercel bot commented on 214efa1 Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.