|
|
|
|
|
|
|
|
|
|
|
|
|
|
var hasElxrSync = function(path){ return hasElxr(path, { sync :true}); } |
|
|
var hasElxrSync = function(path){ return hasElxr(path, { sync :true}); } |
|
|
|
|
|
|
|
|
// wd is our own environment variable. |
|
|
|
|
|
if(!processedArgs.wd){ |
|
|
|
|
|
|
|
|
var thisscriptdir = path.normalize(__dirname); // PB : TODO -- Thisscriptdir could be dislocated when run as a standalone file... We need to detect this where and how |
|
|
|
|
|
var root = process.cwd() // Root need not be the launchdir... |
|
|
|
|
|
// wd is our own environment variable probably corresponding to the root but need not be the same. |
|
|
|
|
|
// console.log(processedArgs.root) |
|
|
|
|
|
|
|
|
|
|
|
if(!processedArgs.root){ |
|
|
if(!process.env.wd){ |
|
|
if(!process.env.wd){ |
|
|
// Script may exists in the same location where we were launchded(PWD) but that doesn't mean we r running from elxr. |
|
|
|
|
|
|
|
|
console.log('discovery') |
|
|
|
|
|
// Script may exists in the same location where we were launched(PWD) but that doesn't mean we r running from elxr. |
|
|
// script could have been copied tosome random location and run from there. |
|
|
// script could have been copied tosome random location and run from there. |
|
|
// check elxr is preinstalled in same location. If so we need to chdir to parent. Else promt for confirmation of root. |
|
|
// check elxr is preinstalled in same location. If so we need to chdir to parent. Else promt for confirmation of root. |
|
|
var launchdir = /*process.env.PWD ||*/ process.cwd() // mingw + node --inspect-brk behaves differently has a PWD that windows commands cannot recognize /d instead of D:\ and process.chdir fails.. |
|
|
var launchdir = /*process.env.PWD ||*/ process.cwd() // mingw + node --inspect-brk behaves differently has a PWD that windows commands cannot recognize /d instead of D:\ and process.chdir fails.. |
|
|
var parentdir = path.dirname( launchdir ) |
|
|
var parentdir = path.dirname( launchdir ) |
|
|
var folderHasElxr = hasElxrSync(parentdir) |
|
|
|
|
|
if(folderHasElxr){ |
|
|
|
|
|
ENV.wd = parentdir; // Default to the parent. |
|
|
|
|
|
ENV.PWD = parentdir |
|
|
|
|
|
|
|
|
var parentFolderHasElxr = hasElxrSync(parentdir) |
|
|
|
|
|
var launchFolderHasElxr = hasElxrSync(launchdir) |
|
|
|
|
|
if( parentFolderHasElxr && (path.normalize(parentdir + '/elxr') === thisscriptdir)) { |
|
|
|
|
|
// We were run from the proper root with elxr cli in the subfolder. |
|
|
|
|
|
// PB : TODO -- Cleanup this should no longer be needed... selectedinstance is properly initialized... |
|
|
|
|
|
|
|
|
|
|
|
// instanceroot = root = selectedinstance.root; |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
root = ENV.wd = parentdir; // Default to the parent. |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
ENV.wd = launchdir; // Default to the parent. |
|
|
|
|
|
|
|
|
if( path.normalize(parentdir + '/elxr') === thisscriptdir ) { |
|
|
|
|
|
// launchFolderHasElxr is false -- and yet thiscriptdir is still proper. |
|
|
|
|
|
// PB : TODO -- Maybe a warning / abort if for some reason thisscriptdir should not be used... |
|
|
|
|
|
console.error('Warning : detected thisscriptdir as elxr subfolder but not recognized as elixir. git updates might fail.') |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
root = ENV.wd = parentdir; // Default to the parent. |
|
|
|
|
|
} |
|
|
|
|
|
else if (launchdir === thisscriptdir) { |
|
|
|
|
|
// Same directory doesn't mean we are being run from elxr sub directory. It could be a dislocated standalone elxr script. |
|
|
|
|
|
// PB : TODO -- In case elxr is not full elxr we need to locate it and relaunch to switch to the full version... |
|
|
|
|
|
|
|
|
|
|
|
// if(!parentFolderHasElxr) console.error('Invalid run location in subfolder that looks like elxr. We should probably abort.') |
|
|
|
|
|
|
|
|
|
|
|
if (BUILD_VERSION.indexOf('Version: {version} - built on {date}') > -1) { |
|
|
|
|
|
// Confirmed we were run from an Unbuilt ( meaning non standalone ) elxr therefore we are in the elxr sub directory. |
|
|
|
|
|
root = ENV.wd = parentdir; // Default to the parent. |
|
|
|
|
|
|
|
|
|
|
|
// instanceroot = root = path.normalize(selectedinstance.root + '/..'); |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root }); |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// In standalone build script we may or not be in the same location. |
|
|
|
|
|
if(!parentFolderHasElxr) { |
|
|
|
|
|
// We could have been run from the elxr subfolder. However we cant say for sure. |
|
|
|
|
|
// Most likely that the built version isn't the full elxr. We assume elxr doesnt exist and create an new elxr under.. |
|
|
|
|
|
console.error('Warning : detected thisscriptdir as elxr subfolder but not recognized as elixir. git updates might fail.') |
|
|
|
|
|
root = ENV.wd = launchdir; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// Built version was run from the full elxr subfolder |
|
|
|
|
|
root = ENV.wd = parentdir; // Default to the parent. |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
|
|
|
|
|
|
// Assume current selectedinstance.root is a new instance and create. |
|
|
|
|
|
// Figure out the instnace name and environment from parent folders as an alternative option with confirmation if not provided in the arguments. |
|
|
|
|
|
|
|
|
|
|
|
// if(clioverrides.instanceName) { |
|
|
|
|
|
// if(clioverrides.node_env) { |
|
|
|
|
|
// instanceroot = root = path.normalize(selectedinstance.root + '/' + clioverrides.instanceName + '/' + clioverrides.node_env) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root, instanceName : clioverrides.instanceName, node_env : clioverrides.node_env }) |
|
|
|
|
|
// // instanceoptions.splice( 0, 0, detectfromroot(root)) // This can be an option but is unnecessary unless a confirmation is provided. |
|
|
|
|
|
// // also folder names may have no relation to the actual instanceName and instanceType coz we need to have many |
|
|
|
|
|
// // eg : floder name can be elixir01 but instance name is elixr |
|
|
|
|
|
// } |
|
|
|
|
|
// else { |
|
|
|
|
|
// instanceroot = root = path.normalize(selectedinstance.root + '/' + clioverrides.instanceName + '/' + 'development') |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root, instanceName : clioverrides.instanceName, node_env : 'development' }) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)) // A recessive option only. |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// else { |
|
|
|
|
|
// instanceroot = root = selectedinstance.root; |
|
|
|
|
|
// if(clioverrides.node_env) { |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root, node_env : clioverrides.node_env }) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
// } |
|
|
|
|
|
// else { |
|
|
|
|
|
// // Nothing was specified... We only have one option from root. |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = detectfromroot(launcpath)) |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if(launchFolderHasElxr) { |
|
|
|
|
|
root = ENV.wd = launchdir; |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// Ambiguous but assume script is standalone in the instanceroot. |
|
|
|
|
|
root = ENV.wd = launchdir; |
|
|
|
|
|
// must be a new install in the selectedinstance.root with script invoked from some random location. |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
else root = ENV.wd = process.env.wd |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
ENV.wd = processedArgs.wd |
|
|
|
|
|
|
|
|
if(process.env.wd && process.env.wd !== processedArgs.root) throw 'wd and root must match.' |
|
|
|
|
|
root = ENV.wd = process.env.wd = processedArgs.root |
|
|
} |
|
|
} |
|
|
|
|
|
var instanceroot = root |
|
|
ENV.PWD = ENV.wd |
|
|
ENV.PWD = ENV.wd |
|
|
process.chdir(ENV.wd) // Ensure cwd is the actual working dir. |
|
|
|
|
|
ENV.NODE_ENV = processedArgs.node_env || (ENV.NODE_ENV && ENV.NODE_ENV.trim()) || 'development' |
|
|
ENV.NODE_ENV = processedArgs.node_env || (ENV.NODE_ENV && ENV.NODE_ENV.trim()) || 'development' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('----------------------------------------------------------------') |
|
|
console.log('----------------------------------------------------------------') |
|
|
console.log('version : ' + getVersion()); |
|
|
console.log('version : ' + getVersion()); |
|
|
|
|
|
console.log('process.env.wd : ' + process.env.wd) |
|
|
|
|
|
console.log('processedArgs.root : ' + processedArgs.root) |
|
|
|
|
|
console.log('----------------------------------------------------------------') |
|
|
console.log('wd :' + ENV.wd) |
|
|
console.log('wd :' + ENV.wd) |
|
|
|
|
|
process.chdir(ENV.wd) // Ensure cwd is the actual working dir. |
|
|
console.log('PWD :' + ENV.PWD) |
|
|
console.log('PWD :' + ENV.PWD) |
|
|
console.log('cwd : ' + process.cwd()) |
|
|
console.log('cwd : ' + process.cwd()) |
|
|
|
|
|
console.log(`thisscriptdir = ${thisscriptdir}`) |
|
|
console.log('----------------------------------------------------------------') |
|
|
console.log('----------------------------------------------------------------') |
|
|
// throw 'initbreak' |
|
|
// throw 'initbreak' |
|
|
|
|
|
|
|
|
|
|
|
// We no longer use this Folder name may be different from instanceName |
|
|
|
|
|
// var detectfromroot = function(root){ |
|
|
|
|
|
// return { root, node_env : path.basename(root), instanceName : path.basename( path.dirname(root) ) } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
// independent elxr cli operations |
|
|
// independent elxr cli operations |
|
|
var noprerequisites = { |
|
|
var noprerequisites = { |
|
|
add : true, 'set-url' : true, 'repo-relocate' : true |
|
|
add : true, 'set-url' : true, 'repo-relocate' : true |
|
|
|
|
|
|
|
|
if(existsSync( localinstancesPath )) { |
|
|
if(existsSync( localinstancesPath )) { |
|
|
try { |
|
|
try { |
|
|
var chessinstances = acquirelocalinstances( { root : `${instanceroot}/${p}` } ) |
|
|
var chessinstances = acquirelocalinstances( { root : `${instanceroot}/${p}` } ) |
|
|
if(chessinstances.error) delete chessinstances.error |
|
|
|
|
|
|
|
|
if(chessinstances.error) { |
|
|
|
|
|
delete chessinstances.error; delete chessinstances.e |
|
|
|
|
|
return {} |
|
|
|
|
|
} |
|
|
return Object.keys(chessinstances).earlyreduce( ( reduced, instanceName) => { |
|
|
return Object.keys(chessinstances).earlyreduce( ( reduced, instanceName) => { |
|
|
return Object.keys(chessinstances[instanceName]).earlyreduce( (reduced, instanceType) => { |
|
|
return Object.keys(chessinstances[instanceName]).earlyreduce( (reduced, instanceType) => { |
|
|
|
|
|
// Scan to find a matching instanceroot |
|
|
if( path.normalize(chessinstances[instanceName][instanceType].root) === path.normalize( instanceroot) ) { |
|
|
if( path.normalize(chessinstances[instanceName][instanceType].root) === path.normalize( instanceroot) ) { |
|
|
instanceoptions.splice( 0, 0, chessinstances[instanceName][instanceType]) |
|
|
instanceoptions.splice( 0, 0, chessinstances[instanceName][instanceType]) |
|
|
return { |
|
|
return { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- Override cli prefs and call with undefined selectedinstance only if there is no cli overide or selection. |
|
|
// PB : TODO -- Override cli prefs and call with undefined selectedinstance only if there is no cli overide or selection. |
|
|
var chessinstances = acquirelocalinstances( { root : ENV.wd } ) |
|
|
var chessinstances = acquirelocalinstances( { root : ENV.wd } ) |
|
|
|
|
|
|
|
|
if(chessinstances.error) { |
|
|
if(chessinstances.error) { |
|
|
delete chessinstances.error |
|
|
delete chessinstances.error |
|
|
// use installchoices only when we don't find chessinstances. |
|
|
// use installchoices only when we don't find chessinstances. |
|
|
try { var installchoices = require(path.normalize(ENV.wd + '/installchoices.js')) |
|
|
try { var installchoices = require(path.normalize(ENV.wd + '/installchoices.js')) |
|
|
chessinstances[installchoices.instanceName] = chessinstances[installchoices.instanceName] || {} |
|
|
chessinstances[installchoices.instanceName] = chessinstances[installchoices.instanceName] || {} |
|
|
chessinstances[installchoices.instanceName][installchoices.node_env || clioverrides.node_env] = installchoices |
|
|
chessinstances[installchoices.instanceName][installchoices.node_env || clioverrides.node_env] = installchoices |
|
|
|
|
|
installchoices.username = installchoices.gitUser |
|
|
|
|
|
installchoices.email = installchoices.gitEmail |
|
|
} |
|
|
} |
|
|
catch(e){ |
|
|
catch(e){ |
|
|
console.warn( 'Install choices not found. WIll prompt for choices' ) // This is not an error. A new fresh instance is probably being setup. |
|
|
console.warn( 'Install choices not found. WIll prompt for choices' ) // This is not an error. A new fresh instance is probably being setup. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var __repo_manifest_elxr = loadmanifest( instance.root + '/elxr' |
|
|
var __repo_manifest_elxr = loadmanifest( instance.root + '/elxr' |
|
|
, { utils, username : instance.username /** ??? TODO */ , instanceName : instance.instanceName /** ??? TODO */ |
|
|
, { utils, username : instance.username /** ??? TODO */ , instanceName : instance.instanceName /** ??? TODO */ |
|
|
, node_env : clioverrides.node_env, reposerver : instance.instanceName /** ??? TODO */ } // options |
|
|
|
|
|
|
|
|
, node_env : clioverrides.node_env, reposerver : instance.reposerver /** ??? TODO */ } // options |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
if(__repo_manifest_elxr.error) console.log(__repo_manifest_elxr.e.message) |
|
|
if(__repo_manifest_elxr.error) console.log(__repo_manifest_elxr.e.message) |
|
|
|
|
|
|
|
|
var instance_specific_config_manifest = loadmanifest( instance.root + `/${instance.instanceName}-config-${clioverrides.node_env}` |
|
|
var instance_specific_config_manifest = loadmanifest( instance.root + `/${instance.instanceName}-config-${clioverrides.node_env}` |
|
|
, { utils, username : instance.username /** ??? TODO */ , instanceName : instance.instanceName /** ??? TODO */ |
|
|
, { utils, username : instance.username /** ??? TODO */ , instanceName : instance.instanceName /** ??? TODO */ |
|
|
, node_env : clioverrides.node_env, reposerver : instance.instanceName /** ??? TODO */ } // options |
|
|
|
|
|
|
|
|
, node_env : clioverrides.node_env, reposerver : instance.reposerver /** ??? TODO */ } // options |
|
|
) |
|
|
) |
|
|
if(instance_specific_config_manifest.error) console.log(instance_specific_config_manifest.e.message) |
|
|
if(instance_specific_config_manifest.error) console.log(instance_specific_config_manifest.e.message) |
|
|
delete __repo_manifest_elxr.error |
|
|
delete __repo_manifest_elxr.error |
|
|
|
|
|
|
|
|
, instance_specific_config_manifest |
|
|
, instance_specific_config_manifest |
|
|
, clioverrides |
|
|
, clioverrides |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
console.dir(__pvt) |
|
|
// Unmergable server overrides |
|
|
// Unmergable server overrides |
|
|
Object.keys(instance_specific_config_manifest).forEach( key => { |
|
|
Object.keys(instance_specific_config_manifest).forEach( key => { |
|
|
__pvt[key] = instance_specific_config_manifest[key] |
|
|
__pvt[key] = instance_specific_config_manifest[key] |
|
|
|
|
|
|
|
|
var __pub = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION }, {}, __pvt |
|
|
var __pub = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION }, {}, __pvt |
|
|
// Finalized immutables. |
|
|
// Finalized immutables. |
|
|
// We don't need pub to prevent immutability. |
|
|
// We don't need pub to prevent immutability. |
|
|
, { get root(){ return __pvt.root } |
|
|
|
|
|
|
|
|
, { get root(){ |
|
|
|
|
|
return __pvt.root |
|
|
|
|
|
} |
|
|
, get node_env(){ return __pvt.node_env } |
|
|
, get node_env(){ return __pvt.node_env } |
|
|
, get instanceName() { return __pvt.instanceName } |
|
|
, get instanceName() { return __pvt.instanceName } |
|
|
, get reposindexed(){ |
|
|
, get reposindexed(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(__g, 'selectedinstance', { |
|
|
Object.defineProperty(__g, 'selectedinstance', { |
|
|
get(){ return __pub} |
|
|
get(){ return __pub} |
|
|
, set( inst ){ __pvt = inst; return __pub } |
|
|
|
|
|
|
|
|
, set( inst ){ |
|
|
|
|
|
utils.assign(__pub, inst); return __pub |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
return __pub; |
|
|
return __pub; |
|
|
})() |
|
|
})() |
|
|
|
|
|
|
|
|
var __default = selectedinstance; // PB : TODO -- Eliminate __default references. |
|
|
var __default = selectedinstance; // PB : TODO -- Eliminate __default references. |
|
|
|
|
|
|
|
|
// console.log(selectedinstance) |
|
|
|
|
|
// initinstances(selectedinstance) |
|
|
// initinstances(selectedinstance) |
|
|
|
|
|
|
|
|
var any = utils.any; |
|
|
var any = utils.any; |
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------- |
|
|
// ---------------------------------------------------------------- |
|
|
// var launchpath = path.resolve(path.normalize(ENV.wd)) |
|
|
// var launchpath = path.resolve(path.normalize(ENV.wd)) |
|
|
var launchpath = selectedinstance.root |
|
|
var launchpath = selectedinstance.root |
|
|
var thisscriptdir = path.normalize(__dirname); // PB : TODO -- Thisscriptdir could be dislocated when run as a standalone file... We need to detect this where and how |
|
|
|
|
|
// // we were run. |
|
|
// // we were run. |
|
|
// // The easisest would be to ask for a target directory and default to current dir.... |
|
|
// // The easisest would be to ask for a target directory and default to current dir.... |
|
|
// // path.dirname(launchpath).split(path.sep).pop() |
|
|
// // path.dirname(launchpath).split(path.sep).pop() |
|
|
|
|
|
|
|
|
// }).catch(()=>{ |
|
|
// }).catch(()=>{ |
|
|
// instanceroot = path.normalize(thisscriptdir) === path.normalize(launchpath) ? path.normalize(thisscriptdir + '/..') : launchpath ; |
|
|
// instanceroot = path.normalize(thisscriptdir) === path.normalize(launchpath) ? path.normalize(thisscriptdir + '/..') : launchpath ; |
|
|
// }) |
|
|
// }) |
|
|
var instanceroot = selectedinstance.root |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We first load the default and then override with a runconfig if it exists else we override with the interactive prompts. |
|
|
// We first load the default and then override with a runconfig if it exists else we override with the interactive prompts. |
|
|
// Then acquire and reload and replace this default. |
|
|
// Then acquire and reload and replace this default. |
|
|
|
|
|
|
|
|
var detectfromroot = function(root){ |
|
|
|
|
|
return { root, node_env : path.basename(root), instanceName : path.basename( path.dirname(root) ) } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD |
|
|
|
|
|
// PB : TODO -- Cleanup this should no longer be needed... selectedinstance is properly initialized... |
|
|
|
|
|
var detectLocalInstances = function(){ |
|
|
|
|
|
// console.log(`launchpath = ${launchpath}`) |
|
|
|
|
|
// console.log(`thisscriptdir = ${thisscriptdir}`) |
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- !Postpone this. |
|
|
|
|
|
// console.log(`instanceroot = ${instanceroot}`) // Not yet confirmed... |
|
|
|
|
|
|
|
|
|
|
|
// Note : Paths should already be normalized fefore this. |
|
|
|
|
|
|
|
|
|
|
|
var root = instanceroot; |
|
|
|
|
|
var detected = { root }; |
|
|
|
|
|
var instanceoptions = [clioverrides] |
|
|
|
|
|
|
|
|
|
|
|
return hasElxr(launchpath).then( (launchpathHasElxr) => { |
|
|
|
|
|
|
|
|
|
|
|
// We need a reference to the root directory for elxr cli to be properly oriented. |
|
|
|
|
|
if (( launchpathHasElxr && path.normalize(launchpath + '/elxr')) === thisscriptdir) { |
|
|
|
|
|
// We were run from the proper root with elxr cli in the subfolder. |
|
|
|
|
|
// PB : TODO -- Cleanup this should no longer be needed... selectedinstance is properly initialized... |
|
|
|
|
|
|
|
|
|
|
|
instanceroot = root = launchpath; |
|
|
|
|
|
instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if(path.normalize(launchpath + '/elxr') === thisscriptdir) { |
|
|
|
|
|
// launchpathHasElxr is false -- and yet thiscriptdir is still proper. |
|
|
|
|
|
// PB : TODO -- Maybe a warning / abort if for some reason thisscriptdir should not be used... |
|
|
|
|
|
console.error('Warning : detected thisscriptdir as elxr subfolder but not recognized as elixir. git updates might fail.') |
|
|
|
|
|
instanceroot = root = launchpath; |
|
|
|
|
|
instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
} |
|
|
|
|
|
else if (launchpath === thisscriptdir) { |
|
|
|
|
|
|
|
|
|
|
|
var parentHasElxr = hasElxrSync(launchpath + '/..') |
|
|
|
|
|
// PB : TODO -- verify if we have .elxr folder in the parent... |
|
|
|
|
|
if(!parentHasElxr) { |
|
|
|
|
|
// ! thisscriptdir is not elxr. |
|
|
|
|
|
console.error('Invalid run location in subfolder that looks like elxr. We should probably abort as elxr will not sync.') |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Same directory doesn't mean we are being run from elxr sub directory. |
|
|
|
|
|
// In standalone build script we may or not be in the same location. |
|
|
|
|
|
if (BUILD_VERSION.indexOf('Version: {version} - built on {date}') > -1) { |
|
|
|
|
|
// Unbuilt therefore we are in the elxr sub directory. |
|
|
|
|
|
|
|
|
|
|
|
instanceroot = root = path.normalize(launchpath + '/..'); |
|
|
|
|
|
instanceoptions.splice( 0, 0, detected = { root }); |
|
|
|
|
|
instanceoptions.splice( 0, 0, detectfromroot(root)); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
// Built version. |
|
|
|
|
|
// We could have been run from the elxr subfolder. Highly likely that the built version isn't the full elxr. |
|
|
|
|
|
if(parentHasElxr) { |
|
|
|
|
|
// Built version was run from the full elxr subfolder. Should work |
|
|
|
|
|
// PB : TODO -- but we should switch to the full version... |
|
|
|
|
|
instanceroot = root = path.normalize(launchpath + '/..'); |
|
|
|
|
|
instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
instanceroot = root = launchpath; |
|
|
|
|
|
instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
// Assume current launchpath is a new instance and create. |
|
|
|
|
|
// Figure out the instnace name and environment from parent folders as an alternative option with confirmation if not provided in the arguments. |
|
|
|
|
|
|
|
|
|
|
|
// if(clioverrides.instanceName) { |
|
|
|
|
|
// if(clioverrides.node_env) { |
|
|
|
|
|
// instanceroot = root = path.normalize(launchpath + '/' + clioverrides.instanceName + '/' + clioverrides.node_env) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root, instanceName : clioverrides.instanceName, node_env : clioverrides.node_env }) |
|
|
|
|
|
// // instanceoptions.splice( 0, 0, detectfromroot(root)) // This can be an option but is unnecessary unless a confirmation is provided. |
|
|
|
|
|
// // also folder names may have no relation to the actual instanceName and instanceType coz we need to have many |
|
|
|
|
|
// // eg : floder name can be elixir01 but instance name is elixr |
|
|
|
|
|
// } |
|
|
|
|
|
// else { |
|
|
|
|
|
// instanceroot = root = path.normalize(launchpath + '/' + clioverrides.instanceName + '/' + 'development') |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root, instanceName : clioverrides.instanceName, node_env : 'development' }) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)) // A recessive option only. |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// else { |
|
|
|
|
|
// instanceroot = root = launchpath; |
|
|
|
|
|
// if(clioverrides.node_env) { |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = { root, node_env : clioverrides.node_env }) |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
// } |
|
|
|
|
|
// else { |
|
|
|
|
|
// // Nothing was specified... We only have one option from root. |
|
|
|
|
|
// instanceoptions.splice( 0, 0, detected = detectfromroot(launcpath)) |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if(launchpathHasElxr) { |
|
|
|
|
|
instanceroot = root = launchpath; |
|
|
|
|
|
instanceoptions.splice( 0, 0, detected = { root }) |
|
|
|
|
|
instanceoptions.splice( 0, 0, detectfromroot(root)) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
instanceroot = detected.root |
|
|
|
|
|
clioverrides.root = clioverrides.root || root; |
|
|
|
|
|
|
|
|
|
|
|
// Resolves empty array when No known instances detected. |
|
|
|
|
|
return Promise.resolve(instanceoptions) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var getReconfirmAll = ()=>{return { instanceName : true, instanceType : true, reposerver : true, username : true, password : true } } |
|
|
var getReconfirmAll = ()=>{return { instanceName : true, instanceType : true, reposerver : true, username : true, password : true } } |
|
|
if(clioverrides.reconfirm) { |
|
|
if(clioverrides.reconfirm) { |
|
|
var reconfirm = getReconfirmAll() |
|
|
var reconfirm = getReconfirmAll() |
|
|
|
|
|
|
|
|
// We need to take a snapshot... Shallow.. !! If required deep should be used based on use case. |
|
|
// We need to take a snapshot... Shallow.. !! If required deep should be used based on use case. |
|
|
// var asyncthis = Object.assign(this); |
|
|
// var asyncthis = Object.assign(this); |
|
|
// By default Latest altered state is provided which is an implicit reference directly. |
|
|
// By default Latest altered state is provided which is an implicit reference directly. |
|
|
|
|
|
console.log('----------------------------------------------------') |
|
|
|
|
|
console.log(k) |
|
|
|
|
|
console.dir(possiblePrompts) |
|
|
|
|
|
console.dir(choices[k]) |
|
|
promptables[k].choices = choices[k] |
|
|
promptables[k].choices = choices[k] |
|
|
Object.defineProperty(target, k, getPromptableAsyncPropDescriptor(k, promptables[k])); |
|
|
Object.defineProperty(target, k, getPromptableAsyncPropDescriptor(k, promptables[k])); |
|
|
return await target[k] |
|
|
return await target[k] |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
, reposerver : { label : `Enter Repo Server Base Url ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : ` |
|
|
, reposerver : { label : `Enter Repo Server Base Url ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : ` |
|
|
, get choices() { |
|
|
, get choices() { |
|
|
choices['reposerver'].forEach( rs => { |
|
|
|
|
|
var __rs = new URL(rs); |
|
|
|
|
|
__rs.hostname = __rs.host; |
|
|
|
|
|
__rs.path = '/' |
|
|
|
|
|
__rs.method = 'GET' |
|
|
|
|
|
RESTAPI.get(__rs, function(data){ rs.accessibility = 'accessible' } |
|
|
|
|
|
, function(error){ rs.accessibility = 'unaccessible' } ) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
// choices['reposerver'].forEach( rs => { |
|
|
|
|
|
// var __rs = new URL(rs); |
|
|
|
|
|
// __rs.hostname = __rs.host; |
|
|
|
|
|
// __rs.path = '/' |
|
|
|
|
|
// __rs.method = 'GET' |
|
|
|
|
|
// RESTAPI.get(__rs, function(data){ rs.accessibility = 'accessible' } |
|
|
|
|
|
// , function(error){ rs.accessibility = 'unaccessible' } ) |
|
|
|
|
|
// }) |
|
|
return choices['reposerver'] |
|
|
return choices['reposerver'] |
|
|
} |
|
|
} |
|
|
, defaultchoice : 'https://git.bbh.org.in' |
|
|
|
|
|
|
|
|
, set choices(cs) { |
|
|
|
|
|
return choices['reposerver'].concat([selectedinstance.reposerver]).concat(cs) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, defaultchoice : selectedinstance.reposerver || 'https://git.bbh.org.in' |
|
|
, selectedchoice : target.reposerver |
|
|
, selectedchoice : target.reposerver |
|
|
} |
|
|
} |
|
|
, 'upstream-remote' : { label : `Enter Remote Name ( <= ${target['upstream-remote'] || 'chess'} ) : ` |
|
|
|
|
|
, get choices() { |
|
|
|
|
|
var reposerver = target['reposerver'] |
|
|
|
|
|
var remotes = [] |
|
|
|
|
|
var trs = target.reposervers || [] |
|
|
|
|
|
trs.forEach(rs => { |
|
|
|
|
|
if(rs.server === reposerver){ |
|
|
|
|
|
remotes.push(remote) |
|
|
|
|
|
// PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
return remotes |
|
|
|
|
|
} |
|
|
|
|
|
, defaultchoice : 'userfork' |
|
|
|
|
|
, selectedchoice : target['upstream-remote'] || 'userfork' |
|
|
|
|
|
// Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
|
|
|
} |
|
|
|
|
|
, 'remote-type' : { label : `Enter Remote Type ( <= ${target['remote-type'] || 'public'} ) : ` |
|
|
|
|
|
, get choices() { |
|
|
|
|
|
return ['external', 'public', 'private', 'github', 'unc'] |
|
|
|
|
|
} |
|
|
|
|
|
, defaultchoice : 'public' |
|
|
|
|
|
, selectedchoice : target['remote-type'] || 'public' |
|
|
|
|
|
// Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
|
|
|
} |
|
|
|
|
|
, 'selectedremotes' : { label : `Chose Remote Names ( <= ${target['selectedremotes'] || 'chess'} ) : ` |
|
|
|
|
|
, get choices() { |
|
|
|
|
|
var reposerver = target['reposerver'] // PB : TODO -- We need options to work with multiple selected reposervers at the same time.. |
|
|
|
|
|
var remotenames = [] |
|
|
|
|
|
Object.entries(target.remotes || []).forEach( ([rname, r]) => { |
|
|
|
|
|
if(r.server === reposerver && r.accessibility.find( target[ 'remote-type' ] )){ |
|
|
|
|
|
remotes.push(rname) |
|
|
|
|
|
// PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
// PB : TODO -- Need to generate all possible permuted choices nP( 1 -> n ) |
|
|
|
|
|
// Currenty handles all combinations without any priority order. |
|
|
|
|
|
var _remotechoices = [] // Array of arrays of choices. |
|
|
|
|
|
remotenames.forEach( r => { |
|
|
|
|
|
var __rcs = [] |
|
|
|
|
|
_remotechoices.forEach(rc => { |
|
|
|
|
|
__rcs.push( rc.concat(r) ) |
|
|
|
|
|
}) |
|
|
|
|
|
Array.prototype.push.apply( _remotechoices, __rcs) |
|
|
|
|
|
_remotechoices.push(r) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return _remotechoices |
|
|
|
|
|
} |
|
|
|
|
|
, defaultchoice : ['userfork', 'chess'] // userfork and chess should imlicitly point to userfork-external and chess-external when external connectivity is dtetected. |
|
|
|
|
|
, selectedchoice : target['selectedremotes'] || ['userfork-external', 'chess-external'] |
|
|
|
|
|
// , defaultchoice : { 'userfork-external' : target.remotes['userfork-external'] , 'chess-external' : target.remotes['chess-external'] } |
|
|
|
|
|
// , selectedchoice : target['selectedremotes'] || { 'userfork-external' : target.remotes['userfork-external'] , 'chess-external' : target.remotes['chess-external'] } |
|
|
|
|
|
|
|
|
// , 'upstream-remote' : { label : `Enter Remote Name ( <= ${target['upstream-remote'] || 'chess'} ) : ` |
|
|
|
|
|
// , get choices() { |
|
|
|
|
|
// var reposerver = target['reposerver'] |
|
|
|
|
|
// var remotes = [] |
|
|
|
|
|
// var trs = target.reposervers || [] |
|
|
|
|
|
// trs.forEach(rs => { |
|
|
|
|
|
// if(rs.server === reposerver){ |
|
|
|
|
|
// remotes.push(remote) |
|
|
|
|
|
// // PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
|
|
|
// } |
|
|
|
|
|
// }) |
|
|
|
|
|
// return remotes |
|
|
|
|
|
// } |
|
|
|
|
|
// , set choices(addlchoices){ |
|
|
|
|
|
// var reposerver = target['reposerver'] |
|
|
|
|
|
// var remotes = [] |
|
|
|
|
|
// var trs = target.reposervers || [] |
|
|
|
|
|
// trs.forEach(rs => { |
|
|
|
|
|
// if(rs.server === reposerver){ |
|
|
|
|
|
// remotes.push(remote) |
|
|
|
|
|
// // PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
|
|
|
// } |
|
|
|
|
|
// }) |
|
|
|
|
|
// return remotes.concat(addlchoices) |
|
|
|
|
|
// } |
|
|
|
|
|
// , defaultchoice : 'userfork' |
|
|
|
|
|
// , selectedchoice : target['upstream-remote'] || 'userfork' |
|
|
|
|
|
// // Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
|
|
|
// } |
|
|
|
|
|
// , 'remote-type' : { label : `Enter Remote Type ( <= ${target['remote-type'] || 'public'} ) : ` |
|
|
|
|
|
// , get choices() { |
|
|
|
|
|
// return ['external', 'public', 'private', 'github', 'unc'] |
|
|
|
|
|
// } |
|
|
|
|
|
// , set choices(addlchoices){ |
|
|
|
|
|
// var reposerver = target['reposerver'] |
|
|
|
|
|
// var remotes = [] |
|
|
|
|
|
// var trs = target.reposervers || [] |
|
|
|
|
|
// trs.forEach(rs => { |
|
|
|
|
|
// if(rs.server === reposerver){ |
|
|
|
|
|
// remotes.push(remote) |
|
|
|
|
|
// // PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
|
|
|
// } |
|
|
|
|
|
// }) |
|
|
|
|
|
// return ['external', 'public', 'private', 'github', 'unc'].concat(addlchoices) |
|
|
|
|
|
// } |
|
|
|
|
|
// , defaultchoice : 'public' |
|
|
|
|
|
// , selectedchoice : target['remote-type'] || 'public' |
|
|
|
|
|
// // Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
|
|
|
// } |
|
|
|
|
|
// , 'selectedremotes' : { label : `Chose Remote Names ( <= ${target['selectedremotes'] || 'chess'} ) : ` |
|
|
|
|
|
// , get choices() { |
|
|
|
|
|
// var reposerver = target['reposerver'] // PB : TODO -- We need options to work with multiple selected reposervers at the same time.. |
|
|
|
|
|
// var remotenames = [] |
|
|
|
|
|
// Object.entries(target.remotes || []).forEach( ([rname, r]) => { |
|
|
|
|
|
// if(r.server === reposerver && r.accessibility.find( target[ 'remote-type' ] )){ |
|
|
|
|
|
// remotes.push(rname) |
|
|
|
|
|
// // PB : TODO -- Sort and display highest priority target.remotes.sort( ) |
|
|
|
|
|
// } |
|
|
|
|
|
// }) |
|
|
|
|
|
// // PB : TODO -- Need to generate all possible permuted choices nP( 1 -> n ) |
|
|
|
|
|
// // Currenty handles all combinations without any priority order. |
|
|
|
|
|
// var _remotechoices = [] // Array of arrays of choices. |
|
|
|
|
|
// remotenames.forEach( r => { |
|
|
|
|
|
// var __rcs = [] |
|
|
|
|
|
// _remotechoices.forEach(rc => { |
|
|
|
|
|
// __rcs.push( rc.concat(r) ) |
|
|
|
|
|
// }) |
|
|
|
|
|
// Array.prototype.push.apply( _remotechoices, __rcs) |
|
|
|
|
|
// _remotechoices.push(r) |
|
|
|
|
|
// }) |
|
|
|
|
|
|
|
|
|
|
|
// return _remotechoices |
|
|
|
|
|
// } |
|
|
|
|
|
// , defaultchoice : ['userfork', 'chess'] // userfork and chess should imlicitly point to userfork-external and chess-external when external connectivity is dtetected. |
|
|
|
|
|
// , selectedchoice : target['selectedremotes'] || ['userfork-external', 'chess-external'] |
|
|
|
|
|
// // , defaultchoice : { 'userfork-external' : target.remotes['userfork-external'] , 'chess-external' : target.remotes['chess-external'] } |
|
|
|
|
|
// // , selectedchoice : target['selectedremotes'] || { 'userfork-external' : target.remotes['userfork-external'] , 'chess-external' : target.remotes['chess-external'] } |
|
|
|
|
|
|
|
|
// Info : Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// // Info : Just using getters resolves dependencies..., dependencies : [ ()=>{ return target['reposerver'] } ] |
|
|
|
|
|
// } |
|
|
, get username() { return { label : `Enter User Id for ${target.reposerver} ( <= ${target.username || 'chess'} ) : ` |
|
|
, get username() { return { label : `Enter User Id for ${target.reposerver} ( <= ${target.username || 'chess'} ) : ` |
|
|
, choices : choices['username'], defaultchoice : 'chess', selectedchoice : target.username } } |
|
|
|
|
|
|
|
|
, choices : choices['username'], defaultchoice : target.username || 'chess', selectedchoice : target.username } } |
|
|
, get password() { return { label : `Enter Password for ${target.username} @ ${target.reposerver} ( <= ${target.password || ''} ) : ` |
|
|
, get password() { return { label : `Enter Password for ${target.username} @ ${target.reposerver} ( <= ${target.password || ''} ) : ` |
|
|
, choices : choices['password'], defaultchoice : '***', selectedchoice : target.password } } |
|
|
, choices : choices['password'], defaultchoice : '***', selectedchoice : target.password } } |
|
|
, get email() { return { label : `Enter Email for ${target.username} @ ${target.reposerver} ( <= ${target.email || ''} ) : ` |
|
|
, get email() { return { label : `Enter Email for ${target.username} @ ${target.reposerver} ( <= ${target.email || ''} ) : ` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 detectLocalInstances. |
|
|
|
|
|
|
|
|
var root = selected_overrides.root // We should always have this coz we are running at some place which is fixed by . |
|
|
|
|
|
|
|
|
var instanceName = selected_overrides.instanceName |
|
|
var instanceName = selected_overrides.instanceName |
|
|
|| clioverrides.instanceName |
|
|
|| clioverrides.instanceName |
|
|
|
|
|
|
|
|
reconfirm = getReconfirmAll() |
|
|
reconfirm = getReconfirmAll() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return detectLocalInstances().then((detectedinstanceoptions)=>{ |
|
|
|
|
|
|
|
|
|
|
|
detectedinstanceoptions.splice(0,0, __default) |
|
|
|
|
|
|
|
|
|
|
|
var cmdinstance = cmds[clioverrides.cmd] |
|
|
|
|
|
var cmdprompts = cmdinstance.getPossiblePrompts() |
|
|
|
|
|
selectedinstance.node_env ? selectedinstance.node_env : selectedinstance.node_env = clioverrides.node_env |
|
|
|
|
|
// PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!! |
|
|
|
|
|
selectedinstance = __g.selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } |
|
|
|
|
|
, ...detectedinstanceoptions.slice(-2), promptkeys ) |
|
|
|
|
|
// promptkeys = utils.assign(promptkeys, clioverrides) |
|
|
|
|
|
|
|
|
|
|
|
// startElxr requires instance // Independent cmds should have already been bypassed. |
|
|
|
|
|
|
|
|
|
|
|
// if(cmdprompts.instanceName) { |
|
|
|
|
|
// not an instanceless cmd. |
|
|
|
|
|
console.dir(selectedinstance) |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
// detectedinstanceoptions.splice(0,0, __default) // PB : TODO -- Merge multiple... |
|
|
|
|
|
var detectedinstanceoptions = [selectedinstance] |
|
|
|
|
|
|
|
|
|
|
|
var cmdinstance = cmds[clioverrides.cmd] |
|
|
|
|
|
var cmdprompts = cmdinstance.getPossiblePrompts() |
|
|
|
|
|
// selectedinstance.node_env ? selectedinstance.node_env : selectedinstance.node_env = clioverrides.node_env |
|
|
|
|
|
// PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!! |
|
|
|
|
|
utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION }, selectedinstance, promptkeys ) |
|
|
|
|
|
// promptkeys = utils.assign(promptkeys, clioverrides) |
|
|
|
|
|
|
|
|
|
|
|
// startElxr requires instance // Independent cmds should have already been bypassed. |
|
|
|
|
|
|
|
|
chessinstances = acquirelocalinstances(selectedinstance); |
|
|
|
|
|
findlocalinstances(chessinstances, detectedinstanceoptions) |
|
|
|
|
|
initinstances(selectedinstance) // use the local instances for defaults if at all possible. |
|
|
|
|
|
var todo = any( getInteractionPoints(detectedinstanceoptions, promptkeys) ).then(()=>{ |
|
|
|
|
|
var inst = initinstances(selectedinstance) |
|
|
|
|
|
detection_state.localInstanceDetected = true; |
|
|
|
|
|
return inst; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
catch (e) { |
|
|
|
|
|
// PB : TODO -- verbose mode warning.. console.warn(e) // Missing chessinstances is not an error... |
|
|
|
|
|
var todo = any( getInteractionPoints(detectedinstanceoptions, promptkeys) ).then(()=>{ |
|
|
|
|
|
return initinstances(selectedinstance) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
// if(cmdprompts.instanceName) { |
|
|
|
|
|
// not an instanceless cmd. |
|
|
|
|
|
console.dir(selectedinstance) |
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
// chessinstances = acquirelocalinstances(selectedinstance); |
|
|
|
|
|
// findlocalinstances(chessinstances, detectedinstanceoptions) |
|
|
|
|
|
initinstances(selectedinstance) // use the local instances for defaults if at all possible. |
|
|
|
|
|
var todo = any( getInteractionPoints([selectedinstance], promptkeys) ).then(()=>{ |
|
|
|
|
|
var inst = initinstances(selectedinstance) |
|
|
|
|
|
detection_state.localInstanceDetected = true; |
|
|
|
|
|
return inst; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
catch (e) { |
|
|
|
|
|
// PB : TODO -- verbose mode warning.. console.warn(e) // Missing chessinstances is not an error... |
|
|
|
|
|
var todo = any( getInteractionPoints(detectedinstanceoptions, promptkeys) ).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) }) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
// if(!processedArgs._[0] || !selectedinstance.node_env || !selectedinstance.instanceName){ |
|
|
|
|
|
// // Weve not been told what to do. |
|
|
|
|
|
// todo = todo.then(() => { return acquireChoices(selectedinstance) }) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
todo = todo.then(() => { |
|
|
|
|
|
try { |
|
|
|
|
|
chessinstances = acquirelocalinstances(selectedinstance) |
|
|
|
|
|
findlocalinstances(chessinstances, detectedinstanceoptions) |
|
|
|
|
|
detectedinstanceoptions.splice(0,0, __default) |
|
|
|
|
|
initinstances(selectedinstance) |
|
|
|
|
|
detection_state.localInstanceDetected = true; |
|
|
|
|
|
} |
|
|
|
|
|
catch (e) { |
|
|
|
|
|
// console.error(e) |
|
|
|
|
|
console.log('No local instances config found in current root = ' + selectedinstance.root); |
|
|
|
|
|
console.log('A config will be createed with the instance and environment chosen...') |
|
|
|
|
|
// return (async ()=>{return await __default.reposerver})().then(()=>{ |
|
|
|
|
|
// // selectedinstance = Object.assign(detectedInstance, clioverrides); |
|
|
|
|
|
// return selectedinstance = Object.assign(__default, selectedinstance); |
|
|
|
|
|
// }) |
|
|
|
|
|
detection_state.localInstanceDetected = false; |
|
|
|
|
|
return selectedinstance |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
return todo.then( ()=>{ |
|
|
|
|
|
// PB : TODO -- Embed this in the build instead of inlining it. |
|
|
|
|
|
// Also attepmt to load from ../chess-config/... |
|
|
|
|
|
// PB : TODO -- OBSOLETEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE |
|
|
|
|
|
var __repo_manifest_elxr = (require(path.normalize(instanceroot + '/elxr/repo-manifest.js')))( |
|
|
|
|
|
'defaultmanifest' // name |
|
|
|
|
|
, { utils, username : selectedinstance.username, instanceName : selectedinstance.instanceName |
|
|
|
|
|
, node_env : selectedinstance.node_env, reposerver : selectedinstance.reposerver } // options |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
__default = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } |
|
|
|
|
|
, __default, __repo_manifest_elxr, { |
|
|
|
|
|
// Common baseline repos for all chess instances. |
|
|
|
|
|
repos : (()=> { |
|
|
|
|
|
var __repos = [ |
|
|
|
|
|
{ repo : 'ember-masonry-grid' /*, branch : master*/ } // Default need not be specified. |
|
|
|
|
|
, { repo : 'bbhverse' } |
|
|
|
|
|
, { repo : 'clientverse' } |
|
|
|
|
|
, { repo : 'serververse' } |
|
|
|
|
|
, { repo : 'elxr' } |
|
|
|
|
|
, { repo : 'ember-searchable-select' } |
|
|
|
|
|
, { repo : 'loopback-component-jsonapi' } |
|
|
|
|
|
, { repo : 'loopback-jsonapi-model-serializer' } |
|
|
|
|
|
, { repo : 'loopback-connector-mysql' } |
|
|
|
|
|
, { repo : 'loopback-connector-ds' } |
|
|
|
|
|
|
|
|
|
|
|
, { repo : 'ember-service-worker' } |
|
|
|
|
|
, { repo : 'ember-service-worker-asset-cache' } |
|
|
|
|
|
, { repo : 'ember-service-worker-cache-fallback' } |
|
|
|
|
|
, { repo : 'ember-service-worker-index' } |
|
|
|
|
|
, { repo : 'ember-sw-client-route' } |
|
|
|
|
|
, { repo : 'global-this' } |
|
|
|
|
|
] |
|
|
|
|
|
Array.prototype.push.apply( __repos, __repo_manifest_elxr.repos) |
|
|
|
|
|
return __repos; |
|
|
|
|
|
})() |
|
|
|
|
|
// Requires elevation only in windows |
|
|
|
|
|
, elevated : [ { repo : 'chess-server-lib', requiresElevation : true } ] |
|
|
|
|
|
, exludeMergeRepos : { } |
|
|
|
|
|
}, ) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
todo = todo.then(() => { |
|
|
|
|
|
try { |
|
|
|
|
|
// chessinstances = acquirelocalinstances(selectedinstance) |
|
|
|
|
|
// findlocalinstances(chessinstances, detectedinstanceoptions) |
|
|
|
|
|
// detectedinstanceoptions.splice(0,0, __default) |
|
|
initinstances(selectedinstance) |
|
|
initinstances(selectedinstance) |
|
|
|
|
|
detection_state.localInstanceDetected = true; |
|
|
|
|
|
} |
|
|
|
|
|
catch (e) { |
|
|
|
|
|
// console.error(e) |
|
|
|
|
|
console.log('No local instances config found in current root = ' + selectedinstance.root); |
|
|
|
|
|
console.log('A config will be createed with the instance and environment chosen...') |
|
|
|
|
|
// return (async ()=>{return await __default.reposerver})().then(()=>{ |
|
|
|
|
|
// // selectedinstance = Object.assign(detectedInstance, clioverrides); |
|
|
|
|
|
// return selectedinstance = Object.assign(__default, selectedinstance); |
|
|
|
|
|
// }) |
|
|
|
|
|
detection_state.localInstanceDetected = false; |
|
|
return selectedinstance |
|
|
return selectedinstance |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
// } |
|
|
|
|
|
// else return Promise.resolve(true) |
|
|
|
|
|
}) |
|
|
|
|
|
.then(()=>{ |
|
|
|
|
|
runconfig = { NODE_ENV: selectedinstance.node_env } |
|
|
|
|
|
try { runconfig = Object.assign(runconfig, require(instanceroot + '/run.js')) } catch (e) { } |
|
|
|
|
|
generateDependencies(); |
|
|
|
|
|
if(noprerequisites[processedArgs._[0]] |
|
|
|
|
|
|| skipprereqs[processedArgs._[0]] |
|
|
|
|
|
) { |
|
|
|
|
|
return elxrworker() |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var neTask = ()=>{ |
|
|
|
|
|
ensureDirectoryExistence(`${selectedinstance.root}/.elxr/${__ALIAS__STAMP__}`) |
|
|
|
|
|
// collect garbage |
|
|
|
|
|
return dirs( (dir)=>{ |
|
|
|
|
|
var matches = /run-(.*)/gm.exec(dir.name) |
|
|
|
|
|
if(matches) { |
|
|
|
|
|
if(+(matches[1]) < min) { |
|
|
|
|
|
min = matches[1] |
|
|
|
|
|
collect.splice( 0, 0, matches[1] ) |
|
|
|
|
|
} |
|
|
|
|
|
else collect.push(matches[1]) |
|
|
|
|
|
|
|
|
return todo.then( ()=>{ |
|
|
|
|
|
// PB : TODO -- Embed this in the build instead of inlining it. |
|
|
|
|
|
// PB : TODO -- Also attepmt to load from ../chess-config/... as base for new instances... |
|
|
|
|
|
|
|
|
|
|
|
initinstances(selectedinstance) // PB : TODO Review Initinstancess... and cleanup |
|
|
|
|
|
// --------------------------- |
|
|
|
|
|
runconfig = { NODE_ENV: selectedinstance.node_env } |
|
|
|
|
|
try { runconfig = Object.assign(runconfig, require(instanceroot + '/run.js')) } catch (e) { } |
|
|
|
|
|
generateDependencies(); |
|
|
|
|
|
if(noprerequisites[processedArgs._[0]] |
|
|
|
|
|
|| skipprereqs[processedArgs._[0]] |
|
|
|
|
|
) { |
|
|
|
|
|
return elxrworker() |
|
|
} |
|
|
} |
|
|
return Promise.resolve(collect); |
|
|
|
|
|
}, `${selectedinstance.root}/.elxr` ) |
|
|
|
|
|
.then(()=>{ |
|
|
|
|
|
// delete garbage |
|
|
|
|
|
if(collect.length > retaincount) { |
|
|
|
|
|
|
|
|
|
|
|
var asyncs = []; |
|
|
|
|
|
while((collect.length - asyncs.length) > retaincount) { |
|
|
|
|
|
asyncs.push(getShellTask('rm',['-rf', `run-${collect[asyncs.length]}`], { cwd : `${selectedinstance.root}/.elxr` })()); |
|
|
|
|
|
} |
|
|
|
|
|
return Promise.all(asyncs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var neTask = ()=>{ |
|
|
|
|
|
ensureDirectoryExistence(`${selectedinstance.root}/.elxr/${__ALIAS__STAMP__}`) |
|
|
|
|
|
// collect garbage |
|
|
|
|
|
return dirs( (dir)=>{ |
|
|
|
|
|
var matches = /run-(.*)/gm.exec(dir.name) |
|
|
|
|
|
if(matches) { |
|
|
|
|
|
if(+(matches[1]) < min) { |
|
|
|
|
|
min = matches[1] |
|
|
|
|
|
collect.splice( 0, 0, matches[1] ) |
|
|
|
|
|
} |
|
|
|
|
|
else collect.push(matches[1]) |
|
|
|
|
|
} |
|
|
|
|
|
return Promise.resolve(collect); |
|
|
|
|
|
}, `${selectedinstance.root}/.elxr` ) |
|
|
|
|
|
.then(()=>{ |
|
|
|
|
|
// delete garbage |
|
|
|
|
|
if(collect.length > retaincount) { |
|
|
|
|
|
|
|
|
|
|
|
var asyncs = []; |
|
|
|
|
|
while((collect.length - asyncs.length) > retaincount) { |
|
|
|
|
|
asyncs.push(getShellTask('rm',['-rf', `run-${collect[asyncs.length]}`], { cwd : `${selectedinstance.root}/.elxr` })()); |
|
|
|
|
|
} |
|
|
|
|
|
return Promise.all(asyncs) |
|
|
|
|
|
} |
|
|
|
|
|
else return true |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(e => { |
|
|
|
|
|
console.error |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
neTask.statuslog = statuslog |
|
|
|
|
|
|
|
|
|
|
|
shell_verse.getNonElevatedTask( neTask )() |
|
|
|
|
|
|
|
|
|
|
|
var commonTask = ()=>{ |
|
|
|
|
|
verifyAndInstallPrerequisites.statuslog = statuslog |
|
|
|
|
|
if((!skipprerequisites || processedArgs.forceprereqs)) mainTasks.push(verifyAndInstallPrerequisites); |
|
|
|
|
|
mainTasks.push(maintask) |
|
|
|
|
|
return any(mainTasks); |
|
|
} |
|
|
} |
|
|
else return true |
|
|
|
|
|
}) |
|
|
|
|
|
.catch(e => { |
|
|
|
|
|
console.error |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
neTask.statuslog = statuslog |
|
|
|
|
|
|
|
|
|
|
|
shell_verse.getNonElevatedTask( neTask )() |
|
|
|
|
|
|
|
|
|
|
|
var commonTask = ()=>{ |
|
|
|
|
|
verifyAndInstallPrerequisites.statuslog = statuslog |
|
|
|
|
|
if((!skipprerequisites || processedArgs.forceprereqs)) mainTasks.push(verifyAndInstallPrerequisites); |
|
|
|
|
|
mainTasks.push(maintask) |
|
|
|
|
|
return any(mainTasks); |
|
|
|
|
|
} |
|
|
|
|
|
return commonTask() |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
return commonTask() |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
// } |
|
|
|
|
|
// else return Promise.resolve(true) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|