22
33// npm run deps update
44
5- import { $ } from 'zx' ;
5+ import { $ , minimist , path } from 'zx' ;
66import { roots , json } from './nx.js' ;
77import process from 'node:process' ;
88
9- const not = ( actor ) => ( ...args ) => ! actor ( ...args ) ;
10- const FLAGS = ( arg ) => / ^ - / . test ( arg ) ;
11-
12- const command = process . argv [ 2 ] ;
13- const args = process . argv . slice ( 3 ) . filter ( not ( FLAGS ) ) ;
14- const flags = process . argv . slice ( 3 ) . filter ( FLAGS ) ;
15-
9+ const argvPos = process . argv . findIndex ( a => a . endsWith ( path . parse ( import . meta. url ) . base ) ) + 1 ;
10+ const flags = minimist ( process . argv . slice ( argvPos ) , {
11+ boolean : [ 'commit' , 'dryrun' ] ,
12+ alias : {
13+ 'dry-run' : 'dryrun' ,
14+ } ,
15+ } ) ;
16+ const [ command , ...deps ] = flags . _ ;
1617switch ( command ) {
1718 case 'update' : await update ( ) ; break ;
1819 default : throw 'Unknown command ' + command ;
1920}
2021
2122async function update ( ) {
22- const dryRun = flags . includes ( '--dry-run' ) ;
23- const commit = flags . includes ( '--commit' ) ;
24- const deps = args . slice ( ) ;
23+ const { dryrun, commit } = flags ;
2524 const projects = await roots ( ) ;
2625
2726 const work = [ ] ;
@@ -39,7 +38,15 @@ async function update() {
3938 const dependencies = pkg [ key ] || { } ;
4039
4140 if ( dependencies [ name ] && dependencies [ name ] !== '*' ) {
42- work . push ( { pkg : pkg . name , name, key, mode, root, prev : dependencies [ name ] , next : version } ) ;
41+ work . push ( {
42+ pkg : pkg . name ,
43+ name,
44+ key,
45+ mode,
46+ root,
47+ prev : dependencies [ name ] ,
48+ next : version
49+ } ) ;
4350 }
4451 }
4552 }
@@ -63,7 +70,7 @@ async function update() {
6370
6471 console . log ( log . join ( '\n' ) ) ;
6572
66- if ( dryRun ) {
73+ if ( dryrun ) {
6774 continue ;
6875 }
6976
0 commit comments