fix: GH-935 replaced compare-func with native sort method (#937)

This commit is contained in:
Norman Breau 2020-04-01 00:43:36 -03:00 committed by GitHub
parent fb26050fab
commit 8ab1dbc373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 12 deletions

View File

@ -24,7 +24,6 @@ var events = require('cordova-common').events;
var CordovaError = require('cordova-common').CordovaError; var CordovaError = require('cordova-common').CordovaError;
var check_reqs = require('../check_reqs'); var check_reqs = require('../check_reqs');
var PackageType = require('../PackageType'); var PackageType = require('../PackageType');
const compareFunc = require('compare-func');
const { createEditor } = require('properties-parser'); const { createEditor } = require('properties-parser');
const MARKER = 'YOUR CHANGES WILL BE ERASED!'; const MARKER = 'YOUR CHANGES WILL BE ERASED!';
@ -33,19 +32,37 @@ const TEMPLATE =
'# This file is automatically generated.\n' + '# This file is automatically generated.\n' +
'# Do not modify this file -- ' + MARKER + '\n'; '# Do not modify this file -- ' + MARKER + '\n';
const fileSorter = compareFunc([ const archSpecificRegex = /-x86|-arm/;
// Sort arch specific builds after generic ones const unsignedBuildRegex = /-unsigned/;
filePath => /-x86|-arm/.test(filePath),
// Sort unsigned builds after signed ones const fileSorter = (filePathA, filePathB) => {
filePath => /-unsigned/.test(filePath), const archSpecificA = archSpecificRegex.test(filePathA);
const archSpecificB = archSpecificRegex.test(filePathB);
// Sort by file modification time, latest first // If they are not equal, then sort by specific archs after generic ones
filePath => -fs.statSync(filePath).mtime.getTime(), if (archSpecificA !== archSpecificB) {
return archSpecificA < archSpecificB ? -1 : 1;
}
// Sort by file name length, ascending // Otherwise, move onto the next sort item, which is by sorting unsigned bulds after signed ones
'length' const unsignedA = unsignedBuildRegex.test(filePathA);
]); const unsignedB = unsignedBuildRegex.test(filePathB);
if (unsignedA !== unsignedB) {
return unsignedA < unsignedB ? -1 : 1;
}
// Then, sort by modification time, latest first
const modTimeA = fs.statSync(filePathA).mtime.getTime();
const modTimeB = fs.statSync(filePathB).mtime.getTime();
if (modTimeA !== modTimeB) {
return modTimeA < modTimeB ? 1 : -1;
}
// Finally, if all above is the same, sort by file name length, ascending
return filePathB.length < filePathA.length ? -1 : 1;
};
/** /**
* If the provided directory does not exist or extension is missing, return an empty array. * If the provided directory does not exist or extension is missing, return an empty array.

View File

@ -31,7 +31,6 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"android-versions": "^1.4.0", "android-versions": "^1.4.0",
"compare-func": "^1.3.2",
"cordova-common": "^3.2.0", "cordova-common": "^3.2.0",
"execa": "^3.2.0", "execa": "^3.2.0",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",