import spawn from 'cross-spawn' ; import path from 'path' ; import { templates } from './templates' ; export function install ( root , type ) { const command = 'npm' ; process . chdir ( root ) ; const args = [ 'i' , ... templates [ type ] ] ; const child = spawn ( command , args , { stdio : 'inherit' } ) ; return new Promise ( ( resolve , reject ) => { child . on ( 'close' , code => { if ( code !== 0 ) { reject ( { command : `${ command } ${ args . join ( ' ' ) }` , } ) ; return ; } process . chdir ( path . resolve ( root , '..' ) ) ; resolve ( '' ) ; } ) ; } ) ; }