|
|
|
|
|
|
|
|
const homedir = require('os').homedir(); |
|
|
const homedir = require('os').homedir(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ENV = Object.assign({}, process.env); // Shallow clone it. |
|
|
|
|
|
|
|
|
|
|
|
function sysAddPathVar(path){ |
|
|
function sysAddPathVar(path){ |
|
|
// Object.assign({ |
|
|
// Object.assign({ |
|
|
// inherit: true, shell: true, env: ENV, title: `${command} ${args}` |
|
|
// inherit: true, shell: true, env: ENV, title: `${command} ${args}` |
|
|
|
|
|
|
|
|
var creds = fs.readFileSync(path.normalize(`${homedir}/.elxrcredentials`), { encoding: 'utf8' }); |
|
|
var creds = fs.readFileSync(path.normalize(`${homedir}/.elxrcredentials`), { encoding: 'utf8' }); |
|
|
var creds = creds.split('\n').map( c => c.trim() && new URL(c)); |
|
|
var creds = creds.split('\n').map( c => c.trim() && new URL(c)); |
|
|
console.log(creds); |
|
|
console.log(creds); |
|
|
|
|
|
creds.forEach(cred => {console.log( cred.hostname ); console.log( cred.username )} ); |
|
|
|
|
|
|
|
|
// Subsequent calls |
|
|
// Subsequent calls |
|
|
getCredentials = ()=>{ return creds } |
|
|
getCredentials = ()=>{ return creds } |
|
|
return getCredentials(); |
|
|
return getCredentials(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getCurrentFolder(){ |
|
|
|
|
|
var tasks = [ |
|
|
|
|
|
// () => { |
|
|
|
|
|
// // Use junctions to avoid npm package issues |
|
|
|
|
|
// var p = nodeShellExec('cd').then((result)=>{ |
|
|
|
|
|
// console.dir(result) |
|
|
|
|
|
// }).catch((e) => { console.error(e) }) |
|
|
|
|
|
// return p; |
|
|
|
|
|
// } |
|
|
|
|
|
()=>{ |
|
|
|
|
|
return Promise.resolve(process.cwd()) |
|
|
|
|
|
} |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
return any(tasks); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b' |
|
|
const __ALIAS__STAMP__ = '9e7bebe0-1f57-11ec-8f88-778ffeea9d1b' |
|
|
const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; |
|
|
const BUILD_VERSION = '[VI]Version: {version} - built on {date}[/VI]'; |
|
|
const runtimestamp = (new Date()).getTime(); |
|
|
const runtimestamp = (new Date()).getTime(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cliargs = utils.cliargs; |
|
|
const cliargs = utils.cliargs; |
|
|
const processedArgs = cliargs(process.argv.slice(2)); |
|
|
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. |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else process.env.wd = processedArgs.wd |
|
|
|
|
|
var ENV = Object.assign({}, process.env); // Shallow clone it. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.dir(processedArgs) |
|
|
console.dir(processedArgs) |
|
|
// PB : TODO -- defaults for valuless arguments if passed. |
|
|
// PB : TODO -- defaults for valuless arguments if passed. |
|
|
// Object.keys(processedArgs).forEach(a=>{ |
|
|
// Object.keys(processedArgs).forEach(a=>{ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var templateprocess = function(str, substitutes){ |
|
|
|
|
|
const regex = /__(.*?)__/gm; |
|
|
|
|
|
// const str = `__link____instance__server-lib__name__`; |
|
|
|
|
|
let m; |
|
|
|
|
|
|
|
|
|
|
|
return str.replace(regex, function(match, key) { |
|
|
|
|
|
console.log(`Found match, group ${match}: ${key}`); |
|
|
|
|
|
return substitutes[key] || match; |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// while ((m = regex.exec(str)) !== null) { |
|
|
|
|
|
// // This is necessary to avoid infinite loops with zero-width matches |
|
|
|
|
|
// if (m.index === regex.lastIndex) { |
|
|
|
|
|
// regex.lastIndex++; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// var rstr = str; |
|
|
|
|
|
// // The result can be accessed through the `m`-variable. |
|
|
|
|
|
// m.forEach((match, groupIndex) => { |
|
|
|
|
|
|
|
|
|
|
|
// // rstr = rstr.replace( groupIndex |
|
|
|
|
|
// console.log(`Found match, group ${groupIndex}: ${match}`); |
|
|
|
|
|
// if(groupIndex === 0) return |
|
|
|
|
|
|
|
|
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function copyFileSync( source, target , options) { |
|
|
|
|
|
|
|
|
|
|
|
var targetFile = target; |
|
|
|
|
|
|
|
|
|
|
|
// If target is a directory, a new file with the same name will be created |
|
|
|
|
|
if ( fs.existsSync( target ) ) { |
|
|
|
|
|
if ( fs.lstatSync( target ).isDirectory() ) { |
|
|
|
|
|
targetFile = path.join( target, path.basename( source ) ); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync(targetFile, fs.readFileSync(source)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function copyFolderRecursiveSync( source, target, options ) { |
|
|
|
|
|
var files = []; |
|
|
|
|
|
|
|
|
|
|
|
// Check if folder needs to be created or integrated |
|
|
|
|
|
var targetFolder = path.join( target, path.basename( source ) ); |
|
|
|
|
|
if ( !fs.existsSync( targetFolder ) ) { |
|
|
|
|
|
fs.mkdirSync( targetFolder ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Copy |
|
|
|
|
|
if ( fs.lstatSync( source ).isDirectory() ) { |
|
|
|
|
|
files = fs.readdirSync( source ); |
|
|
|
|
|
files.forEach( function ( file ) { |
|
|
|
|
|
var curSource = path.join( source, file ); |
|
|
|
|
|
if ( fs.lstatSync( curSource ).isDirectory() ) { |
|
|
|
|
|
copyFolderRecursiveSync( curSource, targetFolder ); |
|
|
|
|
|
} else { |
|
|
|
|
|
copyFileSync( curSource, targetFolder ); |
|
|
|
|
|
} |
|
|
|
|
|
} ); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var getShellTask = (command, args, options) => { |
|
|
var getShellTask = (command, args, options) => { |
|
|
options = options || {} |
|
|
options = options || {} |
|
|
var callshell = command === 'rm' ? getgitbashtask : getshelltask; |
|
|
var callshell = command === 'rm' ? getgitbashtask : getshelltask; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (__isElevated) { |
|
|
if (__isElevated) { |
|
|
try { |
|
|
try { |
|
|
op[processedArgs.label || processedArgs._[0] || 'undefined']() |
|
|
|
|
|
|
|
|
op[processedArgs.label || processedArgs._[0] || 'undefined'](processedArgs) |
|
|
} |
|
|
} |
|
|
catch (e) { |
|
|
catch (e) { |
|
|
console.error('Error Invalid command : ' + e) |
|
|
console.error('Error Invalid command : ' + e) |
|
|
|
|
|
|
|
|
console.log('result : ' + JSON.stringify(r)) |
|
|
console.log('result : ' + JSON.stringify(r)) |
|
|
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._) |
|
|
|
|
|
namedArgs.length > 0 ? args = args.concat(namedArgs.join(' ')) : null; |
|
|
|
|
|
args.push('--runas=self'); |
|
|
// args.push('--nodepath=' + r.messages[r.messages.length - 1]) |
|
|
// args.push('--nodepath=' + r.messages[r.messages.length - 1]) |
|
|
// if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) |
|
|
// if (!processedArgs.node_env) args.push('--node_env=' + ENV.NODE_ENV) |
|
|
// if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. |
|
|
// if (processedArgs.debug) args.push('--debug=true') // Enable to debug elevated.. |
|
|
console.dir(processedArgs) |
|
|
|
|
|
|
|
|
// console.dir(processedArgs._) |
|
|
|
|
|
// console.dir(namedArgs.join(' ')) |
|
|
|
|
|
console.dir(args) |
|
|
|
|
|
// throw 'test' |
|
|
|
|
|
|
|
|
return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] |
|
|
return nodeShellExec('MSHTA', [`"${args.join('" "')}"`] |
|
|
, { |
|
|
, { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else return op['runas']() |
|
|
else return op['runas']() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
, 'use' : () => { |
|
|
, 'use' : () => { |
|
|
// use a certain named instance. |
|
|
// use a certain named instance. |
|
|
// Eg : |
|
|
// Eg : |
|
|
|
|
|
|
|
|
// 2nd use Pharmacy needs justification Form. |
|
|
// 2nd use Pharmacy needs justification Form. |
|
|
// Approval after a certain period of time. |
|
|
// Approval after a certain period of time. |
|
|
} |
|
|
} |
|
|
, 'g': () => { |
|
|
|
|
|
|
|
|
, 'g' : () => { |
|
|
if (processedArgs.h) { |
|
|
if (processedArgs.h) { |
|
|
|
|
|
|
|
|
console.log('elxr g [modelname] => generate a model named [modelname]'); |
|
|
|
|
|
|
|
|
console.log('elxr g model [modelname] => generate a model named [modelname]'); |
|
|
|
|
|
console.log('elxr g vmodel [modelname] => generate a model named [modelname]'); |
|
|
console.log('elxr g => regenerate all known models'); |
|
|
console.log('elxr g => regenerate all known models'); |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
, 'undefined' : ()=>{ |
|
|
|
|
|
console.warn('Are you sure you want to refresh all the models.'); |
|
|
|
|
|
throw 'NOT YET IMPLMENTED' |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
, 'vmodel' : ()=>{ |
|
|
|
|
|
var verse = [ '__universe__/vmodel' ] |
|
|
|
|
|
|
|
|
|
|
|
// console.dir(templateprocess(`__link____instance__server-lib__name__`, { link( ){ |
|
|
|
|
|
// return processed }, instance : 'elixir-', name : 'newmodel' } ) |
|
|
|
|
|
// ) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
g[processedArgs._[1]](); |
|
|
g[processedArgs._[1]](); |
|
|
|
|
|
|
|
|
, cmd : 'users list' |
|
|
, cmd : 'users list' |
|
|
, noprerequisites : true |
|
|
, noprerequisites : true |
|
|
} |
|
|
} |
|
|
|
|
|
, 'g' : { |
|
|
|
|
|
cmdFn : op['g'] // default |
|
|
|
|
|
, cmd : 'g' |
|
|
|
|
|
, noprerequisites : true |
|
|
|
|
|
, getPossiblePrompts(){ return {} } |
|
|
|
|
|
} |
|
|
|
|
|
, 'link' : { |
|
|
|
|
|
'cmd' : 'link' |
|
|
|
|
|
// , cmdFn : function( sourecpath, filename, dir ){ |
|
|
|
|
|
// var afterTargetPath = (dir)=>{ |
|
|
|
|
|
// console.dir(dir); |
|
|
|
|
|
|
|
|
|
|
|
// // var tasks = [ |
|
|
|
|
|
// // () => { |
|
|
|
|
|
// // // Use junctions to avoid npm package issues |
|
|
|
|
|
// // var p = nodeShellExec('mklink', ['/J', filename, sourecpath], { |
|
|
|
|
|
// // inherit: true, shell: true |
|
|
|
|
|
// // , cwd : dir || instanceroot |
|
|
|
|
|
// // , env: process.env |
|
|
|
|
|
// // }).catch((e) => { console.error(e) }) |
|
|
|
|
|
// // return p; |
|
|
|
|
|
// // } |
|
|
|
|
|
// // ]; |
|
|
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// // console.dir(process.env) |
|
|
|
|
|
// if(!dir) getCurrentFolder().then(afterTargetPath); |
|
|
|
|
|
// else afterTargetPath(dir) |
|
|
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
, cmdFn : function( cmdopts ){ |
|
|
|
|
|
// sourecpathandfile should include name of file name |
|
|
|
|
|
targetfilename = cmdopts.targetfilename || processedArgs._[1] |
|
|
|
|
|
// console.log(processedArgs) |
|
|
|
|
|
if(!targetfilename) return Promise.reject('error no file provided for linking') |
|
|
|
|
|
targetdir = cmdopts.targetdir || process.env.wd |
|
|
|
|
|
sourecpathandfile = cmdopts.sourecpathandfile || path.normalize(`../../node_modules/chess-server-lib/common/models/${targetfilename}`) |
|
|
|
|
|
|
|
|
|
|
|
var tasks = [ |
|
|
|
|
|
() => { |
|
|
|
|
|
// Use junctions to avoid npm package issues |
|
|
|
|
|
var p = nodeShellExec('mklink', [path.normalize(`${targetdir + '/' + targetfilename}`), sourecpathandfile], { |
|
|
|
|
|
inherit: true, shell: true |
|
|
|
|
|
, cwd : targetdir |
|
|
|
|
|
, env: process.env |
|
|
|
|
|
}).catch((e) => { console.error(e) }) |
|
|
|
|
|
return p; |
|
|
|
|
|
} |
|
|
|
|
|
]; |
|
|
|
|
|
if (__isElevated) { |
|
|
|
|
|
return any(tasks).then(() => { |
|
|
|
|
|
fs.writeFileSync('run.done', 'success') |
|
|
|
|
|
}).catch(() => { |
|
|
|
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
else return op['runas']() |
|
|
|
|
|
} |
|
|
|
|
|
, noprerequisites : true |
|
|
|
|
|
, privileged : true |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var elxrcmd = (function(){ |
|
|
var elxrcmd = (function(){ |
|
|
|
|
|
|
|
|
function __createO(o){ |
|
|
function __createO(o){ |
|
|
if(o.finalized) return o; |
|
|
if(o.finalized) return o; |
|
|
var subs = Object.keys(cmds[o.cmd].subcommands || {}) |
|
|
var subs = Object.keys(cmds[o.cmd].subcommands || {}) |
|
|
console.log(subs) |
|
|
|
|
|
console.log(o) |
|
|
|
|
|
|
|
|
// console.log(subs) |
|
|
|
|
|
// console.log(o) |
|
|
subs.forEach(sub=>elxrcmd.create( cmds[subcommandlabelFor(o.cmd, sub)] )) |
|
|
subs.forEach(sub=>elxrcmd.create( cmds[subcommandlabelFor(o.cmd, sub)] )) |
|
|
|
|
|
|
|
|
var created = utils.assign_strict({}, __cmd, cmds[o.cmd], o) |
|
|
var created = utils.assign_strict({}, __cmd, cmds[o.cmd], o) |
|
|
|
|
|
|
|
|
})() |
|
|
})() |
|
|
|
|
|
|
|
|
elxrcmd.create(cmds['users']) |
|
|
elxrcmd.create(cmds['users']) |
|
|
|
|
|
elxrcmd.create(cmds['g']) |
|
|
|
|
|
elxrcmd.create(cmds['link']) |
|
|
|
|
|
|
|
|
var interpretrun = function(){ |
|
|
var interpretrun = function(){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var launchpath = path.normalize(process.cwd()) |
|
|
|
|
|
|
|
|
var launchpath = path.resolve(path.normalize(process.env.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 we were run. |
|
|
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.... |
|
|
// The easisest would be to ask for a target directory and default to current dir.... |
|
|
var instanceroot = path.normalize(thisscriptdir) === path.normalize(launchpath) ? path.normalize(thisscriptdir + '/..') : launchpath ; |
|
|
|
|
|
|
|
|
// path.dirname(launchpath).split(path.sep).pop() |
|
|
|
|
|
|
|
|
|
|
|
var parent = path.dirname(launchpath); |
|
|
|
|
|
var pp = launchpath; |
|
|
|
|
|
var instancediscoverytasks = []; |
|
|
|
|
|
while(parent !== pp){ |
|
|
|
|
|
instancediscoverytasks.push( |
|
|
|
|
|
((pa)=>{ |
|
|
|
|
|
var p = pa; |
|
|
|
|
|
return function(){ |
|
|
|
|
|
return hasElxr(p).then((value)=>{ |
|
|
|
|
|
if(value) return p |
|
|
|
|
|
throw { value : false }; |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
})(pp) |
|
|
|
|
|
) |
|
|
|
|
|
pp = parent; |
|
|
|
|
|
parent = path.dirname(parent); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var instanceroot = null |
|
|
|
|
|
var detectInstanceRoot = any(instancediscoverytasks, true, true).then( ir => { |
|
|
|
|
|
if(ir.error) { instanceroot = path.normalize(thisscriptdir) === path.normalize(launchpath) ? path.normalize(thisscriptdir + '/..') : launchpath ; } |
|
|
|
|
|
else instanceroot = ir.pVal |
|
|
|
|
|
return instanceroot |
|
|
|
|
|
}).catch(()=>{ |
|
|
|
|
|
instanceroot = path.normalize(thisscriptdir) === path.normalize(launchpath) ? path.normalize(thisscriptdir + '/..') : launchpath ; |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO -- Embed this in the build instead of inlining it. |
|
|
// PB : TODO -- Embed this in the build instead of inlining it. |
|
|
// Also attepmt to load from ../chess-config/... |
|
|
// Also attepmt to load from ../chess-config/... |
|
|
|
|
|
|
|
|
, { repo : 'loopback-jsonapi-model-serializer' } |
|
|
, { repo : 'loopback-jsonapi-model-serializer' } |
|
|
, { repo : 'loopback-connector-mysql' } |
|
|
, { repo : 'loopback-connector-mysql' } |
|
|
, { repo : 'loopback-connector-ds' } |
|
|
, { repo : 'loopback-connector-ds' } |
|
|
, { repo : 'chess-server-lib' } |
|
|
|
|
|
|
|
|
|
|
|
, { repo : 'ember-service-worker' } |
|
|
, { repo : 'ember-service-worker' } |
|
|
, { repo : 'ember-service-worker-asset-cache' } |
|
|
, { repo : 'ember-service-worker-asset-cache' } |
|
|
, { repo : 'ember-service-worker-cache-fallback' } |
|
|
, { repo : 'ember-service-worker-cache-fallback' } |
|
|
|
|
|
|
|
|
, { repo : 'global-this' } |
|
|
, { repo : 'global-this' } |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
, elevated : [ ] |
|
|
|
|
|
|
|
|
, elevated : [ { repo : 'chess-server-lib' } ] |
|
|
, exludeMergeRepos : { } |
|
|
, exludeMergeRepos : { } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// console.log(k) |
|
|
// console.log(k) |
|
|
// console.dir(possiblePrompts); //console.dir(target) |
|
|
// console.dir(possiblePrompts); //console.dir(target) |
|
|
prompts.push(async ()=>{ |
|
|
prompts.push(async ()=>{ |
|
|
// PB : NOTE -- Important in async cases when this needs to be in the same state as when it was invoked. |
|
|
|
|
|
// We take a snapshot... Shallow.. !! If required deep should be used based on use case. |
|
|
|
|
|
// If latest altered state is required we can reerence this directly. |
|
|
|
|
|
|
|
|
// PB : NOTE -- Important in async cases when this {{target}} needs to be in the same state as when it was invoked. |
|
|
|
|
|
// We need to take a snapshot... Shallow.. !! If required deep should be used based on use case. |
|
|
// var asyncthis = Object.assign(this); |
|
|
// var asyncthis = Object.assign(this); |
|
|
|
|
|
// By default Latest altered state is provided which is an implicit reference directly. |
|
|
promptables[k].choices = choices[k] |
|
|
promptables[k].choices = choices[k] |
|
|
Object.defineProperty(target, k, getPromptableAsyncPropDescriptor(k, promptables[k])); |
|
|
Object.defineProperty(target, k, getPromptableAsyncPropDescriptor(k, promptables[k])); |
|
|
return await target[k] |
|
|
return await target[k] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var mainTasks = []; |
|
|
var mainTasks = []; |
|
|
function verifyAndInstallPrerequisites() { |
|
|
function verifyAndInstallPrerequisites() { |
|
|
fs.writeFileSync(ensureDirectoryExistence(path.normalize(`${selectedinstance.root}/${downloadsdir}/readme.txt`)), `${getVersion()} Your local downloads for this instance`) |
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO include and build from files... using rollup.. |
|
|
|
|
|
var downloadbatch = |
|
|
|
|
|
`::************************************************************************** |
|
|
|
|
|
:Download_ <url> <File> |
|
|
|
|
|
Powershell.exe ^ |
|
|
|
|
|
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'; ^ |
|
|
|
|
|
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols; ^ |
|
|
|
|
|
(New-Object System.Net.WebClient).DownloadFile('%1','%2') |
|
|
|
|
|
exit /b |
|
|
|
|
|
::**************************************************************************` |
|
|
|
|
|
fs.writeFileSync(`${selectedinstance.root}/.elxr/run-${runtimestamp}/download.bat`, downloadbatch) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var windowselevate = |
|
|
|
|
|
` |
|
|
|
|
|
<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('cmd.exe', '/k notepad.exe', '', 'runas', 1); |
|
|
|
|
|
// shell.ShellExecute('cmd.exe ', '/k node "' + cargs + '"', '', 'runas', 1); |
|
|
|
|
|
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> |
|
|
|
|
|
|
|
|
|
|
|
` |
|
|
|
|
|
fs.writeFileSync(`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`, windowselevate) |
|
|
|
|
|
|
|
|
|
|
|
var downloadtasks = []; |
|
|
var downloadtasks = []; |
|
|
var installtasks = []; |
|
|
var installtasks = []; |
|
|
prerequisites.forEach(preq => { |
|
|
prerequisites.forEach(preq => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var generateDependencies = function(){ |
|
|
|
|
|
// PB : TODO -- Keep only the last n runs... |
|
|
|
|
|
// Currently it retains 2*n when proc needs to be relaunched in elevated mode !!! |
|
|
|
|
|
|
|
|
|
|
|
ensureDirectoryExistence(`${selectedinstance.root}/.elxr/run-${runtimestamp}/download.bat`) |
|
|
|
|
|
fs.writeFileSync(ensureDirectoryExistence(path.normalize(`${selectedinstance.root}/${downloadsdir}/readme.txt`)), `${getVersion()} Your local downloads for this instance`) |
|
|
|
|
|
|
|
|
|
|
|
// PB : TODO include and build from files... using rollup.. |
|
|
|
|
|
var downloadbatch = |
|
|
|
|
|
`::************************************************************************** |
|
|
|
|
|
:Download_ <url> <File> |
|
|
|
|
|
Powershell.exe ^ |
|
|
|
|
|
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'; ^ |
|
|
|
|
|
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols; ^ |
|
|
|
|
|
(New-Object System.Net.WebClient).DownloadFile('%1','%2') |
|
|
|
|
|
exit /b |
|
|
|
|
|
::**************************************************************************` |
|
|
|
|
|
fs.writeFileSync(`${selectedinstance.root}/.elxr/run-${runtimestamp}/download.bat`, downloadbatch) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var windowselevate = |
|
|
|
|
|
` |
|
|
|
|
|
<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 = []; |
|
|
|
|
|
namedArgs.push('--wd=' + objENV('wd')) |
|
|
|
|
|
// alert(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); |
|
|
|
|
|
// alert(objENV('wd')) |
|
|
|
|
|
// PB : TODO -- Convert all the cli args back to string. |
|
|
|
|
|
// __filename will sure we are launhed using the same entry point. |
|
|
|
|
|
var cargs = (processedArgs.debug ? '--inspect-brk=9228' : '') + ' ${__filename.replace(/\\/g, '\\\\')} ' + 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('cmd.exe', '/k notepad.exe', '', 'runas', 1); |
|
|
|
|
|
// shell.ShellExecute('cmd.exe ', '/k node "' + cargs + '"', '', 'runas', 1); |
|
|
|
|
|
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> |
|
|
|
|
|
|
|
|
|
|
|
` |
|
|
|
|
|
fs.writeFileSync(`${selectedinstance.root}/.elxr/run-${runtimestamp}/windowselevate.hta`, windowselevate) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var startElxr = function() { |
|
|
var startElxr = function() { |
|
|
const retaincount = 2 |
|
|
const retaincount = 2 |
|
|
var min = runtimestamp; |
|
|
var min = runtimestamp; |
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
.then(()=>{ |
|
|
.then(()=>{ |
|
|
|
|
|
|
|
|
|
|
|
generateDependencies(); |
|
|
if(noprerequisites[processedArgs._[0]] |
|
|
if(noprerequisites[processedArgs._[0]] |
|
|
|| skipprereqs[processedArgs._[0]] |
|
|
|| skipprereqs[processedArgs._[0]] |
|
|
) { |
|
|
) { |
|
|
|
|
|
|
|
|
else collect.push(matches[1]) |
|
|
else collect.push(matches[1]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}, `${selectedinstance.root}/.elxr` ).then(()=>{ |
|
|
|
|
|
|
|
|
}, `${selectedinstance.root}/.elxr` ) |
|
|
|
|
|
.then(()=>{ |
|
|
// delete garbage |
|
|
// delete garbage |
|
|
if(collect.length > retaincount) { |
|
|
if(collect.length > retaincount) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
else return true |
|
|
else return true |
|
|
}) |
|
|
}) |
|
|
|
|
|
.then(()=>{ |
|
|
|
|
|
if (!skipprerequisites && !__isElevated || processedArgs.forceprereqs && !__isElevated ) mainTasks.push(verifyAndInstallPrerequisites); |
|
|
|
|
|
mainTasks.push(maintask) |
|
|
|
|
|
return any(mainTasks); |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
if (!skipprerequisites && !__isElevated || processedArgs.forceprereqs && !__isElevated ) mainTasks.push(verifyAndInstallPrerequisites); |
|
|
|
|
|
mainTasks.push(maintask) |
|
|
|
|
|
return any(mainTasks); |
|
|
} |
|
|
} |
|
|
else return true; |
|
|
|
|
|
}) |
|
|
|
|
|
.then(()=>{ |
|
|
|
|
|
// PB : TODO -- Keep only the last n runs... |
|
|
|
|
|
// Currently it retains 2*n when proc needs to be relaunched in elevated mode !!! |
|
|
|
|
|
ensureDirectoryExistence(`${selectedinstance.root}/.elxr/run-${runtimestamp}/download.bat`) |
|
|
|
|
|
|
|
|
|
|
|
if (!skipprerequisites && !__isElevated || processedArgs.forceprereqs && !__isElevated ) mainTasks.push(verifyAndInstallPrerequisites); |
|
|
|
|
|
mainTasks.push(maintask) |
|
|
|
|
|
return any(mainTasks); |
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
acquireElevationState().then(() => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return startElxr() |
|
|
|
|
|
|
|
|
detectInstanceRoot.then(()=>{ |
|
|
|
|
|
return acquireElevationState().then(() => { |
|
|
|
|
|
return startElxr() |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// detect if alread installed -> Take no action. |
|
|
// detect if alread installed -> Take no action. |