|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
.catch((e) => { |
|
|
.catch((e) => { |
|
|
e.repo = repo; |
|
|
e.repo = repo; |
|
|
if(errHandler) return errHandler(e) |
|
|
|
|
|
|
|
|
if(errHandler) throw errHandler(e) |
|
|
if (__isElevated) { |
|
|
if (__isElevated) { |
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) |
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
.catch(e => { |
|
|
.catch(e => { |
|
|
e.repo = repo; |
|
|
e.repo = repo; |
|
|
if(errHandler) return errHandler(e) |
|
|
|
|
|
|
|
|
if(errHandler) throw errHandler(e) |
|
|
if (__isElevated) { |
|
|
if (__isElevated) { |
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) |
|
|
fs.writeFileSync('run.log', ', ' + JSON.stringify(e), { 'flag': 'a+' }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
clusterNodeInstance(selected) { var clusternodename = 'node01' |
|
|
clusterNodeInstance(selected) { var clusternodename = 'node01' |
|
|
return __acquireConfig(selected, selected.username, clusternodename |
|
|
return __acquireConfig(selected, selected.username, clusternodename |
|
|
, selected.instanceName + '-config-' + selected.node_env + `-${clusternodename}` |
|
|
, selected.instanceName + '-config-' + selected.node_env + `-${clusternodename}` |
|
|
, function(e){ console.info('Customized node level config not found. This is not an Error. Will attempt with owner level config.') } |
|
|
|
|
|
|
|
|
, function(e){ console.info('Customized node level config not found. This is not an Error. Will attempt with owner level config.'); |
|
|
|
|
|
return e; } |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
, ownerInstnace(selected) { return __acquireConfig(selected, selected.username, null, null |
|
|
, ownerInstnace(selected) { return __acquireConfig(selected, selected.username, null, null |
|
|
, function(e){ console.info('Customized user level config not found. This is not an Error. Will attempt global common instance config.') } |
|
|
|
|
|
|
|
|
, function(e){ console.info('Customized user level config not found. This is not an Error. Will attempt global common instance config.'); |
|
|
|
|
|
return e } |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
// 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. |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
})() |
|
|
})() |
|
|
|
|
|
|
|
|
|
|
|
var eNotImplemented = function(){ |
|
|
|
|
|
console.error('Not yet implemented') |
|
|
|
|
|
process.exit() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var acquireConfig = function(slections){ |
|
|
var acquireConfig = function(slections){ |
|
|
var configPriority = [ 'clusterNodeInstance', 'ownerInstnace', 'commonInstance', 'genericChess' ] |
|
|
|
|
|
|
|
|
var configPriority = [ 'clusterNodeInstance', 'ownerInstnace', 'commonInstance', 'genericChessInstance' ] |
|
|
return any(configPriority.map(cfg => { return function() { return configs[cfg](slections) } } ), true, true) |
|
|
return any(configPriority.map(cfg => { return function() { return configs[cfg](slections) } } ), true, true) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else process.exit() |
|
|
else process.exit() |
|
|
}) |
|
|
}) |
|
|
console.error() |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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' |
|
|
, '(c) customize your personal instance for this node' |
|
|
|
|
|
|
|
|
, '(o) fork a new instance for your organization' // prompt organization name... |
|
|
|
|
|
, '(c) create a custom personal instance for this node' // prompt hostname as nodename |
|
|
|
|
|
, '(p) create a custom personal instance' |
|
|
, '(e) exit'] |
|
|
, '(e) exit'] |
|
|
, 'Config for instance not found. Would you like to with this name ? (y/n) ', 'y' ).then(propValue => { |
|
|
|
|
|
|
|
|
, 'Config for instance not found. Would you like to ', 'e' ).then(propValue => { |
|
|
|
|
|
|
|
|
if(propValue === 'y') { |
|
|
|
|
|
return createLocalChessInsance() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(propValue === 'i') return eNotImplemented() // return createLocalChessInsance(selectedinstance) |
|
|
|
|
|
if(propValue === 'f') return eNotImplemented() // return createChessInstance(selectedinstance) |
|
|
|
|
|
// if(propValue === 'o') createChessInstance(selectedinstance, orgname) |
|
|
else process.exit() |
|
|
else process.exit() |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.warn(e) |
|
|
console.warn(e) |
|
|
console.warn('Config acquisition failed.') |
|
|
|
|
|
|
|
|
throw e; //('Config acquisition failed.') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var successHandler = () => { |
|
|
var successHandler = () => { |
|
|
|
|
|
|
|
|
ENV.NODE_ENV = selectedinstance.node_env; |
|
|
ENV.NODE_ENV = selectedinstance.node_env; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return performPull(configrepo, null, owner, errHandler || ((e)=>{ throw e })).then( successHandler ) |
|
|
|
|
|
.catch( errorHandler ) |
|
|
|
|
|
|
|
|
return performPull(configrepo, null, owner, errHandler || errorHandler || ((e)=>{ throw e })).then( successHandler ) |
|
|
|
|
|
.catch( (e)=>{ |
|
|
|
|
|
// if(e){ |
|
|
|
|
|
if(Promise.resolve(e) === e) return e; |
|
|
|
|
|
console.error(e) |
|
|
|
|
|
throw e; // Not a hard error but we need this for bcontinueonfailure |
|
|
|
|
|
// } |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var launchpath = path.normalize(process.cwd()) |
|
|
var launchpath = path.normalize(process.cwd()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createChessInstance( cfg ){ |
|
|
function createChessInstance( cfg ){ |
|
|
return createInstance(cfg) |
|
|
return createInstance(cfg) |
|
|
var inst = {}; |
|
|
|
|
|
var __new = Object.assign({}, __default, cfg) |
|
|
|
|
|
inst[cfg.node_env] = __new; return inst; |
|
|
|
|
|
|
|
|
// var inst = {}; |
|
|
|
|
|
// var __new = Object.assign({}, __default, cfg) |
|
|
|
|
|
// inst[cfg.node_env] = __new; return inst; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var choices = { |
|
|
var choices = { |