Last active
July 29, 2018 08:28
-
-
Save AWolf81/65b6d08a6ff65d3aa86dd0d45f1ff591 to your computer and use it in GitHub Desktop.
Add logger functionality - created method for spawnProcess - type annotation not working yet.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import packageMan from './package-manager.service'; | |
import { PACKAGE_MANAGER_CMD } from './platform.services'; | |
import { logger } from './logger.service'; | |
const childProcess = window.require('child_process'); | |
type executor = Promise.executor; | |
const spawnProcess = ( | |
cmd: string, | |
cmdArgs: Array<string>, | |
projectPath: string, | |
{ resolve, reject }: executor | |
) => { | |
const child = childProcess.spawn(cmd, [...cmdArgs], { | |
cwd: projectPath, | |
}); | |
child.on('exit', code => { | |
if (code) { | |
reject(child.stderr); | |
} else { | |
resolve(child.stdout); | |
} | |
}); | |
return child; | |
}; | |
export const installDependency = ( | |
projectPath: string, | |
dependencyName: string, | |
version: string | |
) => { | |
return new Promise(executor => { | |
const child = spawnProcess( | |
PACKAGE_MANAGER_CMD, | |
[ | |
packageMan.addDependencyCommand(), | |
`${dependencyName}@${version}`, | |
'-SE', | |
], | |
projectPath, | |
executor | |
); | |
logger(child); | |
}); | |
}; | |
export const uninstallDependency = ( | |
projectPath: string, | |
dependencyName: string | |
) => { | |
return new Promise(executor => { | |
const child = spawnProcess( | |
PACKAGE_MANAGER_CMD, | |
[packageMan.removeDependencyCommand(), dependencyName], | |
projectPath, | |
executor | |
); | |
logger(child); | |
}); | |
}; | |
export const reinstallDependencies = (projectPath: string) => { | |
return new Promise(executor => { | |
const child = spawnProcess( | |
PACKAGE_MANAGER_CMD, | |
[packageMan.addDependencyCommand()], | |
projectPath, | |
executor | |
); | |
logger(child); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment