Skip to content

Commit a84c552

Browse files
author
Lasim
committed
feat(gateway): add version command to display gateway version info
1 parent e62ef11 commit a84c552

File tree

5 files changed

+107
-2
lines changed

5 files changed

+107
-2
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const packageJson = require('../package.json');
5+
const versionInfo = {
6+
version: packageJson.version,
7+
buildTime: new Date().toISOString(),
8+
source: 'release'
9+
};
10+
11+
// Read the current version.ts file
12+
const versionTsPath = path.join(__dirname, '../src/config/version.ts');
13+
let versionTsContent = fs.readFileSync(versionTsPath, 'utf8');
14+
15+
// Replace the versionData object
16+
const newVersionData = `let versionData: VersionInfo = {
17+
version: '${versionInfo.version}',
18+
buildTime: '${versionInfo.buildTime}',
19+
source: '${versionInfo.source}'
20+
};`;
21+
22+
// Use regex to replace the versionData assignment
23+
versionTsContent = versionTsContent.replace(
24+
/let versionData: VersionInfo = \{[\s\S]*?\};/,
25+
newVersionData
26+
);
27+
28+
// Write the updated file
29+
fs.writeFileSync(versionTsPath, versionTsContent);
30+
console.log(`Updated version.ts to version ${versionInfo.version}`);

services/gateway/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export { registerStartCommand } from './start';
44
export { registerStopCommand } from './stop';
55
export { registerStatusCommand } from './status';
66
export { registerConfigCommand } from './config';
7+
export { registerVersionCommand } from './version';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Command } from 'commander';
2+
import chalk from 'chalk';
3+
import { getGatewayVersion } from '../config/version';
4+
5+
export function registerVersionCommand(program: Command) {
6+
program
7+
.command('version')
8+
.description('Display DeployStack Gateway version information')
9+
.action(async () => {
10+
try {
11+
const versionInfo = getGatewayVersion();
12+
13+
console.log(chalk.cyan('DeployStack Gateway'));
14+
console.log(chalk.green(`Version: ${versionInfo.version}`));
15+
console.log(chalk.gray(`Build Time: ${versionInfo.buildTime}`));
16+
console.log(chalk.gray(`Source: ${versionInfo.source}`));
17+
18+
// Add some additional info
19+
console.log();
20+
console.log(chalk.yellow('Environment:'));
21+
console.log(chalk.gray(`Node.js: ${process.version}`));
22+
console.log(chalk.gray(`Platform: ${process.platform} ${process.arch}`));
23+
24+
} catch (error) {
25+
console.error(chalk.red('Error getting version information:'), error);
26+
process.exit(1);
27+
}
28+
});
29+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
4+
export interface VersionInfo {
5+
version: string;
6+
buildTime: string;
7+
source: string;
8+
}
9+
10+
// This will be replaced by the build script
11+
let versionData: VersionInfo = {
12+
version: '0.1.0',
13+
buildTime: '2025-07-26T14:30:00.000Z',
14+
source: 'development'
15+
};
16+
17+
// Try to read from package.json as fallback for development
18+
try {
19+
const packageJsonPath = path.join(__dirname, '../../package.json');
20+
if (fs.existsSync(packageJsonPath)) {
21+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
22+
versionData = {
23+
version: packageJson.version || '0.1.0',
24+
buildTime: new Date().toISOString(),
25+
source: 'package.json'
26+
};
27+
}
28+
} catch {
29+
// Use static fallback if package.json can't be read
30+
}
31+
32+
export const getGatewayVersion = (): VersionInfo => {
33+
return {
34+
version: versionData.version || '0.1.0',
35+
buildTime: versionData.buildTime,
36+
source: versionData.source
37+
};
38+
};
39+
40+
export const getVersionString = (): string => {
41+
return getGatewayVersion().version;
42+
};

services/gateway/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22

33
import { Command } from 'commander';
44
import chalk from 'chalk';
5+
import { getVersionString } from './config/version';
56
import {
67
registerLoginCommand,
78
registerLogoutCommand,
89
registerStartCommand,
910
registerStopCommand,
1011
registerStatusCommand,
11-
registerConfigCommand
12+
registerConfigCommand,
13+
registerVersionCommand
1214
} from './commands';
1315

1416
const program = new Command();
1517

1618
program
1719
.name('deploystack')
1820
.description('DeployStack Gateway - Local secure proxy for MCP servers')
19-
.version('0.1.0');
21+
.version(getVersionString());
2022

2123
// Register all commands
2224
registerLoginCommand(program);
@@ -25,6 +27,7 @@ registerStartCommand(program);
2527
registerStopCommand(program);
2628
registerStatusCommand(program);
2729
registerConfigCommand(program);
30+
registerVersionCommand(program);
2831

2932
// Show help if no command is provided
3033
if (process.argv.length <= 2) {

0 commit comments

Comments
 (0)