Просмотр исходного кода

Added dedup for array merge.

production
chess 3 лет назад
Родитель
Сommit
5769618cb0
1 измененных файлов: 33 добавлений и 14 удалений
  1. 33
    14
      index.js

+ 33
- 14
index.js Просмотреть файл

@@ -1698,15 +1698,9 @@ var elxr = {
// Or a single repo ( Either Elevated or normal. )


def = (def ? (
// def.requiresElevation = true,
// def.repos = def.repos,
// def.elevatedRepos = def.elevatedRunasRepos,
def

) : false) || {
def = def || {
repos : repomanifest.repos,
elevatedRepos : repomanifest.elevated
elevated : repomanifest.elevated
}

var elevatedpulltasks = null;
@@ -1741,20 +1735,20 @@ var elxr = {

var useGitPull = processedArgs.useGitPull || false;

if(def.elevatedRepos || def.repos) {
if(def.elevatedRepos) def.requiresElevation = true;
if(def.elevated || def.repos) {
if(def.elevated) def.requiresElevation = true;
else delete def.requiresElevation;
}
else {
if(def.requiresElevation) def.elevatedRepos = [def]
if(def.requiresElevation) def.elevated = [def]
else def.repos = [def]
}

var regularpulltasks = function(){ return Promise.resolve(true) }
if(def.elevatedRepos){
if(def.elevated){
elevatedpulltasks = function() {
return any(def.elevatedRepos.map((def) => performPull(def.repo))).then(() => {
return any(def.elevated.map((def) => performPull(def.repo))).then(() => {
return true;
}).catch((e) => {
console.error(e)
@@ -1914,6 +1908,29 @@ We will run your choice at the next prompt.
})
}

var mergeObjByKey = function(arrOfObjs, keyName) {

var keyedDistinct = {}
var distinctArrOfObjs = []

arrOfObjs.forEach( o => {
if(o) (keyedDistinct[o[keyName]] || (keyedDistinct[o[keyName]] = []) ).push(o)
})
Object.keys(keyedDistinct).forEach(key => {
distinctArrOfObjs.push( utils.assign( ...keyedDistinct[key] ) ) // PB : TODO -- Shallow use utils.assign
})

return distinctArrOfObjs;
}

var cacheWriteInstanceConfig = function(chessinstances){
var instanceName = chessinstances['current_run'].instanceName;
var node_env = chessinstances['current_run'].node_env;
chessinstances[instanceName][node_env].repos = mergeObjByKey(chessinstances[instanceName][node_env].repos, 'repo') ;
chessinstances[instanceName][node_env].elevated = mergeObjByKey(chessinstances[instanceName][node_env].elevated, 'repo') ;
fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances, null, 2) + '', { 'flag': 'w' })
}

var acquireConfig = function (selected, chessinstances) {

var configrepo = selected.instanceName + '-config-' + selected.node_env;
@@ -1926,9 +1943,11 @@ var acquireConfig = function (selected, chessinstances) {
chessinstances[selected.instanceName][selected.node_env] = chessinstances[selected.instanceName][selected.node_env] || {}
chessinstances['current_run'] = { instanceName: selected.instanceName, node_env: selected.node_env }
// Config from server always override merges into selection ecept for the current selection.
// PB : TODO -- utils.assign Array merges are non-distinct...
selectedinstance = utils.assign(chessinstances[selected.instanceName][selected.node_env], selected, repomanifest)
// chessinstances[selectedinstance.instanceName][selectedinstance.node_env] = selectedinstance;
fs.writeFileSync(instanceroot + '/chessinstances.js', 'module.exports = ' + JSON.stringify(chessinstances, null, 2) + '', { 'flag': 'w' })
cacheWriteInstanceConfig(chessinstances)
selectedinstance = chessinstances[selected.instanceName][selected.node_env]
// PB : TODO -- We should probably write the new server config also...
selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online...
ENV.NODE_ENV = selectedinstance.node_env;

Загрузка…
Отмена
Сохранить