浏览代码

Fixed use issues

master
guest 3 年前
父节点
当前提交
076385624c
共有 1 个文件被更改,包括 123 次插入123 次删除
  1. 123
    123
      index.js

+ 123
- 123
index.js 查看文件

} }
// PB : TODO -- Use the ORG level instance before falling back to common Instance coz common instance may not exist for certain orgs. // PB : TODO -- Use the ORG level instance before falling back to common Instance coz common instance may not exist for certain orgs.
, commonInstance(selected) { return __acquireConfig(selected, defaultRepoOwner , commonInstance(selected) { return __acquireConfig(selected, defaultRepoOwner
// , function(e){ console.info('This is an error prompt choices.') } // , function(e){ console.info('This is probably an error unless the user is asking to create a new instance with this name.') }
) } ) }
, genericChessInstance(selected) { return __acquireConfig(selected) } , genericChessInstance(selected) { return __acquireConfig(selected) }
} }
} }


if(e.messages.join(' ').match(new RegExp (`fatal: repository '${selectedinstance.reposerver}/${owner}/${configrepo}.git/' not found`))){ if(e.messages.join(' ').match(new RegExp (`fatal: repository '${selectedinstance.reposerver}/${owner}/${configrepo}.git/' not found`))){
return cli.prompt( ['(i) install new instance with this name locally' return cli.prompt( { i : 'install new instance with this name locally'
, '(f) fork a new instance for yourself' , f : 'fork a new instance for yourself from another instance'
, '(o) fork a new instance for your organization' // prompt organization name... , o : 'fork a new instance for your organization' // prompt organization name...
, '(c) create a custom personal instance for this node' // prompt hostname as nodename , c : 'create a custom personal instance for this node' // prompt hostname as nodename
, '(p) create a custom personal instance' , p : 'create a custom personal instance'
, '(e) exit'] , e : 'exit'}
, 'Config for instance not found. Would you like to ', 'e' ).then(propValue => { , 'Config for instance not found. Would you like to ', 'e' ).then(propValue => {
if(propValue === 'i') return eNotImplemented() // return createLocalChessInsance(selectedinstance) if(propValue === 'i') return eNotImplemented() // return createLocalChessInsance(selectedinstance)
return { root, node_env : path.basename(root), instanceName : path.basename( path.dirname(root) ) } return { root, node_env : path.basename(root), instanceName : path.basename( path.dirname(root) ) }
} }
var detectinstances = function () { var detectLocalInstances = function () {
console.log(`launchpath = ${launchpath}`) console.log(`launchpath = ${launchpath}`)
console.log(`thisscriptdir = ${thisscriptdir}`) console.log(`thisscriptdir = ${thisscriptdir}`)


} }
// promptkeys.runchoice = promptkeys.cmd ? 'c' : undefined // promptkeys.runchoice = promptkeys.cmd ? 'c' : undefined


function createChessInstance( cfg ){ function createLocalChessInstance( cfg ){
return createInstance(cfg) // return createInstance(cfg)
// var inst = {}; var inst = {};
// var __new = Object.assign({}, __default, cfg) var __new = Object.assign({}, /*__default,*/ cfg)
// inst[cfg.node_env] = __new; return inst; inst[cfg.node_env] = __new; return inst;
} }


var choices = { var choices = {
} }


var detection_state = { var detection_state = {
didWeFindInstance : false localInstanceDetected : false
} }


const https = require('https') const https = require('https')
} }


var skipprerequisites = false; var skipprerequisites = false;
function initinstances(selected_overrides) { 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 root = selected_overrides.root // We should always have this coz we are running at some place which is fixed by detectLocalInstances.


var instanceName = selected_overrides.instanceName var instanceName = selected_overrides.instanceName
|| clioverrides.instanceName || clioverrides.instanceName
// || processedArgs._[1] // || processedArgs._[1]
|| chessinstances.current_run.instanceName || chessinstances.current_run.instanceName
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) { var node_env = selected_overrides.node_env
promptkeys['instanceName'] = instanceName = chessinstances.current_run.instanceName = promptkeys['instanceName'] || __default.instanceName; || clioverrides.node_env
promptkeys['node_env'] = node_env = chessinstances.current_run.node_env = promptkeys['node_env'] || __default.node_env; // || processedArgs.node_env
promptkeys['reposerver'] = reposerver = chessinstances.current_run.reposerver = promptkeys['reposerver'] || __default.reposervers[0]; || chessinstances.current_run.node_env
} var reposerver = selected_overrides.reposerver
|| clioverrides.reposerver
// || processedArgs.node_env
|| chessinstances.current_run.reposerver
if(!node_env) { if(!instanceName) {
promptkeys['node_env'] = node_env = chessinstances.current_run.node_env = promptkeys['node_env'] || __default.node_env; promptkeys['instanceName'] = instanceName = chessinstances.current_run.instanceName = promptkeys['instanceName'] || __default.instanceName;
promptkeys['reposerver'] = reposerver = chessinstances.current_run.reposerver = promptkeys['reposerver'] || __default.reposervers[0]; promptkeys['node_env'] = node_env = chessinstances.current_run.node_env = promptkeys['node_env'] || __default.node_env;
} promptkeys['reposerver'] = reposerver = chessinstances.current_run.reposerver = promptkeys['reposerver'] || __default.reposervers[0];
}


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


chessinstances[instanceName] = chessinstances[instanceName] || createChessInstance( { if(!reposerver) {
instanceName, node_env, root : selected_overrides.root, reposerver : promptkeys['reposerver'] } ); promptkeys['reposerver'] = reposerver = chessinstances.current_run.reposerver = promptkeys['reposerver'] || __default.reposervers[0];
chessinstances['current_run'] = { instanceName: instanceName, node_env, reposerver, root } }


if(path.normalize(selected_overrides.root) !== path.normalize(chessinstances[instanceName][node_env].root)) { chessinstances[instanceName] = chessinstances[instanceName] || createLocalChessInstance( {
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 instanceName, node_env, root : selected_overrides.root, reposerver : selected_overrides.reposerver /* promptkeys['reposerver'] */ } );
} chessinstances['current_run'] = { instanceName: instanceName, node_env, reposerver, root }
// Override sequence.
// __default, chessinstances[current_run], instanceName-config-development, cliargs, interactve_promts
selectedinstance = utils.assign(
chessinstances[instanceName][node_env]
, clioverrides
, selected_overrides
// , __interactive_prompts -- Cant just override. Also need selectedinstance to be ready...
);


// chessinstances[instanceName] = chessinstances[instanceName] || {} if(path.normalize(selected_overrides.root) !== path.normalize(chessinstances[instanceName][node_env].root)) {
// chessinstances[instanceName][node_env] = chessinstances[instanceName][node_env] || {} 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
}
// if(!selectedinstance.repos || selectedinstance.instanceName) { // Override sequence.
// // Brand New. // __default, chessinstances[current_run], instanceName-config-development, cliargs, interactve_promts
// selectedinstance = Object.assign( __default, selectedinstance ) selectedinstance = utils.assign(
// } chessinstances[instanceName][node_env]
, clioverrides
if(!selectedinstance.repos[0].repo) { , selected_overrides
console.warn('repo manifest has obsolete format. Attempting upgrade.') // , __interactive_prompts -- Cant just override. Also need selectedinstance to be ready...
selectedinstance.repos = selectedinstance.repos.map(function(repo){ return { repo } }) );
}
if(selectedinstance.elevated[0] && !selectedinstance.elevated[0].repo) {
console.warn('elevated repo manifest has obsolete format. Attempting upgrade.')
selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } })
}
// 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;
// chessinstances[selectedinstance.instanceName][selectedinstance.node_env] = selectedinstance;
cacheWriteInstanceConfig(chessinstances)
// 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...


