aboutsummaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorJulien Déramond <[email protected]>2023-04-12 21:56:22 +0200
committerGitHub <[email protected]>2023-04-12 22:56:22 +0300
commitb4befee506260d2b62705f3faec5142054feac6b (patch)
tree02599a15ad31707fe30854334812f7b76df82c7e /build
parent65831d2ea87b9e714ff9451f939bf9b96b3be1fe (diff)
downloadbootstrap-b4befee506260d2b62705f3faec5142054feac6b.tar.xz
bootstrap-b4befee506260d2b62705f3faec5142054feac6b.zip
change-version.js: handle rubygems specific version number (#38452)
* Handle Ruby specific version in `change-version.js` * Guard against the same version --------- Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'build')
-rw-r--r--build/change-version.js39
1 files changed, 30 insertions, 9 deletions
diff --git a/build/change-version.js b/build/change-version.js
index cda0ea12d..9685df589 100644
--- a/build/change-version.js
+++ b/build/change-version.js
@@ -35,9 +35,17 @@ function regExpQuoteReplacement(string) {
async function replaceRecursively(file, oldVersion, newVersion) {
const originalString = await fs.readFile(file, 'utf8')
- const newString = originalString.replace(
- new RegExp(regExpQuote(oldVersion), 'g'), regExpQuoteReplacement(newVersion)
- )
+ const newString = originalString
+ .replace(
+ new RegExp(regExpQuote(oldVersion), 'g'),
+ regExpQuoteReplacement(newVersion)
+ )
+ // Also replace the version used by the rubygem,
+ // which is using periods (`.`) instead of hyphens (`-`)
+ .replace(
+ new RegExp(regExpQuote(oldVersion.replace(/-/g, '.')), 'g'),
+ regExpQuoteReplacement(newVersion.replace(/-/g, '.'))
+ )
// No need to move any further if the strings are identical
if (originalString === newString) {
@@ -55,22 +63,35 @@ async function replaceRecursively(file, oldVersion, newVersion) {
await fs.writeFile(file, newString, 'utf8')
}
+function showUsage(args) {
+ console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]')
+ console.error('Got arguments:', args)
+ process.exit(1)
+}
+
async function main(args) {
let [oldVersion, newVersion] = args
if (!oldVersion || !newVersion) {
- console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]')
- console.error('Got arguments:', args)
- process.exit(1)
+ showUsage(args)
}
- // Strip any leading `v` from arguments because otherwise we will end up with duplicate `v`s
- [oldVersion, newVersion] = [oldVersion, newVersion].map(arg => arg.startsWith('v') ? arg.slice(1) : arg)
+ // Strip any leading `v` from arguments because
+ // otherwise we will end up with duplicate `v`s
+ [oldVersion, newVersion] = [oldVersion, newVersion].map(arg => {
+ return arg.startsWith('v') ? arg.slice(1) : arg
+ })
+
+ if (oldVersion === newVersion) {
+ showUsage(args)
+ }
try {
const files = await globby(GLOB, GLOBBY_OPTIONS)
- await Promise.all(files.map(file => replaceRecursively(file, oldVersion, newVersion)))
+ await Promise.all(
+ files.map(file => replaceRecursively(file, oldVersion, newVersion))
+ )
} catch (error) {
console.error(error)
process.exit(1)