From 86687cb6a35e4260c9efa05863b9c7618a9dae38 Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Wed, 21 Jan 2026 21:06:35 +0100 Subject: [PATCH] Improve version management system - Fix version-check.js to use git tag version for releases - Add new-version.js script for proper version/tag synchronization - Update package.json to correct version 1.1.0 The new-version.js script ensures package.json and git tags are always synchronized by: 1. Updating package.json with new version 2. Committing the change 3. Tagging the commit This prevents version mismatches and git dirty states. --- package.json | 2 +- scripts/new-version.js | 92 ++++++++++++++++++++++++++++++++++++++++ scripts/version-check.js | 6 ++- 3 files changed, 97 insertions(+), 3 deletions(-) create mode 100755 scripts/new-version.js diff --git a/package.json b/package.json index cabe615..61c271a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jmespath-playground", - "version": "1.0.4", + "version": "1.1.0", "description": "A React-based web application for testing JMESPath expressions against JSON data", "main": "index.js", "scripts": { diff --git a/scripts/new-version.js b/scripts/new-version.js new file mode 100755 index 0000000..df80a8e --- /dev/null +++ b/scripts/new-version.js @@ -0,0 +1,92 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const { execSync } = require('child_process'); + +function showUsage() { + console.log('Usage: node scripts/new-version.js '); + console.log(''); + console.log('Creates a new version by updating package.json, committing, and tagging.'); + console.log(''); + console.log('Example:'); + console.log(' node scripts/new-version.js 1.2.0'); + console.log(' node scripts/new-version.js 2.0.0-beta.1'); +} + +function main() { + // Parse command line arguments + const args = process.argv.slice(2); + + if (args.length === 0 || args[0] === '-h' || args[0] === '--help') { + showUsage(); + process.exit(args.length === 0 ? 1 : 0); + } + + if (args.length !== 1) { + console.error('Error: Exactly one version argument required'); + showUsage(); + process.exit(1); + } + + const newVersion = args[0]; + const tagName = `v${newVersion}`; + + console.log(`🏷️ Creating new version: ${newVersion}`); + + try { + // Check if tag already exists + try { + const existingTags = execSync('git tag -l', { encoding: 'utf8' }); + if (existingTags.split('\n').includes(tagName)) { + console.error(`❌ Error: Tag '${tagName}' already exists`); + process.exit(1); + } + } catch (error) { + console.error('❌ Error: Failed to check existing tags'); + process.exit(1); + } + + // Check if working directory is clean + try { + const status = execSync('git status --porcelain', { encoding: 'utf8' }); + if (status.trim()) { + console.error('❌ Error: Working directory has uncommitted changes'); + console.error('Please commit or stash your changes first'); + process.exit(1); + } + } catch (error) { + console.error('❌ Error: Failed to check git status'); + process.exit(1); + } + + // Read and update package.json + const packagePath = './package.json'; + const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8')); + const oldVersion = pkg.version; + + pkg.version = newVersion; + fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n'); + console.log(`📦 Updated package.json: ${oldVersion} → ${newVersion}`); + + // Commit the package.json change + execSync('git add package.json', { stdio: 'inherit' }); + execSync(`git commit -m "Bump version to ${newVersion}"`, { stdio: 'inherit' }); + console.log(`✅ Committed version change`); + + // Tag the commit + execSync(`git tag ${tagName}`, { stdio: 'inherit' }); + console.log(`🏷️ Created tag: ${tagName}`); + + console.log(''); + console.log('🎉 Version created successfully!'); + console.log(''); + console.log('Next steps:'); + console.log(` git push origin main --tags # Push the commit and tag`); + + } catch (error) { + console.error('❌ Error during version creation:', error.message); + process.exit(1); + } +} + +main(); \ No newline at end of file diff --git a/scripts/version-check.js b/scripts/version-check.js index 050202f..49a2ae3 100755 --- a/scripts/version-check.js +++ b/scripts/version-check.js @@ -16,7 +16,9 @@ try { const gitTag = execSync('git tag --points-at HEAD', { encoding: 'utf8' }).trim(); if (gitTag) { - // We're at a tagged commit - use clean version + // We're at a tagged commit - extract version from tag + const tagVersion = gitTag.replace(/^v/, ''); // Remove 'v' prefix if present + version = tagVersion; console.log(`✅ Building release version ${version} (tagged: ${gitTag})`); isRelease = true; } else { @@ -43,4 +45,4 @@ export const BUILD_TIME = '${new Date().toISOString()}'; `; fs.writeFileSync(versionFile, versionContent); -console.log(`📝 Generated ${versionFile} with version ${version}`); \ No newline at end of file +console.log(`📝 Generated ${versionFile} with version ${version}`);