瀏覽代碼

Merge branch 'production' of http://git.bbh/chess/elxr into production

production
samuel 3 年之前
父節點
當前提交
ef1ea46741
共有 3 個文件被更改,包括 47 次插入33 次删除
  1. 3
    0
      bin/elxr
  2. 43
    32
      index.js
  3. 1
    1
      package.json

+ 3
- 0
bin/elxr 查看文件

#!/usr/bin/env node

require('../index.js')

+ 43
- 32
index.js 查看文件

#!/usr/bin/env node

// 'use strict';


// PB : TODO -- make sure folder context is proper coz we can now run elxr from anywhere. // PB : TODO -- make sure folder context is proper coz we can now run elxr from anywhere.


}) })
} }
, 'runas' : ()=>{ , 'runas' : ()=>{
console.log('Testing Elevation')
return isRunningElevated().then( return isRunningElevated().then(
(isElevated) => { (isElevated) => {
if(isElevated) { if(isElevated) {
} }
catch(e) { } //Ignore catch(e) { } //Ignore
// PB : TODO -- Convert all the cli args back to string.
var namedArgs = [];
Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; })
//console.log(' namedArgs : ' + namedArgs)
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
, {
inherit : true
, shell: true
, env: process.env
, runas : 'self'
, title : `runas`
}
).then(()=>{
// runas returned.
try {
var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']');
runaslog.forEach((logEntry)=>{
logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')))
})
}
catch(e){
// Ignore nonexistent log
console.warn('Run log error probably was not created by runas : ' + e)
}
// Find node path to send to hta.
nodeShellExec('where', ['node']).then(r => {
console.log('result : ' + r)
// throw 'rrrrrrrrrrrrrrrrr'
// PB : TODO -- Convert all the cli args back to string.
var namedArgs = [];
Object.keys(processedArgs).forEach((v)=>{ v!='_' ? namedArgs.push('--'+v+'='+processedArgs[v]) : null; })
//console.log(' namedArgs : ' + namedArgs)
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var args = [__dirname + '/windowselevate.hta'].concat(processedArgs._).concat(namedArgs.join(' ')); args.push('--runas=self');
args.push('--nodepath='+r[r.length-1])
nodeShellExec('MSHTA', [`"${args.join('" "')}"`]
, {
inherit : true
, shell: true
, env: process.env
, runas : 'self'
, title : `runas`
}
).then(()=>{
// runas returned.
try {
var runaslog = JSON.parse('[ { "success" : true, "result" : "runas Log" }' + fs.readFileSync('run.log', { flags : 'a+'}) + ']');
runaslog.forEach((logEntry)=>{
logEntry.success ? (console.log(['success :' + logEntry.result]), console.log((logEntry.messages || []).join(' '))) : (console.error(['error :' + logEntry.result]), console.error((logEntry.messages || []).join(' ')))
})
}
catch(e){
// Ignore nonexistent log
console.warn('Run log error probably was not created by runas : ' + e)
}
})
.catch(err => console.error('Elevation failed : ' + err));
}) })
.catch(err => console.error('Elevation failed : ' + err));
}) })
} }
, 'push' : ()=>{ , 'push' : ()=>{
if(opts.stdio !== 'ignore') { if(opts.stdio !== 'ignore') {
child.stdout.setEncoding('utf8'); child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8'); child.stderr.setEncoding('utf8');
child.stdout.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
child.on('error', (chunk) => { success = false; messages.push(chunk); /*console.error(chunk)*/ });
child.stderr.on('data', (chunk) => { messages.push(chunk); /*console.log(chunk)*/});
child.stdout.on('data', (chunk) => { chunk.trim() === '' ? null : messages.push(chunk); /* console.log('d: ' + chunk) */ });
child.on('error', (chunk) => { success = false; messages.push(chunk); /* console.error('e: ' + chunk) */ } );
child.stderr.on('data', (chunk) => { messages.push(chunk);
// console.error('stderr e: ' + chunk)
});
} }
child.on('close', (code) => { child.on('close', (code) => {
if(+code !== 0) success = false; if(+code !== 0) success = false;
} }
} }
if(code !== 0) return reject(code) if(code !== 0) return reject(code)
resolve(true)
resolve(messages)
}); });
} }
else { else {

+ 1
- 1
package.json 查看文件

"glob": "^7.1.2" "glob": "^7.1.2"
}, },
"bin": { "bin": {
"elxr": "./index.js"
"elxr": "bin/elxr"
} }
} }

Loading…
取消
儲存