From 5379b1519dad69c521f4725771fc9ed814913ba7 Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Wed, 21 Jan 2026 19:57:06 +0100 Subject: [PATCH] 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 --- .gitignore | 3 +++ demo.sh | 1 + package.json | 1 + scripts/version-check.js | 46 ++++++++++++++++++++++++++++++++++++++++ src/App.js | 4 ++-- 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100755 scripts/version-check.js diff --git a/.gitignore b/.gitignore index d91a54c..e38724d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ npm-debug.log* yarn-debug.log* yarn-error.log* +# Auto-generated version file +/src/version.js + # IDE .vscode/ .idea/ diff --git a/demo.sh b/demo.sh index f034132..6f8a7ec 100755 --- a/demo.sh +++ b/demo.sh @@ -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 "" diff --git a/package.json b/package.json index 83d5774..cabe615 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/scripts/version-check.js b/scripts/version-check.js new file mode 100755 index 0000000..050202f --- /dev/null +++ b/scripts/version-check.js @@ -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}`); \ No newline at end of file diff --git a/src/App.js b/src/App.js index 2cd6b69..77b26a3 100644 --- a/src/App.js +++ b/src/App.js @@ -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() {

- JMESPath Testing Tool v{packageJson.version} - Created for testing and validating JMESPath expressions + JMESPath Testing Tool v{VERSION} - Created for testing and validating JMESPath expressions