import { getPackageTool , PackageTool } from "parser/package-tool" ; import { exec } from "child-process-promise" ; function formatDependencies ( dependencies ) { return dependencies . reduce ( ( dependencyString , dependency ) => `${ dependencyString } ${ dependency }@latest` , "" ) ; } function installDependenciesYarn ( dependencies , dirpath ) { return exec ( `yarn add --cwd ${ dirpath } ${ formatDependencies ( dependencies ) } -D -W` ) . then ( ( ) => Promise . resolve ( ) ) ; } function installDependenciesNpm ( dependencies , dirpath ) { return exec ( `npm install --prefix ${ dirpath } ${ formatDependencies ( dependencies ) } --save-dev` ) . then ( ( ) => Promise . resolve ( ) ) ; } export function installDevDependencies ( dependencies , dirPath ) { switch ( getPackageTool ( dirPath ) ) { case PackageTool . NPM : return installDependenciesNpm ( dependencies , dirPath ) ; case PackageTool . YARN : return installDependenciesYarn ( dependencies , dirPath ) ; } }