Pārlūkot izejas kodu

Added reposerver config attribute with instance to facilitate clone for missing items

production
pb pirms 3 gadiem
vecāks
revīzija
58ffe916ac
1 mainītis faili ar 77 papildinājumiem un 12 dzēšanām
  1. 77
    12
      index.js

+ 77
- 12
index.js Parādīt failu

@@ -33,6 +33,13 @@ const fs = require('fs')
const cliargs = utils.cliargs;
const processedArgs = cliargs(process.argv.slice(2));
console.dir(processedArgs)
// PB : TODO -- defaults for valuless arguments if passed.
// Object.keys(processedArgs).forEach(a=>{
// if(Object.prototype.toString.call(processedArgs[a]) === '[object Undefined]' || !processedArgs[a]) || trim(processedArgs[a])) == '') {

// }
// })

var globSync = require('glob').sync;

var ENV = Object.assign({}, process.env); // Shallow clone it.
@@ -93,12 +100,15 @@ var getTaskWithElevation = function(tasdef){
}
else {
// PB : TODO -- Rename op['runas'] to 'elevate'
return op['runas']().then(() => { return true; })

var __runasresult = null;

return op['runas']().then((r) => { return __runasresult = r; })
.catch((e) => {
console.error(e)
})
.finally(() => {
fs.unlinkSync('run.done')
if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done')
if (!processedArgs.runas) { return tasdef.regularpulltasks(); }
})
}
@@ -139,7 +149,11 @@ var getPullCmd = (repo, branch) => {
}
else {
console.warn('No branch was specified detecting from working client.')
var pullCmd = gitops.getdiscoverbranchcmd(repo)
// First check if working client exits.
// if (existsSync(instanceroot + '/' + repo)) {
var pullCmd = gitops.getdiscoverbranchcmd(repo)
// }
// else performpull
}
// var pullCmd = ['pullall', [], { cwd : repo }]
if (useGitPull) pullCmd = ['git', ['pull'], {
@@ -388,6 +402,9 @@ var op = {
})
}
, 'runas': () => {

if(processedArgs.skipelevated) return Promise.resolve({ skipped : true });

console.log('Testing Elevation')

if (__isElevated) {
@@ -1844,6 +1861,7 @@ var acquireConfig = function (selected, chessinstances) {
chessinstances['current_run'] = { instanceName: selected.instanceName, node_env: selected.node_env }
// Config from server always override merges into selection ecept for the current selection.
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' })
// 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...
@@ -1929,7 +1947,8 @@ var __interactve_promts = {
Object.defineProperty(this, 'reposerver', {
value: reposerver,
writable: false,
configurable : true
configurable : true,
enumerable : true
});
return reposerver
})
@@ -1938,7 +1957,8 @@ var __interactve_promts = {
Object.defineProperty(this, 'reposerver', {
value: reposerver,
writable: false,
configurable : true
configurable : true,
enumerable : true
});
return reposerver
}
@@ -2186,7 +2206,8 @@ var getPromptableAsyncPropDescriptor = function(propName, choices, defaultchoise
Object.defineProperty(this, propName, {
value: propValue,
writable: false,
configurable : true
configurable : true,
enumerable : true
});
return propValue
})
@@ -2195,11 +2216,13 @@ var getPromptableAsyncPropDescriptor = function(propName, choices, defaultchoise
// Object.defineProperty(this, propName, {
// value: propValue,
// writable: false,
// configurable : true
// configurable : true,
// enumerable : true
// })
// return propValue;
// }
, configurable : true
, enumerable : true
}
}

@@ -2287,7 +2310,49 @@ acquireElevationState().then(() => {
var todo = Promise.resolve(true);
try {
chessinstances = acquirelocalinstances(selectedinstance);
var promptkeys = {
'instanceName' : processedArgs._[1]
}

var reconfirm = {
'instanceName' : true
}

initinstances(chessinstances, selectedinstance)
var instanceNameChoices = new Set(Object.keys( chessinstances) )
instanceNameChoices.delete('current_run')
instanceNameChoices.add(selectedinstance['instanceName'])
instanceNameChoices.add(promptkeys['instanceName'])
var choices = {
'instanceName' : Array.from(instanceNameChoices)
, 'reposerver' : selectedinstance['reposervers']
}
var prompts = [];
var eachPrompt = function(k, i, a){
// No local instances config found. We use a default initialized instance available in selectedinstance
// Confirm those that were not supplied as user choices in runtime args and proceed to reattempt.
if(selectedinstance[k] !== promptkeys[k] || promptkeys[k] === undefined || reconfirm[k]) {
prompts.push(async ()=>{
// PB : NOTE -- Important in async cases when this needs to be in the same state as when it was invoked.
// We take a snapshot... Shallow.. !! If required deep should be used based on use case.
// If latest altered state is required we can reerence this directly.
// var asyncthis = Object.assign(this);
Object.defineProperty(selectedinstance, k, getPromptableAsyncPropDescriptor(k, choices[k], promptkeys[k] || selectedinstance[k] ));
return await selectedinstance[k]
})
}
delete promptkeys[k]
}

Object.keys(__interactve_promts).forEach(eachPrompt, __interactve_promts)
Object.keys(promptkeys).forEach(eachPrompt, promptkeys)
todo = any(prompts).then(()=>{ return selectedinstance })
}
catch (e) {
console.error(e)
@@ -2305,23 +2370,23 @@ acquireElevationState().then(() => {

// No local instances config found. We use a default initialized instance available in selectedinstance
// Confirm those that were not supplied as user choices in runtime args and proceed to reattempt.
initinstances(chessinstances, selectedinstance)
var instanceNameChoices = new Set(Object.keys( chessinstances) )
instanceNameChoices.delete('current_run')
instanceNameChoices.add(selectedinstance['instanceName'])
instanceNameChoices.add(promptkeys['instanceName'])
var choices = {
'instanceName' : Array.from(instanceNameChoices)
, 'reposerver' : selectedinstance['reposervers']
}
var prompts = [];
var eachPrompt = function(k, i, a){
// No local instances config found. We use a default initialized instance available in selectedinstance
// Confirm those that were not supplied as user choices in runtime args and proceed to reattempt.
if(selectedinstance[k] !== promptkeys[k] || promptkeys[k] === undefined || reconfirm[k]) {
prompts.push(async ()=>{
// PB : NOTE -- Important in async cases when this needs to be in the same state as when it was invoked.

Notiek ielāde…
Atcelt
Saglabāt