mirror of https://gitee.com/bigwinds/arangodb
Sort using semver
This commit is contained in:
parent
6f21b59b75
commit
0ef698a28b
|
@ -103,57 +103,6 @@ var compareApps = function(l, r) {
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// @brief comparator for versions
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
var compareVersions = function (a, b) {
|
|
||||||
var i;
|
|
||||||
|
|
||||||
if (a === b) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// error handling
|
|
||||||
if (typeof a !== "string") {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (typeof b !== "string") {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var aComponents = a.split(".");
|
|
||||||
var bComponents = b.split(".");
|
|
||||||
var len = Math.min(aComponents.length, bComponents.length);
|
|
||||||
|
|
||||||
// loop while the components are equal
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
|
|
||||||
// A bigger than B
|
|
||||||
if (parseInt(aComponents[i], 10) > parseInt(bComponents[i], 10)) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// B bigger than A
|
|
||||||
if (parseInt(aComponents[i], 10) < parseInt(bComponents[i], 10)) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If one's a prefix of the other, the longer one is bigger one.
|
|
||||||
if (aComponents.length > bComponents.length) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aComponents.length < bComponents.length) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise they are the same.
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief updates the fishbowl from a zip archive
|
/// @brief updates the fishbowl from a zip archive
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -334,7 +283,7 @@ var search = function (name) {
|
||||||
function extractMaxVersion(matchEngine, versionDoc) {
|
function extractMaxVersion(matchEngine, versionDoc) {
|
||||||
let serverVersion = plainServerVersion();
|
let serverVersion = plainServerVersion();
|
||||||
let versions = Object.keys(versionDoc);
|
let versions = Object.keys(versionDoc);
|
||||||
versions.sort(compareVersions).reverse();
|
versions.sort(semver.compare).reverse();
|
||||||
|
|
||||||
for (let version of versions) {
|
for (let version of versions) {
|
||||||
if (matchEngine) {
|
if (matchEngine) {
|
||||||
|
@ -544,7 +493,7 @@ var info = function (name) {
|
||||||
|
|
||||||
var header = false;
|
var header = false;
|
||||||
var versions = Object.keys(desc.versions);
|
var versions = Object.keys(desc.versions);
|
||||||
versions.sort(compareVersions);
|
versions.sort(semver.compare).reverse();
|
||||||
|
|
||||||
versions.forEach(function (v) {
|
versions.forEach(function (v) {
|
||||||
var version = desc.versions[v];
|
var version = desc.versions[v];
|
||||||
|
@ -583,9 +532,6 @@ exports.search = search;
|
||||||
exports.searchJson = searchJson;
|
exports.searchJson = searchJson;
|
||||||
exports.update = update;
|
exports.update = update;
|
||||||
|
|
||||||
// Temporary export to avoid breaking the client
|
|
||||||
exports.compareVersions = compareVersions;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// --SECTION-- END-OF-FILE
|
// --SECTION-- END-OF-FILE
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue