diff --git a/package-lock.json b/package-lock.json index c784a3b..bafc3b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "jmespath-playground", - "version": "1.3.1", + "version": "1.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "jmespath-playground", - "version": "1.3.1", + "version": "1.4.0", "license": "MIT", "dependencies": { "@emotion/react": "^11.14.0", @@ -20,6 +20,7 @@ "jmespath": "^0.16.0", "react": "^18.2.0", "react-dom": "^18.2.0", + "semver": "^7.7.3", "uuid": "^9.0.0" }, "devDependencies": { @@ -158,6 +159,16 @@ "url": "https://opencollective.com/babel" } }, + "node_modules/@babel/core/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/generator": { "version": "7.28.6", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.28.6.tgz", @@ -191,6 +202,16 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/helper-compilation-targets/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/helper-globals": { "version": "7.28.0", "resolved": "https://registry.npmjs.org/@babel/helper-globals/-/helper-globals-7.28.0.tgz", @@ -4122,9 +4143,9 @@ "license": "MIT" }, "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "version": "4.17.23", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.23.tgz", + "integrity": "sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==", "dev": true, "license": "MIT" }, @@ -4891,13 +4912,15 @@ } }, "node_modules/semver": { - "version": "6.3.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", - "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", - "dev": true, + "version": "7.7.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", + "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", "license": "ISC", "bin": { "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" } }, "node_modules/send": { diff --git a/package.json b/package.json index f41449a..2d02e2c 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,13 @@ "main": "index.js", "scripts": { "start": "vite", - "prebuild": "node scripts/version-check.js", + "prebuild": "node scripts/version.mjs", "build": "vite build", "preview": "vite preview", "test": "vitest", "server": "node server.js --dev", "dev": "concurrently \"npm start\" \"node --watch server.js --dev\"", - "build-image": "node scripts/build-image.js" + "build-image": "vite build && node scripts/build-image.js" }, "engines": { "node": ">=24.0.0" @@ -28,6 +28,7 @@ "jmespath": "^0.16.0", "react": "^18.2.0", "react-dom": "^18.2.0", + "semver": "^7.7.3", "uuid": "^9.0.0" }, "browserslist": { diff --git a/scripts/build-image.js b/scripts/build-image.js index 35cff19..80a97bc 100755 --- a/scripts/build-image.js +++ b/scripts/build-image.js @@ -2,6 +2,8 @@ const { execSync } = require('child_process'); const fs = require('fs'); +const path = require('path'); +const { pathToFileURL } = require('url'); const { parseArgs } = require('util'); function execCommand(command, description) { @@ -31,20 +33,27 @@ function getContainerTool() { } } -function getVersion() { - try { - // Try to get version from git tag - const gitTag = execSync('git tag --points-at HEAD', { encoding: 'utf8' }).trim(); - if (gitTag) { - return { version: gitTag.replace(/^v/, ''), isRelease: true }; - } - } catch (error) { - // Git command failed, ignore +async function generateVersionFile() { + const versionModuleUrl = pathToFileURL(path.join(__dirname, 'version.mjs')).href; + const { generateVersionFile: generate } = await import(versionModuleUrl); + const versionFilePath = path.join(__dirname, '..', 'src', 'version.js'); + generate(versionFilePath); + return versionFilePath; +} + +function readVersionFile(versionFilePath) { + const contents = fs.readFileSync(versionFilePath, 'utf8'); + const versionMatch = contents.match(/export const VERSION = '([^']+)';/); + const releaseMatch = contents.match(/export const IS_RELEASE = (true|false);/); + + if (!versionMatch || !releaseMatch) { + throw new Error(`Could not parse version file at ${versionFilePath}`); } - // Development build - use package.json version with -dev suffix - const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); - return { version: `${packageJson.version}-dev`, isRelease: false }; + return { + version: versionMatch[1], + isRelease: releaseMatch[1] === 'true' + }; } function getHostArchitecture() { @@ -77,7 +86,7 @@ Examples: build-image.js -h # Show help`); } -function main() { +async function main() { const { values } = parseArgs({ options: { help: { @@ -105,7 +114,8 @@ function main() { } const containerTool = getContainerTool(); - const { version, isRelease } = getVersion(); + const versionFilePath = await generateVersionFile(); + const { version, isRelease } = readVersionFile(versionFilePath); let architectures; if (values['all-arch']) { @@ -160,5 +170,8 @@ function main() { } if (require.main === module) { - main(); -} \ No newline at end of file + main().catch((error) => { + console.error(`Error: ${error.message}`); + process.exit(1); + }); +} diff --git a/scripts/version-check.js b/scripts/version-check.js deleted file mode 100755 index d9bc7e2..0000000 --- a/scripts/version-check.js +++ /dev/null @@ -1,48 +0,0 @@ -#!/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 - 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 { - // We're not at a tagged commit - use unknown version - version = 'unknown'; - console.log(`📦 Building development version with unknown version`); - isRelease = false; - } -} catch (error) { - // Git command failed (maybe not in a git repo) - version = 'unknown'; - console.log(`⚠️ Cannot determine git status, using unknown 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}`); diff --git a/scripts/version.mjs b/scripts/version.mjs index 2e9276e..7248940 100644 --- a/scripts/version.mjs +++ b/scripts/version.mjs @@ -63,3 +63,7 @@ export const BUILD_TIME = '${buildDate}'; `, ); } + +if (import.meta.url === `file://${process.argv[1]}`) { + generateVersionFile("src/version.js"); +}