Skip to content

Commit 50f8085

Browse files
committed
Add a script to bump the version
Also, add the version in font CSS and SCSS files
1 parent 7f54c78 commit 50f8085

File tree

4 files changed

+106
-3
lines changed

4 files changed

+106
-3
lines changed

build/bump-version.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env node
2+
3+
/*!
4+
* Script to update version number references in the project.
5+
* Copyright 2023 The Bootstrap Authors
6+
* Licensed under MIT (https://github.com/twbs/icons/blob/main/LICENSE)
7+
*/
8+
9+
'use strict'
10+
11+
const { execFile } = require('node:child_process')
12+
const fs = require('node:fs').promises
13+
14+
const VERBOSE = process.argv.includes('--verbose')
15+
const DRY_RUN = process.argv.includes('--dry') || process.argv.includes('--dry-run')
16+
17+
// These are the files we only care about replacing the version
18+
const FILES = [
19+
'build/font/css.hbs',
20+
'build/font/scss.hbs',
21+
'config.yml'
22+
]
23+
24+
// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
25+
function regExpQuote(string) {
26+
return string.replace(/[$()*+-.?[\\\]^{|}]/g, '\\$&')
27+
}
28+
29+
function regExpQuoteReplacement(string) {
30+
return string.replace(/\$/g, '$$')
31+
}
32+
33+
async function replaceRecursively(file, oldVersion, newVersion) {
34+
const originalString = await fs.readFile(file, 'utf8')
35+
const newString = originalString.replace(
36+
new RegExp(regExpQuote(oldVersion), 'g'),
37+
regExpQuoteReplacement(newVersion)
38+
)
39+
40+
// No need to move any further if the strings are identical
41+
if (originalString === newString) {
42+
return
43+
}
44+
45+
if (VERBOSE) {
46+
console.log(`Found ${oldVersion} in ${file}`)
47+
}
48+
49+
if (DRY_RUN) {
50+
return
51+
}
52+
53+
await fs.writeFile(file, newString, 'utf8')
54+
}
55+
56+
function bumpNpmVersion(newVersion) {
57+
if (DRY_RUN) {
58+
return
59+
}
60+
61+
execFile('npm', ['version', newVersion, '--no-git-tag'], { shell: true }, (error) => {
62+
if (error) {
63+
console.error(error)
64+
process.exit(1)
65+
}
66+
})
67+
}
68+
69+
function showUsage(args) {
70+
console.error('USAGE: change-version old_version new_version [--verbose] [--dry[-run]]')
71+
console.error('Got arguments:', args)
72+
process.exit(1)
73+
}
74+
75+
async function main(args) {
76+
let [oldVersion, newVersion] = args
77+
78+
if (!oldVersion || !newVersion) {
79+
showUsage(args)
80+
}
81+
82+
// Strip any leading `v` from arguments because
83+
// otherwise we will end up with duplicate `v`s
84+
[oldVersion, newVersion] = [oldVersion, newVersion].map(arg => {
85+
return arg.startsWith('v') ? arg.slice(1) : arg
86+
})
87+
88+
if (oldVersion === newVersion) {
89+
showUsage(args)
90+
}
91+
92+
bumpNpmVersion(newVersion)
93+
94+
try {
95+
await Promise.all(FILES.map(file => replaceRecursively(file, oldVersion, newVersion)))
96+
} catch (error) {
97+
console.error(error)
98+
process.exit(1)
99+
}
100+
}
101+
102+
main(process.argv.slice(2))

build/font/css.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Bootstrap Icons (https://icons.getbootstrap.com/)
2+
* Bootstrap Icons v1.10.4 (https://icons.getbootstrap.com/)
33
* Copyright 2019-2023 The Bootstrap Authors
44
* Licensed under MIT (https://github.com/twbs/icons/blob/main/LICENSE.md)
55
*/

build/font/scss.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Bootstrap Icons (https://icons.getbootstrap.com/)
2+
* Bootstrap Icons v1.10.4 (https://icons.getbootstrap.com/)
33
* Copyright 2019-2023 The Bootstrap Authors
44
* Licensed under MIT (https://github.com/twbs/icons/blob/main/LICENSE.md)
55
*/

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@
5252
"icons": "npm-run-all icons-main --aggregate-output --parallel icons-sprite icons-font",
5353
"icons-main": "node build/build-svgs.js",
5454
"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\"",
55-
"icons-sprite": "svg-sprite --config svg-sprite.json --log=info icons/*.svg",
55+
"icons-sprite": "svg-sprite --config svg-sprite.json --log=info \"icons/*.svg\"",
5656
"icons-font": "npm-run-all icons-font-*",
5757
"icons-font-main": "fantasticon",
5858
"icons-font-min": "cleancss -O1 --format breakWith=lf --with-rebase --output font/bootstrap-icons.min.css font/bootstrap-icons.css",
5959
"release": "npm-run-all icons docs-build icons-zip",
60+
"release-version": "node build/bump-version.js",
6061
"netlify": "cross-env-shell HUGO_BASEURL=$DEPLOY_PRIME_URL npm-run-all icons docs-build",
6162
"test:fusv": "fusv docs/assets/scss/",
6263
"test:eslint": "eslint --cache --cache-location .cache/.eslintcache --report-unused-disable-directives .",

0 commit comments

Comments
 (0)