From a03874fef2d5cd881ebe0907088570d50dcc1605 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Tue, 22 Jul 2025 10:43:19 -0700 Subject: [PATCH] **refactor(core): remove generate-version script and update prebuild/version workflows** - **Removal of `generate-version.js`**: - Deleted `scripts/generate-version.js` as it is no longer required for version handling. - Removed associated output files, including `src/utils/version.ts`. - **Prebuild and Version Process Updates**: - Updated `prebuild` and `version` scripts in `package.json` to reflect the new workflow: - Replaced `generate-version.js` with simplified echo commands for version updates and build steps. - Adjusted deployment scripts (`deploy:cli` and `deploy:web-service`) to align with the removal of the script. - **Documentation and Config Updates**: - Cleaned up `README.md` by removing unused version badge references. - Updated `cli-package/package.json` to specify a version range (`^0.15.0`) for `@soulcraft/brainy`. **Purpose**: This refactor simplifies the version handling process by removing outdated scripts, reducing maintenance overhead, and aligning workflows with project conventions. Improves clarity and consistency in both configuration and documentation. --- README.md | 1 - cli-package/package.json | 4 +- package.json | 8 +-- scripts/generate-version.js | 131 ------------------------------------ src/utils/version.ts | 6 -- 5 files changed, 6 insertions(+), 144 deletions(-) delete mode 100755 scripts/generate-version.js delete mode 100644 src/utils/version.ts diff --git a/README.md b/README.md index 118581f9..5dcd2e48 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ [![Node.js](https://img.shields.io/badge/node-%3E%3D24.4.0-brightgreen.svg)](https://nodejs.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-5.4.5-blue.svg)](https://www.typescriptlang.org/) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md) -[![npm](https://img.shields.io/badge/npm-v0.15.0-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy) [//]: # ([![Cartographer](https://img.shields.io/badge/Cartographer-Official%20Standard-brightgreen)](https://github.com/sodal-project/cartographer)) diff --git a/cli-package/package.json b/cli-package/package.json index cfe56fbe..1cc43b5e 100644 --- a/cli-package/package.json +++ b/cli-package/package.json @@ -40,7 +40,7 @@ "url": "git+https://github.com/soulcraft-research/brainy.git" }, "dependencies": { - "@soulcraft/brainy": "0.15.0", + "@soulcraft/brainy": "^0.15.0", "commander": "^14.0.0", "omelette": "^0.4.17" }, @@ -58,4 +58,4 @@ "engines": { "node": ">=24.4.0" } -} \ No newline at end of file +} diff --git a/package.json b/package.json index eb71eebe..57dc5b8d 100644 --- a/package.json +++ b/package.json @@ -49,13 +49,13 @@ "node": ">=24.4.0" }, "scripts": { - "prebuild": "node scripts/generate-version.js", + "prebuild": "echo 'Prebuild step - no version generation needed'", "build": "BUILD_TYPE=unified rollup -c rollup.config.js", "build:browser": "BUILD_TYPE=browser rollup -c rollup.config.js", "build:cli": "cd cli-package && npm run build", "start": "node dist/unified.js", "demo": "npm run build && npm run build:browser && npx http-server -o /demo/index.html", - "version": "node scripts/generate-version.js", + "version": "echo 'Version updated in package.json'", "version:patch": "npm version patch", "version:minor": "npm version minor", "version:major": "npm version major", @@ -66,8 +66,8 @@ "check:style": "node scripts/check-code-style.js", "prepare": "npm run build", "deploy": "npm run build && npm publish && node scripts/create-github-release.js", - "deploy:cli": "node scripts/generate-version.js && cd cli-package && npm run build && npm publish", - "deploy:web-service": "node scripts/generate-version.js && cd web-service-package && npm run build && npm publish", + "deploy:cli": "cd cli-package && npm run build && npm publish", + "deploy:web-service": "cd web-service-package && npm run build && npm publish", "dry-run": "npm pack --dry-run", "test": "vitest run", "test:watch": "vitest", diff --git a/scripts/generate-version.js b/scripts/generate-version.js deleted file mode 100755 index b4d352b1..00000000 --- a/scripts/generate-version.js +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env node - -/** - * Generate Version Script - * - * This script generates a version.js file that exports the version from package.json. - * This allows the CLI to access the version without having to read package.json directly, - * which can be problematic when the package is installed globally. - * - * It also updates the version in the README.md file and CLI package.json to ensure they - * stay in sync with the main package.json. - */ - -import fs from 'fs' -import path from 'path' -import { fileURLToPath } from 'url' - -// Get the directory of the current module -const __filename = fileURLToPath(import.meta.url) -const __dirname = path.dirname(__filename) - -// Path to the root directory -const rootDir = path.join(__dirname, '..') - -// Path to package.json -const packageJsonPath = path.join(rootDir, 'package.json') - -// Path to the output directory -const outputDir = path.join(rootDir, 'src', 'utils') - -// Path to the output file -const outputFile = path.join(outputDir, 'version.ts') - -// Path to README.md -const readmePath = path.join(rootDir, 'README.md') - -// Path to CLI package.json -const cliPackageJsonPath = path.join(rootDir, 'cli-package', 'package.json') - -// Read package.json -const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) -const version = packageJson.version - -// Create the output directory if it doesn't exist -if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir, { recursive: true }) -} - -// Generate the version.ts file -const content = `/** - * This file is auto-generated during the build process. - * Do not modify this file directly. - */ - -export const VERSION = '${version}'; -` - -// Write the file -fs.writeFileSync(outputFile, content) - -console.log(`Generated version.ts with version ${version}`) - -// Update README.md with the current version, Node.js version, and TypeScript version -try { - let readmeContent = fs.readFileSync(readmePath, 'utf8') - - // Get Node.js version requirement from package.json - const nodeVersion = packageJson.engines.node.replace('>=', '') - - // Get TypeScript version from package.json devDependencies - const typescriptVersion = packageJson.devDependencies.typescript.replace('^', '') - - // Update npm badge - using a more flexible approach with explicit version - const npmBadgeRegex = /\[\!\[npm\].*?\]\(https:\/\/www\.npmjs\.com\/package\/@soulcraft\/brainy\)/g - if (npmBadgeRegex.test(readmeContent)) { - readmeContent = readmeContent.replace( - npmBadgeRegex, - `[![npm](https://img.shields.io/badge/npm-v${version}-blue.svg)](https://www.npmjs.com/package/@soulcraft/brainy)` - ) - } else { - console.log('Warning: Could not find npm badge in README.md') - } - - // Update Node.js badge - using a more flexible approach - const nodeBadgeRegex = /\[\!\[Node\.js\].*?\]\(https:\/\/nodejs\.org\/\)/g - if (nodeBadgeRegex.test(readmeContent)) { - readmeContent = readmeContent.replace( - nodeBadgeRegex, - `[![Node.js](https://img.shields.io/badge/node-%3E%3D${nodeVersion}-brightgreen.svg)](https://nodejs.org/)` - ) - } else { - console.log('Warning: Could not find Node.js badge in README.md') - } - - // Update TypeScript badge - using a more flexible approach - const tsBadgeRegex = /\[\!\[TypeScript\].*?\]\(https:\/\/www\.typescriptlang\.org\/\)/g - if (tsBadgeRegex.test(readmeContent)) { - readmeContent = readmeContent.replace( - tsBadgeRegex, - `[![TypeScript](https://img.shields.io/badge/TypeScript-${typescriptVersion}-blue.svg)](https://www.typescriptlang.org/)` - ) - } else { - console.log('Warning: Could not find TypeScript badge in README.md') - } - - // Write the updated README back to disk - fs.writeFileSync(readmePath, readmeContent) - console.log(`Updated README.md with npm version ${version}, Node.js version ${nodeVersion}, and TypeScript version ${typescriptVersion}`) -} catch (error) { - console.error('Error updating README.md:', error) -} - -// Update CLI package.json with the same version -try { - // Read CLI package.json - const cliPackageJson = JSON.parse(fs.readFileSync(cliPackageJsonPath, 'utf8')) - - // Update version - cliPackageJson.version = version - - // Update dependency on main package to be exact - if (cliPackageJson.dependencies && cliPackageJson.dependencies['@soulcraft/brainy']) { - cliPackageJson.dependencies['@soulcraft/brainy'] = version - } - - // Write the updated CLI package.json back to disk - fs.writeFileSync(cliPackageJsonPath, JSON.stringify(cliPackageJson, null, 2)) - console.log(`Updated CLI package.json with version ${version} and exact dependency on main package`) -} catch (error) { - console.error('Error updating CLI package.json:', error) -} diff --git a/src/utils/version.ts b/src/utils/version.ts deleted file mode 100644 index 9a430880..00000000 --- a/src/utils/version.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * This file is auto-generated during the build process. - * Do not modify this file directly. - */ - -export const VERSION = '0.15.0';