1
+ const fs = require ( 'fs' ) ;
2
+ const path = require ( 'path' ) ;
3
+ const { execSync } = require ( 'child_process' ) ;
4
+
5
+ // Get the version number provided as argument
6
+ let version = process . argv [ 2 ] ;
7
+
8
+ if ( version . startsWith ( 'v' ) ) {
9
+ version = version . slice ( 1 )
10
+ }
11
+
12
+ if ( ! version ) {
13
+ console . error ( 'Please provide a version number to bump.' ) ;
14
+ process . exit ( 1 ) ;
15
+ }
16
+
17
+ const packageJsonPath = path . join ( process . cwd ( ) , 'package.json' ) ;
18
+ const packageJson = require ( packageJsonPath ) ;
19
+
20
+ packageJson . version = version ;
21
+
22
+ fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 4 ) ) ;
23
+
24
+ console . log ( `Version bumped to ${ version } in package.json successfully.` ) ;
25
+
26
+ const readmePath = path . join ( process . cwd ( ) , 'Readme.md' ) ;
27
+ let readmeContent = fs . readFileSync ( readmePath , 'utf8' ) ;
28
+
29
+ const oldVersionRegex = / \/ c o o k i e c o n s e n t \/ r e l e a s e s ( v ? \d + \. \d + \. \d + ) / g;
30
+ readmeContent = readmeContent . replace ( oldVersionRegex , `/cookieconsent/releases/${ version } ` ) ;
31
+
32
+ fs . writeFileSync ( readmePath , readmeContent ) ;
33
+
34
+ console . log ( `Version updated to ${ version } in Readme.md successfully.` ) ;
35
+
36
+ const gettingStartedPath = path . join ( process . cwd ( ) , 'docs' , 'essential' , 'getting-started.md' ) ;
37
+ let gettingStartedContent = fs . readFileSync ( gettingStartedPath , 'utf8' ) ;
38
+
39
+ const oldVersionRegex2 = / c o o k i e c o n s e n t @ ( v ? \d + \. \d + \. \d + ) / g;
40
+ gettingStartedContent = gettingStartedContent . replace ( oldVersionRegex2 , `cookieconsent@${ version } ` ) ;
41
+
42
+ fs . writeFileSync ( gettingStartedPath , gettingStartedContent ) ;
43
+
44
+ console . log ( `Version updated to ${ version } in getting-started.md successfully.` ) ;
45
+
46
+ try {
47
+ execSync ( 'pnpm run build' ) ;
48
+ execSync ( 'git add .' ) ;
49
+ execSync ( `git commit -m "build: bump version to ${ version } "` ) ;
50
+ } catch ( error ) {
51
+ console . error ( 'Error committing changes:' , error . message ) ;
52
+ }
0 commit comments