Skip to content
This repository has been archived by the owner on Aug 19, 2019. It is now read-only.

Commit

Permalink
Fixed msbuild-finder test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rowan Potgieter committed Jun 13, 2017
1 parent 183a7ec commit 9976435
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions lib/msbuild-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ var constants = require('./constants');
var fs = require('fs');
var PluginError = gutil.PluginError;

var detectMsBuild15Dir = function(pathRoot) {
var detectMsBuild15Dir = function (pathRoot) {
var vs2017Path = path.join(pathRoot, 'Microsoft Visual Studio', '2017');
var possibleFolders = ['BuildTools', 'Enterprise', 'Professional', 'Community'];

for(var index = 0; index < possibleFolders.length; index++) {
for (var index = 0; index < possibleFolders.length; index++) {
try {
var folderPath = path.join(vs2017Path, possibleFolders[index]);
fs.statSync(folderPath);
return folderPath;
} catch (e) { }
} catch (e) {}
}
}

// Use MSBuild over XBuild where possible
var detectLinuxMsBuildExecutable = function() {
var detectLinuxMsBuildExecutable = function () {
var msbuildExecutable = 'msbuild';
var possibleFolders = ['/usr/bin/'];

for(var index = 0; index < possibleFolders.length; index++) {
for (var index = 0; index < possibleFolders.length; index++) {
try {
var filePath = path.join(possibleFolders[index], msbuildExecutable);
fs.statSync(filePath);
return filePath;
} catch (e) { }
} catch (e) {}
}
}

var autoDetectVersion = function(pathRoot) {
var autoDetectVersion = function (pathRoot) {
// Try to detect MSBuild 15.0.
var msbuild15Dir = detectMsBuild15Dir(pathRoot);
if (msbuild15Dir) {
Expand All @@ -53,7 +53,7 @@ var autoDetectVersion = function(pathRoot) {

if (msbuildDirExists) {
var msbuildVersions = fs.readdirSync(msbuildDir)
.filter(function(entryName) {
.filter(function (entryName) {
var binDirExists = true;
var binDirPath = path.join(msbuildDir, entryName, 'Bin');
try {
Expand All @@ -75,12 +75,14 @@ var autoDetectVersion = function(pathRoot) {
};

module.exports.find = function (options) {
if (!options.platform.match(/^win/)) {
if (options.platform.match(/linux/)) {
var msbuildPath = detectLinuxMsBuildExecutable();
if (msbuildPath) {
return msbuildPath;
}
return 'xbuild';
} else if (!options.platform.match(/^win/)) {
return 'xbuild';
}

var msbuildRoot;
Expand Down
4 changes: 2 additions & 2 deletions test/msbuild-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ describe('msbuild-finder', function () {
var fs = require('fs');
var mock;

it('should use xbuild on linux', function () {
it('should use msbuild on linux', function () {
var result = msbuildFinder.find({ platform: 'linux' });

expect(result).to.be.equal('xbuild');
expect(result).to.include('msbuild');
});

it('should use xbuild on darwin', function () {
Expand Down

0 comments on commit 9976435

Please sign in to comment.