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();
sortableArray.forEach((dockerfileArg)=>{
if(cleanTags.indexOf(dockerfileArg.baseImage) == -1){
let dockerfileArgIndex = sortableArray.indexOf(dockerfileArg);
sortableArray.splice(dockerfileArgIndex);
sortedArray.push(dockerfileArg);
}
}); });
let aIndex = cleanTags.indexOf(a.baseImage); if(sortableArray.length == 0){
let bIndex = cleanTags.indexOf(b.cleanTag); console.log(sortedArray);
console.log(cleanTags); NpmciEnv.dockerFiles = sortedArray;
console.log(a.baseImage,aIndex); done.resolve();
console.log(b.cleanTag,bIndex); } else if (sorterFunctionCounter < 100) {
if(aIndex < bIndex && bIndex != -1){ sorterFunctionCounter++;
return 1; sorterFunction();
} else { };
return 0 }
} sorterFunction();
});
done.resolve();
return done.promise; return done.promise;
} }