mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-07 04:54:24 +01:00
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 <xhmikosr@gmail.com>
This commit is contained in:
parent
65831d2ea8
commit
b4befee506
@ -35,9 +35,17 @@ function regExpQuoteReplacement(string) {
|
|||||||
|
|
||||||
async function replaceRecursively(file, oldVersion, newVersion) {
|
async function replaceRecursively(file, oldVersion, newVersion) {
|
||||||
const originalString = await fs.readFile(file, 'utf8')
|
const originalString = await fs.readFile(file, 'utf8')
|
||||||
const newString = originalString.replace(
|
const newString = originalString
|
||||||
new RegExp(regExpQuote(oldVersion), 'g'), regExpQuoteReplacement(newVersion)
|
.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
|
// No need to move any further if the strings are identical
|
||||||
if (originalString === newString) {
|
if (originalString === newString) {
|
||||||
@ -55,22 +63,35 @@ async function replaceRecursively(file, oldVersion, newVersion) {
|
|||||||
await fs.writeFile(file, newString, 'utf8')
|
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) {
|
async function main(args) {
|
||||||
let [oldVersion, newVersion] = args
|
let [oldVersion, newVersion] = args
|
||||||
|
|
||||||
if (!oldVersion || !newVersion) {
|
if (!oldVersion || !newVersion) {
|
||||||
console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]')
|
showUsage(args)
|
||||||
console.error('Got arguments:', args)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip any leading `v` from arguments because otherwise we will end up with duplicate `v`s
|
// Strip any leading `v` from arguments because
|
||||||
[oldVersion, newVersion] = [oldVersion, newVersion].map(arg => arg.startsWith('v') ? arg.slice(1) : arg)
|
// 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 {
|
try {
|
||||||
const files = await globby(GLOB, GLOBBY_OPTIONS)
|
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) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user