better sorter function

This commit is contained in:
Philipp Kunz 2016-06-05 11:08:20 +02:00
parent a965cf38c8
commit 19e3aa3721
2 changed files with 58 additions and 32 deletions

File diff suppressed because one or more lines are too long

View File

@ -27,25 +27,38 @@ let readDockerfiles = function(){
}); });
} }
let cleanTagsArrayFunction = function(){
let cleanTagsArray = [];
NpmciEnv.dockerFiles.forEach(function(dockerfileArg){
cleanTagsArray.push(dockerfileArg.cleanTag);
});
return cleanTagsArray;
}
let sortDockerfiles = function(){ let sortDockerfiles = function(){
let done = plugins.q.defer(); let done = plugins.q.defer();
NpmciEnv.dockerFiles.sort(function(a,b){ let sortableArray = NpmciEnv.dockerFiles;
let cleanTags = []; let sortedArray:Dockerfile[] = [];
NpmciEnv.dockerFiles.forEach(function(dockerfileArg){ let sorterFunctionCounter:number = 0;
cleanTags.push(dockerfileArg.cleanTag); let sorterFunction = function(){
}); let cleanTags = cleanTagsArrayFunction();
let aIndex = cleanTags.indexOf(a.baseImage); sortableArray.forEach((dockerfileArg)=>{
let bIndex = cleanTags.indexOf(b.cleanTag); if(cleanTags.indexOf(dockerfileArg.baseImage) == -1){
console.log(cleanTags); let dockerfileArgIndex = sortableArray.indexOf(dockerfileArg);
console.log(a.baseImage,aIndex); sortableArray.splice(dockerfileArgIndex);
console.log(b.cleanTag,bIndex); sortedArray.push(dockerfileArg);
if(aIndex < bIndex && bIndex != -1){
return 1;
} else {
return 0
} }
}); });
if(sortableArray.length == 0){
console.log(sortedArray);
NpmciEnv.dockerFiles = sortedArray;
done.resolve(); done.resolve();
} else if (sorterFunctionCounter < 100) {
sorterFunctionCounter++;
sorterFunction();
};
}
sorterFunction();
return done.promise; return done.promise;
} }