small conditional check and formatting.
This commit is contained in:
Родитель
cdf852c997
Коммит
57f4e98a2f
59
src/utils.js
59
src/utils.js
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче