瀏覽代碼

Fixes for autoinstall

master
developer 2 年之前
父節點
當前提交
2d5a4d391e
共有 2 個文件被更改,包括 366 次插入381 次删除
  1. 29
    24
      i.win.js
  2. 337
    357
      index.js

+ 29
- 24
i.win.js 查看文件

@@ -1170,21 +1170,22 @@ function __main( selectedinstance ){

var gitpostinstallsteps = function(){

// Load just in case someone was smart enough to fill in before install.
var icf = fs.readFileSync( 'installchoices.js')
icf = icf.replace('module.exports = ', 'icf = ')
console.log(icf)
try {
// Load just in case someone was smart enough to fill in before install.
var icf = fs.readFileSync( 'installchoices.js')
icf = icf.replace('module.exports = ', 'icf = ')
console.log(icf)
icf = eval(icf)
// console.log(icf.reposerver)
instanceName = icf.instanceName
reposerver = icf.reposerver;
gitUser = icf.gitUser;
gitEmail = icf.gitEmail
}
catch(e) {
console.error(e)
}
// console.log(icf.reposerver)
instanceName = icf.instanceName
reposerver = icf.reposerver;
gitUser = icf.gitUser;
gitEmail = icf.gitEmail

// gitpassword = icf.??? ; we do not store password it should already be cached in the credential store.

// PB : TODO -- Detect failure or cancellation before attenpting postinstall steps...
@@ -1626,20 +1627,21 @@ function __main( selectedinstance ){
// var reposerver = 'https://git.bbh.org.in';
// var gitUser = 'guest';
// var gitEmail = 'guest@bbh.org.in';
var icf = fs.readFileSync( 'installchoices.js')
icf = icf.replace('module.exports = ', 'icf = ')
console.log(icf)
try {
var icf = fs.readFileSync( 'installchoices.js')
icf = icf.replace('module.exports = ', 'icf = ')
console.log(icf)
icf = eval(icf)
// console.log(icf.reposerver)
instanceName = icf.instanceName
reposerver = icf.reposerver;
gitUser = icf.gitUser;
gitEmail = icf.gitEmail
}
catch(e) {
console.error(e)
}
// console.log(icf.reposerver)
instanceName = icf.instanceName
reposerver = icf.reposerver;
gitUser = icf.gitUser;
gitEmail = icf.gitEmail
console.log('-------------------------------------')
console.dir(icf)
@@ -1667,7 +1669,9 @@ function __main( selectedinstance ){
// resetgitconfig requires the password to be loaded from credential store. Currently just prompt for it.
return any(steps).then( function(){
console.log('calling resetgitconfig')
return resetgitconfig().then(function(){
console.log('cloning elxr now')
var ifns = [
['git', ['clone', reposerver + '/chess/elxr'] ]
]
@@ -1681,14 +1685,15 @@ function __main( selectedinstance ){
}
}
else console.log(selectedinstance.root + '\\elxr' + ' NOT FOUND ')
var pkgjson = selectedinstance.root + '\\elxr\\package.json'
var pkgcontents = fs.readFileSync(pkgjson)
// PB : TODO -- Remove hardcode use proper replacement url..
fs.writeFileSync( pkgjson, pkgcontents.replace(/http\:\/\/git\.bbh/g, reposerver));
ifns.push(['npm', ['i'], { cwd : '.\\elxr' } ])
if(!ifns.map) ifns.map = map;
return any(ifns.map(callsheltask))['catch'](function(e){
return any(ifns.map(callsheltask)).then(function(){
var pkgjson = selectedinstance.root + '\\elxr\\package.json'
var pkgcontents = fs.readFileSync(pkgjson)
// PB : TODO -- Remove hardcode use proper replacement url..
fs.writeFileSync( pkgjson, pkgcontents.replace(/http\:\/\/git\.bbh/g, reposerver));
return callsheltask(['npm', ['i'], { cwd : '.\\elxr' } ])
})['catch'](function(e){
if(e.code === 1602) {
console.warn("Installation was probably cancelled.")
}

+ 337
- 357
index.js 查看文件

@@ -114,39 +114,138 @@ shell_verse.acquireElevationState().then((isElevated) => {

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){
// 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.
// 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 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 {
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 {
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
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'

console.log('----------------------------------------------------------------')
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)
process.chdir(ENV.wd) // Ensure cwd is the actual working dir.
console.log('PWD :' + ENV.PWD)
console.log('cwd : ' + process.cwd())
console.log(`thisscriptdir = ${thisscriptdir}`)
console.log('----------------------------------------------------------------')
// 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
var noprerequisites = {
add : true, 'set-url' : true, 'repo-relocate' : true
@@ -2310,9 +2409,13 @@ shell_verse.acquireElevationState().then((isElevated) => {
if(existsSync( localinstancesPath )) {
try {
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[instanceName]).earlyreduce( (reduced, instanceType) => {
// Scan to find a matching instanceroot
if( path.normalize(chessinstances[instanceName][instanceType].root) === path.normalize( instanceroot) ) {
instanceoptions.splice( 0, 0, chessinstances[instanceName][instanceType])
return {
@@ -2379,12 +2482,15 @@ shell_verse.acquireElevationState().then((isElevated) => {
// 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 } )

if(chessinstances.error) {
delete chessinstances.error
// use installchoices only when we don't find chessinstances.
try { var installchoices = require(path.normalize(ENV.wd + '/installchoices.js'))
chessinstances[installchoices.instanceName] = chessinstances[installchoices.instanceName] || {}
chessinstances[installchoices.instanceName][installchoices.node_env || clioverrides.node_env] = installchoices
installchoices.username = installchoices.gitUser
installchoices.email = installchoices.gitEmail
}
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.
@@ -2432,14 +2538,14 @@ shell_verse.acquireElevationState().then((isElevated) => {
var __repo_manifest_elxr = loadmanifest( instance.root + '/elxr'
, { 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)
var instance_specific_config_manifest = loadmanifest( instance.root + `/${instance.instanceName}-config-${clioverrides.node_env}`
, { 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)
delete __repo_manifest_elxr.error
@@ -2469,7 +2575,7 @@ shell_verse.acquireElevationState().then((isElevated) => {
, instance_specific_config_manifest
, clioverrides
)
console.dir(__pvt)
// Unmergable server overrides
Object.keys(instance_specific_config_manifest).forEach( key => {
__pvt[key] = instance_specific_config_manifest[key]
@@ -2478,7 +2584,9 @@ shell_verse.acquireElevationState().then((isElevated) => {
var __pub = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION }, {}, __pvt
// Finalized immutables.
// 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 instanceName() { return __pvt.instanceName }
, get reposindexed(){
@@ -2507,14 +2615,15 @@ shell_verse.acquireElevationState().then((isElevated) => {

Object.defineProperty(__g, 'selectedinstance', {
get(){ return __pub}
, set( inst ){ __pvt = inst; return __pub }
, set( inst ){
utils.assign(__pub, inst); return __pub
}
})
return __pub;
})()

var __default = selectedinstance; // PB : TODO -- Eliminate __default references.

// console.log(selectedinstance)
// initinstances(selectedinstance)

var any = utils.any;
@@ -3926,7 +4035,6 @@ shell_verse.acquireElevationState().then((isElevated) => {
// ----------------------------------------------------------------
// var launchpath = path.resolve(path.normalize(ENV.wd))
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.
// // The easisest would be to ask for a target directory and default to current dir....
// // path.dirname(launchpath).split(path.sep).pop()
@@ -3960,130 +4068,10 @@ shell_verse.acquireElevationState().then((isElevated) => {
// }).catch(()=>{
// 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.
// 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 } }
if(clioverrides.reconfirm) {
var reconfirm = getReconfirmAll()
@@ -4112,6 +4100,10 @@ shell_verse.acquireElevationState().then((isElevated) => {
// We need to take a snapshot... Shallow.. !! If required deep should be used based on use case.
// var asyncthis = Object.assign(this);
// 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]
Object.defineProperty(target, k, getPromptableAsyncPropDescriptor(k, promptables[k]));
return await target[k]
@@ -4201,77 +4193,106 @@ shell_verse.acquireElevationState().then((isElevated) => {
}
, reposerver : { label : `Enter Repo Server Base Url ( <= ${target.reposerver || 'https://git.bbh.org.in'} ) : `
, 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']
}
, 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
}
, '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'} ) : `
, 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 || ''} ) : `
, choices : choices['password'], defaultchoice : '***', selectedchoice : target.password } }
, get email() { return { label : `Enter Email for ${target.username} @ ${target.reposerver} ( <= ${target.email || ''} ) : `
@@ -4889,7 +4910,7 @@ shell_verse.acquireElevationState().then((isElevated) => {

var skipprerequisites = false;
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
|| clioverrides.instanceName
@@ -5137,165 +5158,124 @@ shell_verse.acquireElevationState().then((isElevated) => {
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)
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
}
})
// }
// 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)
}



Loading…
取消
儲存