Skip to content

Commit

Permalink
refactor(windows): Work on windowslib refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi committed Jul 2, 2019
1 parent a5cf8de commit 5dea3a9
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 199 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
},
"scripts": {
"build": "lerna exec gulp build",
"link": "lerna exec yarn link"
"link": "lerna exec yarn link",
"unlink": "lerna exec yarn unlink"
},
"workspaces": {
"packages": [
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# v2.0.0

* BREAKING CHANGE: Removed all Windows Phone related code.
* BREAKING CHANGE: Renamed `windows` to `sdks` and `visualstudio` to `vs`in info results.

This comment has been minimized.

Copy link
@ewanharris

ewanharris Jul 3, 2019

Contributor

Can we not keep it as visualstudio? Why rename to a 2 letter word that isn't immediately apparent what it is?

This comment has been minimized.

Copy link
@cb1kenobi

cb1kenobi Jul 3, 2019

Author Contributor

Fixed.

* BREAKING CHANGE: Removed `selectedVisualStudio` from info results.
* fix: Updated config to remove redundant `windows` namespace.
* chore: Update dependencies.

Expand Down
40 changes: 12 additions & 28 deletions packages/plugin-windows/conf/config.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
module.exports = {
device: {
sdk: {
/**
* The number of milliseconds to rescan for connected devices.
* @type {Number}
* A list of paths to search for Windows SDKs.
* @type {Array.<String>}
*/
pollInterval: null
searchPaths: null
},

emulators: {
vs: {
/**
* The number of milliseconds to rescan for emulators.
* @type {Number}
* A list of paths to search for Visual Studio installations.
* @type {Array.<String>}
*/
pollInterval: null
searchPaths: null
},

visualstudio: {
vswhere: {
/**
* The number of milliseconds to rescan for Visual Studio installations.
* @type {Number}
* A list of paths to search for the `vswhere.exe` utility.
* @type {Array.<String>}
*/
pollInterval: null
},

windowsPhone: {
/**
* The number of milliseconds to rescan for Windows Phone SDKs.
* @type {Number}
*/
pollInterval: null
},

windowsSDK: {
/**
* The number of milliseconds to rescan for Windows SDKs.
* @type {Number}
*/
pollInterval: null
searchPaths: null
}
};
77 changes: 77 additions & 0 deletions packages/plugin-windows/src/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import semver from 'semver';

function format(ver, min, max, chopDash) {
ver = ('' + (ver || 0));
if (chopDash) {
ver = ver.replace(/(-.*)?$/, '');
}
ver = ver.split('.');
if (min !== undefined) {
while (ver.length < min) {
ver.push('0');
}
}
if (max !== undefined) {
ver = ver.slice(0, max);
}
return ver.join('.');
}

function eq(v1, v2) {
return semver.eq(format(v1, 3, 3), format(v2, 3, 3));
}

function gte(v1, v2) {
return semver.gte(format(v1, 3, 3), format(v2, 3, 3));
}

function gt(v1, v2) {
return semver.gt(format(v1, 3, 3), format(v2, 3, 3));
}

function lte(v1, v2) {
return semver.lte(format(v1, 3, 3), format(v2, 3, 3));
}

function lt(v1, v2) {
return semver.lt(format(v1, 3, 3), format(v2, 3, 3));
}

function compare(v1, v2) {
return eq(v1, v2) ? 0 : lt(v1, v2) ? -1 : 1;
}

function rcompare(v1, v2) {
return eq(v1, v2) ? 0 : lt(v1, v2) ? 1 : -1;
}

function satisfies(ver, str) {
ver = format(ver, 3, 3, true);
str = str.replace(/(<=?\d+(\.\d+)*?)\.x/g, '$1.99999999').replace(/(>=?\d+(\.\d+)*?)\.x/g, '$1.0');
try {
if (str === '*' || eq(ver, str)) {
return true;
}
} catch (ex) {
// squelch
}

return str.split(/\s*\|\|\s*/).some(function (range) {
// semver is picky with the '-' in comparisons and it just so happens when it
// parses versions in the range, it will add '-0' and cause '1.0.0' != '1.0.0-0',
// so we test our version with and without the '-9'
return range === '*' || semver.satisfies(ver, range) || (ver.indexOf('-') === -1 && semver.satisfies(ver + '-0', range));
});
}

export default {
format,
eq,
gte,
gt,
lte,
lt,
compare,
rcompare,
satisfies
};
Loading

0 comments on commit 5dea3a9

Please sign in to comment.