small conditional check and formatting.

This commit is contained in:
Balaji Krishnan 2017-03-10 10:48:33 -08:00
Родитель cdf852c997
Коммит 57f4e98a2f
1 изменённых файлов: 31 добавлений и 28 удалений

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

@ -5,18 +5,18 @@ let exec = require('child_process').exec;
// checks if there exists a valid installation of NodeJs on this machine
exports.isNodeInstalled = function isNodeInstalled() {
var cmdString = "node -v";
return new Promise(function (resolve, reject) {
exec(cmdString, (error, stdout) => {
if (error) {
return reject(error);
}
if (stdout.startsWith('v')) {
return resolve(true);
}
return resolve(false);
var cmdString = "node -v";
return new Promise(function (resolve, reject) {
exec(cmdString, (error, stdout) => {
if (error) {
return reject(error);
}
if (stdout.startsWith('v')) {
return resolve(true);
}
return resolve(false);
});
});
});
};
// lists all globally installed npm packages.
@ -86,27 +86,30 @@ exports.npmInstall = function npmInstall(packages, opts) {
});
};
exports.getPackageJsonPath = function getPackageJsonPath(){
var dirAboveRoot = path.join(vscode.workspace.rootPath, '..');
var srcPath = getSourceLocation();
var packageJsonPath;
exports.getPackageJsonPath = function getPackageJsonPath() {
var dirAboveRoot = path.join(vscode.workspace.rootPath, '..');
var srcPath = getSourceLocation();
if (!srcPath) {
return;
}
while (srcPath !== dirAboveRoot) {
packageJsonPath = path.join(srcPath, 'package.json');
if(fs.existsSync(packageJsonPath)){
return packageJsonPath;
var packageJsonPath;
while (srcPath !== dirAboveRoot) {
packageJsonPath = path.join(srcPath, 'package.json');
if (fs.existsSync(packageJsonPath)) {
return packageJsonPath;
}
else {
srcPath = path.join(srcPath, '..');
}
}
else{
srcPath = path.join(srcPath, '..');
}
}
};
function getSourceLocation() {
var files = vscode.workspace.textDocuments.filter(item => item.isUntitled === false);
if (files) {
var sourceFile = files[0].fileName;
return sourceFile.slice(0, sourceFile.lastIndexOf('\\') + 1);
}
var files = vscode.workspace.textDocuments.filter(item => item.isUntitled === false);
if (files) {
var sourceFile = files[0].fileName;
return sourceFile.slice(0, sourceFile.lastIndexOf('\\') + 1);
}
}