@@ -87,15 +87,17 @@ export interface CoreOptions {
87
87
88
88
export default class Cli {
89
89
private cli : any
90
+ private updateTime : number
90
91
private rawArgv : string [ ] | string
91
92
private argv : IParameters
92
93
private plugins : PluginItem [ ] = [ ]
93
94
private cliConfiguration : CliConfiguration
94
95
constructor ( data : CliConfiguration , options : CoreOptions = { } ) {
95
96
debug ( 'Init Cli instance on <%s>' , __filename )
96
-
97
97
this . rawArgv = data . argv
98
98
99
+ this . updateTime = data . configs . update_time || 7
100
+
99
101
this . argv = parseParams ( data . argv )
100
102
101
103
this . cliConfiguration = data
@@ -167,8 +169,13 @@ export default class Cli {
167
169
} )
168
170
for ( let i = 0 ; i < packages . length ; i ++ ) {
169
171
const commandBasePath = path . join ( packages [ i ] . root , 'commands' )
172
+ const extensionBasePath = path . join ( packages [ i ] . root , 'extensions' )
170
173
const commandFiles : string [ ] = fs . list ( commandBasePath ) || [ ]
171
174
commands = [ ]
175
+ // continue next package while the package has not commands and extensions folder
176
+ if ( ! fs . existsAsync ( commandBasePath ) && ! fs . existsAsync ( extensionBasePath ) ) {
177
+ continue
178
+ }
172
179
commandFiles . forEach ( file => {
173
180
let content : Command = { }
174
181
try {
@@ -217,18 +224,34 @@ export default class Cli {
217
224
} else {
218
225
// check if there has some module need to be upgraded
219
226
// check last_update_time
220
- const info : any = await updateNpmPackageInfo ( this . cliConfiguration . modules , this . cliConfiguration . registry )
227
+ const info : any = await updateNpmPackageInfo ( this . cliConfiguration . modules , this . cliConfiguration . registry , this . updateTime )
221
228
if ( info ) {
222
229
let upgradeList = { }
223
230
for ( let mod in info . mods ) {
224
231
if ( ! info . mods [ mod ] . is_next ) {
225
232
upgradeList [ mod ] = info . mods [ mod ]
226
233
}
227
234
}
228
- let lists = Object . keys ( upgradeList )
235
+ const generateChangelog = ( changelog : any [ ] | string ) : string => {
236
+ if ( ! changelog ) {
237
+ return ''
238
+ }
239
+ if ( typeof changelog === 'string' ) {
240
+ changelog = [ changelog ]
241
+ }
242
+ changelog = changelog . map ( log => `\n • ${ log } ` )
243
+ return `\n changelog:${ changelog . join ( '' ) } `
244
+ }
245
+
246
+ let lists = Object . keys ( upgradeList ) . map ( key => {
247
+ return {
248
+ name : `${ key } ${ logger . colors . grey ( `${ upgradeList [ key ] . version } -> ${ upgradeList [ key ] . next_version } ${ generateChangelog ( upgradeList [ key ] . changelog ) } ` ) } ` ,
249
+ value : key
250
+ }
251
+ } )
229
252
let yes = 'Yes, update all'
230
253
let no = 'No, next time'
231
- let choices = [ yes , no , new inquirer . Separator ( 'Or choose update package' ) ] . concat ( Object . keys ( upgradeList ) )
254
+ let choices = [ yes , no , new inquirer . Separator ( 'Or choose update package' ) ] . concat ( lists )
232
255
if ( lists . length > 0 ) {
233
256
let res = await inquirer . prompt ( {
234
257
name : 'choose' ,
@@ -418,24 +441,35 @@ export async function updateNpmPackageInfo(modules: ModData, registry: string, t
418
441
return false
419
442
}
420
443
logger . info ( `Time: ${ formateTime ( date ) } , verify if there is an update` )
421
- const spinner = logger . spin ( 'Checking ... please wait' )
422
444
for ( let mod in modData . mods ) {
423
- spinner . text = `Checking ${ mod } ...`
424
- let res = await getNpmPackageLatestVersion ( mod , registry )
445
+ let spinner = logger . spin ( `Checking ${ mod } ... ${ logger . colors . grey ( 'this may take a few seconds' ) } ` )
446
+ spinner . text = ``
447
+ let res = await getLatestNpmPackageInfo ( mod , registry )
425
448
if ( ! res . error ) {
426
- spinner . succeed ( `Finished checking [${ mod } ]` )
449
+ spinner . stopAndPersist ( {
450
+ symbol : `${ logger . colors . green ( `[${ logger . checkmark } ]` ) } ` ,
451
+ text : `sync module [${ mod } ]`
452
+ } )
427
453
if ( semver . gt ( res . latest , modData . mods [ mod ] . version ) ) {
428
454
modData . mods [ mod ] . is_next = false
429
455
modData . mods [ mod ] . next_version = res . latest
456
+ modData . mods [ mod ] . changelog = res . package . changelog || ''
430
457
} else {
431
458
modData . mods [ mod ] . is_next = true
432
459
modData . mods [ mod ] . next_version = res . latest
460
+ modData . mods [ mod ] . changelog = res . package . changelog || ''
433
461
}
434
462
} else {
435
463
if ( res . error === ErrorType . PACKAGE_NOT_FOUND ) {
436
- spinner . fail ( `Package [${ mod } ] not found on registry ${ registry } ` )
464
+ spinner . stopAndPersist ( {
465
+ symbol : `${ logger . colors . red ( `[${ logger . xmark } ]` ) } ` ,
466
+ text : `Package [${ mod } ] not found on registry ${ registry } `
467
+ } )
437
468
} else {
438
- spinner . fail ( `Unkonw error with checking [${ mod } ], ${ res . error } ` )
469
+ spinner . stopAndPersist ( {
470
+ symbol : `${ logger . colors . red ( `[${ logger . xmark } ]` ) } ` ,
471
+ text : `Unkonw error with checking [${ mod } ], ${ res . error } `
472
+ } )
439
473
}
440
474
}
441
475
}
@@ -450,20 +484,21 @@ export async function updateNpmPackageInfo(modules: ModData, registry: string, t
450
484
* @param registry npm registry
451
485
* @returns {error?:string, latest?:string }
452
486
*/
453
- export async function getNpmPackageLatestVersion ( name : string , registry : string ) {
487
+ export async function getLatestNpmPackageInfo ( name : string , registry : string ) {
454
488
const npmApi = http . create ( {
455
489
baseURL : `${ registry } ` ,
456
490
} )
457
- const res : any = await npmApi . get ( `${ name } ` )
491
+ const res : any = await npmApi . get ( `${ name } /latest ` )
458
492
let error
459
493
if ( res . data . error ) {
460
494
if ( / n o t _ f o u n d / . test ( res . data . error ) ) {
461
495
error = ErrorType . PACKAGE_NOT_FOUND
462
496
}
463
- } else if ( res . data [ 'dist-tags' ] [ 'latest '] ) {
464
- const latest = res . data [ 'dist-tags' ] [ 'latest ']
497
+ } else if ( res . data [ 'version ' ] ) {
498
+ const latest = res . data [ 'version ' ]
465
499
return {
466
500
latest : latest ,
501
+ package : res . data
467
502
}
468
503
} else {
469
504
error = `can't found ${ name } latest version`
@@ -481,6 +516,7 @@ export async function getNpmPackageLatestVersion(name: string, registry: string)
481
516
* @param options data from error stack
482
517
*/
483
518
export async function analyzer ( type : string , stack : any , options ?: any ) {
519
+ logger . log ( '\n' )
484
520
if ( type === 'repair' ) {
485
521
if ( ErrorType . PACKAGE_NOT_FOUND === stack ) {
486
522
const innerMods = [ '@weex-cli/debug' , '@weex-cli/generator' , '@weex-cli/build' , '@weex-cli/preview' , '@weex-cli/run' , '@weex-cli/doctor' , '@weex-cli/lint' , '@weex-cli/device' ]
@@ -538,8 +574,6 @@ export async function analyzer(type: string, stack: any, options?: any) {
538
574
logger . log ( logger . colors . grey ( `\nLooking for related issues on:` ) )
539
575
logger . log ( 'https://github.com/weexteam/weex-toolkit/issues?q=is%3Aclosed' )
540
576
}
541
- console . log ( '\n\n\n\n\n' )
542
- console . log ( type , stack , options )
543
577
}
544
578
545
579
export function formateTime ( date : Date ) {
0 commit comments