diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 57851b0fece..c5eda4fbc84 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -8,6 +8,5 @@ packages: - 'tools/package-release' - 'tools/cherry-pick' - 'tools/release-posts' - - 'tools/version-bump' - 'tools/storybook' - 'tools/monorepo-utils' diff --git a/tools/version-bump/.eslintrc b/tools/version-bump/.eslintrc deleted file mode 100644 index b2a08066eea..00000000000 --- a/tools/version-bump/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": [ "plugin:@woocommerce/eslint-plugin/recommended" ] -} diff --git a/tools/version-bump/README.md b/tools/version-bump/README.md deleted file mode 100644 index 3bb50735fd3..00000000000 --- a/tools/version-bump/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# Version Bump - -## Description - -`version-bump` is a CLI tool to bump versions in plugins found in the Monorepo. - -## Usage - -Bump WooCommerce to version 7.1.0: - -``` -pnpm --filter version-bump run version bump woocommerce -v 7.1.0 -``` - -**Arguments**: -plugin - Monorepo plugin - -**Options**: --v, --version Version to bump to --h, --help display help for command - -### Prereleases - -Prerelease versions such as `7.3.0-dev` and `7.5.0-beta.1` are acceptable. - -When updating with a `-dev` prerelease suffix, the tool will not update the stable tag but will update the readme changelog to prepare for the next release cycle. diff --git a/tools/version-bump/commands/bump.ts b/tools/version-bump/commands/bump.ts deleted file mode 100644 index 4792b9e6254..00000000000 --- a/tools/version-bump/commands/bump.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * External dependencies - */ -import { prerelease } from 'semver'; -import { Logger } from '@woocommerce/monorepo-utils/src/core/logger'; - -/** - * Internal dependencies - */ -import { program } from '../program'; -import { validateArgs, stripPrereleaseParameters } from '../lib/validate'; -import { - updatePluginFile, - updateReadmeChangelog, - updateJSON, - updateClassPluginFile, - updateReadmeStableTag, -} from '../lib/update'; - -program - .command( 'bump' ) - .description( 'CLI to automate version bumping.' ) - .argument( '', 'Monorepo plugin' ) - .requiredOption( '-v, --version ', 'Version to bump to' ) - .action( async ( plugin: string, options ) => { - Logger.startTask( `Bumping versions to ${ options.version }` ); - - await validateArgs( plugin, options ); - - let nextVersion = options.version; - - const prereleaseParameters = prerelease( nextVersion ); - const isDevVersionBump = - prereleaseParameters && prereleaseParameters[ 0 ] === 'dev'; - - await updatePluginFile( plugin, nextVersion ); - - // Any updated files besides the plugin file get a version stripped of prerelease parameters. - nextVersion = stripPrereleaseParameters( nextVersion ); - - if ( isDevVersionBump ) { - // Bumping the dev version means updating the readme's changelog. - await updateReadmeChangelog( plugin, nextVersion ); - } else { - // Only update stable tag on real releases. - await updateReadmeStableTag( plugin, nextVersion ); - } - - await updateJSON( 'composer', plugin, nextVersion ); - await updateJSON( 'package', plugin, nextVersion ); - await updateClassPluginFile( plugin, nextVersion ); - - Logger.endTask(); - } ); diff --git a/tools/version-bump/index.ts b/tools/version-bump/index.ts deleted file mode 100644 index d7d76db112d..00000000000 --- a/tools/version-bump/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Internal dependencies - */ -import { program } from './program'; -import './commands/bump'; - -// Start the program -program.parse(); diff --git a/tools/version-bump/lib/const.ts b/tools/version-bump/lib/const.ts deleted file mode 100644 index 7b6fbef42ad..00000000000 --- a/tools/version-bump/lib/const.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * External dependencies - */ -import { dirname } from 'path'; - -// Escape from ./tools/package-release/src -export const MONOREPO_ROOT = dirname( dirname( dirname( __dirname ) ) ); diff --git a/tools/version-bump/lib/update.ts b/tools/version-bump/lib/update.ts deleted file mode 100644 index f10555dacdd..00000000000 --- a/tools/version-bump/lib/update.ts +++ /dev/null @@ -1,152 +0,0 @@ -/** - * External dependencies - */ -import { readFile, writeFile, stat } from 'fs/promises'; -import { join } from 'path'; -import { Logger } from '@woocommerce/monorepo-utils/src/core/logger'; - -/** - * Internal dependencies - */ -import { MONOREPO_ROOT } from './const'; - -/** - * Update plugin readme stable tag. - * - * @param plugin plugin to update - * @param nextVersion version to bump to - */ -export const updateReadmeStableTag = async ( - plugin: string, - nextVersion: string -): Promise< void > => { - const filePath = join( MONOREPO_ROOT, `plugins/${ plugin }/readme.txt` ); - try { - const readmeContents = await readFile( filePath, 'utf8' ); - - const updatedReadmeContents = readmeContents.replace( - /Stable tag: \d+\.\d+\.\d+\n/m, - `Stable tag: ${ nextVersion }\n` - ); - - await writeFile( filePath, updatedReadmeContents ); - } catch ( e ) { - Logger.error( 'Unable to update readme stable tag' ); - } -}; - -/** - * Update plugin readme changelog. - * - * @param plugin plugin to update - * @param nextVersion version to bump to - */ -export const updateReadmeChangelog = async ( - plugin: string, - nextVersion: string -): Promise< void > => { - const filePath = join( MONOREPO_ROOT, `plugins/${ plugin }/readme.txt` ); - try { - const readmeContents = await readFile( filePath, 'utf8' ); - - const updatedReadmeContents = readmeContents.replace( - /= \d+\.\d+\.\d+ \d\d\d\d-XX-XX =\n/m, - `= ${ nextVersion } ${ new Date().getFullYear() }-XX-XX =\n` - ); - - await writeFile( filePath, updatedReadmeContents ); - } catch ( e ) { - Logger.error( 'Unable to update readme changelog' ); - } -}; - -/** - * Update plugin class file. - * - * @param plugin plugin to update - * @param nextVersion version to bump to - */ -export const updateClassPluginFile = async ( - plugin: string, - nextVersion: string -): Promise< void > => { - const filePath = join( - MONOREPO_ROOT, - `plugins/${ plugin }/includes/class-${ plugin }.php` - ); - - try { - await stat( filePath ); - } catch ( e ) { - // Class file does not exist, return early. - return; - } - - try { - const classPluginFileContents = await readFile( filePath, 'utf8' ); - - const updatedClassPluginFileContents = classPluginFileContents.replace( - /public \$version = '\d+\.\d+\.\d+';\n/m, - `public $version = '${ nextVersion }';\n` - ); - - await writeFile( filePath, updatedClassPluginFileContents ); - } catch ( e ) { - Logger.error( 'Unable to update plugin file.' ); - } -}; - -/** - * Update plugin JSON files. - * - * @param {string} type plugin to update - * @param {string} plugin plugin to update - * @param {string} nextVersion version to bump to - */ -export const updateJSON = async ( - type: 'package' | 'composer', - plugin: string, - nextVersion: string -): Promise< void > => { - const filePath = join( - MONOREPO_ROOT, - `plugins/${ plugin }/${ type }.json` - ); - try { - const composerJson = JSON.parse( await readFile( filePath, 'utf8' ) ); - composerJson.version = nextVersion; - await writeFile( - filePath, - JSON.stringify( composerJson, null, '\t' ) + '\n' - ); - } catch ( e ) { - Logger.error( 'Unable to update composer.json' ); - } -}; - -/** - * Update plugin main file. - * - * @param plugin plugin to update - * @param nextVersion version to bump to - */ -export const updatePluginFile = async ( - plugin: string, - nextVersion: string -): Promise< void > => { - const filePath = join( - MONOREPO_ROOT, - `plugins/${ plugin }/${ plugin }.php` - ); - try { - const pluginFileContents = await readFile( filePath, 'utf8' ); - - const updatedPluginFileContents = pluginFileContents.replace( - /Version: \d+\.\d+\.\d+.*\n/m, - `Version: ${ nextVersion }\n` - ); - await writeFile( filePath, updatedPluginFileContents ); - } catch ( e ) { - Logger.error( 'Unable to update plugin file.' ); - } -}; diff --git a/tools/version-bump/lib/validate.ts b/tools/version-bump/lib/validate.ts deleted file mode 100644 index ae6ed7353f8..00000000000 --- a/tools/version-bump/lib/validate.ts +++ /dev/null @@ -1,76 +0,0 @@ -/** - * External dependencies - */ -import { valid, lt as versionLessThan, parse } from 'semver'; -import { join } from 'path'; -import { readFile } from 'fs/promises'; -import { Logger } from '@woocommerce/monorepo-utils/src/core/logger'; - -/** - * Internal dependencies - */ -import { MONOREPO_ROOT } from './const'; - -/** - * Get a plugin's current version. - * - * @param plugin plugin to update. - */ -export const getCurrentVersion = async ( - plugin: string -): Promise< string | void > => { - const filePath = join( MONOREPO_ROOT, `plugins/${ plugin }/composer.json` ); - try { - const composerJSON = JSON.parse( await readFile( filePath, 'utf8' ) ); - return composerJSON.version; - } catch ( e ) { - Logger.error( 'Unable to read current version.' ); - } -}; - -/** - * When given a prerelease version, return just the version. - * - * @param {string} prereleaseVersion version with prerelease params - * @return {string} version - */ -export const stripPrereleaseParameters = ( - prereleaseVersion: string -): string => { - const parsedVersion = parse( prereleaseVersion ); - if ( parsedVersion ) { - const { major, minor, patch } = parsedVersion; - return `${ major }.${ minor }.${ patch }`; - } - return prereleaseVersion; -}; - -/** - * Validate inputs. - * - * @param plugin plugin - * @param options options - * @param options.version version - */ -export const validateArgs = async ( - plugin: string, - options: { version: string } -): Promise< void > => { - const nextVersion = options.version; - - if ( ! valid( nextVersion ) ) { - Logger.error( - 'Invalid version supplied, please pass in a semantically correct version.' - ); - } - - const currentVersion = await getCurrentVersion( plugin ); - - if ( ! currentVersion ) { - Logger.error( 'Unable to determine current version' ); - } else if ( versionLessThan( nextVersion, currentVersion ) ) { - Logger.error( - 'The version supplied is less than the current version, please supply a valid version.' - ); - } -}; diff --git a/tools/version-bump/package.json b/tools/version-bump/package.json deleted file mode 100644 index da9789252a2..00000000000 --- a/tools/version-bump/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "version-bump", - "version": "0.1.0", - "description": "Automate version bumping for WooCommerce plugins", - "main": " ", - "author": "", - "license": "GPL-2.0-or-later", - "engines": { - "node": "^16.14.1", - "pnpm": "^8.3.1" - }, - "devDependencies": { - "@tsconfig/node16": "^1.0.3", - "@types/express": "^4.17.13", - "typescript": "^4.9.5" - }, - "dependencies": { - "@commander-js/extra-typings": "^0.1.0", - "@woocommerce/monorepo-utils": "workspace:*", - "chalk": "^4.1.2", - "commander": "9.4.0", - "express": "^4.18.1", - "ora": "^5.4.1", - "semver": "^7.3.2", - "ts-node": "^10.9.1" - }, - "scripts": { - "lint": "eslint . --ext .ts --config .eslintrc", - "version": "node -r ts-node/register ./index.ts" - } -} diff --git a/tools/version-bump/program.ts b/tools/version-bump/program.ts deleted file mode 100644 index f593816b288..00000000000 --- a/tools/version-bump/program.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * External dependencies - */ -import { Command } from '@commander-js/extra-typings'; - -export const program = new Command(); - -program - .name( 'version-bump' ) - .description( 'CLI to automate version bumping for WooCommerce plugins.' ); diff --git a/tools/version-bump/tsconfig.json b/tools/version-bump/tsconfig.json deleted file mode 100644 index ec4177ddeb8..00000000000 --- a/tools/version-bump/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "@tsconfig/node16/tsconfig.json", - "ts-node": { - "transpileOnly": true, - "files": true - } -}