|  |  | @@ -1,16 +1,72 @@ | 
		
	
		
			
			|  |  |  | global.env = process.env | 
		
	
		
			
			|  |  |  | global.env.NODE_ENV = global.env.NODE_ENV || 'development' | 
		
	
		
			
			|  |  |  | var __g = require('global-this'); | 
		
	
		
			
			|  |  |  | __g.env = process.env | 
		
	
		
			
			|  |  |  | __g.env.NODE_ENV = __g.env.NODE_ENV || 'development' | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | const fs = require('fs') | 
		
	
		
			
			|  |  |  | var path = require('path'); | 
		
	
		
			
			|  |  |  | var utils = require('bbhverse'); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | const cliargs = utils.cliargs; | 
		
	
		
			
			|  |  |  | const processedArgs = cliargs(process.argv.slice(2)); | 
		
	
		
			
			|  |  |  | if(!processedArgs.wd){ | 
		
	
		
			
			|  |  |  | if(process.env.wd){ | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else { | 
		
	
		
			
			|  |  |  | process.env.wd = process.cwd(); | 
		
	
		
			
			|  |  |  | if(process.cwd() === __dirname) { | 
		
	
		
			
			|  |  |  | // This script was launched in the same dir. | 
		
	
		
			
			|  |  |  | // We do not know if it was copied to some random location. Check if we have elxr installed in current location. Or subidr. | 
		
	
		
			
			|  |  |  | process.env.wd = path.dirname( process.env.wd ); // Default to the parent. | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else process.env.wd = processedArgs.wd | 
		
	
		
			
			|  |  |  | var ENV = Object.assign({}, process.env); // Shallow clone it. | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b' | 
		
	
		
			
			|  |  |  | const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; | 
		
	
		
			
			|  |  |  | const runtimestamp = processedArgs.runtimestamp ? (new Date(processedArgs.runtimestamp)).getTime() : (new Date()).getTime(); | 
		
	
		
			
			|  |  |  | function getVersion() { return BUILD_VERSION; } | 
		
	
		
			
			|  |  |  | console.log(getVersion()); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | var selectedinstance = (function() { | 
		
	
		
			
			|  |  |  | var __pvt = { root :  process.env.wd || process.env.PWD } | 
		
	
		
			
			|  |  |  | var __pub = { | 
		
	
		
			
			|  |  |  | get root(){ return __pvt.root } | 
		
	
		
			
			|  |  |  | , set root(val){ | 
		
	
		
			
			|  |  |  | throw 'root has changed' | 
		
	
		
			
			|  |  |  | // if the root changes for this run we need to relocate all the necessary files to that folder for this run. | 
		
	
		
			
			|  |  |  | if(__pvt.root === val){ | 
		
	
		
			
			|  |  |  | fsMove() | 
		
	
		
			
			|  |  |  | return __pvt.root = val | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else __pvt.root | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | Object.defineProperty(__g, 'selectedinstance', { | 
		
	
		
			
			|  |  |  | get(){ return __pub} | 
		
	
		
			
			|  |  |  | , set( inst ){ __pvt = inst; return __pub  } | 
		
	
		
			
			|  |  |  | }) | 
		
	
		
			
			|  |  |  | return __pub; | 
		
	
		
			
			|  |  |  | })() | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | var any = utils.any; | 
		
	
		
			
			|  |  |  | var Tasq = utils.Tasq | 
		
	
		
			
			|  |  |  | var statuslog = utils.Traq | 
		
	
		
			
			|  |  |  | var Traq = utils.Traq | 
		
	
		
			
			|  |  |  | Tasq.addlistener(statuslog.statuslog) | 
		
	
		
			
			|  |  |  | // fs.writeFileSync('run.log', ', ' + JSON.stringify( { m : 'Hello'} ), { 'flag': 'a+' }) | 
		
	
		
			
			|  |  |  | Tasq.addlistener((e)=>{ fs.writeFileSync('run.log', ', ' + JSON.stringify( e ), { 'flag': 'a+' }) }) | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // Instead of waiting for the root to be establised we start working at the current locatoin and then relocate when root changes. | 
		
	
		
			
			|  |  |  | var runlogjson = `${selectedinstance.root}/.elxr/run-${runtimestamp}/run.log` | 
		
	
		
			
			|  |  |  | ensureDirectoryExistence(runlogjson) | 
		
	
		
			
			|  |  |  | fs.writeFileSync(runlogjson, JSON.stringify( `Started ${runtimestamp}`)) // Initialize a new log file with "logrotate" for every run | 
		
	
		
			
			|  |  |  | Tasq.addlistener((e)=>{ fs.writeFileSync(runlogjson, ', ' + JSON.stringify( e ), { 'flag': 'a+' }) }) | 
		
	
		
			
			|  |  |  | var cli = require('./cliverse') | 
		
	
		
			
			|  |  |  | function isWin(){ return /^win/.test(process.platform) } | 
		
	
		
			
			|  |  |  | if(isWin()) { | 
		
	
	
		
			
			|  |  | @@ -22,13 +78,10 @@ else { | 
		
	
		
			
			|  |  |  | var shell_verse = lin_verse; | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | var nodeShellExec = cli.nodeShellExec; | 
		
	
		
			
			|  |  |  | var chalk = require('chalk') | 
		
	
		
			
			|  |  |  | const homedir = require('os').homedir(); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | function sysAddPathVar(addpath){ | 
		
	
		
			
			|  |  |  | // Object.assign({ | 
		
	
		
			
			|  |  |  | //   inherit: true, shell: true, env: ENV, title: `${command} ${args}` | 
		
	
	
		
			
			|  |  | @@ -41,7 +94,7 @@ function sysAddPathVar(addpath){ | 
		
	
		
			
			|  |  |  | $newpath = $path + ';${addpath}' | 
		
	
		
			
			|  |  |  | [Environment]::SetEnvironmentVariable("PATH", $newpath, 'Machine')` | 
		
	
		
			
			|  |  |  | ]).then(() => { | 
		
	
		
			
			|  |  |  | fs.writeFileSync('run.done', 'success') | 
		
	
		
			
			|  |  |  | fs.writeFileSync('run.done', 'success') // PB : TODO -- IPC through files is needed only for windows. | 
		
	
		
			
			|  |  |  | }).catch(() => { | 
		
	
		
			
			|  |  |  | fs.writeFileSync('run.done', 'error') | 
		
	
		
			
			|  |  |  | }) | 
		
	
	
		
			
			|  |  | @@ -94,12 +147,6 @@ function getCurrentFolder(){ | 
		
	
		
			
			|  |  |  | return any(tasks); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b' | 
		
	
		
			
			|  |  |  | const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; | 
		
	
		
			
			|  |  |  | const runtimestamp = (new Date()).getTime(); | 
		
	
		
			
			|  |  |  | function getVersion() { return BUILD_VERSION; } | 
		
	
		
			
			|  |  |  | console.log(getVersion()); | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // 'use strict'; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // PB : TODO -- make sure folder context is proper coz we can now run elxr from anywhere. | 
		
	
	
		
			
			|  |  | @@ -153,23 +200,6 @@ const existslink = function(name, cb){ | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | const existsFolderSync = existsSync; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | const cliargs = utils.cliargs; | 
		
	
		
			
			|  |  |  | const processedArgs = cliargs(process.argv.slice(2)); | 
		
	
		
			
			|  |  |  | if(!processedArgs.wd){ | 
		
	
		
			
			|  |  |  | if(process.env.wd){ | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else { | 
		
	
		
			
			|  |  |  | process.env.wd = process.cwd(); | 
		
	
		
			
			|  |  |  | if(process.cwd() === __dirname) { | 
		
	
		
			
			|  |  |  | // This script was launched in the same dir. | 
		
	
		
			
			|  |  |  | // We do not know if it was copied to some random location. Check if we have elxr installed in current location. Or subidr. | 
		
	
		
			
			|  |  |  | process.env.wd = path.dirname( process.env.wd ); // Default to the parent. | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else process.env.wd = processedArgs.wd | 
		
	
		
			
			|  |  |  | var ENV = Object.assign({}, process.env); // Shallow clone it. | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
	
		
			
			|  |  | @@ -1987,7 +2017,7 @@ var op = { | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | ]; | 
		
	
		
			
			|  |  |  | return any(tasks).then(() => { | 
		
	
		
			
			|  |  |  | fs.writeFileSync('run.done', 'success') | 
		
	
		
			
			|  |  |  | fs.writeFileSync('run.done', 'success')  // PB : TODO -- IPC through files is needed only for windows. | 
		
	
		
			
			|  |  |  | }).catch(() => { | 
		
	
		
			
			|  |  |  | fs.writeFileSync('run.done', 'error') | 
		
	
		
			
			|  |  |  | }) | 
		
	
	
		
			
			|  |  | @@ -2022,7 +2052,7 @@ var op = { | 
		
	
		
			
			|  |  |  | selectedinstance.instanceName && runconfig.use === selectedinstance.instanceName) { | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | console.log(`No change detected. Already using requested specs : ${runconfig.NODE_ENV} ${runconfig.use}`) | 
		
	
		
			
			|  |  |  | if (processedArgs.runas) { fs.writeFileSync('run.done', 'success') } | 
		
	
		
			
			|  |  |  | if (processedArgs.runas) { fs.writeFileSync('run.done', 'success') } // PB : TODO -- IPC through files is needed only for windows. | 
		
	
		
			
			|  |  |  | if (existsSync('config') && existsSync('data')){ | 
		
	
		
			
			|  |  |  | return | 
		
	
		
			
			|  |  |  | } | 
		
	
	
		
			
			|  |  | @@ -3081,7 +3111,7 @@ var configs = (function(){ | 
		
	
		
			
			|  |  |  | console.warn('elevated repo manifest has obsolete format. Attempting upgrade.') | 
		
	
		
			
			|  |  |  | selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } }) | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | chessinstances[selected.instanceName][selected.node_env] = selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } | 
		
	
		
			
			|  |  |  | chessinstances[selected.instanceName][selected.node_env] = selectedinstance = __g.selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } | 
		
	
		
			
			|  |  |  | , selected, selectedinstance) | 
		
	
		
			
			|  |  |  | chessinstances[selected.instanceName][selected.node_env].reposervers = Array.from(new Set(chessinstances[selected.instanceName][selected.node_env].reposervers)) | 
		
	
		
			
			|  |  |  | selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online... | 
		
	
	
		
			
			|  |  | @@ -3302,7 +3332,7 @@ var __acquireConfig = function (selected, options, configrepo, errHandler) { | 
		
	
		
			
			|  |  |  | console.warn('elevated repo manifest has obsolete format. Attempting upgrade.') | 
		
	
		
			
			|  |  |  | selectedinstance.elevated = selectedinstance.elevated.map(function(repo){ return { repo } }) | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | chessinstances[selected.instanceName][selected.node_env] = selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } | 
		
	
		
			
			|  |  |  | chessinstances[selected.instanceName][selected.node_env] = selectedinstance = __g.selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } | 
		
	
		
			
			|  |  |  | , selected, selectedinstance) | 
		
	
		
			
			|  |  |  | chessinstances[selected.instanceName][selected.node_env].reposervers = Array.from(new Set(chessinstances[selected.instanceName][selected.node_env].reposervers)) | 
		
	
		
			
			|  |  |  | selectedinstance.reposerver = selectedinstance.reposerver || selectedinstance.reposervers[0] // PB : TODO -- Attempt first one that is available and online... | 
		
	
	
		
			
			|  |  | @@ -4039,7 +4069,6 @@ function findlocalinstances(chessinstances, instanceoptions){ | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | // function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) } | 
		
	
		
			
			|  |  |  | var selectedinstance = { root : process.env.wd }; | 
		
	
		
			
			|  |  |  | var runconfig = null; | 
		
	
		
			
			|  |  |  | 
 | 
		
	
		
			
			|  |  |  | var chessinstances = { current_run : {} }; | 
		
	
	
		
			
			|  |  | @@ -4451,7 +4480,7 @@ function initinstances(selected_overrides) { | 
		
	
		
			
			|  |  |  | // PB : TODO -- We now have options that can be passed into assign_core to control this behavior. | 
		
	
		
			
			|  |  |  | if(selected_overrides.node_env ===  undefined) delete selected_overrides.node_env | 
		
	
		
			
			|  |  |  |  | 
		
	
		
			
			|  |  |  | selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } | 
		
	
		
			
			|  |  |  | selectedinstance = __g.selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } | 
		
	
		
			
			|  |  |  | , __default | 
		
	
		
			
			|  |  |  | , chessinstances[instanceName][node_env] | 
		
	
		
			
			|  |  |  | , clioverrides | 
		
	
	
		
			
			|  |  | @@ -4629,7 +4658,7 @@ function generateDependencies(){ | 
		
	
		
			
			|  |  |  | var timer = function(){ | 
		
	
		
			
			|  |  |  | l('.'); | 
		
	
		
			
			|  |  |  | if(fso.FileExists("run.done")) { | 
		
	
		
			
			|  |  |  | fso.DeleteFile('run.done') | 
		
	
		
			
			|  |  |  | fso.DeleteFile('run.done')  // PB : TODO -- IPC through files is needed only for windows we need to do it per run... | 
		
	
		
			
			|  |  |  | close(); | 
		
	
		
			
			|  |  |  | } | 
		
	
		
			
			|  |  |  | else window.setTimeout(timer, 1000); | 
		
	
	
		
			
			|  |  | @@ -4661,7 +4690,7 @@ var startElxr = function() { | 
		
	
		
			
			|  |  |  | 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 = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } | 
		
	
		
			
			|  |  |  | selectedinstance = __g.selectedinstance = utils.assign_core( { arraymergetype : utils.assign_core.DISTINCT_UNION } | 
		
	
		
			
			|  |  |  | , ...detectedinstanceoptions.slice(-2), promptkeys ) | 
		
	
		
			
			|  |  |  | // promptkeys = utils.assign(promptkeys, clioverrides) | 
		
	
		
			
			|  |  |  | 
 |