|
|
@@ -2,6 +2,15 @@ |
|
|
|
// -------------- |
|
|
|
// elxr |
|
|
|
// A cli tool for elixr. |
|
|
|
|
|
|
|
// PB : TODO -- |
|
|
|
// runas bypass non elevated tasks when we request privelege |
|
|
|
// runas message is always error needs to be fixed. |
|
|
|
// runas wait needs to be parallelized. |
|
|
|
// suppress elevation check error messages |
|
|
|
// support runas lauched directly from shell. |
|
|
|
// pass in environment in hta to shellexecute. |
|
|
|
|
|
|
|
const { existsSync } = require('fs'); |
|
|
|
const fs = require('fs') |
|
|
|
const { spawn, spawnSync } = require('child_process'); |
|
|
@@ -163,8 +172,10 @@ var elevatedRunasRepos = [ |
|
|
|
] |
|
|
|
|
|
|
|
var productionRepos = [ |
|
|
|
'elixir-config-production' |
|
|
|
'elixir-config-production' |
|
|
|
] |
|
|
|
var productionIsAllowed = true; |
|
|
|
if(productionIsAllowed) gitRepos = gitRepos.concat(productionRepos) |
|
|
|
|
|
|
|
var env = Object.assign({}, process.env); // Shallow clone it. |
|
|
|
var __runcmd = function(label){ |
|
|
@@ -274,18 +285,15 @@ var __runcmd = function(label){ |
|
|
|
// PB : TODO -- Convert all the cli args back to string. |
|
|
|
var namedArgs = []; |
|
|
|
Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; }) |
|
|
|
var cargs = `${processedArgs.debug ? '--inspect-brk' : ''} --inspect-brk elxr ${processedArgs._.join(' ')} ${namedArgs.join(' ') } --runas=true` |
|
|
|
console.log('Requesting Elevated Privileges for : ' + `node ${cargs}`) |
|
|
|
//console.log(' namedArgs : ' + namedArgs) |
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; |
|
|
|
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._); args.push('--runas') |
|
|
|
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self'); |
|
|
|
nodeShellExec('MSHTA', [`"${args.join('" "')}"`] |
|
|
|
, { |
|
|
|
inherit : true |
|
|
|
, |
|
|
|
shell: true |
|
|
|
// , |
|
|
|
inherit : true |
|
|
|
, shell: true |
|
|
|
, env: process.env |
|
|
|
, runas : true |
|
|
|
, runas : 'self' |
|
|
|
, title : `runas` |
|
|
|
} |
|
|
|
).then(()=>{ |
|
|
@@ -526,10 +534,15 @@ var __runcmd = function(label){ |
|
|
|
, 'use' : ()=>{ |
|
|
|
|
|
|
|
var runconfig = { NODE_ENV : process.env.NODE_ENV } |
|
|
|
try { |
|
|
|
runconfig = Object.assign(runconfig, require('../run.js')) |
|
|
|
} catch(e) { } |
|
|
|
if(runconfig.NODE_ENV === process.env.NODE_ENV && processedArgs._[1] && runconfig.use === processedArgs._[1]) return; |
|
|
|
try { runconfig = Object.assign(runconfig, require('../run.js')) } catch(e) { } |
|
|
|
if((!processedArgs.runas || processedArgs.runas !== 'self') && |
|
|
|
runconfig.NODE_ENV && runconfig.NODE_ENV === (process.env.NODE_ENV || runconfig.NODE_ENV) && |
|
|
|
processedArgs._[1] && runconfig.use === processedArgs._[1]) { |
|
|
|
|
|
|
|
console.log(`No change detected. Already using requested specs : ${runconfig.NODE_ENV} ${runconfig.use}`) |
|
|
|
if(processedArgs.runas) { fs.writeFileSync('run.done', 'success') } |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
var tasks = [ |
|
|
|
()=>{ |
|
|
@@ -549,41 +562,43 @@ var __runcmd = function(label){ |
|
|
|
else return Promise.resolve(true); |
|
|
|
} |
|
|
|
]; |
|
|
|
any(tasks) |
|
|
|
if(!processedArgs.runas) return op['runas']() |
|
|
|
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; |
|
|
|
runconfig.NODE_ENV = process.env.NODE_ENV = process.env.NODE_ENV || runconfig.NODE_ENV || 'development'; |
|
|
|
if(processedArgs._[1] && runconfig.use !== processedArgs._[1]) runconfig.use = processedArgs._[1]; |
|
|
|
if(!runconfig.use) { throw 'unspecifed use not allowed. Please specify chess instance name.' } |
|
|
|
|
|
|
|
// console.log(process.env.cwd) |
|
|
|
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig)) |
|
|
|
|
|
|
|
tasks = [ |
|
|
|
()=>{ |
|
|
|
// Use junctions to avoid npm package issues |
|
|
|
var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-' + process.env.NODE_ENV + '-config'], { |
|
|
|
inherit : true, shell: true |
|
|
|
, env: process.env |
|
|
|
}).catch((e)=>{ console.error(e) }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
]; |
|
|
|
if(processedArgs._[1]) { |
|
|
|
tasks.concat( |
|
|
|
[ |
|
|
|
()=>{ |
|
|
|
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], { |
|
|
|
inherit : true, shell: true |
|
|
|
, env: process.env |
|
|
|
}).catch((e)=>{ console.error(e) }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
] |
|
|
|
) |
|
|
|
} |
|
|
|
any(tasks).then(()=>{ |
|
|
|
fs.writeFileSync('run.done', 'success') |
|
|
|
if(!processedArgs.runas) return op['runas']() |
|
|
|
|
|
|
|
tasks = [ |
|
|
|
()=>{ |
|
|
|
// Use junctions to avoid npm package issues |
|
|
|
var p = nodeShellExec('mklink', ['/J', 'config', runconfig.use + '-config' + '-' + process.env.NODE_ENV ], { |
|
|
|
inherit : true, shell: true |
|
|
|
, env: process.env |
|
|
|
}).catch((e)=>{ console.error(e) }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
]; |
|
|
|
if(processedArgs._[1]) { |
|
|
|
tasks = tasks.concat( |
|
|
|
[ |
|
|
|
()=>{ |
|
|
|
var p = nodeShellExec('mklink', ['/D', 'data', runconfig.use + '-data'], { |
|
|
|
inherit : true, shell: true |
|
|
|
, env: process.env |
|
|
|
}).catch((e)=>{ console.error(e) }) |
|
|
|
return p; |
|
|
|
} |
|
|
|
] |
|
|
|
) |
|
|
|
} |
|
|
|
return any(tasks).then(()=>{ |
|
|
|
fs.writeFileSync('run.done', 'success') |
|
|
|
}).catch(()=>{ |
|
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
}) |
|
|
|
}).catch(()=>{ |
|
|
|
fs.writeFileSync('run.done', 'error') |
|
|
|
}) |