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:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -22,6 +22,9 @@ npm-debug.log*
|
|||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Auto-generated version file
|
||||||
|
/src/version.js
|
||||||
|
|
||||||
# IDE
|
# IDE
|
||||||
.vscode/
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
|
|||||||
1
demo.sh
1
demo.sh
@@ -41,6 +41,7 @@ npm test -- --watchAll=false
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "🔨 Building React application..."
|
echo "🔨 Building React application..."
|
||||||
|
echo " (Version will be automatically tagged as -dev since not building from git tag)"
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
"prebuild": "node scripts/version-check.js",
|
||||||
"build": "react-scripts build",
|
"build": "react-scripts build",
|
||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"server": "node server.js"
|
"server": "node server.js"
|
||||||
|
|||||||
46
scripts/version-check.js
Executable file
46
scripts/version-check.js
Executable 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}`);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import jmespath from 'jmespath';
|
import jmespath from 'jmespath';
|
||||||
import packageJson from '../package.json';
|
import { VERSION } from './version';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
|
|
||||||
// JMESPath Testing Tool - Main Application Component
|
// JMESPath Testing Tool - Main Application Component
|
||||||
@@ -457,7 +457,7 @@ function App() {
|
|||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-md-6">
|
<div className="col-md-6">
|
||||||
<p className="mb-0 text-muted small">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-md-6 text-md-end">
|
<div className="col-md-6 text-md-end">
|
||||||
|
|||||||
Reference in New Issue
Block a user