return chessinstances // chessinstances[instanceName] = chessinstances[instanceName] || {}
// chessinstances[instanceName][node_env] = chessinstances[instanceName][node_env] || {}
// if(!selectedinstance.repos || selectedinstance.instanceName) {
// // Brand New.
// selectedinstance = Object.assign( __default, selectedinstance )
// }
if(!selectedinstance.repos[0].repo) {
console.warn('repo manifest has obsolete format. Attempting upgrade.')
selectedinstance.repos = selectedinstance.repos.map(function(repo){ return { repo } })
}
if(selectedinstance.elevated[0] && !selectedinstance.elevated[0].repo) {
console.warn('elevated repo manifest has obsolete format. Attempting upgrade.')
selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } })
} }
var skipprereqs = {} // Config from server always override merges into selection except for the current selection.
var maintask = () => { // PB : TODO -- utils.assign Array merges are non-distinct...
chessinstances[instanceName][node_env] = selectedinstance;
// Default cmd to run ! // chessinstances[selectedinstance.instanceName][selectedinstance.node_env] = selectedinstance;
processedArgs._[0] === processedArgs._[0] || 'pull'; cacheWriteInstanceConfig(chessinstances)
// selectedinstance.reposerver = selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available. // 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...
if(!noprerequisites[processedArgs._[0]] return chessinstances
&& !skipprereqs[processedArgs._[0]] }
) { var skipprereqs = {}
return prerequisites.git.verifyAndInstall().then(()=>{ var maintask = () => {
var e = { message : 'verifyAndInstall', success : true} // Default cmd to run !
var inittasks = [] processedArgs._[0] === processedArgs._[0] || 'pull';
if(!detection_state.didWeFindInstance) { // selectedinstance.reposerver = selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online from all that are available.
inittasks.push(createInstance(selectedinstance).then(() => { preworkerconfig(); return elxrworker(true) }))
}
else {
inittasks.push(acquireConfig(selectedinstance).catch((err) => {
e = err;
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.')
console.error(err)
}).then(() => { preworkerconfig(); return elxrworker(true) })
// .finally(()=>{
// fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' })
// if(!e.success) fs.writeFileSync('run.done', 'error');
// // return process.exit()
// }))
)
}
return any(inittasks)
})
}
else {
console.log('cmd has no preqs or has been configured to skip preqs')
preworkerconfig()
return elxrworker()
}


if(!noprerequisites[processedArgs._[0]]
&& !skipprereqs[processedArgs._[0]]
) {
return prerequisites.git.verifyAndInstall().then(()=>{
var e = { message : 'verifyAndInstall', success : true}
var inittasks = []
if(!detection_state.localInstanceDetected) {
inittasks.push(createInstance(selectedinstance).then(() => { preworkerconfig(); return elxrworker(true) }))
}
else {
inittasks.push(acquireConfig(selectedinstance).catch((err) => {
e = err;
console.error('Chosen cofiguraton failed or not found. Fix config and rerun or chose another.')
console.error(err)
}).then(() => { preworkerconfig(); return elxrworker(true) })
// .finally(()=>{
// fs.writeFileSync('run.log', ', ' + JSON.stringify({ error: e.message }), { 'flag': 'a+' })
// if(!e.success) fs.writeFileSync('run.done', 'error');
// // return process.exit()
// }))
)
}
return any(inittasks)
})
} }
else {
console.log('cmd has no preqs or has been configured to skip preqs')
preworkerconfig()
return elxrworker()
}

}


