Clean version management with generated version.js

- Replace package.json modification with generated src/version.js
- App imports VERSION from ./version instead of package.json
- version.js is auto-generated during prebuild and git-ignored
- Provides VERSION, IS_RELEASE, and BUILD_TIME constants
- No more dirty git status from version changes

Development builds show 1.0.4-dev, tagged releases show 1.0.4
This commit is contained in:
2026-01-21 19:57:06 +01:00
parent 601f80ab06
commit 5379b1519d
5 changed files with 53 additions and 2 deletions

3
.gitignore vendored
View File

@@ -22,6 +22,9 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Auto-generated version file
/src/version.js
# IDE
.vscode/
.idea/

View File

@@ -41,6 +41,7 @@ npm test -- --watchAll=false
echo ""
echo "🔨 Building React application..."
echo " (Version will be automatically tagged as -dev since not building from git tag)"
npm run build
echo ""

View File

@@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"start": "react-scripts start",
"prebuild": "node scripts/version-check.js",
"build": "react-scripts build",
"test": "react-scripts test",
"server": "node server.js"

46
scripts/version-check.js Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Read package.json for base version
const packagePath = './package.json';
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
let version = pkg.version;
let isRelease = false;
try {
// Check if current commit is tagged
const gitTag = execSync('git tag --points-at HEAD', { encoding: 'utf8' }).trim();
if (gitTag) {
// We're at a tagged commit - use clean version
console.log(`✅ Building release version ${version} (tagged: ${gitTag})`);
isRelease = true;
} else {
// We're not at a tagged commit - add -dev suffix
version = `${version}-dev`;
console.log(`📦 Building development version ${version}`);
isRelease = false;
}
} catch (error) {
// Git command failed (maybe not in a git repo)
version = `${version}-dev`;
console.log(`⚠️ Cannot determine git status, using development version ${version}`);
isRelease = false;
}
// Generate version.js file
const versionFile = path.join('./src', 'version.js');
const versionContent = `// Auto-generated version file - do not edit manually
// Generated at: ${new Date().toISOString()}
export const VERSION = '${version}';
export const IS_RELEASE = ${isRelease};
export const BUILD_TIME = '${new Date().toISOString()}';
`;
fs.writeFileSync(versionFile, versionContent);
console.log(`📝 Generated ${versionFile} with version ${version}`);

View File

@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import jmespath from 'jmespath';
import packageJson from '../package.json';
import { VERSION } from './version';
import './App.css';
// JMESPath Testing Tool - Main Application Component
@@ -457,7 +457,7 @@ function App() {
<div className="row">
<div className="col-md-6">
<p className="mb-0 text-muted small">
<strong>JMESPath Testing Tool</strong> v{packageJson.version} - Created for testing and validating JMESPath expressions
<strong>JMESPath Testing Tool</strong> v{VERSION} - Created for testing and validating JMESPath expressions
</p>
</div>
<div className="col-md-6 text-md-end">