Bläddra i källkod

updates for prompts

pull/6/head
chess 3 år sedan
förälder
incheckning
ee769f2e49
1 ändrade filer med 115 tillägg och 101 borttagningar
  1. 115
    101
      index.js

+ 115
- 101
index.js Visa fil

@@ -1866,7 +1866,7 @@ function elxrworker() {
function acquireChoices(selectedinstance) {

var hasconfig = false;
console.warn(chalk.yellow(`
console.warn(chalk.cyan(`
-------------------------------------------------------------------------------
Warning : Cannot locate your preferred configuration since it was not specified
You should fork the default chess configuration to customize and make it
@@ -1942,7 +1942,7 @@ We will run your choice at the next prompt.
}
else processedArgs._[0] = cmd
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposerver || selectedinstance.reposervers[0]} ) : `).then(function (reposerver) {
selectedinstance.reposerver = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in'
selectedinstance.reposerver = reposerver || selectedinstance.reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in'
})
})
})
@@ -2185,9 +2185,35 @@ var detectinstances = function () {

}

var __interactve_promts = function( target ){
var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) {
return function(prompts, 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.
// PB : TODO -- selectedinstance === __default check to prompt everything...
if( (mustPrompt[k] !== undefined && mustPrompt[k] !== null) && target[k] !== mustPrompt[k]
|| (mustPrompt[k] === undefined || mustPrompt[k] === null) && (target[k] === undefined || target[k] === null)
|| 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);
promptables[k].choices = choices[k]
Object.defineProperty(target, k, getPromptableAsyncPropDescriptor(k, promptables[k]));
return await target[k]
})
}
delete mustPrompt[k]
return prompts
}
}

return {
var __interactve_promts = function( target, choices ){

Object.defineProperty(target, 'node_env', { get : function(){ return this.instanceType } });

var interactionpoints = {
runchoice : {
label :
`Choose an option :
@@ -2243,6 +2269,9 @@ var __interactve_promts = function( target ){
, instanceType : { label : `Enter Instance Type ( <= ${target.instanceType || 'development'} ) : `, choices : [], defaultchoice : 'development'}
, reposerver : { label : `Enter Instance Name ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : `, choices : [], defaultchoice : 'https://git.bbh.org.in'}
}

var eachPrompt = getBoundEachPrompt( target, promptkeys, interactionpoints, choices)
return Object.keys(interactionpoints).reduce(eachPrompt, [])
}


