66 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
77 */
88
9- 'use strict'
10-
11- const fs = require ( 'node:fs' ) . promises
12- const path = require ( 'node:path' )
13- const globby = require ( 'globby' )
9+ import { execFile } from 'node:child_process'
10+ import fs from 'node:fs/promises'
11+ import process from 'node:process'
1412
1513const VERBOSE = process . argv . includes ( '--verbose' )
1614const DRY_RUN = process . argv . includes ( '--dry' ) || process . argv . includes ( '--dry-run' )
1715
18- // These are the filetypes we only care about replacing the version
19- const GLOB = [
20- '**/*.{css,html,js,json,md,scss,txt,yml}'
16+ // These are the files we only care about replacing the version
17+ const FILES = [
18+ 'README.md' ,
19+ 'hugo.yml' ,
20+ 'js/src/base-component.js' ,
21+ 'package.js' ,
22+ 'scss/mixins/_banner.scss'
2123]
22- const GLOBBY_OPTIONS = {
23- cwd : path . join ( __dirname , '..' ) ,
24- gitignore : true
25- }
2624
2725// Blame TC39... https://github.com/benjamingr/RegExp.escape/issues/37
2826function regExpQuote ( string ) {
@@ -53,7 +51,7 @@ async function replaceRecursively(file, oldVersion, newVersion) {
5351 }
5452
5553 if ( VERBOSE ) {
56- console . log ( `FILE: ${ file } ` )
54+ console . log ( `Found ${ oldVersion } in ${ file } ` )
5755 }
5856
5957 if ( DRY_RUN ) {
@@ -63,6 +61,19 @@ async function replaceRecursively(file, oldVersion, newVersion) {
6361 await fs . writeFile ( file , newString , 'utf8' )
6462}
6563
64+ function bumpNpmVersion ( newVersion ) {
65+ if ( DRY_RUN ) {
66+ return
67+ }
68+
69+ execFile ( 'npm' , [ 'version' , newVersion , '--no-git-tag' ] , { shell : true } , error => {
70+ if ( error ) {
71+ console . error ( error )
72+ process . exit ( 1 )
73+ }
74+ } )
75+ }
76+
6677function showUsage ( args ) {
6778 console . error ( 'USAGE: change-version old_version new_version [--verbose] [--dry[-run]]' )
6879 console . error ( 'Got arguments:' , args )
@@ -86,11 +97,11 @@ async function main(args) {
8697 showUsage ( args )
8798 }
8899
89- try {
90- const files = await globby ( GLOB , GLOBBY_OPTIONS )
100+ bumpNpmVersion ( newVersion )
91101
102+ try {
92103 await Promise . all (
93- files . map ( file => replaceRecursively ( file , oldVersion , newVersion ) )
104+ FILES . map ( file => replaceRecursively ( file , oldVersion , newVersion ) )
94105 )
95106 } catch ( error ) {
96107 console . error ( error )
0 commit comments