Explorar o código

feat: enhance Nuxt configuration and AppHeader to include package version

- Implemented a function to locate the monorepo root package.json, enabling dynamic retrieval of the package version.
- Updated `nuxt.config.ts` to include the package version in the runtime configuration.
- Modified `AppHeader.vue` to display the current package version using a new `UBadge` component, improving user awareness of the application version.
alvarosabu hai 5 días
pai
achega
7a8b53f9e2
Modificáronse 2 ficheiros con 37 adicións e 2 borrados
  1. 10 1
      docs/app/components/AppHeader.vue
  2. 27 1
      docs/nuxt.config.ts

+ 10 - 1
docs/app/components/AppHeader.vue

@@ -4,6 +4,8 @@ const navigation = inject(navigationInjectionKey)
 const { header } = useAppConfig()
 
 const route = useRoute()
+
+const version = useRuntimeConfig().public.pkgVersion
 </script>
 
 <template>
@@ -39,9 +41,16 @@ const route = useRoute()
       v-else
       #left
     >
-      <NuxtLink :to="header?.to || '/'">
+      <NuxtLink :to="header?.to || '/'" class="mr-2">
         <TheLogo class="w-auto h-6 shrink-0" />
       </NuxtLink>
+      <UBadge
+        color="primary"
+        variant="subtle"
+        size="sm"
+      >
+        {{ version }}
+      </UBadge>
     </template>
 
     <template #right>

+ 27 - 1
docs/nuxt.config.ts

@@ -1,4 +1,26 @@
 import { templateCompilerOptions } from '@tresjs/core'
+import { existsSync, readFileSync } from 'node:fs'
+import { dirname, resolve } from 'node:path'
+
+function findMonorepoRootPackageJson(startDir: string): string | undefined {
+  let dir = startDir
+  while (true) {
+    const pkgPath = resolve(dir, 'package.json')
+    if (existsSync(pkgPath)) {
+      const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
+      // Check for a field unique to your monorepo root
+      if (pkg.workspaces || pkg.name === '@tresjs/core') { return pkgPath }
+    }
+    const parentDir = dirname(dir)
+    if (parentDir === dir) { break }
+    dir = parentDir
+  }
+  return undefined
+}
+
+const rootPkgPath = findMonorepoRootPackageJson(__dirname)
+const pkg = JSON.parse(readFileSync(rootPkgPath!, 'utf-8'))
+
 // https://nuxt.com/docs/api/configuration/nuxt-config
 export default defineNuxtConfig({
   modules: [
@@ -13,7 +35,11 @@ export default defineNuxtConfig({
   devtools: {
     enabled: true,
   },
-
+  runtimeConfig: {
+    public: {
+      pkgVersion: pkg.version,
+    },
+  },
   css: ['~/assets/css/main.css'],
 
   vue: {