import spawn from 'cross-spawn' ; import * as fs from 'fs-extra' ; param { * } root param { * } allDependencies param { * } action export async function doAction ( root , allDependencies , action = 'install' ) { typeof allDependencies === 'string' ? ( allDependencies = [ allDependencies ] ) : null ; return new Promise ( ( resolve ) => { const command = 'npm' ; const args = [ action , '--save' , '--save-exact' , '--loglevel' , 'error' , ... allDependencies , '--cwd' , root , ] ; const child = spawn ( command , args , { stdio : 'inherit' } ) ; child . on ( 'close' , resolve ) ; } ) ; } export async function buildAction ( root , script , cwd , isLerna , name ) { return new Promise ( ( resolve ) => { if ( isLerna ) { const command = `lerna exec npm run ` ; const args = [ script , `--scope=${ name }` , '--loglevel' , 'error' ] ; const child = spawn ( command , args , { stdio : 'inherit' , cwd : cwd } ) ; child . on ( 'close' , resolve ) ; } else { const command = 'npm run ' ; const args = [ script , '--loglevel' , 'error' ] ; const child = spawn ( command , args , { stdio : 'inherit' , cwd : root } ) ; child . on ( 'close' , resolve ) ; } } ) ; } export async function copyFolder ( workPath , targetPath ) { return fs . copy ( workPath , targetPath ) ; } param { * } path export function deleteFolder ( path ) { let files = [ ] ; if ( fs . existsSync ( path ) ) { if ( ! fs . statSync ( path ) . isDirectory ( ) ) { fs . unlinkSync ( path ) ; } else { files = fs . readdirSync ( path ) ; files . forEach ( function ( file ) { let curPath = path + '/' + file ; deleteFolder ( curPath ) ; } ) ; fs . rmdirSync ( path ) ; } } }