diff --git a/node-tests/replace-url-versions.js b/node-tests/replace-url-versions.js new file mode 100644 index 0000000000..322730b9ed --- /dev/null +++ b/node-tests/replace-url-versions.js @@ -0,0 +1,106 @@ +const { expect } = require('chai'); +const replaceURLVersions = require('../scripts/helpers/replace-url-versions'); + +describe('replace url versions', function () { + it('works', function () { + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember/release/', + '3.15', + '3.15' + ) + ).to.equal('https://api.emberjs.com/ember/3.15/'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember/release', + '3.15', + '3.15' + ) + ).to.equal('https://api.emberjs.com/ember/3.15'); + expect( + replaceURLVersions('https://api.emberjs.com/ember/3.20/', '3.15', '3.15') + ).to.equal('https://api.emberjs.com/ember/3.15/'); + expect( + replaceURLVersions('https://api.emberjs.com/ember/3.20', '3.15', '3.15') + ).to.equal('https://api.emberjs.com/ember/3.15'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember/release/classes/Application', + '3.15', + '3.15' + ) + ).to.equal('https://api.emberjs.com/ember/3.15/classes/Application'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember-data/release/', + '3.15', + '3.15' + ) + ).to.equal('https://api.emberjs.com/ember-data/3.15/'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember-data/release', + '3.15', + '3.15' + ) + ).to.equal('https://api.emberjs.com/ember-data/3.15'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember-data/release', + '3.15', + '3.12' + ) + ).to.equal('https://api.emberjs.com/ember-data/3.12'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember/release', + '3.15', + '3.12' + ) + ).to.equal('https://api.emberjs.com/ember/3.15'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember-data/release/classes/Model/', + '3.15', + '3.15' + ) + ).to.equal('https://api.emberjs.com/ember-data/3.15/classes/Model/'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember-data/3.20/classes/Model/', + '3.15', + '3.15' + ) + ).to.equal('https://api.emberjs.com/ember-data/3.15/classes/Model/'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember-data/3.20/classes/Model/', + '3.15', + '3.12' + ) + ).to.equal('https://api.emberjs.com/ember-data/3.12/classes/Model/'); + expect( + replaceURLVersions( + 'https://api.emberjs.com/ember/release/classes/@ember%2Fapplication/methods/getOwner', + '3.15', + '3.15' + ) + ).to.equal( + 'https://api.emberjs.com/ember/3.15/classes/@ember%2Fapplication/methods/getOwner' + ); + expect( + replaceURLVersions( + 'https://guides.emberjs.com/release/getting-started/', + '3.15', + '3.15' + ) + ).to.equal('https://guides.emberjs.com/v3.15.0/getting-started/'); + expect( + replaceURLVersions( + 'https://guides.emberjs.com/release/getting-started/', + '3.16.0', + '3.16.0' + ) + ).to.equal('https://guides.emberjs.com/v3.16.0/getting-started/'); + }); +}); diff --git a/package-lock.json b/package-lock.json index 1d04d61b0c..987e39bd57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "babel-eslint": "^10.1.0", "broccoli-asset-rev": "^3.0.0", "chai": "^4.3.4", + "commander": "^11.1.0", "compare-versions": "^6.0.0-rc.2", "ember-auto-import": "^2.6.1", "ember-cli": "~4.0.1", @@ -10312,6 +10313,12 @@ "node": "10.* || >= 12.*" } }, + "node_modules/broccoli-terser-sourcemap/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "node_modules/broccoli-terser-sourcemap/node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -11418,10 +11425,13 @@ } }, "node_modules/commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", + "dev": true, + "engines": { + "node": ">=16" + } }, "node_modules/common-tags": { "version": "1.8.0", @@ -38515,6 +38525,13 @@ "node": ">=0.4.0" } }, + "node_modules/terser-webpack-plugin/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true, + "peer": true + }, "node_modules/terser-webpack-plugin/node_modules/schema-utils": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", @@ -38570,6 +38587,12 @@ "node": ">=10" } }, + "node_modules/terser/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "node_modules/terser/node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -38645,6 +38668,12 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/testem/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "node_modules/testem/node_modules/cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -49399,6 +49428,12 @@ "symlink-or-copy": "^1.3.1" } }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -50191,9 +50226,9 @@ } }, "commander": { - "version": "2.20.3", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", "dev": true }, "common-tags": { @@ -71927,6 +71962,12 @@ "source-map-support": "~0.5.12" }, "dependencies": { + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -71964,6 +72005,13 @@ "integrity": "sha512-jaVNAFBHNLXspO543WnNNPZFRtavh3skAkITqD0/2aeMkKZTN+254PyhwxFYrk3vQ1xfY+2wbesJMs/JC8/PwQ==", "dev": true }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true, + "peer": true + }, "schema-utils": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-3.3.0.tgz", @@ -72052,6 +72100,12 @@ "readable-stream": "^3.6.0" } }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", diff --git a/package.json b/package.json index 14e7811267..bf01c47f4c 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "babel-eslint": "^10.1.0", "broccoli-asset-rev": "^3.0.0", "chai": "^4.3.4", + "commander": "^11.1.0", "compare-versions": "^6.0.0-rc.2", "ember-auto-import": "^2.6.1", "ember-cli": "~4.0.1", diff --git a/scripts/helpers/replace-url-versions.js b/scripts/helpers/replace-url-versions.js new file mode 100644 index 0000000000..e9f774f096 --- /dev/null +++ b/scripts/helpers/replace-url-versions.js @@ -0,0 +1,37 @@ +module.exports = function replaceURLVersions( + str, + emberVersion, + emberDataVersion +) { + let output; + + // guides use `v3.20.0` version format + const emberPatchVersion = /\d+\.\d+.\d+/.test(emberVersion) + ? emberVersion + : emberVersion + '.0'; + output = str.replace( + /https:\/\/guides.emberjs.com\/(release|v\d+\.\d+.\d+)(\/?)/g, + `https://guides.emberjs.com/v${emberPatchVersion}$2` + ); + + const emberDataPatchVersion = /\d+\.\d+.\d+/.test(emberDataVersion) + ? emberDataVersion + : emberDataVersion + '.0'; + output = str.replace( + /https:\/\/guides.emberjs.com\/(release|v\d+\.\d+.\d+)(\/?)/g, + `https://guides.emberjs.com/v${emberDataPatchVersion}$2` + ); + + // apis use `3.20` version format + output = output.replace( + /https:\/\/api.emberjs.com\/(ember)\/(release|\d+\.\d+)(\/?)/g, + `https://api.emberjs.com/$1/${emberVersion}$3` + ); + + output = output.replace( + /https:\/\/api.emberjs.com\/(ember-data)\/(release|\d+\.\d+)(\/?)/g, + `https://api.emberjs.com/$1/${emberDataVersion}$3` + ); + + return output; +}; diff --git a/scripts/update-version-links b/scripts/update-version-links index caebd5eb12..a1df2d72bc 100755 --- a/scripts/update-version-links +++ b/scripts/update-version-links @@ -1,4 +1,4 @@ -#!/usr/bin/node +#!/usr/bin/env node /** * Search & Replace previous release numbers @@ -26,86 +26,24 @@ */ const fs = require('fs'); - -const replaceURLsVersions = (str, version) => { - let output; - - // guides use `v3.20.0` version format - const patchVersion = /\d+\.\d+.\d+/.test(version) ? version : version + '.0'; - output = str.replace( - /https:\/\/guides.emberjs.com\/(release|v\d+\.\d+.\d+)(\/?)/g, - `https://guides.emberjs.com/v${patchVersion}$2` - ); - - // apis use `3.20` version format - output = output.replace( - /https:\/\/api.emberjs.com\/(ember|ember-data)\/(release|\d+\.\d+)(\/?)/g, - `https://api.emberjs.com/$1/${version}$3` - ); - - return output; -}; - -const runTests = () => { - let test; - - console.log('Running tests...'); - - test = replaceURLsVersions('https://api.emberjs.com/ember/release/', '3.15'); - console.log(test === 'https://api.emberjs.com/ember/3.15/' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember/release', '3.15'); - console.log(test === 'https://api.emberjs.com/ember/3.15' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember/3.20/', '3.15'); - console.log(test === 'https://api.emberjs.com/ember/3.15/' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember/3.20', '3.15'); - console.log(test === 'https://api.emberjs.com/ember/3.15' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember/release/classes/Application', '3.15'); - console.log(test === 'https://api.emberjs.com/ember/3.15/classes/Application' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember-data/release/', '3.15'); - console.log(test === 'https://api.emberjs.com/ember-data/3.15/' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember-data/release', '3.15'); - console.log(test === 'https://api.emberjs.com/ember-data/3.15' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember-data/release/classes/Model/', '3.15'); - console.log(test === 'https://api.emberjs.com/ember-data/3.15/classes/Model/' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember-data/3.20/classes/Model/', '3.15'); - console.log(test === 'https://api.emberjs.com/ember-data/3.15/classes/Model/' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://api.emberjs.com/ember/release/classes/@ember%2Fapplication/methods/getOwner', '3.15'); - console.log(test === 'https://api.emberjs.com/ember/3.15/classes/@ember%2Fapplication/methods/getOwner' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://guides.emberjs.com/release/getting-started/', '3.15'); - console.log(test === 'https://guides.emberjs.com/v3.15.0/getting-started/' ? '✅' : '❌', test); - - test = replaceURLsVersions('https://guides.emberjs.com/release/getting-started/', '3.16.0'); - console.log(test === 'https://guides.emberjs.com/v3.16.0/getting-started/' ? '✅' : '❌', test); -}; - -if (process.argv[2] === '--tests') { - runTests(); - process.exit(0); -} - -const currentFolder = fs.realpathSync(process.argv[2]); -const newVersionNumber = process.argv[3]; - -let dryRun = false; -let verbose = false; -let silent = false; - -if (process.argv.length > 4) { - const options = process.argv.slice(4); - dryRun = options.includes('--dry-run'); - verbose = options.includes('--verbose'); - silent = options.includes('--silent'); -} +const replaceURLsVersions = require('./helpers/replace-url-versions') +const { Command } = require('commander'); +const program = new Command(); + program.option('--dry-run') + .option('--verbose') + .option('--silent') + .argument('') + .argument('') + .argument(''); +program.parse(process.argv); +const options = program.opts(); + +const currentFolder = fs.realpathSync(program.args[0]); +const newVersionNumber = program.args[1]; + +let dryRun = options.dryRun; +let verbose = options.verbose; +let silent = options.silent; let filesFound = []; let filesUpdated = [];