var startElxr = function() { var startElxr = function() {
const retaincount = 2 const retaincount = 2
reconfirm = getReconfirmAll() reconfirm = getReconfirmAll()
} }


return detectinstances().then((detectedinstanceoptions)=>{ return detectLocalInstances().then((detectedinstanceoptions)=>{
detectedinstanceoptions.splice(0,0, __default) detectedinstanceoptions.splice(0,0, __default)
initinstances(selectedinstance) // use the local instances for defaults if at all possible. initinstances(selectedinstance) // use the local instances for defaults if at all possible.
var todo = any( getInteractionPoints(detectedinstanceoptions, promptkeys) ).then(()=>{ var todo = any( getInteractionPoints(detectedinstanceoptions, promptkeys) ).then(()=>{
var inst = initinstances(selectedinstance) var inst = initinstances(selectedinstance)
detection_state.didWeFindInstance = true; detection_state.localInstanceDetected = true;
return inst; return inst;
}) })
} }
findlocalinstances(chessinstances, detectedinstanceoptions) findlocalinstances(chessinstances, detectedinstanceoptions)
detectedinstanceoptions.splice(0,0, __default) detectedinstanceoptions.splice(0,0, __default)
initinstances(selectedinstance) initinstances(selectedinstance)
detection_state.didWeFindInstance = true; detection_state.localInstanceDetected = true;
} }
catch (e) { catch (e) {
// console.error(e) // console.error(e)
// // selectedinstance = Object.assign(detectedInstance, clioverrides); // // selectedinstance = Object.assign(detectedInstance, clioverrides);
// return selectedinstance = Object.assign(__default, selectedinstance); // return selectedinstance = Object.assign(__default, selectedinstance);
// }) // })
detection_state.didWeFindInstance = false; detection_state.localInstanceDetected = false;
return selectedinstance return selectedinstance
} }
}) })

正在加载...
取消
保存