1+ import pc from "picocolors" ;
12import { isMatching , match , P } from "ts-pattern" ;
23
34import { ignores } from "./ignores" ;
@@ -6,32 +7,30 @@ import { version } from "./version";
67
78const GLOB_PACKAGE_JSON = [ "package.json" , "packages/*/package.json" , "packages/*/*/package.json" ] ;
89
9- const mkTask = ( path : string ) => {
10- return async ( ) => {
11- const packageJson = await readJsonFile ( path ) ;
12- if ( ! isMatching ( { version : P . string } , packageJson ) ) {
13- throw new Error ( `Invalid package.json at ${ path } ` ) ;
14- }
15- const newVersion = version ;
16- const oldVersion = match ( packageJson )
17- . with ( { version : P . select ( P . string ) } , v => v )
18- . otherwise ( ( ) => "0.0.0" ) ;
19- if ( oldVersion === newVersion ) {
20- console . info ( `Skipping ${ path } as it's already on version ${ newVersion } ` ) ;
21- return ;
22- }
23- const packageJsonUpdated = {
24- ...packageJson ,
25- version : newVersion ,
26- } ;
27- await writeJsonFile ( path , packageJsonUpdated ) ;
28- console . info ( `Updated ${ path } to version ${ packageJsonUpdated . version } ` ) ;
10+ async function update ( path : string ) {
11+ const packageJson = await readJsonFile ( path ) ;
12+ if ( ! isMatching ( { version : P . string } , packageJson ) ) {
13+ throw new Error ( `Invalid package.json at ${ path } ` ) ;
14+ }
15+ const newVersion = version ;
16+ const oldVersion = match ( packageJson )
17+ . with ( { version : P . select ( P . string ) } , v => v )
18+ . otherwise ( ( ) => "0.0.0" ) ;
19+ if ( oldVersion === newVersion ) {
20+ console . info ( pc . greenBright ( `Skipping ${ path } as it's already on version ${ newVersion } ` ) ) ;
21+ return ;
22+ }
23+ const packageJsonUpdated = {
24+ ...packageJson ,
25+ version : newVersion ,
2926 } ;
30- } ;
27+ await writeJsonFile ( path , packageJsonUpdated ) ;
28+ console . info ( pc . green ( `Updated ${ path } to version ${ packageJsonUpdated . version } ` ) ) ;
29+ }
3130
3231async function main ( ) {
3332 const tasks = glob ( GLOB_PACKAGE_JSON , ignores ) ;
34- await Promise . all ( tasks . map ( mkTask ) ) ;
33+ await Promise . all ( tasks . map ( path => update ( path ) ) ) ;
3534}
3635
3736await main ( ) ;
0 commit comments