@@ -42,85 +42,71 @@ function getBuildInfo() {
4242 }
4343}
4444
45- function createVersionEndpoint ( buildInfo ) {
46- const versionDir = path . join ( __dirname , '..' , 'src/api/system' ) ;
47- const versionFilePath = path . join ( versionDir , 'version.controller.ts' ) ;
45+ function updateVersionConfig ( buildInfo ) {
46+ const versionConfigPath = path . join ( __dirname , '..' , 'src/common/config/version.ts' ) ;
4847
49- // Ensure directory exists
50- if ( ! fs . existsSync ( versionDir ) ) {
51- fs . mkdirSync ( versionDir , { recursive : true } ) ;
52- }
53-
54- const content = `import { Request, Response } from 'express';
48+ const content = `/**
49+ * Version configuration for the Express.js server
50+ * These values are injected during build time from environment variables
51+ */
5552
5653/**
57- * Version information for the server
58- * Updated during build process
54+ * Server version following semantic versioning (SemVer)
55+ * Format: MAJOR.MINOR.PATCH
5956 */
60- export const VERSION_INFO = {
61- name: '${ buildInfo . name } ',
62- description: '${ buildInfo . description } ',
63- version: '${ buildInfo . version } ',
64- buildNumber: '${ buildInfo . buildNumber } ',
65- buildDate: '${ buildInfo . buildDate } ',
66- commitHash: '${ buildInfo . commitHash } ',
67- environment: '${ buildInfo . buildEnv } ',
68- timestamp: Date.now(),
69- uptime: process.uptime(),
70- nodeVersion: process.version,
71- platform: process.platform,
72- arch: process.arch
73- } as const;
57+ export const SERVER_VERSION = '${ buildInfo . version } ';
7458
7559/**
76- * GET /api/version
77- * Returns version and build information
60+ * Build number for tracking specific builds
61+ * Typically incremented with each CI/CD build
7862 */
79- export const getVersion = (req: Request, res: Response) => {
80- res.json({
81- ...VERSION_INFO,
82- uptime: process.uptime(),
83- timestamp: Date.now()
84- });
85- };
63+ export const BUILD_NUMBER = '${ buildInfo . buildNumber } ';
8664
8765/**
88- * GET /api/health
89- * Health check endpoint with version info
66+ * Build date in ISO format
67+ * Set during the build process
9068 */
91- export const getHealth = (req: Request, res: Response) => {
92- res.json({
93- status: 'healthy',
94- version: VERSION_INFO.version,
95- buildNumber: VERSION_INFO.buildNumber,
96- uptime: process.uptime(),
97- timestamp: Date.now(),
98- environment: VERSION_INFO.environment
99- });
100- };
101- ` ;
69+ export const BUILD_DATE = '${ buildInfo . buildDate } ';
10270
103- fs . writeFileSync ( versionFilePath , content ) ;
104- console . log ( '✅ Created version controller' ) ;
71+ /**
72+ * Git commit hash (short)
73+ * Useful for debugging and tracking specific builds
74+ */
75+ export const COMMIT_HASH = '${ buildInfo . commitHash } ';
10576
106- // Create routes file
107- const routesFilePath = path . join ( versionDir , 'version.routes.ts' ) ;
108- const routesContent = `import { Router } from 'express';
109- import { getVersion, getHealth } from './version.controller';
77+ /**
78+ * Build environment
79+ * development, staging, production
80+ */
81+ export const BUILD_ENV = '${ buildInfo . buildEnv } ';
11082
111- const router = Router();
83+ /**
84+ * Complete version information object
85+ */
86+ export const VERSION_INFO = {
87+ version: SERVER_VERSION,
88+ buildNumber: BUILD_NUMBER,
89+ buildDate: BUILD_DATE,
90+ commitHash: COMMIT_HASH,
91+ environment: BUILD_ENV,
92+ timestamp: Date.now(),
93+ } as const;
11294
11395/**
114- * Version and health routes
96+ * Human-readable version string
97+ * Format: "v1.1.1 (Build 42)"
11598 */
116- router.get('/version', getVersion);
117- router.get('/health', getHealth);
99+ export const VERSION_STRING = \`v\${SERVER_VERSION} (Build \${BUILD_NUMBER})\`;
118100
119- export default router;
101+ /**
102+ * Detailed version string with date
103+ * Format: "v1.1.1 (Build 42) - Sep 4, 2025"
104+ */
105+ export const DETAILED_VERSION_STRING = \`\${VERSION_STRING} - \${new Date(BUILD_DATE).toLocaleDateString()}\`;
120106` ;
121107
122- fs . writeFileSync ( routesFilePath , routesContent ) ;
123- console . log ( '✅ Created version routes ' ) ;
108+ fs . writeFileSync ( versionConfigPath , content ) ;
109+ console . log ( '✅ Updated version configuration ' ) ;
124110}
125111
126112function main ( ) {
@@ -129,7 +115,7 @@ function main() {
129115 const buildInfo = getBuildInfo ( ) ;
130116 console . log ( '📦 Build Info:' , buildInfo ) ;
131117
132- createVersionEndpoint ( buildInfo ) ;
118+ updateVersionConfig ( buildInfo ) ;
133119
134120 console . log ( '✅ Server version build completed' ) ;
135121}
@@ -138,4 +124,4 @@ if (require.main === module) {
138124 main ( ) ;
139125}
140126
141- module . exports = { getBuildInfo, createVersionEndpoint } ;
127+ module . exports = { getBuildInfo, updateVersionConfig } ;
0 commit comments