@altafusion/fugue-devtools 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/components/DevTools/Diagnostics.vue +107 -30
- package/components/DevTools/Panel.client.vue +19 -18
- package/components/DevTools/Section.vue +5 -2
- package/nuxt.config.ts +19 -0
- package/package.json +4 -4
- package/types/nuxt-fugue-devtools.d.ts +4 -0
- package/utils/altafusionPackages.ts +36 -0
- package/utils/appInfo.ts +18 -0
- package/utils/readAltafusionPackages.ts +27 -0
- package/utils/readAppInfo.ts +42 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @altafusion/fugue-devtools
|
|
2
2
|
|
|
3
|
+
## 0.6.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 689e5a3: Tidy the Diagnostics section and list the site's `@altafusion/*` packages.
|
|
8
|
+
|
|
9
|
+
- Diagnostics is two `UCard`s like Studio Drafts: **Page** (the site: its `package.json` name and version and the commit it was built from, then url, viewport, theme, language, user agent, and a Copy Diagnostics button) and **Altafusion Packages**.
|
|
10
|
+
- The packages card reads each installed `@altafusion/*` package and its version from the site's `node_modules` at build time (into `runtimeConfig.public.fugueDevtools.packages`). When they all share one version it says so once ("All 10 packages are on version 0.6.3") and shows the names as badges; mixed versions are grouped. The copied diagnostics include the list.
|
|
11
|
+
- Removed the "Turn off dev tools" button from Diagnostics: the drawer header already has the turn-off control.
|
|
12
|
+
- @altafusion/fugue-ui@0.6.4
|
|
13
|
+
|
|
14
|
+
## 0.6.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 431c0d0: Add buttons to the Studio drafts section of the dev tools drawer, and show it to signed-in editors in production.
|
|
19
|
+
|
|
20
|
+
- **Delete Matching** removes every draft whose key contains some text (`qeTools.studioDrafts.deleteMatching`), **Clear All Drafts** removes them all after a second click to confirm (`clearAll`), each row shows its status, and a **Reload Page To Apply** button appears after a delete (Studio keeps a merged copy in memory).
|
|
21
|
+
- The section is privileged, and without an access resolver it only showed in development. `fugue-content` now sets one: development, or a signed-in Studio editor (the `studio-session-check` cookie). A site that wants a different rule calls `setAccessResolver` after it. It is a UI convenience, not a security boundary: the section only touches the browser's own drafts.
|
|
22
|
+
- The section is now called **Studio Drafts**, comes first so it opens by default, and sits in a thin bordered card (`max-w-xl`) with Refresh and Clear All Drafts at the top, Delete Matching under them, then the list.
|
|
23
|
+
- The drawer's section switcher is a Nuxt UI `UTabs` (pill, no content) instead of a row of buttons, and a section no longer repeats its title under the tabs; with a single section there are no tabs, so the title still shows.
|
|
24
|
+
- @altafusion/fugue-ui@0.6.3
|
|
25
|
+
|
|
3
26
|
## 0.6.2
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { summarizePackageVersions } from '#devtools/utils/altafusionPackages'
|
|
3
|
+
import { formatAppInfo } from '#devtools/utils/appInfo'
|
|
4
|
+
|
|
2
5
|
/** Built-in public section: safe for any visitor to see, and handy to paste into a bug report. */
|
|
3
6
|
const route = useRoute()
|
|
4
7
|
const colorMode = useColorMode()
|
|
5
|
-
const api = useDevTools()
|
|
6
8
|
const width = ref(window.innerWidth)
|
|
7
9
|
const height = ref(window.innerHeight)
|
|
8
10
|
|
|
@@ -14,7 +16,12 @@ function measure() {
|
|
|
14
16
|
onMounted(() => window.addEventListener('resize', measure))
|
|
15
17
|
onBeforeUnmount(() => window.removeEventListener('resize', measure))
|
|
16
18
|
|
|
19
|
+
const app = formatAppInfo(useRuntimeConfig().public.fugueDevtools.app)
|
|
20
|
+
|
|
17
21
|
const rows = computed(() => ({
|
|
22
|
+
...(app
|
|
23
|
+
? { app }
|
|
24
|
+
: {}),
|
|
18
25
|
url: route.fullPath,
|
|
19
26
|
viewport: `${width.value}x${height.value}`,
|
|
20
27
|
theme: colorMode.value,
|
|
@@ -22,45 +29,115 @@ const rows = computed(() => ({
|
|
|
22
29
|
userAgent: navigator.userAgent,
|
|
23
30
|
}))
|
|
24
31
|
|
|
32
|
+
const packages = useRuntimeConfig().public.fugueDevtools.packages ?? {}
|
|
33
|
+
const summary = summarizePackageVersions(packages)
|
|
34
|
+
|
|
25
35
|
const copied = ref(false)
|
|
26
36
|
|
|
27
37
|
async function copy() {
|
|
28
|
-
await navigator.clipboard.writeText(JSON.stringify(rows.value, null, 2))
|
|
38
|
+
await navigator.clipboard.writeText(JSON.stringify({ ...rows.value, altafusion: packages }, null, 2))
|
|
29
39
|
copied.value = true
|
|
30
40
|
setTimeout(() => (copied.value = false), 1500)
|
|
31
41
|
}
|
|
42
|
+
|
|
43
|
+
// A transparent card with the stronger `accented` border, so it reads on the drawer's solid background.
|
|
44
|
+
const cardUi = { root: 'bg-transparent ring-accented', header: 'px-3 py-2 sm:px-3', body: 'p-3 sm:p-3' }
|
|
32
45
|
</script>
|
|
33
46
|
|
|
34
47
|
<template>
|
|
35
|
-
<div class="
|
|
36
|
-
<
|
|
37
|
-
<template
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
<div class="grid w-full gap-4 text-sm sm:grid-cols-2">
|
|
49
|
+
<UCard :ui="cardUi">
|
|
50
|
+
<template #header>
|
|
51
|
+
<div class="flex items-center justify-between gap-2">
|
|
52
|
+
<span class="font-medium">Page</span>
|
|
53
|
+
<UButton
|
|
54
|
+
:label="copied ? 'Copied' : 'Copy Diagnostics'"
|
|
55
|
+
:icon="copied ? 'i-lucide-check' : 'i-lucide-copy'"
|
|
56
|
+
size="xs"
|
|
57
|
+
color="neutral"
|
|
58
|
+
variant="outline"
|
|
59
|
+
@click="copy"
|
|
60
|
+
/>
|
|
61
|
+
</div>
|
|
47
62
|
</template>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
|
|
64
|
+
<dl class="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1">
|
|
65
|
+
<template
|
|
66
|
+
v-for="(value, key) in rows"
|
|
67
|
+
:key="key"
|
|
68
|
+
>
|
|
69
|
+
<dt class="text-muted">
|
|
70
|
+
{{ key }}
|
|
71
|
+
</dt>
|
|
72
|
+
<dd class="break-all font-mono text-xs">
|
|
73
|
+
{{ value }}
|
|
74
|
+
</dd>
|
|
75
|
+
</template>
|
|
76
|
+
</dl>
|
|
77
|
+
</UCard>
|
|
78
|
+
|
|
79
|
+
<UCard :ui="cardUi">
|
|
80
|
+
<template #header>
|
|
81
|
+
<div class="flex items-center justify-between gap-2">
|
|
82
|
+
<span class="font-medium">Altafusion Packages</span>
|
|
83
|
+
<UBadge
|
|
84
|
+
:label="`${summary.count} installed`"
|
|
85
|
+
size="sm"
|
|
86
|
+
color="neutral"
|
|
87
|
+
variant="subtle"
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
</template>
|
|
91
|
+
|
|
92
|
+
<UEmpty
|
|
93
|
+
v-if="!summary.count"
|
|
94
|
+
icon="i-lucide-package"
|
|
95
|
+
title="No Packages Found"
|
|
96
|
+
description="The site's @altafusion packages were not found at build time."
|
|
97
|
+
size="sm"
|
|
98
|
+
variant="naked"
|
|
63
99
|
/>
|
|
64
|
-
|
|
100
|
+
|
|
101
|
+
<div
|
|
102
|
+
v-else
|
|
103
|
+
class="space-y-3"
|
|
104
|
+
>
|
|
105
|
+
<p
|
|
106
|
+
v-if="summary.uniform"
|
|
107
|
+
class="text-muted"
|
|
108
|
+
>
|
|
109
|
+
All {{ summary.count }} packages are on version
|
|
110
|
+
<UBadge
|
|
111
|
+
:label="summary.groups[0]!.version"
|
|
112
|
+
size="sm"
|
|
113
|
+
color="primary"
|
|
114
|
+
variant="subtle"
|
|
115
|
+
/>
|
|
116
|
+
</p>
|
|
117
|
+
|
|
118
|
+
<div
|
|
119
|
+
v-for="group in summary.groups"
|
|
120
|
+
:key="group.version"
|
|
121
|
+
class="space-y-1"
|
|
122
|
+
>
|
|
123
|
+
<p
|
|
124
|
+
v-if="!summary.uniform"
|
|
125
|
+
class="font-mono text-xs"
|
|
126
|
+
>
|
|
127
|
+
{{ group.version }} ({{ group.names.length }})
|
|
128
|
+
</p>
|
|
129
|
+
<div class="flex flex-wrap gap-1">
|
|
130
|
+
<UBadge
|
|
131
|
+
v-for="name in group.names"
|
|
132
|
+
:key="name"
|
|
133
|
+
:label="name"
|
|
134
|
+
size="sm"
|
|
135
|
+
color="neutral"
|
|
136
|
+
variant="outline"
|
|
137
|
+
/>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</UCard>
|
|
65
142
|
</div>
|
|
66
143
|
</template>
|
|
@@ -44,6 +44,16 @@ const panelPosition = computed<DevToolsPanelPosition>({
|
|
|
44
44
|
|
|
45
45
|
const isHorizontalDock = computed(() => isHorizontalDevToolsDock(panelPosition.value))
|
|
46
46
|
|
|
47
|
+
// The tab strip names the active section, so the section only repeats its title when there are no tabs (a single section).
|
|
48
|
+
const tabItems = computed(() => visibleSections.value.map(section => ({ label: section.label, value: section.id })))
|
|
49
|
+
const activeTab = computed({
|
|
50
|
+
get: () => activeSection.value?.id,
|
|
51
|
+
set: (id) => {
|
|
52
|
+
if (id !== undefined)
|
|
53
|
+
api.activeId.value = String(id)
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
47
57
|
function toggle() {
|
|
48
58
|
open.value = !open.value
|
|
49
59
|
}
|
|
@@ -133,24 +143,15 @@ const drawerUi = computed(() => {
|
|
|
133
143
|
</template>
|
|
134
144
|
</DevToolsNav>
|
|
135
145
|
|
|
136
|
-
<
|
|
146
|
+
<UTabs
|
|
137
147
|
v-if="visibleSections.length > 1"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
:color="activeSection?.id === section.id ? 'primary' : 'neutral'"
|
|
146
|
-
:variant="activeSection?.id === section.id ? 'soft' : 'ghost'"
|
|
147
|
-
size="xs"
|
|
148
|
-
role="tab"
|
|
149
|
-
:aria-selected="activeSection?.id === section.id"
|
|
150
|
-
:data-testid="`devtools-tab-${section.id}`"
|
|
151
|
-
@click="api.activeId.value = section.id"
|
|
152
|
-
/>
|
|
153
|
-
</div>
|
|
148
|
+
v-model="activeTab"
|
|
149
|
+
:items="tabItems"
|
|
150
|
+
:content="false"
|
|
151
|
+
variant="pill"
|
|
152
|
+
size="xs"
|
|
153
|
+
class="mt-2"
|
|
154
|
+
/>
|
|
154
155
|
|
|
155
156
|
<div
|
|
156
157
|
class="mt-3 grid grid-cols-1 gap-4"
|
|
@@ -164,7 +165,7 @@ const drawerUi = computed(() => {
|
|
|
164
165
|
:is-horizontal-dock="isHorizontalDock"
|
|
165
166
|
>
|
|
166
167
|
<DevToolsSection
|
|
167
|
-
:title="activeSection.label"
|
|
168
|
+
:title="visibleSections.length > 1 ? undefined : activeSection.label"
|
|
168
169
|
:class="sectionClass"
|
|
169
170
|
>
|
|
170
171
|
<component :is="activeSection.component" />
|
|
@@ -3,14 +3,17 @@ const {
|
|
|
3
3
|
title,
|
|
4
4
|
class: className,
|
|
5
5
|
} = defineProps<{
|
|
6
|
-
title
|
|
6
|
+
title?: string
|
|
7
7
|
class?: string
|
|
8
8
|
}>()
|
|
9
9
|
</script>
|
|
10
10
|
|
|
11
11
|
<template>
|
|
12
12
|
<section class="devtools-panel__section" :class="className">
|
|
13
|
-
<div
|
|
13
|
+
<div
|
|
14
|
+
v-if="title"
|
|
15
|
+
class="devtools-panel__section-title"
|
|
16
|
+
>
|
|
14
17
|
{{ title }}
|
|
15
18
|
</div>
|
|
16
19
|
<slot />
|
package/nuxt.config.ts
CHANGED
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
/// <reference path="./types/nuxt-fugue-devtools.d.ts" />
|
|
9
9
|
|
|
10
|
+
import type { Nuxt } from 'nuxt/schema'
|
|
10
11
|
import { fileURLToPath } from 'node:url'
|
|
12
|
+
import { readAltafusionPackages } from './utils/readAltafusionPackages'
|
|
13
|
+
import { readAppInfo } from './utils/readAppInfo'
|
|
11
14
|
|
|
12
15
|
const layerRoot = fileURLToPath(new URL('.', import.meta.url))
|
|
13
16
|
|
|
@@ -18,6 +21,22 @@ export default defineNuxtConfig({
|
|
|
18
21
|
'#devtools': layerRoot,
|
|
19
22
|
},
|
|
20
23
|
|
|
24
|
+
modules: [
|
|
25
|
+
// Reads the site's installed `@altafusion/*` packages and versions, and its own name, version and commit, for the Diagnostics section (once, at build time).
|
|
26
|
+
(_options: unknown, nuxt: Nuxt) => {
|
|
27
|
+
const current = nuxt.options.runtimeConfig.public.fugueDevtools
|
|
28
|
+
nuxt.options.runtimeConfig.public.fugueDevtools = {
|
|
29
|
+
...current,
|
|
30
|
+
packages: readAltafusionPackages(nuxt.options.rootDir),
|
|
31
|
+
// What the site sets in its own `nuxt.config` (say, a release name) wins over what is read here.
|
|
32
|
+
app: {
|
|
33
|
+
...readAppInfo(nuxt.options.rootDir),
|
|
34
|
+
...current.app,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
|
|
21
40
|
// Ship the type augmentations (`$fugueDevtools`, runtime config) to every site that extends this layer.
|
|
22
41
|
hooks: {
|
|
23
42
|
'prepare:types': ({ references }) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altafusion/fugue-devtools",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.4",
|
|
5
5
|
"description": "Generic non-modal dev tools drawer for Nuxt apps — Fugue family",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/altafusion/fugue/tree/main/packages-fugue/fugue-devtools#readme",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"vue-router": "^5.0.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@altafusion/fugue-ui": "0.6.
|
|
39
|
+
"@altafusion/fugue-ui": "0.6.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@altafusion/eslint-config": "0.6.
|
|
43
|
-
"@altafusion/nuxt-base": "0.6.
|
|
42
|
+
"@altafusion/eslint-config": "0.6.4",
|
|
43
|
+
"@altafusion/nuxt-base": "0.6.4",
|
|
44
44
|
"@types/node": "^26.6.11",
|
|
45
45
|
"eslint": "^10.15.0",
|
|
46
46
|
"nuxt": "^4.7.0",
|
|
@@ -9,6 +9,10 @@ declare module 'nuxt/schema' {
|
|
|
9
9
|
persistNamespace?: string
|
|
10
10
|
persistKey?: string
|
|
11
11
|
defaultPosition?: 'top' | 'right' | 'bottom' | 'left'
|
|
12
|
+
/** The site's installed `@altafusion/*` packages and versions, filled in at build time. */
|
|
13
|
+
packages?: Record<string, string>
|
|
14
|
+
/** The site's own name, version and build commit, filled in at build time; set a field in `nuxt.config` to override it. */
|
|
15
|
+
app?: import('../utils/appInfo').AppInfo
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** One version and the `@altafusion/*` packages installed at it. */
|
|
2
|
+
export interface PackageVersionGroup {
|
|
3
|
+
version: string
|
|
4
|
+
names: string[]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface PackageVersionSummary {
|
|
8
|
+
count: number
|
|
9
|
+
/** Newest-first is not assumed: groups are ordered by how many packages share the version, then by version text. */
|
|
10
|
+
groups: PackageVersionGroup[]
|
|
11
|
+
/** True when every package is on the same version, so the UI can say it once. */
|
|
12
|
+
uniform: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Groups `{ '@altafusion/shell': '0.6.3', ... }` by version, with short names (the scope dropped) sorted inside each group. */
|
|
16
|
+
export function summarizePackageVersions(packages: Record<string, string> = {}): PackageVersionSummary {
|
|
17
|
+
const byVersion = new Map<string, string[]>()
|
|
18
|
+
for (const [name, version] of Object.entries(packages)) {
|
|
19
|
+
const names = byVersion.get(version) ?? []
|
|
20
|
+
names.push(name.replace(/^@altafusion\//, ''))
|
|
21
|
+
byVersion.set(version, names)
|
|
22
|
+
}
|
|
23
|
+
const groups = [
|
|
24
|
+
...byVersion.entries(),
|
|
25
|
+
]
|
|
26
|
+
.map(([version, names]) => ({
|
|
27
|
+
version,
|
|
28
|
+
names: names.sort(),
|
|
29
|
+
}))
|
|
30
|
+
.sort((a, b) => b.names.length - a.names.length || b.version.localeCompare(a.version))
|
|
31
|
+
return {
|
|
32
|
+
count: Object.keys(packages).length,
|
|
33
|
+
groups,
|
|
34
|
+
uniform: groups.length === 1,
|
|
35
|
+
}
|
|
36
|
+
}
|
package/utils/appInfo.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** The site running the dev tools: its `package.json` name and version, and the commit it was built from. */
|
|
2
|
+
export interface AppInfo {
|
|
3
|
+
name?: string
|
|
4
|
+
version?: string
|
|
5
|
+
/** Full or short commit hash of the build (Netlify's `COMMIT_REF`, GitHub's `GITHUB_SHA`, else `git rev-parse HEAD`). */
|
|
6
|
+
commit?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** `camilajessica 0.1.0 (9e5769e)`; any missing part is left out, and `undefined` when there is nothing to show. */
|
|
10
|
+
export function formatAppInfo(app?: AppInfo): string | undefined {
|
|
11
|
+
if (!app)
|
|
12
|
+
return undefined
|
|
13
|
+
const label = [app.name, app.version].filter(Boolean).join(' ')
|
|
14
|
+
const commit = app.commit
|
|
15
|
+
? `(${app.commit.slice(0, 7)})`
|
|
16
|
+
: ''
|
|
17
|
+
return [label, commit].filter(Boolean).join(' ') || undefined
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Build-time only (it imports `node:fs`, so only `nuxt.config.ts` may import it): the `@altafusion/*` packages a site has
|
|
6
|
+
* installed, as `{ '@altafusion/shell': '0.6.3' }`, read from `<rootDir>/node_modules/@altafusion/*\/package.json`.
|
|
7
|
+
*/
|
|
8
|
+
export function readAltafusionPackages(rootDir: string): Record<string, string> {
|
|
9
|
+
const scopeDir = join(rootDir, 'node_modules', '@altafusion')
|
|
10
|
+
if (!existsSync(scopeDir))
|
|
11
|
+
return {}
|
|
12
|
+
|
|
13
|
+
const packages: Record<string, string> = {}
|
|
14
|
+
for (const dir of readdirSync(scopeDir).sort()) {
|
|
15
|
+
const file = join(scopeDir, dir, 'package.json')
|
|
16
|
+
if (!existsSync(file))
|
|
17
|
+
continue
|
|
18
|
+
try {
|
|
19
|
+
const pkg = JSON.parse(readFileSync(file, 'utf8')) as { name?: string, version?: string }
|
|
20
|
+
if (pkg.name && pkg.version)
|
|
21
|
+
packages[pkg.name] = pkg.version
|
|
22
|
+
} catch {
|
|
23
|
+
// A package.json that cannot be read is skipped; the list is a convenience for bug reports.
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return packages
|
|
27
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AppInfo } from './appInfo'
|
|
2
|
+
import { execFileSync } from 'node:child_process'
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import process from 'node:process'
|
|
6
|
+
|
|
7
|
+
/** Asks git for the current commit; `undefined` when there is no git or no repository (a build from a tarball). */
|
|
8
|
+
function gitCommit(rootDir: string): string | undefined {
|
|
9
|
+
try {
|
|
10
|
+
return execFileSync('git', ['rev-parse', 'HEAD'], {
|
|
11
|
+
cwd: rootDir,
|
|
12
|
+
encoding: 'utf8',
|
|
13
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
14
|
+
}).trim() || undefined
|
|
15
|
+
} catch {
|
|
16
|
+
return undefined
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Build-time only (it imports `node:fs`, so only `nuxt.config.ts` may import it): the site's own name and version from its
|
|
22
|
+
* `package.json`, plus the commit it was built from. The version alone barely changes between deploys; the commit does.
|
|
23
|
+
*/
|
|
24
|
+
export function readAppInfo(
|
|
25
|
+
rootDir: string,
|
|
26
|
+
env: Record<string, string | undefined> = process.env,
|
|
27
|
+
commitFromGit: (dir: string) => string | undefined = gitCommit,
|
|
28
|
+
): AppInfo {
|
|
29
|
+
const file = join(rootDir, 'package.json')
|
|
30
|
+
let name: string | undefined
|
|
31
|
+
let version: string | undefined
|
|
32
|
+
if (existsSync(file)) {
|
|
33
|
+
try {
|
|
34
|
+
const pkg = JSON.parse(readFileSync(file, 'utf8')) as { name?: string, version?: string }
|
|
35
|
+
name = pkg.name
|
|
36
|
+
version = pkg.version
|
|
37
|
+
} catch {
|
|
38
|
+
// An unreadable package.json leaves the name and version out; the commit can still show.
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { name, version, commit: env.COMMIT_REF || env.GITHUB_SHA || commitFromGit(rootDir) }
|
|
42
|
+
}
|