@@ -2485,20 +2514,23 @@ var getPromptableAsyncPropDescriptor = function(propName, promptable){
return {
get (){
return cli.prompt( promptable.choices, promptable.label, promptable.defaultchoice ).then(propValue => {
var asyncprop = Promise.resolve(propValue)
if(promptable.interpret){
return propName = promptable.interpret(propValue).then(
()=>{
Object.defineProperty(this, propName, {
value: propValue,
writable: true,
configurable : true,
enumerable : true
});
return propValue
}
)
asyncprop = promptable.interpret(propValue)
}
else return propValue

return asyncprop.then(
()=>{
Object.defineProperty(this, propName, {
value: propValue,
writable: true,
configurable : true,
enumerable : true
});
return propValue
}
)
})
}
// , set (propValue){
@@ -2571,42 +2603,52 @@ function createChessInsance( cfg ){

acquireElevationState().then(() => {
var skipprerequisites = false;
function initinstances(selected) {
// PB : TODO -- processedArgs should already be part of selected.
var instanceName = processedArgs._[1]
function initinstances(selected_overrides) {
var root = selected_overrides.root // We should always have this coz we are running at some place which is fixed by detectinstances.

var instanceName = selected_overrides.instanceName
|| clioverrides.instanceName
// || processedArgs._[1]
|| chessinstances.current_run.instanceName
|| selected.instanceName
|| clioverrides.instanceName;
var node_env = processedArgs.node_env
|| chessinstances.current_run.node_env
|| selected.node_env
|| clioverrides.node_env;
var node_env = selected_overrides.node_env
|| clioverrides.node_env
// || processedArgs.node_env
|| chessinstances.current_run.node_env

var reposerver = selected_overrides.reposerver
|| clioverrides.reposerver
// || processedArgs.node_env
|| chessinstances.current_run.reposerver
if(!instanceName) {
promptkeys['instanceName'] = instanceName = chessinstances.current_run.instanceName = promptkeys['instanceName'] || __default.instanceName;
promptkeys['node_env'] = node_env = chessinstances.current_run.node_env = promptkeys['node_env'] || __default.node_env;
promptkeys['reposerver'] = promptkeys['reposerver'] || __default.reposervers[0];
promptkeys['reposerver'] = reposerver = chessinstances.current_run.reposerver = promptkeys['reposerver'] || __default.reposervers[0];
}
if(!node_env) {
promptkeys['node_env'] = node_env = chessinstances.current_run.node_env = promptkeys['node_env'] || __default.node_env;
promptkeys['reposerver'] = promptkeys['reposerver'] || __default.reposervers[0];
promptkeys['reposerver'] = reposerver = chessinstances.current_run.reposerver = promptkeys['reposerver'] || __default.reposervers[0];
}

if(!reposerver) {
promptkeys['reposerver'] = reposerver = chessinstances.current_run.reposerver = promptkeys['reposerver'] || __default.reposervers[0];
}

chessinstances[instanceName] = chessinstances[instanceName] || createChessInsance( {
instanceName, node_env, root : selected.root, reposerver : promptkeys['reposerver'] } );
chessinstances['current_run'] = { instanceName: instanceName, node_env: node_env }
instanceName, node_env, root : selected_overrides.root, reposerver : promptkeys['reposerver'] } );
chessinstances['current_run'] = { instanceName: instanceName, node_env, reposerver, root }

if(path.normalize(selected.root) !== path.normalize(chessinstances[instanceName][node_env].root)) {
throw "Mismatched chessinstances config found " + chessinstances[instanceName][node_env].root + ' does not match ' + selected.root
if(path.normalize(selected_overrides.root) !== path.normalize(chessinstances[instanceName][node_env].root)) {
throw "instanceName and instanceType specified doesn't match whats already present do you want to continue " + chessinstances[instanceName][node_env].root + ' does not match ' + selected_overrides.root
}
// Override sequence.
// __default, chessinstances[current_run], instanceName-config-development, cliargs, interactve_promts
selectedinstance = utils.assign(
selected
, chessinstances[instanceName][node_env]
chessinstances[instanceName][node_env]
, clioverrides
, selected_overrides
// , __interactve_promts -- Cant just override. Also need selectedinstance to be ready...
);

@@ -2629,7 +2671,7 @@ acquireElevationState().then(() => {
// Config from server always override merges into selection except for the current selection.
// PB : TODO -- utils.assign Array merges are non-distinct...
chessinstances[instanceName][node_env] = selectedinstance = utils.assign(selected, selectedinstance)
chessinstances[instanceName][node_env] = selectedinstance;
// chessinstances[selectedinstance.instanceName][selectedinstance.node_env] = selectedinstance;
cacheWriteInstanceConfig(chessinstances)
// PB : TODO -- We should probably write the new server config also...
@@ -2684,41 +2726,42 @@ acquireElevationState().then(() => {
return elxrworker()
}

return detectinstances().then((detectedinstanceoptions)=>{

var getchoices = function(){
detectedinstanceoptions.splice(0,0, __default)

var instances = []
var reposervers = [];
var instnaceNames = []
var instanceTypes = ['development', 'production'];
Object.keys( chessinstances).forEach(instanceName => {
if(instanceName === 'current_run') return;
Object.keys( chessinstances[instanceName] ).forEach(node_env=>{
var instance = chessinstances[instanceName][node_env];
reposervers = reposervers.concat(instance.reposervers)
if(instance.reposerver) reposervers.push(instance.reposerver)
instances.push(instance)
instanceTypes.push(instance.node_env)
instnaceNames.push(instance.instanceName)
})
var getchoices = function(detectedinstanceoptions, promptkeys){

var instances = []
var reposervers = [];
var instnaceNames = []
var instanceTypes = ['development', 'production'];
Object.keys( chessinstances).forEach(instanceName => {
if(instanceName === 'current_run') return;
Object.keys( chessinstances[instanceName] ).forEach(node_env=>{
var instance = chessinstances[instanceName][node_env];
reposervers = reposervers.concat(instance.reposervers)
if(instance.reposerver) reposervers.push(instance.reposerver)
instances.push(instance)
instanceTypes.push(instance.node_env)
instnaceNames.push(instance.instanceName)
})
instances = instances.concat(detectedinstanceoptions)

if(promptkeys['instanceName']) instnaceNames.push(selectedinstance['instanceName'])
if(promptkeys['instanceName']) instnaceNames.push(promptkeys['instanceName'])
if(selectedinstance['reposervers']) reposervers = reposervers.concat(selectedinstance['reposervers'])
var choices = {
'instanceName' : Array.from( new Set(instnaceNames) )
, 'reposerver' : Array.from( new Set(reposervers) )
, 'instanceType' : Array.from( new Set(instanceTypes) )
}
})
instances = instances.concat(detectedinstanceoptions)

return choices;
if(promptkeys['instanceName']) instnaceNames.push(selectedinstance['instanceName'])
if(promptkeys['instanceName']) instnaceNames.push(promptkeys['instanceName'])
if(selectedinstance['reposervers']) reposervers = reposervers.concat(selectedinstance['reposervers'])
var choices = {
'instanceName' : Array.from( new Set(instnaceNames) )
, 'reposerver' : Array.from( new Set(reposervers) )
, 'instanceType' : Array.from( new Set(instanceTypes) )
}

return choices;
}

return detectinstances().then((detectedinstanceoptions)=>{
detectedinstanceoptions.splice(0,0, __default)

// PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!!
selectedinstance = utils.assign( ...detectedinstanceoptions.slice(-2) )
promptkeys = utils.assign(promptkeys, clioverrides)
@@ -2727,53 +2770,24 @@ acquireElevationState().then(() => {
var reconfirm = { 'instanceName' : selectedinstance['instanceName'] === 'chess' }
}
else { var reconfirm = {}; }
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.
// PB : TODO -- selectedinstance === __default check to prompt everything...
if( (promptkeys[k] !== undefined && promptkeys[k] !== null) && selectedinstance[k] !== promptkeys[k]
|| (promptkeys[k] === undefined || promptkeys[k] === null) && (selectedinstance[k] === undefined || selectedinstance[k] === null)
|| 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);
promptables[k].choices = choices[k]
Object.defineProperty(selectedinstance, k, getPromptableAsyncPropDescriptor(k, promptables[k]));
return await selectedinstance[k]
})
}
delete promptkeys[k]
}
try {

chessinstances = acquirelocalinstances(selectedinstance);
findlocalinstances(chessinstances, detectedinstanceoptions)
var choices = getchoices()

var promptables = __interactve_promts(selectedinstance)
Object.keys(promptables).forEach(eachPrompt, selectedinstance)
var todo = Promise.resolve(true);

todo = any(prompts).then(()=>{
var choices = getchoices(detectedinstanceoptions, promptkeys)
var todo = any( __interactve_promts(selectedinstance, choices) ).then(()=>{
return initinstances(selectedinstance)
})
}
catch (e) {
// PB : TODO -- verbose mode warning.. console.warn(e) // Missing chessinstances is not an error...
var choices = getchoices()
var choices = getchoices(detectedinstanceoptions, promptkeys)
var todo = any( __interactve_promts(selectedinstance, choices) ).then(()=>{
return initinstances(selectedinstance)
})

var promptables = __interactve_promts(selectedinstance)
Object.keys(promptables).forEach(eachPrompt, selectedinstance)
todo = any(prompts).then(()=>{ return initinstances(selectedinstance) })
if(!processedArgs._[0] || !selectedinstance.node_env || !selectedinstance.instanceName){
// Weve not been told what to do.
todo = todo.then(() => { return acquireChoices(selectedinstance) })

Laddar…
Avbryt
Spara