Skip to content

Commit 76caac1

Browse files
prmoore77claude
andcommitted
feat: dynamically display version in CLI banner
Read version from package.json and inject at bundle time via esbuild. Updates banner and /api/health endpoint to use dynamic version. Bumps version to 1.0.3. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0be34ef commit 76caac1

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gizmosql-ui",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"description": "GizmoSQL UI - A web-based SQL interface for GizmoSQL servers",
55
"type": "module",
66
"main": "dist/backend/src/index.js",

scripts/bundle.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import * as esbuild from 'esbuild';
2+
import { readFileSync } from 'fs';
3+
4+
// Read version from package.json
5+
const packageJson = JSON.parse(readFileSync('package.json', 'utf-8'));
6+
const version = packageJson.version;
27

38
await esbuild.build({
49
entryPoints: ['dist/backend/src/index.js'],
@@ -11,7 +16,8 @@ await esbuild.build({
1116
js: 'var __import_meta_url = "file://" + __filename;'
1217
},
1318
define: {
14-
'import.meta.url': '__import_meta_url'
19+
'import.meta.url': '__import_meta_url',
20+
'__APP_VERSION__': JSON.stringify(version)
1521
}
1622
});
1723

src/backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gizmosql-ui-backend",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"description": "GizmoSQL UI Backend Server",
55
"main": "dist/index.js",
66
"type": "module",

src/backend/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { fileURLToPath } from 'url';
66
import { apiRouter } from './routes/api.js';
77
import { getStaticPath } from './utils/paths.js';
88
import { openBrowser } from './utils/browser.js';
9+
import { VERSION } from './version.js';
910

1011
// Handle both ESM and CJS contexts
1112
// Note: In CJS bundle, esbuild's banner provides __import_meta_url
@@ -35,6 +36,8 @@ app.get('*', (req, res) => {
3536
// Start server
3637
app.listen(PORT, () => {
3738
const url = `http://localhost:${PORT}`;
39+
const versionText = `GizmoSQL UI v${VERSION}`;
40+
const versionLine = versionText.padStart(37 + Math.floor(versionText.length / 2)).padEnd(74);
3841
console.log(`
3942
╔══════════════════════════════════════════════════════════════════════════╗
4043
║ ║
@@ -45,7 +48,7 @@ app.listen(PORT, () => {
4548
║ ╚██████╔╝██║███████╗██║ ╚═╝ ██║╚██████╔╝███████║╚██████╔╝███████╗ ║
4649
║ ╚═════╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚══▀▀═╝ ╚══════╝ ║
4750
║ ║
48-
GizmoSQL UI v1.0.0
51+
${versionLine}
4952
║ ║
5053
╚══════════════════════════════════════════════════════════════════════════╝
5154

src/backend/src/routes/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Router, Request, Response } from 'express';
22
import { GizmoSQLService } from '../services/gizmosql.js';
3+
import { VERSION } from '../version.js';
34

45
export const apiRouter = Router();
56

@@ -8,7 +9,7 @@ const connections = new Map<string, GizmoSQLService>();
89

910
// Health check
1011
apiRouter.get('/health', (req: Request, res: Response) => {
11-
res.json({ status: 'ok', version: '1.0.0' });
12+
res.json({ status: 'ok', version: VERSION });
1213
});
1314

1415
// Connect to GizmoSQL server

src/backend/src/version.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { readFileSync } from 'fs';
2+
import { fileURLToPath } from 'url';
3+
import path from 'path';
4+
5+
// Declare global constant that esbuild will define at bundle time
6+
declare const __APP_VERSION__: string | undefined;
7+
8+
function getVersion(): string {
9+
// If bundled, esbuild will have defined __APP_VERSION__
10+
if (typeof __APP_VERSION__ !== 'undefined') {
11+
return __APP_VERSION__;
12+
}
13+
14+
// Fallback for development: read from package.json
15+
try {
16+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
17+
// Navigate from src/backend/src to the root package.json
18+
const packageJsonPath = path.resolve(__dirname, '../../../package.json');
19+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
20+
return packageJson.version || '0.0.0';
21+
} catch {
22+
return '0.0.0';
23+
}
24+
}
25+
26+
export const VERSION = getVersion();

src/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gizmosql-ui-frontend",
3-
"version": "1.0.0",
3+
"version": "1.0.3",
44
"private": true,
55
"type": "module",
66
"scripts": {

0 commit comments

Comments
 (0)