var ENV = Object.assign({}, process.env); // Shallow clone it. | var ENV = Object.assign({}, process.env); // Shallow clone it. | ||||
const spawn = require('child_process').spawn; | const spawn = require('child_process').spawn; | ||||
console.dir(process.argv.slice(2)) | |||||
const child = spawn( | const child = spawn( | ||||
(process.platform === 'win32' ? 'npm.cmd' : 'npm') | (process.platform === 'win32' ? 'npm.cmd' : 'npm') | ||||
, ['run', 'index'].concat(process.argv.slice(2)), { cwd: __dirname }); | |||||
, ['run', 'index', '--'].concat(process.argv.slice(2)), { cwd: __dirname }); | |||||
// const child = spawn( | // const child = spawn( | ||||
// 'C:\\Program Files\\Git\\bin\\sh.exe' | // 'C:\\Program Files\\Git\\bin\\sh.exe' |
Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }); | Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }); | ||||
// PB : TODO -- Convert all the cli args back to string. | // PB : TODO -- Convert all the cli args back to string. | ||||
var args = [`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | var args = [`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | ||||
args.push('--nodepath=' + r[r.length - 1]); | |||||
if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV); | |||||
if (processedArgs.debug) args.push('--debug=true'); // Enable to debug elevated.. | |||||
// args.push('--nodepath=' + r.messages[r.messages.length - 1]) | |||||
// if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) | |||||
// if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. | |||||
console.dir(processedArgs); | |||||
return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | ||||
, { | , { | ||||
else return __runcmd(processedArgs.label || processedArgs._[0] || 'h'); | else return __runcmd(processedArgs.label || processedArgs._[0] || 'h'); | ||||
} | } | ||||
function acquireChoices(selectedinstance) { | |||||
console.warn(chalk.cyan(` | |||||
------------------------------------------------------------------------------- | |||||
Warning : Cannot locate your preferred configuration since it was not specified | |||||
You should fork the default chess configuration to customize and make it | |||||
your own instance with a named config as | |||||
{{yourowninstancename}}-config-{{yourchosenenvironment}} | |||||
And then run this tool as follows | |||||
NODE_ENV={{yourchosenenvironment}} elxr i {{yourowninstancename}} | |||||
OR | |||||
Run this tool with the following command to use a quick start default. | |||||
elxr --default | |||||
OR | |||||
Choose one of the options below to run interactively. | |||||
We will run your choice at the next prompt. | |||||
------------------------------------------------------------------------------- | |||||
`)); | |||||
var prompt = cli.prompter; | |||||
return prompt.ask(`Choose an option : | |||||
d) Install the default chess instance. | |||||
=> elxr i chess node_env=development --default | |||||
n) Create your custom new instance interactively | |||||
=> elxr i {{instanceName}} node_env={{environment}} | |||||
i) Choose an instance and environment to install | |||||
=> elxr i {{instanceName}} node_env={{environment}} | |||||
c) Choose a command to run ( pull, use, i, npmi ... ) <= pull | |||||
=> elxr {{cmd}} {{instanceName}} node_env={{environment}} | |||||
h) Help | |||||
q) Quit | |||||
Default <= d | |||||
: `).then((choice) => { | |||||
if (choice && choice === 'd' || !choice) { | |||||
processedArgs._[0] = 'i'; | |||||
selectedinstance.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess'; | |||||
selectedinstance.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development'; | |||||
selectedinstance.reposerver = 'https://git.bbh.org.in'; | |||||
} | |||||
else if (choice === 'h') { | |||||
processedArgs._[0] = 'h'; | |||||
fs.writeFileSync('run.done', 'noop help'); | |||||
console.log(elxr.help()); process.exit(); | |||||
} | |||||
else if (choice === 'n' || choice === 'i') { | |||||
var p1 = cli.prompter; | |||||
return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) { | |||||
processedArgs._[0] = 'i'; | |||||
selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName; | |||||
return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) { | |||||
selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env; | |||||
if (choice === 'n') { | |||||
selectedinstance.reposerver = 'https://git.bbh.org.in'; | |||||
console.warn( | |||||
chalk.magenta('No Option Available. Your account may not have privileges. You can request here http://git.bbh.org.in/chess')); | |||||
process.exit(); | |||||
} | |||||
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposerver || selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { | |||||
selectedinstance.reposerver = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in'; | |||||
}) | |||||
}) | |||||
}) | |||||
} else if (choice === 'c') { | |||||
var p1 = cli.prompter; | |||||
return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) { | |||||
selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName; | |||||
return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) { | |||||
selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env; | |||||
return p1.ask(`Enter cmd : | |||||
p) pull | |||||
Default <= p | |||||
: `).then(function (cmd) { | |||||
if (!cmd || cmd === 'p') { | |||||
processedArgs._[0] = 'pull'; | |||||
} | |||||
else processedArgs._[0] = cmd; | |||||
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposerver || selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { | |||||
selectedinstance.reposerver = reposerver || selectedinstance.reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in'; | |||||
}) | |||||
}) | |||||
}) | |||||
}) | |||||
} else { | |||||
console.log(chalk.gray(`Default option not exercised. Please follow manual instructions to customize your instance here http://git.bbh.org.in/chess and try again.`)); | |||||
fs.writeFileSync('run.log', ', ' + JSON.stringify({ success: 'quit without execution' }), { 'flag': 'a+' }); | |||||
fs.writeFileSync('run.done', 'noop quit'); | |||||
process.exit(); | |||||
} | |||||
}) | |||||
} | |||||
var mergeObjByKey = function(arrOfObjs, keyName) { | var mergeObjByKey = function(arrOfObjs, keyName) { | ||||
var keyedDistinct = {}; | var keyedDistinct = {}; | ||||
}; | }; | ||||
if(clioverrides.reconfirm) { | |||||
var reconfirm = { 'instanceName' : clioverrides['instanceName'] === 'chess' }; | |||||
} | |||||
else { var reconfirm = {}; } | |||||
var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) { | var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) { | ||||
return function(prompts, k, i, a){ | return function(prompts, k, i, a){ | ||||
} | } | ||||
}; | }; | ||||
var __interactve_promts = function( target, choices ){ | |||||
var __interactive_prompts = function( target, choices ){ | |||||
Object.defineProperty(target, 'node_env', { get : function(){ return this.instanceType } }); | Object.defineProperty(target, 'node_env', { get : function(){ return this.instanceType } }); | ||||
// https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/ | // https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/ | ||||
// alert(windowselevate.commandLine) | // alert(windowselevate.commandLine) | ||||
var args = windowselevate.commandLine.split('"').slice(3); | var args = windowselevate.commandLine.split('"').slice(3); | ||||
alert(args) | |||||
// alert(args) | |||||
var processedArgs = { _ : [] } | var processedArgs = { _ : [] } | ||||
var namedArgs = []; | var namedArgs = []; | ||||
for(var item in args){ | for(var item in args){ | ||||
// PB : TODO -- Convert all the cli args back to string. | // PB : TODO -- Convert all the cli args back to string. | ||||
var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' '); | var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' '); | ||||
alert(cargs) | |||||
// alert(cargs) | |||||
var shell = new ActiveXObject('shell.application'); | var shell = new ActiveXObject('shell.application'); | ||||
// alert('launching node privilged. ' + processedArgs['nodepath']) | // alert('launching node privilged. ' + processedArgs['nodepath']) | ||||
// shell.ShellExecute('where', 'node', '', '', 10); | // shell.ShellExecute('where', 'node', '', '', 10); | ||||
chessinstances[instanceName][node_env] | chessinstances[instanceName][node_env] | ||||
, clioverrides | , clioverrides | ||||
, selected_overrides | , selected_overrides | ||||
// , __interactve_promts -- Cant just override. Also need selectedinstance to be ready... | |||||
// , __interactive_prompts -- Cant just override. Also need selectedinstance to be ready... | |||||
); | ); | ||||
// chessinstances[instanceName] = chessinstances[instanceName] || {} | // chessinstances[instanceName] = chessinstances[instanceName] || {} | ||||
}); | }); | ||||
instances = instances.concat(detectedinstanceoptions); | instances = instances.concat(detectedinstanceoptions); | ||||
if(promptkeys['instanceName']) instnaceNames.push(selectedinstance['instanceName']); | |||||
if(selectedinstance['instanceName']) instnaceNames.push(selectedinstance['instanceName']); | |||||
if(promptkeys['instanceName']) instnaceNames.push(promptkeys['instanceName']); | if(promptkeys['instanceName']) instnaceNames.push(promptkeys['instanceName']); | ||||
if(selectedinstance['reposervers']) reposervers = reposervers.concat(selectedinstance['reposervers']); | if(selectedinstance['reposervers']) reposervers = reposervers.concat(selectedinstance['reposervers']); | ||||
// PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!! | // PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!! | ||||
selectedinstance = utils.assign( ...detectedinstanceoptions.slice(-2) ); | selectedinstance = utils.assign( ...detectedinstanceoptions.slice(-2) ); | ||||
promptkeys = utils.assign(promptkeys, clioverrides); | |||||
if(clioverrides.reconfirm) { | |||||
({ 'instanceName' : selectedinstance['instanceName'] === 'chess' }); | |||||
} | |||||
// promptkeys = utils.assign(promptkeys, clioverrides) | |||||
try { | try { | ||||
chessinstances = acquirelocalinstances(selectedinstance); | chessinstances = acquirelocalinstances(selectedinstance); | ||||
findlocalinstances(chessinstances, detectedinstanceoptions); | findlocalinstances(chessinstances, detectedinstanceoptions); | ||||
initinstances(selectedinstance); // use the local instances for defaults if at all possible. | |||||
var choices = getchoices(detectedinstanceoptions, promptkeys); | var choices = getchoices(detectedinstanceoptions, promptkeys); | ||||
var todo = any( __interactve_promts(selectedinstance, choices) ).then(()=>{ | |||||
var todo = any( __interactive_prompts(selectedinstance, choices) ).then(()=>{ | |||||
return initinstances(selectedinstance) | return initinstances(selectedinstance) | ||||
}); | }); | ||||
} | } | ||||
catch (e) { | catch (e) { | ||||
// PB : TODO -- verbose mode warning.. console.warn(e) // Missing chessinstances is not an error... | // PB : TODO -- verbose mode warning.. console.warn(e) // Missing chessinstances is not an error... | ||||
var choices = getchoices(detectedinstanceoptions, promptkeys); | var choices = getchoices(detectedinstanceoptions, promptkeys); | ||||
var todo = any( __interactve_promts(selectedinstance, choices) ).then(()=>{ | |||||
var todo = any( __interactive_prompts(selectedinstance, choices) ).then(()=>{ | |||||
return initinstances(selectedinstance) | 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(() => { | todo = todo.then(() => { | ||||
try { | try { |
/* Version: 1.0.0 - September 29, 2021 17:16:55 */ | |||||
/* Version: 1.0.0 - September 29, 2021 19:31:21 */ | |||||
'use strict'; | 'use strict'; | ||||
var path$1 = require('path'); | var path$1 = require('path'); | ||||
const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b'; | const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b'; | ||||
const BUILD_VERSION = 'Version: 1.0.0 - built on September 29, 2021 17:16:55'; | |||||
const BUILD_VERSION = 'Version: 1.0.0 - built on September 29, 2021 19:31:21'; | |||||
const runtimestamp = (new Date()).getTime(); | const runtimestamp = (new Date()).getTime(); | ||||
function getVersion() { return BUILD_VERSION; } | function getVersion() { return BUILD_VERSION; } | ||||
console.log(getVersion()); | console.log(getVersion()); | ||||
Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }); | Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }); | ||||
// PB : TODO -- Convert all the cli args back to string. | // PB : TODO -- Convert all the cli args back to string. | ||||
var args = [`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | var args = [`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | ||||
args.push('--nodepath=' + r[r.length - 1]); | |||||
if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV); | |||||
if (processedArgs.debug) args.push('--debug=true'); // Enable to debug elevated.. | |||||
// args.push('--nodepath=' + r.messages[r.messages.length - 1]) | |||||
// if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) | |||||
// if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. | |||||
console.dir(processedArgs); | |||||
return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | ||||
, { | , { | ||||
else return __runcmd(processedArgs.label || processedArgs._[0] || 'h'); | else return __runcmd(processedArgs.label || processedArgs._[0] || 'h'); | ||||
} | } | ||||
function acquireChoices(selectedinstance) { | |||||
console.warn(source.cyan(` | |||||
------------------------------------------------------------------------------- | |||||
Warning : Cannot locate your preferred configuration since it was not specified | |||||
You should fork the default chess configuration to customize and make it | |||||
your own instance with a named config as | |||||
{{yourowninstancename}}-config-{{yourchosenenvironment}} | |||||
And then run this tool as follows | |||||
NODE_ENV={{yourchosenenvironment}} elxr i {{yourowninstancename}} | |||||
OR | |||||
Run this tool with the following command to use a quick start default. | |||||
elxr --default | |||||
OR | |||||
Choose one of the options below to run interactively. | |||||
We will run your choice at the next prompt. | |||||
------------------------------------------------------------------------------- | |||||
`)); | |||||
var prompt = cliverse.prompter; | |||||
return prompt.ask(`Choose an option : | |||||
d) Install the default chess instance. | |||||
=> elxr i chess node_env=development --default | |||||
n) Create your custom new instance interactively | |||||
=> elxr i {{instanceName}} node_env={{environment}} | |||||
i) Choose an instance and environment to install | |||||
=> elxr i {{instanceName}} node_env={{environment}} | |||||
c) Choose a command to run ( pull, use, i, npmi ... ) <= pull | |||||
=> elxr {{cmd}} {{instanceName}} node_env={{environment}} | |||||
h) Help | |||||
q) Quit | |||||
Default <= d | |||||
: `).then((choice) => { | |||||
if (choice && choice === 'd' || !choice) { | |||||
processedArgs._[0] = 'i'; | |||||
selectedinstance.instanceName = processedArgs._[1] = processedArgs._[1] || 'chess'; | |||||
selectedinstance.node_env = processedArgs.node_env = (process.env.NODE_ENV && process.env.NODE_ENV.trim()) || processedArgs.node_env || 'development'; | |||||
selectedinstance.reposerver = 'https://git.bbh.org.in'; | |||||
} | |||||
else if (choice === 'h') { | |||||
processedArgs._[0] = 'h'; | |||||
fs.writeFileSync('run.done', 'noop help'); | |||||
console.log(elxr.help()); process.exit(); | |||||
} | |||||
else if (choice === 'n' || choice === 'i') { | |||||
var p1 = cliverse.prompter; | |||||
return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) { | |||||
processedArgs._[0] = 'i'; | |||||
selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName; | |||||
return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) { | |||||
selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env; | |||||
if (choice === 'n') { | |||||
selectedinstance.reposerver = 'https://git.bbh.org.in'; | |||||
console.warn( | |||||
source.magenta('No Option Available. Your account may not have privileges. You can request here http://git.bbh.org.in/chess')); | |||||
process.exit(); | |||||
} | |||||
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposerver || selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { | |||||
selectedinstance.reposerver = reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in'; | |||||
}) | |||||
}) | |||||
}) | |||||
} else if (choice === 'c') { | |||||
var p1 = cliverse.prompter; | |||||
return p1.ask(`Enter Instance Name ( <= ${selectedinstance.instanceName} ) : `).then(function (instanceName) { | |||||
selectedinstance.instanceName = processedArgs._[1] = instanceName || selectedinstance.instanceName; | |||||
return p1.ask(`Enter Environment ( <= ${selectedinstance.node_env} ) : `).then(function (node_env) { | |||||
selectedinstance.node_env = processedArgs.node_env = node_env || selectedinstance.node_env; | |||||
return p1.ask(`Enter cmd : | |||||
p) pull | |||||
Default <= p | |||||
: `).then(function (cmd) { | |||||
if (!cmd || cmd === 'p') { | |||||
processedArgs._[0] = 'pull'; | |||||
} | |||||
else processedArgs._[0] = cmd; | |||||
return p1.ask(`Enter preferred repo server ( <= ${selectedinstance.reposerver || selectedinstance.reposervers[0]} ) : `).then(function (reposerver) { | |||||
selectedinstance.reposerver = reposerver || selectedinstance.reposerver || selectedinstance.reposervers[0] || 'https://git.bbh.org.in'; | |||||
}) | |||||
}) | |||||
}) | |||||
}) | |||||
} else { | |||||
console.log(source.gray(`Default option not exercised. Please follow manual instructions to customize your instance here http://git.bbh.org.in/chess and try again.`)); | |||||
fs.writeFileSync('run.log', ', ' + JSON.stringify({ success: 'quit without execution' }), { 'flag': 'a+' }); | |||||
fs.writeFileSync('run.done', 'noop quit'); | |||||
process.exit(); | |||||
} | |||||
}) | |||||
} | |||||
var mergeObjByKey = function(arrOfObjs, keyName) { | var mergeObjByKey = function(arrOfObjs, keyName) { | ||||
var keyedDistinct = {}; | var keyedDistinct = {}; | ||||
}; | }; | ||||
if(clioverrides.reconfirm) { | |||||
var reconfirm = { 'instanceName' : clioverrides['instanceName'] === 'chess' }; | |||||
} | |||||
else { var reconfirm = {}; } | |||||
var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) { | var getBoundEachPrompt = function(target, mustPrompt, promptables, choices) { | ||||
return function(prompts, k, i, a){ | return function(prompts, k, i, a){ | ||||
} | } | ||||
}; | }; | ||||
var __interactve_promts = function( target, choices ){ | |||||
var __interactive_prompts = function( target, choices ){ | |||||
Object.defineProperty(target, 'node_env', { get : function(){ return this.instanceType } }); | Object.defineProperty(target, 'node_env', { get : function(){ return this.instanceType } }); | ||||
// https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/ | // https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/ | ||||
// alert(windowselevate.commandLine) | // alert(windowselevate.commandLine) | ||||
var args = windowselevate.commandLine.split('"').slice(3); | var args = windowselevate.commandLine.split('"').slice(3); | ||||
alert(args) | |||||
// alert(args) | |||||
var processedArgs = { _ : [] } | var processedArgs = { _ : [] } | ||||
var namedArgs = []; | var namedArgs = []; | ||||
for(var item in args){ | for(var item in args){ | ||||
// PB : TODO -- Convert all the cli args back to string. | // PB : TODO -- Convert all the cli args back to string. | ||||
var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' '); | var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' '); | ||||
alert(cargs) | |||||
// alert(cargs) | |||||
var shell = new ActiveXObject('shell.application'); | var shell = new ActiveXObject('shell.application'); | ||||
// alert('launching node privilged. ' + processedArgs['nodepath']) | // alert('launching node privilged. ' + processedArgs['nodepath']) | ||||
// shell.ShellExecute('where', 'node', '', '', 10); | // shell.ShellExecute('where', 'node', '', '', 10); | ||||
chessinstances[instanceName][node_env] | chessinstances[instanceName][node_env] | ||||
, clioverrides | , clioverrides | ||||
, selected_overrides | , selected_overrides | ||||
// , __interactve_promts -- Cant just override. Also need selectedinstance to be ready... | |||||
// , __interactive_prompts -- Cant just override. Also need selectedinstance to be ready... | |||||
); | ); | ||||
// chessinstances[instanceName] = chessinstances[instanceName] || {} | // chessinstances[instanceName] = chessinstances[instanceName] || {} | ||||
}); | }); | ||||
instances = instances.concat(detectedinstanceoptions); | instances = instances.concat(detectedinstanceoptions); | ||||
if(promptkeys['instanceName']) instnaceNames.push(selectedinstance['instanceName']); | |||||
if(selectedinstance['instanceName']) instnaceNames.push(selectedinstance['instanceName']); | |||||
if(promptkeys['instanceName']) instnaceNames.push(promptkeys['instanceName']); | if(promptkeys['instanceName']) instnaceNames.push(promptkeys['instanceName']); | ||||
if(selectedinstance['reposervers']) reposervers = reposervers.concat(selectedinstance['reposervers']); | if(selectedinstance['reposervers']) reposervers = reposervers.concat(selectedinstance['reposervers']); | ||||
// PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!! | // PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!! | ||||
selectedinstance = bbhverse.assign( ...detectedinstanceoptions.slice(-2) ); | selectedinstance = bbhverse.assign( ...detectedinstanceoptions.slice(-2) ); | ||||
promptkeys = bbhverse.assign(promptkeys, clioverrides); | |||||
if(clioverrides.reconfirm) { | |||||
({ 'instanceName' : selectedinstance['instanceName'] === 'chess' }); | |||||
} | |||||
// promptkeys = utils.assign(promptkeys, clioverrides) | |||||
try { | try { | ||||
chessinstances = acquirelocalinstances(selectedinstance); | chessinstances = acquirelocalinstances(selectedinstance); | ||||
findlocalinstances(chessinstances, detectedinstanceoptions); | findlocalinstances(chessinstances, detectedinstanceoptions); | ||||
initinstances(selectedinstance); // use the local instances for defaults if at all possible. | |||||
var choices = getchoices(detectedinstanceoptions, promptkeys); | var choices = getchoices(detectedinstanceoptions, promptkeys); | ||||
var todo = any( __interactve_promts(selectedinstance, choices) ).then(()=>{ | |||||
var todo = any( __interactive_prompts(selectedinstance, choices) ).then(()=>{ | |||||
return initinstances(selectedinstance) | return initinstances(selectedinstance) | ||||
}); | }); | ||||
} | } | ||||
catch (e) { | catch (e) { | ||||
// PB : TODO -- verbose mode warning.. console.warn(e) // Missing chessinstances is not an error... | // PB : TODO -- verbose mode warning.. console.warn(e) // Missing chessinstances is not an error... | ||||
var choices = getchoices(detectedinstanceoptions, promptkeys); | var choices = getchoices(detectedinstanceoptions, promptkeys); | ||||
var todo = any( __interactve_promts(selectedinstance, choices) ).then(()=>{ | |||||
var todo = any( __interactive_prompts(selectedinstance, choices) ).then(()=>{ | |||||
return initinstances(selectedinstance) | 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(() => { | todo = todo.then(() => { | ||||
try { | try { |
Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }) | Object.keys(processedArgs).forEach((v) => { v != '_' ? namedArgs.push('--' + v + '=' + processedArgs[v]) : null; }) | ||||
// PB : TODO -- Convert all the cli args back to string. | // PB : TODO -- Convert all the cli args back to string. | ||||
var args = [`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | var args = [`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); | ||||
args.push('--nodepath=' + r[r.length - 1]) | |||||
if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) | |||||
if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. | |||||
// args.push('--nodepath=' + r.messages[r.messages.length - 1]) | |||||
// if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) | |||||
// if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. | |||||
console.dir(processedArgs) | |||||
return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] | ||||
, { | , { | ||||
}) | }) | ||||
instances = instances.concat(detectedinstanceoptions) | instances = instances.concat(detectedinstanceoptions) | ||||
if(promptkeys['instanceName']) instnaceNames.push(selectedinstance['instanceName']) | |||||
if(selectedinstance['instanceName']) instnaceNames.push(selectedinstance['instanceName']) | |||||
if(promptkeys['instanceName']) instnaceNames.push(promptkeys['instanceName']) | if(promptkeys['instanceName']) instnaceNames.push(promptkeys['instanceName']) | ||||
if(selectedinstance['reposervers']) reposervers = reposervers.concat(selectedinstance['reposervers']) | if(selectedinstance['reposervers']) reposervers = reposervers.concat(selectedinstance['reposervers']) | ||||
// PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!! | // PB : TODO -- Most recent should be at the tip ! at index 0 so utils.reverseassign is required !!! | ||||
selectedinstance = utils.assign( ...detectedinstanceoptions.slice(-2) ) | selectedinstance = utils.assign( ...detectedinstanceoptions.slice(-2) ) | ||||
promptkeys = utils.assign(promptkeys, clioverrides) | |||||
// promptkeys = utils.assign(promptkeys, clioverrides) | |||||
try { | try { | ||||
return initinstances(selectedinstance) | 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(() => { | todo = todo.then(() => { | ||||
try { | try { |
"main": "index.js", | "main": "index.js", | ||||
"scripts": { | "scripts": { | ||||
"test": "echo \"Error: no test specified\" && exit 1", | "test": "echo \"Error: no test specified\" && exit 1", | ||||
"build-commented": "rollup index.js --format cjs --file elxr.js", | |||||
"build": "rollup -c", | |||||
"build-elxr": "rollup index.js --format cjs --file elxr.js", | |||||
"build": "rollup -c && rollup index.js --format cjs --file elxr.js", | |||||
"index": "SET FORCE_COLOR=true && node index" | "index": "SET FORCE_COLOR=true && node index" | ||||
}, | }, | ||||
"keywords": [], | "keywords": [], |
<html><HTA:APPLICATION ID="windowselevate" icon="#"/> | |||||
<script language="vbscript"> | |||||
document.title = "elxr control panel" | |||||
self.ResizeTo 200,600 | |||||
Sub Window_Onload | |||||
self.MoveTo (screen.availWidth - (document.body.clientWidth + 40)),10 | |||||
End Sub | |||||
Set objShell = CreateObject("WScript.Shell") | |||||
Set objENV = objShell.Environment("Process") | |||||
dim NODE_ENV | |||||
NODE_ENV = objENV("NODE_ENV") | |||||
</script> | |||||
<script language="javascript"> | |||||
//WINDOWSTATE="minimize" SHOWINTASKBAR="no" SYSMENU="no" CAPTION="no" | |||||
// https://devblogs.microsoft.com/scripting/how-can-i-pass-command-line-variables-to-an-hta-when-it-starts/ | |||||
// alert(windowselevate.commandLine) | |||||
var args = windowselevate.commandLine.split('"').slice(3); | |||||
// alert(args) | |||||
var processedArgs = { _ : [] } | |||||
var namedArgs = []; | |||||
for(var item in args){ | |||||
if(args[item].charAt(0) === '-'){ | |||||
namedArgs.push(args[item]) | |||||
var split = args[item].split('='); | |||||
processedArgs[split[0].slice(2)] = split[1] || true; | |||||
} | |||||
else processedArgs._.push(args[item]); | |||||
} | |||||
// args = args.forEach(function(item){ }) | |||||
// alert('processedArgs._ : ' + processedArgs._); | |||||
// alert(processedArgs.runas); | |||||
// PB : TODO -- Convert all the cli args back to string. | |||||
var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' elxr ' + processedArgs._.join(' ') + ' ' + namedArgs.join(' '); | |||||
// alert(cargs) | |||||
var shell = new ActiveXObject('shell.application'); | |||||
// alert('launching node privilged. ' + processedArgs['nodepath']) | |||||
// shell.ShellExecute('where', 'node', '', '', 10); | |||||
shell.ShellExecute('node', cargs, '', 'runas', 1); | |||||
// shell.ShellExecute(processedArgs['nodepath'], cargs, '', 'runas', 1); | |||||
var fso = new ActiveXObject('Scripting.FileSystemObject'); | |||||
window.onload = function() { | |||||
document.body.style.backgroundColor = 'black'; | |||||
document.body.style.fontFamily = 'arial'; | |||||
var log = document.createElement('div'); | |||||
log.innerHTML='Please Wait'; | |||||
function l(msg){ log.innerHTML+= msg; }; | |||||
log.style.color = 'blue'; | |||||
log.style.width = '95%'; | |||||
log.id = 'log'; | |||||
document.body.appendChild(log); | |||||
l('<Br/>Current config : ') | |||||
l('<Br/>NODE_ENV = ' + NODE_ENV) | |||||
l('<Br/>cmd = ' + processedArgs._[0]) | |||||
processedArgs._[1] === 'use' ? l('<Br/>using = ' + processedArgs._[2]) : null; | |||||
l('<Br/><Br/>') | |||||
var timer = function(){ | |||||
l('.'); | |||||
if(fso.FileExists("run.done")) close(); | |||||
else window.setTimeout(timer, 1000); | |||||
}; | |||||
window.setTimeout(timer, 3000); | |||||
}; | |||||
</script> | |||||
</html> |