mirror of https://github.com/twbs/bootstrap.git
Improve change-version script (#38983)
Only replace the version in specific files instead of blindly all repo files
This commit is contained in:
parent
803c5de300
commit
ba449604ce
|
@ -6,24 +6,22 @@
|
||||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { execFile } from 'node:child_process'
|
||||||
import fs from 'node:fs/promises'
|
import fs from 'node:fs/promises'
|
||||||
import path from 'node:path'
|
import process from 'node:process'
|
||||||
import { fileURLToPath } from 'node:url'
|
|
||||||
import globby from 'globby'
|
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
||||||
|
|
||||||
const VERBOSE = process.argv.includes('--verbose')
|
const VERBOSE = process.argv.includes('--verbose')
|
||||||
const DRY_RUN = process.argv.includes('--dry') || process.argv.includes('--dry-run')
|
const DRY_RUN = process.argv.includes('--dry') || process.argv.includes('--dry-run')
|
||||||
|
|
||||||
// These are the filetypes we only care about replacing the version
|
// These are the files we only care about replacing the version
|
||||||
const GLOB = [
|
const FILES = [
|
||||||
'**/*.{css,html,js,json,md,scss,txt,yml}'
|
'README.md',
|
||||||
|
'hugo.yml',
|
||||||
|
'js/src/base-component.js',
|
||||||
|
'package.js',
|
||||||
|
'scss/mixins/_banner.scss',
|
||||||
|
'site/data/docs-versions.yml'
|
||||||
]
|
]
|
||||||
const GLOBBY_OPTIONS = {
|
|
||||||
cwd: path.join(__dirname, '..'),
|
|
||||||
gitignore: true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
|
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
|
||||||
function regExpQuote(string) {
|
function regExpQuote(string) {
|
||||||
|
@ -54,7 +52,7 @@ async function replaceRecursively(file, oldVersion, newVersion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VERBOSE) {
|
if (VERBOSE) {
|
||||||
console.log(`FILE: ${file}`)
|
console.log(`Found ${oldVersion} in ${file}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DRY_RUN) {
|
if (DRY_RUN) {
|
||||||
|
@ -64,6 +62,19 @@ async function replaceRecursively(file, oldVersion, newVersion) {
|
||||||
await fs.writeFile(file, newString, 'utf8')
|
await fs.writeFile(file, newString, 'utf8')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bumpNpmVersion(newVersion) {
|
||||||
|
if (DRY_RUN) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
execFile('npm', ['version', newVersion, '--no-git-tag'], { shell: true }, error => {
|
||||||
|
if (error) {
|
||||||
|
console.error(error)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function showUsage(args) {
|
function showUsage(args) {
|
||||||
console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]')
|
console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]')
|
||||||
console.error('Got arguments:', args)
|
console.error('Got arguments:', args)
|
||||||
|
@ -87,11 +98,11 @@ async function main(args) {
|
||||||
showUsage(args)
|
showUsage(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
bumpNpmVersion(newVersion)
|
||||||
const files = await globby(GLOB, GLOBBY_OPTIONS)
|
|
||||||
|
|
||||||
|
try {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
files.map(file => replaceRecursively(file, oldVersion, newVersion))
|
FILES.map(file => replaceRecursively(file, oldVersion, newVersion))
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
|
|
Loading…
Reference in New Issue