1
1
const { readFile, writeFile } = require ( "fs/promises" ) ;
2
2
const { join } = require ( "path" ) ;
3
3
const [ , tag ] = process . argv . find ( ( value ) => value . startsWith ( "tag" ) ) . split ( "=" ) ;
4
- const splitAt = tag . lastIndexOf ( "-" ) ;
4
+ const splitAt = tag . lastIndexOf ( "-v " ) ;
5
5
const pkgName = tag . substring ( 0 , splitAt ) ;
6
6
const version = tag . substring ( splitAt + 2 ) ;
7
7
@@ -12,16 +12,32 @@ const version = tag.substring(splitAt + 2);
12
12
* @returns {void }
13
13
*/
14
14
module . exports = async function ( packages = [ ] , dev = false ) {
15
+ console . log (
16
+ "\x1b[34m%s\x1b[0m" ,
17
+ `Updating dependant packages with "${ pkgName } " version "${ version } "`
18
+ ) ;
19
+
15
20
for ( let index = 0 ; index < packages . length ; index ++ ) {
21
+ console . log ( "\x1b[34m%s\x1b[0m" , `Updating "${ packages [ index ] } "` ) ;
22
+
16
23
const pkgJSONPath = join ( __dirname , "../packages" , packages [ index ] , "package.json" ) ;
17
24
const pkgJSON = JSON . parse ( await readFile ( pkgJSONPath , { encoding : "utf8" } ) ) ;
18
25
const pkgType = dev ? "devDependencies" : "dependencies" ;
19
26
20
- if ( ! pkgJSON [ pkgType ] ?. [ pkgName ] ) continue ;
27
+ if ( ! pkgJSON [ pkgType ] ?. [ pkgName ] ) {
28
+ console . log (
29
+ "\x1b[34m%s\x1b[0m" ,
30
+ `Couldn't find "${ pkgName } " in "${ packages [ index ] } " ${ pkgType } , skipping`
31
+ ) ;
32
+
33
+ continue ;
34
+ }
21
35
22
36
// update pkg version
23
37
pkgJSON [ pkgType ] [ pkgName ] = `^${ version } ` ;
24
38
// override existing file
25
39
await writeFile ( pkgJSONPath , JSON . stringify ( pkgJSON , null , 2 ) ) ;
40
+
41
+ console . log ( "\x1b[34m%s\x1b[0m" , `Succesfully updated "${ packages [ index ] } " package` ) ;
26
42
}
27
43
} ;
0 commit comments