Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a script to bump the version #1694

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions build/bump-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env node

/*!
* Script to update version number references in the project.
* Copyright 2023 The Bootstrap Authors
* Licensed under MIT (https://github.com/twbs/icons/blob/main/LICENSE)
*/

'use strict'

const { execFile } = require('node:child_process')
const fs = require('node:fs').promises

const VERBOSE = process.argv.includes('--verbose')
const DRY_RUN = process.argv.includes('--dry') || process.argv.includes('--dry-run')

// These are the files we only care about replacing the version
const FILES = [
'build/font/css.hbs',
'build/font/scss.hbs',
'config.yml'
]

// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
function regExpQuote(string) {
return string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&')
}

function regExpQuoteReplacement(string) {
return string.replace(/\$/g, '$$')
}

async function replaceRecursively(file, oldVersion, newVersion) {
const originalString = await fs.readFile(file, 'utf8')
const newString = originalString.replace(
new RegExp(regExpQuote(oldVersion), 'g'),
regExpQuoteReplacement(newVersion)
)

// No need to move any further if the strings are identical
if (originalString === newString) {
return
}

if (VERBOSE) {
console.log(`Found ${oldVersion} in ${file}`)
}

if (DRY_RUN) {
return
}

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) {
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) {
showUsage(args)
}

// 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)
}

bumpNpmVersion(newVersion)

try {
await Promise.all(FILES.map(file => replaceRecursively(file, oldVersion, newVersion)))
} catch (error) {
console.error(error)
process.exit(1)
}
}

main(process.argv.slice(2))
2 changes: 1 addition & 1 deletion build/font/css.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Bootstrap Icons (https://icons.getbootstrap.com/)
* Bootstrap Icons v1.10.4 (https://icons.getbootstrap.com/)
* Copyright 2019-2023 The Bootstrap Authors
* Licensed under MIT (https://github.com/twbs/icons/blob/main/LICENSE.md)
*/
Expand Down
2 changes: 1 addition & 1 deletion build/font/scss.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Bootstrap Icons (https://icons.getbootstrap.com/)
* Bootstrap Icons v1.10.4 (https://icons.getbootstrap.com/)
* Copyright 2019-2023 The Bootstrap Authors
* Licensed under MIT (https://github.com/twbs/icons/blob/main/LICENSE.md)
*/
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@
"icons": "npm-run-all icons-main --aggregate-output --parallel icons-sprite icons-font",
"icons-main": "node build/build-svgs.js",
"icons-zip": "cross-env-shell \"rm -rf bootstrap-icons-$npm_package_version bootstrap-icons-$npm_package_version.zip && cp -r icons/ bootstrap-icons-$npm_package_version && cp bootstrap-icons.svg bootstrap-icons-$npm_package_version && cp -r font/ bootstrap-icons-$npm_package_version && zip -qr9 bootstrap-icons-$npm_package_version.zip bootstrap-icons-$npm_package_version && rm -rf bootstrap-icons-$npm_package_version\"",
"icons-sprite": "svg-sprite --config svg-sprite.json --log=info icons/*.svg",
"icons-sprite": "svg-sprite --config svg-sprite.json --log=info \"icons/*.svg\"",
"icons-font": "npm-run-all icons-font-*",
"icons-font-main": "fantasticon",
"icons-font-min": "cleancss -O1 --format breakWith=lf --with-rebase --output font/bootstrap-icons.min.css font/bootstrap-icons.css",
"release": "npm-run-all icons docs-build icons-zip",
"release-version": "node build/bump-version.js",
"netlify": "cross-env-shell HUGO_BASEURL=$DEPLOY_PRIME_URL npm-run-all icons docs-build",
"test:fusv": "fusv docs/assets/scss/",
"test:eslint": "eslint --cache --cache-location .cache/.eslintcache --report-unused-disable-directives .",
Expand Down