diff --git a/src/commands/azure-node.browse-packages.js b/src/commands/azure-node.browse-packages.js index 3b0e229..7ca21d7 100644 --- a/src/commands/azure-node.browse-packages.js +++ b/src/commands/azure-node.browse-packages.js @@ -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}.`); + } + ); } }; diff --git a/src/commands/azure-node.template-deploy.js b/src/commands/azure-node.template-deploy.js index 736979f..f21bbc9 100644 --- a/src/commands/azure-node.template-deploy.js +++ b/src/commands/azure-node.template-deploy.js @@ -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.`); + } + ); } };