|
|
|
|
|
|
|
|
// -------------- |
|
|
// -------------- |
|
|
// elxr |
|
|
// elxr |
|
|
// A cli tool for elixr. |
|
|
// 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 { existsSync } = require('fs'); |
|
|
const fs = require('fs') |
|
|
const fs = require('fs') |
|
|
const { spawn, spawnSync } = require('child_process'); |
|
|
const { spawn, spawnSync } = require('child_process'); |
|
|
|
|
|
|
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
var productionRepos = [ |
|
|
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 env = Object.assign({}, process.env); // Shallow clone it. |
|
|
var __runcmd = function(label){ |
|
|
var __runcmd = function(label){ |
|
|
|
|
|
|
|
|
// PB : TODO -- Convert all the cli args back to string. |
|
|
// PB : TODO -- Convert all the cli args back to string. |
|
|
var namedArgs = []; |
|
|
var namedArgs = []; |
|
|
Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; }) |
|
|
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'; |
|
|
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('" "')}"`] |
|
|
nodeShellExec('MSHTA', [`"${args.join('" "')}"`] |
|
|
, { |
|
|
, { |
|
|
inherit : true |
|
|
|
|
|
, |
|
|
|
|
|
shell: true |
|
|
|
|
|
// , |
|
|
|
|
|
|
|
|
inherit : true |
|
|
|
|
|
, shell: true |
|
|
, env: process.env |
|
|
, env: process.env |
|
|
, runas : true |
|
|
|
|
|
|
|
|
, runas : 'self' |
|
|
, title : `runas` |
|
|
, title : `runas` |
|
|
} |
|
|
} |
|
|
).then(()=>{ |
|
|
).then(()=>{ |
|
|
|
|
|
|
|
|
, 'use' : ()=>{ |
|
|
, 'use' : ()=>{ |
|
|
|
|
|
|
|
|
var runconfig = { NODE_ENV : process.env.NODE_ENV } |
|
|
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 = [ |
|
|
var tasks = [ |
|
|
()=>{ |
|
|
()=>{ |
|
|
|
|
|
|
|
|
else return Promise.resolve(true); |
|
|
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(processedArgs._[1] && runconfig.use !== processedArgs._[1]) runconfig.use = processedArgs._[1]; |
|
|
if(!runconfig.use) { throw 'unspecifed use not allowed. Please specify chess instance name.' } |
|
|
if(!runconfig.use) { throw 'unspecifed use not allowed. Please specify chess instance name.' } |
|
|
|
|
|
|
|
|
// console.log(process.env.cwd) |
|
|
// console.log(process.env.cwd) |
|
|
fs.writeFileSync('./run.js', 'module.exports = ' + JSON.stringify(runconfig)) |
|
|
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(()=>{ |
|
|
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(()=>{ |
|
|
}).catch(()=>{ |
|
|
fs.writeFileSync('run.done', 'error') |
|
|
fs.writeFileSync('run.done', 'error') |
|
|
}) |
|
|
}) |