run npm install after updating package.json

This commit is contained in:
Balaji Krishnan 2017-03-13 00:29:04 -07:00
Родитель d5c0cb8df0
Коммит b86550fe45
2 изменённых файлов: 28 добавлений и 6 удалений

Просмотреть файл

@ -14,24 +14,35 @@ exports.createCommand = function createCommand() {
});
vscode.window.showQuickPick(pkgs).then((selectedItem) => {
updatePackageJson(selectedItem.label);
updatePackageJsonAndNpmInstall(selectedItem.label);
if (!vscode.window.activeTextEditor) {
return;
}
return generateCodeInEditor(selectedItem.label);
});
});
});
};
function updatePackageJson(packageToAdd) {
function updatePackageJsonAndNpmInstall(packageToAdd) {
var filePath = utils.getPackageJsonPath();
if (filePath && fs.existsSync(filePath)) {
var packages = [packageToAdd];
jsonEditor.addDependenciesIfRequired(filePath, packages);
// TODO: run npm-install only if package.json was touched
var installTask = utils.npmInstall(packages, { global: false });
return installTask.then(
function onFulfilled(value) {
vscode.window.setStatusBarMessage(`npm install succeeded for ${packageToAdd}.`);
},
function onRejected(reason) {
vscode.window.setStatusBarMessage(`npm install failed for ${packageToAdd}.`);
}
);
}
};

Просмотреть файл

@ -13,19 +13,30 @@ exports.createCommand = function createCommand() {
}
// update package.json
updatePackageJson();
updatePackageJsonAndNpmInstall();
// generate code in current document
return generateCodeInEditor();
});
};
function updatePackageJson() {
function updatePackageJsonAndNpmInstall() {
var filePath = utils.getPackageJsonPath();
if (filePath && fs.existsSync(filePath)) {
var packages = codegen.getPackageDependencies();
jsonEditor.addDependenciesIfRequired(filePath, packages);
// TODO: run npm-install only if package.json was touched
var installTask = utils.npmInstall(packages, { global: false });
return installTask.then(
function onFulfilled(value) {
vscode.window.setStatusBarMessage(`npm install succeeded.`);
},
function onRejected(reason) {
vscode.window.setStatusBarMessage(`npm install failed.`);
}
);
}
};