Last active
October 7, 2015 02:56
-
-
Save kyle-ilantzis/763dd81f085e476ef504 to your computer and use it in GitHub Desktop.
nw-builder option.versions as a range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var semver = require('semver'); | |
var NwVersions = require('nw-builder/lib/versions'); | |
var nwDownloadUrl = 'http://dl.nwjs.io/'; | |
function findNwVersion(version) { | |
return new Promise(function(resolve, reject) { | |
NwVersions.getVersions(nwDownloadUrl) | |
.then(function(versions) { | |
var satisfying = semver.maxSatisfying(versions,version); | |
if (satisfying !== null) { | |
resolve(satisfying); | |
} | |
else { | |
reject('No nw version for ' + version + ' found in ' + versions); | |
} | |
}) | |
.catch(function(err) { | |
reject(err); | |
}); | |
}); | |
} | |
function test_nwversions() { | |
var test = function(v) { | |
return function(x) { console.log("version",v,"result",x); }; | |
}; | |
findNwVersion("apple").then(test("apple"),test("apple")); // No nw version for apple | |
findNwVersion("0.11.5").then(test("0.11.5"),test("0.11.5")); // 0.11.5 | |
findNwVersion("^0.11.5").then(test("^0.11.5"),test("^0.11.5")); // 0.11.6 | |
findNwVersion("0.12.3").then(test("0.12.3"),test("0.12.3")); // 0.12.3 | |
findNwVersion("^0.12.3").then(test("^0.12.3"),test("^0.12.3")); // 0.12.3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment