Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add logger functionality - created method for spawnProcess - type annotation not working yet.
// @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
You can’t perform that action at this time.