|
|
@@ -14,16 +14,33 @@ var chalk = require('chalk') |
|
|
|
const homedir = require('os').homedir(); |
|
|
|
|
|
|
|
|
|
|
|
function sysAddPathVar(path){ |
|
|
|
function sysAddPathVar(addpath){ |
|
|
|
// Object.assign({ |
|
|
|
// inherit: true, shell: true, env: ENV, title: `${command} ${args}` |
|
|
|
// }, options) |
|
|
|
|
|
|
|
// powershell $env:Path -split ';' |
|
|
|
if (__isElevated) { |
|
|
|
return nodeShellExec('Powershell.exe', [ |
|
|
|
`$path = [Environment]::GetEnvironmentVariable('PATH', 'Machine') |
|
|
|
$newpath = $path + ';${addpath}' |
|
|
|
[Environment]::SetEnvironmentVariable("PATH", $newpath, 'Machine')` |
|
|
|
]).then(() => { |
|
|
|
fs.writeFileSync('run.done', 'success') |
|
|
|
}).catch(() => { |
|
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
}) |
|
|
|
} |
|
|
|
else return op['runas']() |
|
|
|
|
|
|
|
|
|
|
|
var newpath = path.split(';'); |
|
|
|
newpath = Array.from(new Set(newpath.push(path))).join(';') |
|
|
|
// path.split(';').forEach(pel => { var kv = pel.split('='); kv[0] === key ? null : newpath.push(pel); } ) |
|
|
|
return nodeShellExec('setx', ['/m', 'PATH', newpath ]); |
|
|
|
// var newpath = addpath.split(';'); |
|
|
|
// newpath.push(addpath) |
|
|
|
// newpath = Array.from(new Set(newpath)).join(';') |
|
|
|
// // addpath.split(';').forEach(pel => { var kv = pel.split('='); kv[0] === key ? null : newpath.push(pel); } ) |
|
|
|
// // setx /M PATH "%PATH%;<path-to-executable-folder>" |
|
|
|
// // %AppData%\npm |
|
|
|
// return nodeShellExec('setx', ['/m', 'PATH', `%PATH%;${addpath}` ]); |
|
|
|
} |
|
|
|
|
|
|
|
// singleton one time lazy |
|
|
@@ -127,6 +144,8 @@ if(!processedArgs.wd){ |
|
|
|
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. |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -256,10 +275,12 @@ var callshelltask = (args) => { |
|
|
|
return getshelltask(args)() |
|
|
|
} |
|
|
|
|
|
|
|
var getCmdString = function(args){ return `"${args[0]} ${args[1].join(' ')}"` } |
|
|
|
|
|
|
|
var getshelltask = (args) => { |
|
|
|
return args[0] === 'rm' ? getgitbashtask(args) : () => { return nodeShellExec.apply(null, args) } } |
|
|
|
var getgitbashtask = (args) => { return () => { |
|
|
|
return nodeShellExec( `"${gitbash}"`, ['-c', `"${args[0]} ${args[1].join(' ')}"`], args[2]) } |
|
|
|
var getgitbashtask = (args, onEachError) => { return () => { |
|
|
|
return nodeShellExec( `"${gitbash}"`, ['-c', getCmdString(args)], args[2]).catch( onEachError || function(e){ console.error(e) }) } |
|
|
|
} |
|
|
|
|
|
|
|
var getTaskCheckExists = (command, options) => { |
|
|
@@ -1520,32 +1541,44 @@ var op = { |
|
|
|
}).finally(statuslog.finally) |
|
|
|
|
|
|
|
} |
|
|
|
, 'start': (label) => { |
|
|
|
console.log('Starting Elixir Server.'); |
|
|
|
var env = Object.assign({}, process.env); // Shallow clone it. |
|
|
|
// console.dir(env) |
|
|
|
env.NODE_ENV = process.env.NODE_ENV || 'development'; |
|
|
|
env.DEBUG = 'loopback:connector:' + dbForLabel(label) |
|
|
|
var cmd = env.NODE_ENV === 'development' ? 'nodemon' : 'node'; |
|
|
|
// cmd = 'node' |
|
|
|
cmd = [cmd, ['--inspect=9228', 'elixir/server.js']] |
|
|
|
var childPromise = nodeShellExec(...cmd, { |
|
|
|
// inherit : true, |
|
|
|
shell: true, |
|
|
|
detached: true, |
|
|
|
stdio: 'ignore', |
|
|
|
cwd: instanceroot + '/' + 'elixir-server' |
|
|
|
, env: env |
|
|
|
}) |
|
|
|
, 'start': (args) => { |
|
|
|
|
|
|
|
var child = childPromise.process; |
|
|
|
if (typeof child.pid !== 'undefined') { |
|
|
|
console.log(`started Elixir Server PID(${child.pid}) : NODE_ENV=${process.NODE_ENV} ${cmd}`); |
|
|
|
fs.writeFileSync('.elixir-server.elixir.server.pid', child.pid, { |
|
|
|
encoding: 'utf8' |
|
|
|
var label = clioverrides.cmd |
|
|
|
var env = Object.assign({}, process.env); // Shallow clone it. |
|
|
|
env.NODE_ENV = clioverrides.node_env || 'development'; |
|
|
|
var nodecmd = clioverrides.node_env === 'development' ? 'nodemon' : 'node'; |
|
|
|
|
|
|
|
function startFn( o ){ |
|
|
|
var cmd = [nodecmd, [`--inspect=${o.debugport}`, '--preserve-symlinks', o.script]] |
|
|
|
console.log(`Starting ${o.name}.`); |
|
|
|
var childPromise = nodeShellExec('cmd', ['/k', getCmdString(cmd) ], { |
|
|
|
// inherit : true, |
|
|
|
shell: true, |
|
|
|
detached: true, |
|
|
|
stdio: 'ignore', |
|
|
|
cwd: instanceroot + o.path |
|
|
|
, env: env |
|
|
|
}) |
|
|
|
|
|
|
|
var child = childPromise.process; |
|
|
|
var cpid = child.pid |
|
|
|
if (typeof child.pid !== 'undefined') { |
|
|
|
childPromise.then(()=>{ |
|
|
|
console.log(` *** started Elixir Loopback Server PID(${cpid}) : NODE_ENV=${clioverrides.node_env} ${cmd}`); |
|
|
|
fs.writeFileSync('.elixir-server.elixir.server.pid', '' + cpid) |
|
|
|
}) |
|
|
|
.catch(e => console.errror(e) ) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(clioverrides.node_env === 'development') { |
|
|
|
env.DEBUG = 'loopback:connector:' + dbForLabel(label) |
|
|
|
|
|
|
|
startFn( { debugport : 9228, script : 'elixir/server.js', name : 'Elixir Loopback Server', path : '/' + 'elixir-server' } ) |
|
|
|
startFn( { debugport : 9227, script : 'bin/www', name : 'Express Server', path : '/' + 'chess-server-lib/server' } ) |
|
|
|
|
|
|
|
// cmd = 'node'() |
|
|
|
|
|
|
|
// nodeShellExec('node', ['--inspect=9226', ' bin/www'], { |
|
|
|
// inherit : true, |
|
|
|
// shell: true, detached: true, |
|
|
@@ -1560,28 +1593,28 @@ var op = { |
|
|
|
// cwd : 'client/', |
|
|
|
// env: env |
|
|
|
// }) |
|
|
|
console.log('Starting Elixir Client Host.'); |
|
|
|
var cmd = ['ember', ['s']] |
|
|
|
var childPromise = nodeShellExec(...cmd, { |
|
|
|
// var childPromise = nodeShellExec('node', ['--inspect=9227', './node_modules/.bin/ember', 's'], { |
|
|
|
// PB : TODO -- ember debugging. |
|
|
|
// inherit : true, |
|
|
|
shell: true, |
|
|
|
detached: true, |
|
|
|
stdio: 'ignore', |
|
|
|
cwd: instanceroot + '/' + 'client' |
|
|
|
, env: env |
|
|
|
}) |
|
|
|
// .catch(e=>console.error(e)) |
|
|
|
// console.log('Starting Elixir Client Host.'); |
|
|
|
// var cmd = ['ember', ['s']] |
|
|
|
// var childPromise = nodeShellExec(...cmd, { |
|
|
|
// // var childPromise = nodeShellExec('node', ['--inspect=9227', './node_modules/.bin/ember', 's'], { |
|
|
|
// // PB : TODO -- ember debugging. |
|
|
|
// // inherit : true, |
|
|
|
// shell: true, |
|
|
|
// detached: true, |
|
|
|
// stdio: 'ignore', |
|
|
|
// cwd: instanceroot + '/' + 'client' |
|
|
|
// , env: env |
|
|
|
// }) |
|
|
|
// // .catch(e=>console.error(e)) |
|
|
|
|
|
|
|
child = childPromise.process; |
|
|
|
if (typeof child.pid !== 'undefined') { |
|
|
|
console.log(`started Elixir Client Host PID(${child.pid}) : NODE_ENV=${process.NODE_ENV} ${cmd}`); |
|
|
|
fs.writeFileSync('.client.server.pid', child.pid, { |
|
|
|
encoding: 'utf8' |
|
|
|
}) |
|
|
|
// child = childPromise.process; |
|
|
|
// if (typeof child.pid !== 'undefined') { |
|
|
|
// console.log(`started Elixir Client Host PID(${child.pid}) : NODE_ENV=${process.NODE_ENV} ${cmd}`); |
|
|
|
// fs.writeFileSync('.client.server.pid', child.pid, { |
|
|
|
// encoding: 'utf8' |
|
|
|
// }) |
|
|
|
// } |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
, 'stop': (label) => { |
|
|
|
const kill = require('tree-kill'); |
|
|
@@ -1593,10 +1626,10 @@ var op = { |
|
|
|
console.log(serverPid) |
|
|
|
kill(serverPid) |
|
|
|
|
|
|
|
serverPid = fs.readFileSync('.client.server.pid', { |
|
|
|
serverPid = fs.readFileSync('.express.server.pid', { |
|
|
|
encoding: 'utf8' |
|
|
|
}) |
|
|
|
fs.unlinkSync('.client.server.pid') |
|
|
|
fs.unlinkSync('.express.server.pid') |
|
|
|
console.log(serverPid) |
|
|
|
kill(serverPid) |
|
|
|
} |
|
|
@@ -2051,6 +2084,10 @@ var subcommandlabels = { |
|
|
|
, switch : (`switch ${processedArgs._[1] || ''}`).trim() |
|
|
|
} |
|
|
|
|
|
|
|
var independentcmd = function(){ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var cmds = { |
|
|
|
remote : { |
|
|
|
// return a interpreted set of arguments for this comd run context. |
|
|
@@ -2058,6 +2095,24 @@ var cmds = { |
|
|
|
return { cmd : subcommandlabels['remote'], runchoice : 'c' } |
|
|
|
} |
|
|
|
} |
|
|
|
, resetgitconfig : { |
|
|
|
// return a interpreted set of arguments for this comd run context. |
|
|
|
cmdFn : resetgitconfig |
|
|
|
, interpret() { return { cmd : 'resetgitconfig' } } |
|
|
|
, getPossiblePrompts(){ return {} } |
|
|
|
, noprerequisites : true |
|
|
|
, independentcmd : true |
|
|
|
} |
|
|
|
, reinit : { |
|
|
|
// return a interpreted set of arguments for this comd run context. |
|
|
|
cmdFn : reinit |
|
|
|
, interpret() { return { cmd : 'reinit' } } |
|
|
|
, getPossiblePrompts(){ return {} } |
|
|
|
, noprerequisites : true |
|
|
|
, independentcmd : true |
|
|
|
, requiresElevation : true |
|
|
|
, requires : [ generateDependencies ] |
|
|
|
} |
|
|
|
, switch : { |
|
|
|
interpret() { |
|
|
|
return { cmd : subcommandlabels['switch'], runchoice : 'c', username : processedArgs._[2] |
|
|
@@ -2590,7 +2645,6 @@ var instanceData = (function(){ |
|
|
|
, commonInstance(selected) { return __acquireData(selected, defaultRepoOwner |
|
|
|
// , function(e){ console.info('This is probably an error unless the user is asking to create a new instance with this name.') } |
|
|
|
) } |
|
|
|
, genericChessInstance(selected) { return __acquireData(selected) } |
|
|
|
} |
|
|
|
})() |
|
|
|
|
|
|
@@ -2599,13 +2653,91 @@ var acquireData = function(slections){ |
|
|
|
return any(configPriority.map(cfg => { return function() { return instanceData[cfg](slections) } } ), true, true) |
|
|
|
} |
|
|
|
|
|
|
|
// Git Credential storage... |
|
|
|
// notepad C:/Program Files/Git/etc/gitconfig |
|
|
|
// git config --global --unset credential |
|
|
|
// git config --edit --system |
|
|
|
// git config --global credential.helper "store --file ~/gitcredentials" |
|
|
|
// git credential fill |
|
|
|
// git credential-store --file ~/git.store store |
|
|
|
|
|
|
|
function reinit(){ |
|
|
|
sysAddPathVar('%AppData%\\npm') |
|
|
|
resetgitconfig() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function resetgitconfig(){ |
|
|
|
|
|
|
|
// https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage |
|
|
|
// Git Credential storage... |
|
|
|
// git config --global credential.helper 'store --file ~/.gitcredentials' |
|
|
|
// git credential-store --file ~/.gitcredentials store |
|
|
|
// // notepad C:/Program Files/Git/etc/gitconfig |
|
|
|
// git config --global --unset credential |
|
|
|
// git config --edit --system |
|
|
|
// git config --global credential.helper "store --file ~/gitcredentials" |
|
|
|
// git credential fill |
|
|
|
// git credential-store --file ~/git.store store |
|
|
|
|
|
|
|
// Find system git config |
|
|
|
// git config --global --edit |
|
|
|
// git config --list --show-origin |
|
|
|
// git config --list --show-origin --show-scope |
|
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git |
|
|
|
// Recipie |
|
|
|
// git config --global --unset credentials.helper |
|
|
|
// cd /path/to/my/repo |
|
|
|
// git config --unset credential.helper |
|
|
|
// git config credential.helper 'store --file ~/.git_repo_credentials' |
|
|
|
// git config credential.*.username my_user_name |
|
|
|
// git config credential.https://gitlab.com.username my_user_name |
|
|
|
|
|
|
|
// git credential fill |
|
|
|
// git config --global credential.modalprompt false // doesnst work. |
|
|
|
// core askpass = ;;; https://stackoverflow.com/questions/37182847/how-do-i-disable-git-credential-manager-for-windows |
|
|
|
var options = { |
|
|
|
inherit: true, shell: true //, env: process.env |
|
|
|
, cwd: instanceroot |
|
|
|
, runas: processedArgs.runas |
|
|
|
} |
|
|
|
|
|
|
|
var task = ['git', ['config'], options] |
|
|
|
|
|
|
|
var tasklist = [ |
|
|
|
// ['--global', '--unset credentials.helper'] |
|
|
|
// ['--unset', 'credentials.helper'] |
|
|
|
// , |
|
|
|
// ['credential.helper', `'store --file git_repo_credentials'`] |
|
|
|
['--global', 'credential.helper', "'store --file ~/.git_repo_credentials'"] |
|
|
|
, ['--global', '--replace-all', 'user.name', 'pb'] |
|
|
|
, ['--global', '--replace-all', 'user.email', 'pradeep@bbh.org.in'] |
|
|
|
|
|
|
|
// , ['--list'] |
|
|
|
// , ['credential', 'fill'] |
|
|
|
] |
|
|
|
var onEachError = e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n') |
|
|
|
var shellT = (args) => { return getgitbashtask(args, onEachError) |
|
|
|
// .catch(e => console.error( e.messages.join('\n') + e.result + '\n' + util.inspect(e) + '\n' + tasq.toString()) ) |
|
|
|
} |
|
|
|
execserial(tasklist, task, shellT, onEachError ) |
|
|
|
} |
|
|
|
|
|
|
|
var createTasq = (args, shellT, onEachError) => { |
|
|
|
var tasq = shellT ? shellT(args) : (() => { return nodeShellExec.apply(null, args).catch( onEachError || function(e){ console.error(e) } ) }) |
|
|
|
tasq.toString = function(){ return JSON.stringify(args)} |
|
|
|
return tasq; |
|
|
|
} |
|
|
|
|
|
|
|
var execserial = function(tasklist, task, shellT){ |
|
|
|
var exec = (taskArgs)=>{ |
|
|
|
var thistask = task.concat(); |
|
|
|
thistask[1] = thistask[1].concat() |
|
|
|
thistask[1].push.apply(thistask[1], taskArgs) |
|
|
|
return createTasq(thistask, shellT) |
|
|
|
} |
|
|
|
|
|
|
|
return any(tasklist.map(exec)) |
|
|
|
} |
|
|
|
|
|
|
|
var execone = function(taskArgs, task){ return any([task[1].push.apply(task[1], taskArgs)].map(createTasq)) } |
|
|
|
|
|
|
|
|
|
|
|
var __acquireConfig = function (selected, owner, clusternodename, configrepo, errHandler) { |
|
|
|
|
|
|
|
configrepo = configrepo || selected.instanceName + '-config-' + selected.node_env; |
|
|
@@ -2779,6 +2911,7 @@ while(parent !== pp){ |
|
|
|
return function(){ |
|
|
|
return hasElxr(p).then((value)=>{ |
|
|
|
if(value) return p |
|
|
|
// PB : TODO -- Using throw like this is not friendly with any... |
|
|
|
throw { value : false }; |
|
|
|
}) |
|
|
|
} |
|
|
@@ -2916,8 +3049,8 @@ var hasElxr = function(path, options, cb) { |
|
|
|
var tasks = [ |
|
|
|
'/elxr' // Is there a subfolder named elxr |
|
|
|
, '/elxr/.git' // which is self git repository |
|
|
|
, '/elxr/.elxr' // and has .elxr subfolder |
|
|
|
, '/elxr/.elxr/' + __ALIAS__STAMP__ // Which has our stamp. |
|
|
|
// , '/elxr/.elxr' // and has .elxr subfolder we now store this in the instanceroot. |
|
|
|
, '/elxr/' + __ALIAS__STAMP__ // Which has our stamp. |
|
|
|
] |
|
|
|
|
|
|
|
if(options.sync) { return tasks.earlyreduce((acc, tpath)=>{ |
|
|
@@ -3424,7 +3557,7 @@ function findlocalinstances(chessinstances, instanceoptions){ |
|
|
|
|
|
|
|
|
|
|
|
// function updateselection(selected) { selectedinstance = utils.assign(selectedinstance, selected) } |
|
|
|
var selectedinstance = null; |
|
|
|
var selectedinstance = { root : process.env.wd }; |
|
|
|
var chessinstances = { current_run : {} }; |
|
|
|
var promptkeys = { |
|
|
|
cmd : processedArgs._[0] || 'pull' |
|
|
@@ -3914,7 +4047,7 @@ var maintask = () => { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var generateDependencies = function(){ |
|
|
|
function generateDependencies(){ |
|
|
|
// PB : TODO -- Keep only the last n runs... |
|
|
|
// Currently it retains 2*n when proc needs to be relaunched in elevated mode !!! |
|
|
|
|
|
|
@@ -4138,8 +4271,21 @@ var startElxr = function() { |
|
|
|
} |
|
|
|
|
|
|
|
detectInstanceRoot.then(()=>{ |
|
|
|
return acquireElevationState().then(() => { |
|
|
|
return startElxr() |
|
|
|
var cmdobj = cmds[clioverrides.cmd] |
|
|
|
return Promise.all((cmdobj.requires || []).map( (r) => utils.promisify(null, r) ) ).then(()=>{ |
|
|
|
if(cmdobj.independentcmd) { |
|
|
|
if(cmdobj.requiresElevation) { |
|
|
|
return acquireElevationState().then(() => { |
|
|
|
cmdobj.cmdFn() }) |
|
|
|
} |
|
|
|
else return cmdobj.cmdFn() |
|
|
|
} |
|
|
|
else return acquireElevationState().then(() => { |
|
|
|
return startElxr() |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch(e => { |
|
|
|
console.log('error ') |
|
|
|
}) |
|
|
|
}) |
|
|
|
|