22
33/*!
44 * Script to update version number references in the project.
5- * Copyright 2017-2022 The Bootstrap Authors
6- * Copyright 2017-2022 Twitter, Inc.
5+ * Copyright 2017-2023 The Bootstrap Authors
76 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
87 */
98
@@ -24,9 +23,6 @@ const GLOBBY_OPTIONS = {
2423 cwd : path . join ( __dirname , '..' ) ,
2524 gitignore : true
2625}
27- const EXCLUDED_FILES = [
28- 'CHANGELOG.md'
29- ]
3026
3127// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
3228function regExpQuote ( string ) {
@@ -39,9 +35,17 @@ function regExpQuoteReplacement(string) {
3935
4036async function replaceRecursively ( file , oldVersion , newVersion ) {
4137 const originalString = await fs . readFile ( file , 'utf8' )
42- const newString = originalString . replace (
43- new RegExp ( regExpQuote ( oldVersion ) , 'g' ) , regExpQuoteReplacement ( newVersion )
44- )
38+ const newString = originalString
39+ . replace (
40+ new RegExp ( regExpQuote ( oldVersion ) , 'g' ) ,
41+ regExpQuoteReplacement ( newVersion )
42+ )
43+ // Also replace the version used by the rubygem,
44+ // which is using periods (`.`) instead of hyphens (`-`)
45+ . replace (
46+ new RegExp ( regExpQuote ( oldVersion . replace ( / - / g, '.' ) ) , 'g' ) ,
47+ regExpQuoteReplacement ( newVersion . replace ( / - / g, '.' ) )
48+ )
4549
4650 // No need to move any further if the strings are identical
4751 if ( originalString === newString ) {
@@ -59,22 +63,35 @@ async function replaceRecursively(file, oldVersion, newVersion) {
5963 await fs . writeFile ( file , newString , 'utf8' )
6064}
6165
66+ function showUsage ( args ) {
67+ console . error ( 'USAGE: change-version old_version new_version [--verbose] [--dry[-run]]' )
68+ console . error ( 'Got arguments:' , args )
69+ process . exit ( 1 )
70+ }
71+
6272async function main ( args ) {
6373 let [ oldVersion , newVersion ] = args
6474
6575 if ( ! oldVersion || ! newVersion ) {
66- console . error ( 'USAGE: change-version old_version new_version [--verbose] [--dry[-run]]' )
67- console . error ( 'Got arguments:' , args )
68- process . exit ( 1 )
76+ showUsage ( args )
6977 }
7078
71- // Strip any leading `v` from arguments because otherwise we will end up with duplicate `v`s
72- [ oldVersion , newVersion ] = [ oldVersion , newVersion ] . map ( arg => arg . startsWith ( 'v' ) ? arg . slice ( 1 ) : arg )
79+ // Strip any leading `v` from arguments because
80+ // otherwise we will end up with duplicate `v`s
81+ [ oldVersion , newVersion ] = [ oldVersion , newVersion ] . map ( arg => {
82+ return arg . startsWith ( 'v' ) ? arg . slice ( 1 ) : arg
83+ } )
84+
85+ if ( oldVersion === newVersion ) {
86+ showUsage ( args )
87+ }
7388
7489 try {
75- const files = await globby ( GLOB , GLOBBY_OPTIONS , EXCLUDED_FILES )
90+ const files = await globby ( GLOB , GLOBBY_OPTIONS )
7691
77- await Promise . all ( files . map ( file => replaceRecursively ( file , oldVersion , newVersion ) ) )
92+ await Promise . all (
93+ files . map ( file => replaceRecursively ( file , oldVersion , newVersion ) )
94+ )
7895 } catch ( error ) {
7996 console . error ( error )
8097 process . exit ( 1 )
0 commit comments