@@ -26,9 +26,29 @@ import childProcess from 'node:child_process';
2626import fs from 'node:fs' ;
2727import path from 'node:path' ;
2828import { fileURLToPath , URL } from 'node:url' ;
29+ import parseArgs from 'minimist' ;
30+ import semver from 'semver' ;
2931
32+ const flags = parseArgs ( process . argv . slice ( 2 ) ) ;
33+ if ( ! flags [ 'new-version' ] ) {
34+ process . stderr . write ( `No new version specified\n` ) ;
35+ process . exit ( ) ;
36+ }
3037const __dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
31- const newVersion = process . env . npm_package_version ;
38+ const rootPackageJsonPath = path . resolve ( __dirname , '../package.json' ) ;
39+ const rootPackageJson = JSON . parse ( fs . readFileSync ( rootPackageJsonPath , 'utf-8' ) ) ;
40+ const currentVersion = semver ( rootPackageJson . version ) ;
41+ const newVersion = semver ( flags [ 'new-version' ] ) ;
42+
43+ if ( ! semver . gt ( newVersion , currentVersion ) ) {
44+ process . stderr . write ( `New version must be greater than current version\n` ) ;
45+ process . exit ( ) ;
46+ }
47+
48+ rootPackageJson . version = newVersion . toString ( ) ;
49+ fs . writeFileSync ( rootPackageJsonPath , `${ JSON . stringify ( rootPackageJson , null , 2 ) } \n` , 'utf8' ) ;
50+ childProcess . execSync ( `git add "${ rootPackageJsonPath } "` ) ;
51+
3252const packagesDirPath = path . resolve ( __dirname , '../packages' ) ;
3353const packages = fs . readdirSync ( packagesDirPath ) ;
3454
@@ -43,7 +63,7 @@ packages.forEach((packageName) => {
4363 return ;
4464 }
4565 const pkgJson = JSON . parse ( fs . readFileSync ( packageJsonPath ) ) ;
46- pkgJson . version = newVersion ;
66+ pkgJson . version = newVersion . toString ( ) ;
4767
4868 [ 'dependencies' , 'devDependencies' , 'optionalDependencies' , 'peerDependencies' ]
4969 . forEach ( ( dependencyType ) => {
@@ -52,10 +72,15 @@ packages.forEach((packageName) => {
5272 }
5373 Object . keys ( pkgJson [ dependencyType ] ) . forEach ( ( dependencyName ) => {
5474 if ( packages . includes ( dependencyName ) ) {
55- pkgJson [ dependencyType ] [ dependencyName ] = `^${ newVersion } ` ;
75+ pkgJson [ dependencyType ] [ dependencyName ] = `^${ newVersion . toString ( ) } ` ;
5676 }
5777 } ) ;
5878 } ) ;
5979 fs . writeFileSync ( packageJsonPath , `${ JSON . stringify ( pkgJson , null , 2 ) } \n` , 'utf8' ) ;
6080 childProcess . execSync ( `git add "${ packageJsonPath } "` ) ;
6181} ) ;
82+
83+ childProcess . execSync ( `yarn install` ) ;
84+ childProcess . execSync ( `git add "${ path . resolve ( __dirname , '../yarn.lock' ) } "` ) ;
85+ childProcess . execSync ( `git commit -m "v${ newVersion . toString ( ) } "` ) ;
86+ childProcess . execSync ( `git tag -a v${ newVersion . toString ( ) } -m "v${ newVersion . toString ( ) } "` ) ;
0 commit comments