11import * as cp from 'child_process'
2- import * as path from 'path'
32
4- import { Files , Log , Logger , Project , Updater } from './index'
3+ import { Log , Logger , Project , Updater } from './index'
54
65export abstract class UpdateScript implements Updater {
76 protected readonly log : Log
@@ -16,17 +15,14 @@ export abstract class UpdateScript implements Updater {
1615 return this . _name
1716 }
1817
19- public get testing ( ) : boolean {
20- const env = ( process . env . NODE_ENV || '' ) . toLowerCase ( )
21- return [ 'test' , 'testing' ] . some ( value => value === env )
22- }
23-
2418 public exec ( project : Project ) : Promise < Project > {
25- return (
26- project . children && project . children . length
27- ? Promise . all ( project . children . map ( child => this . workspace ( child ) . then ( proj => this . log . task ( proj . name ) ) ) ) . then ( ( ) => project )
28- : Promise . resolve ( project )
29- ) . then ( ( ) => this . log . task ( this . name , project . name ) ) . then ( ( ) => project )
19+ const rootProject = project . children && project . children . length
20+ ? Promise . all ( project . children . map ( child => this . workspace ( child ) . then ( proj => this . log . task ( proj . name ) ) ) ) . then ( ( ) => project )
21+ : Promise . resolve ( project )
22+
23+ return rootProject
24+ . then ( ( ) => this . log . start ( this . name , project . name ) )
25+ . then ( ( ) => project )
3026 }
3127
3228 protected workspace ( project : Project ) : Promise < Project > {
@@ -35,32 +31,31 @@ export abstract class UpdateScript implements Updater {
3531 . then ( ( ) => project )
3632 }
3733
38- protected npm < NPM > ( basepath : string ) : Promise < NPM > {
39- const filename = path . join ( basepath , 'package.json' )
40- return Files . exists ( filename ) . then ( ( ) => Files . json < NPM > ( filename ) )
41- }
42-
4334 protected run ( project : Project , command : string , ...args : string [ ] ) : Promise < void > {
4435 return new Promise < void > ( ( resolve , reject ) => {
4536 this . log . debug ( 'run' , project . name , command , ...args )
4637
4738 const child = cp . exec ( `${ command } ${ args . join ( ' ' ) } ` , { cwd : project . path } , error => {
48- if ( error ) this . log . error ( error )
39+ /* istanbul ignore next */
40+ if ( error ) {
41+ this . log . error ( error )
42+ }
4943 } )
5044
5145 child . stderr . on ( 'data' , data =>
52- this . args ( project , process . stderr , data )
46+ this . stream ( project , process . stderr , data )
5347 . map ( lines => lines )
5448 . forEach ( args => this . log . error ( ...args ) )
5549 )
5650
5751 child . stdout . on ( 'data' , data =>
58- this . args ( project , process . stdout , data )
52+ this . stream ( project , process . stdout , data )
5953 . map ( lines => lines )
6054 . forEach ( args => this . log . task ( ...args ) )
6155 )
6256
6357 child . addListener ( 'exit' , ( code : number , signal : string ) => {
58+ /* istanbul ignore next */
6459 if ( code === 0 ) {
6560 resolve ( )
6661 } else {
@@ -70,11 +65,12 @@ export abstract class UpdateScript implements Updater {
7065 } )
7166 }
7267
73- private args ( project : Project , stream : NodeJS . WriteStream , data : string | Buffer ) : string [ ] [ ] {
68+ private stream ( project : Project , stream : NodeJS . WriteStream , data : string | Buffer ) : string [ ] [ ] {
7469 const format = ( lines : string [ ] ) : string [ ] [ ] => {
7570 return lines . filter ( line => line . trim ( ) ) . map ( line => [ project . name , '>' , line ] )
7671 }
7772
73+ /* istanbul ignore next */
7874 if ( data instanceof Buffer ) {
7975 return format ( data . toString ( ) . replace ( '\r' , '' ) . split ( '\n' ) )
8076 }
0 commit comments