瀏覽代碼

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

master
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 查看文件

@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../index.js')

+ 43
- 32
index.js 查看文件

@@ -1,4 +1,5 @@
#!/usr/bin/env node

// 'use strict';

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

@@ -319,6 +320,7 @@ var __runcmd = function(label){
})
}
, 'runas' : ()=>{
console.log('Testing Elevation')
return isRunningElevated().then(
(isElevated) => {
if(isElevated) {
@@ -343,34 +345,41 @@ var __runcmd = function(label){
}
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' : ()=>{
@@ -1160,9 +1169,11 @@ function nodeShellExec() {
if(opts.stdio !== 'ignore') {
child.stdout.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) => {
if(+code !== 0) success = false;
@@ -1179,7 +1190,7 @@ function nodeShellExec() {
}
}
if(code !== 0) return reject(code)
resolve(true)
resolve(messages)
});
}
else {

+ 1
- 1
package.json 查看文件

@@ -14,6 +14,6 @@
"glob": "^7.1.2"
},
"bin": {
"elxr": "./index.js"
"elxr": "bin/elxr"
}
}

Loading…
取消
儲存