| const cliargs = utils.cliargs; | const cliargs = utils.cliargs; | ||||
| const processedArgs = cliargs(process.argv.slice(2)); | const processedArgs = cliargs(process.argv.slice(2)); | ||||
| console.dir(processedArgs) | 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 globSync = require('glob').sync; | ||||
| var ENV = Object.assign({}, process.env); // Shallow clone it. | var ENV = Object.assign({}, process.env); // Shallow clone it. | ||||
| } | } | ||||
| else { | else { | ||||
| // PB : TODO -- Rename op['runas'] to 'elevate' | // 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) => { | .catch((e) => { | ||||
| console.error(e) | console.error(e) | ||||
| }) | }) | ||||
| .finally(() => { | .finally(() => { | ||||
| fs.unlinkSync('run.done') | |||||
| if(__runasresult && !__runasresult.skipped) fs.unlinkSync('run.done') | |||||
| if (!processedArgs.runas) { return tasdef.regularpulltasks(); } | if (!processedArgs.runas) { return tasdef.regularpulltasks(); } | ||||
| }) | }) | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| console.warn('No branch was specified detecting from working client.') | 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 }] | // var pullCmd = ['pullall', [], { cwd : repo }] | ||||
| if (useGitPull) pullCmd = ['git', ['pull'], { | if (useGitPull) pullCmd = ['git', ['pull'], { | ||||
| }) | }) | ||||
| } | } | ||||
| , 'runas': () => { | , 'runas': () => { | ||||
| if(processedArgs.skipelevated) return Promise.resolve({ skipped : true }); | |||||
| console.log('Testing Elevation') | console.log('Testing Elevation') | ||||
| if (__isElevated) { | if (__isElevated) { | ||||
| chessinstances['current_run'] = { instanceName: selected.instanceName, node_env: 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. | // Config from server always override merges into selection ecept for the current selection. | ||||
| selectedinstance = utils.assign(chessinstances[selected.instanceName][selected.node_env], selected, repomanifest) | 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' }) | 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... | // 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... | selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online... | ||||
| Object.defineProperty(this, 'reposerver', { | Object.defineProperty(this, 'reposerver', { | ||||
| value: reposerver, | value: reposerver, | ||||
| writable: false, | writable: false, | ||||
| configurable : true | |||||
| configurable : true, | |||||
| enumerable : true | |||||
| }); | }); | ||||
| return reposerver | return reposerver | ||||
| }) | }) | ||||
| Object.defineProperty(this, 'reposerver', { | Object.defineProperty(this, 'reposerver', { | ||||
| value: reposerver, | value: reposerver, | ||||
| writable: false, | writable: false, | ||||
| configurable : true | |||||
| configurable : true, | |||||
| enumerable : true | |||||
| }); | }); | ||||
| return reposerver | return reposerver | ||||
| } | } | ||||
| Object.defineProperty(this, propName, { | Object.defineProperty(this, propName, { | ||||
| value: propValue, | value: propValue, | ||||
| writable: false, | writable: false, | ||||
| configurable : true | |||||
| configurable : true, | |||||
| enumerable : true | |||||
| }); | }); | ||||
| return propValue | return propValue | ||||
| }) | }) | ||||
| // Object.defineProperty(this, propName, { | // Object.defineProperty(this, propName, { | ||||
| // value: propValue, | // value: propValue, | ||||
| // writable: false, | // writable: false, | ||||
| // configurable : true | |||||
| // configurable : true, | |||||
| // enumerable : true | |||||
| // }) | // }) | ||||
| // return propValue; | // return propValue; | ||||
| // } | // } | ||||
| , configurable : true | , configurable : true | ||||
| , enumerable : true | |||||
| } | } | ||||
| } | } | ||||
| var todo = Promise.resolve(true); | var todo = Promise.resolve(true); | ||||
| try { | try { | ||||
| chessinstances = acquirelocalinstances(selectedinstance); | chessinstances = acquirelocalinstances(selectedinstance); | ||||
| var promptkeys = { | |||||
| 'instanceName' : processedArgs._[1] | |||||
| } | |||||
| var reconfirm = { | |||||
| 'instanceName' : true | |||||
| } | |||||
| initinstances(chessinstances, selectedinstance) | 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) { | catch (e) { | ||||
| console.error(e) | console.error(e) | ||||
| // 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) | initinstances(chessinstances, selectedinstance) | ||||
| var instanceNameChoices = new Set(Object.keys( chessinstances) ) | var instanceNameChoices = new Set(Object.keys( chessinstances) ) | ||||
| instanceNameChoices.delete('current_run') | instanceNameChoices.delete('current_run') | ||||
| instanceNameChoices.add(selectedinstance['instanceName']) | instanceNameChoices.add(selectedinstance['instanceName']) | ||||
| instanceNameChoices.add(promptkeys['instanceName']) | instanceNameChoices.add(promptkeys['instanceName']) | ||||
| var choices = { | var choices = { | ||||
| 'instanceName' : Array.from(instanceNameChoices) | 'instanceName' : Array.from(instanceNameChoices) | ||||
| , 'reposerver' : selectedinstance['reposervers'] | , 'reposerver' : selectedinstance['reposervers'] | ||||
| } | } | ||||
| var prompts = []; | var prompts = []; | ||||
| var eachPrompt = function(k, i, a){ | 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]) { | if(selectedinstance[k] !== promptkeys[k] || promptkeys[k] === undefined || reconfirm[k]) { | ||||
| prompts.push(async ()=>{ | prompts.push(async ()=>{ | ||||
| // PB : NOTE -- Important in async cases when this needs to be in the same state as when it was invoked. | // PB : NOTE -- Important in async cases when this needs to be in the same state as when it was invoked. |