adb-driver
Advanced tools
Comparing version 0.0.5 to 0.0.6
61
index.js
const path= require('path') | ||
const path = require('path') | ||
const exec = require('child_process').exec | ||
class ADBDriver { | ||
/** | ||
* 执行adb命令 | ||
* | ||
* @param command {string} adb命令 | ||
* @param option {object} 配置exec启动进程的选项 | ||
* @returns {Promise<String, Error>} 成功时返回stdout输出, 执行失败返回Error对象 | ||
*/ | ||
static execCommand (command, option) { | ||
let cmd = command.split(' ') | ||
const binFile = ADBDriver.ADB_BINARY_FILE[process.platform] | ||
cmd[0] = binFile | ||
cmd = cmd.join(' ') | ||
return new Promise((resolve, reject) => { | ||
exec(cmd, option || { 'stdio': 'inherit'}, (err, stdout, stderr) => { | ||
if (err) { | ||
console.error(`ADBDriver::execCommand: ${command} 执行出错: ${err.message}`) | ||
reject(err) | ||
} | ||
resolve(stdout) | ||
}) | ||
}).catch(err => { | ||
return err | ||
}) | ||
} | ||
} | ||
/** | ||
@@ -37,3 +9,3 @@ * binary文件位置信息 | ||
*/ | ||
ADBDriver.ADB_BINARY_FILE = { | ||
const ADB_BINARY_FILE = { | ||
'win32': path.resolve(__dirname, 'bin/window/adb.exe'), | ||
@@ -44,2 +16,29 @@ 'darwin': path.resolve(__dirname, 'bin/mac/adb'), | ||
module.exports = ADBDriver | ||
/** | ||
* 执行adb命令 | ||
* | ||
* @param command {string} adb命令 | ||
* @param option {object} 配置exec启动进程的选项 | ||
* @returns {Promise<String, Error>} 成功时返回stdout输出, 执行失败返回Error对象 | ||
*/ | ||
function execADBCommand (command, option) { | ||
let cmd = command.split(' ') | ||
const binFile = ADB_BINARY_FILE[process.platform] | ||
cmd[0] = binFile | ||
cmd = cmd.join(' ') | ||
return new Promise((resolve, reject) => { | ||
exec(cmd, option || { 'stdio': 'inherit' }, (err, stdout, stderr) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
resolve(stdout) | ||
}) | ||
}).catch(err => { | ||
return err | ||
}) | ||
} | ||
module.exports = { | ||
'exec': execADBCommand | ||
} |
{ | ||
"name": "adb-driver", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A ADB(Android Debugging Bridge) command executor", | ||
@@ -9,7 +9,3 @@ "main": "index.js", | ||
}, | ||
"author": [ | ||
"cangpeng<dustyface@163.com>", | ||
"diydyq<diydyq@126.com>", | ||
"yupeng528<etcyby@126.com>" | ||
] | ||
"author": "cangpeng<dustyface@163.com>" | ||
} |
@@ -8,11 +8,11 @@ # adb-driver | ||
```javascript | ||
const ADBDriver = require('adb-driver') | ||
const adbDriver = require('adb-driver') | ||
const { exec } = adbDriver | ||
ADBDriver.exeCommand(`adb devices`) | ||
exec(`adb devices`) | ||
.then((result) => { | ||
if (result instanceof Error) { | ||
console.error(`fail to execute adb devices`) | ||
return | ||
console.error(`fail to execute adb devices`) | ||
return | ||
} | ||
console.info(`you can parse your devices info here: ${result}`) | ||
@@ -26,6 +26,7 @@ }) | ||
```javascript | ||
const ADBDriver = require('adb-driver') | ||
const adbDriver = require('adb-driver') | ||
const { exec } = adbDriver | ||
async function getDevices (callback) { | ||
const result = await adbDriver.execCommand(`adb devices`) | ||
const result = await exec(`adb devices`) | ||
if (result instanceof Error) { | ||
@@ -35,3 +36,2 @@ console.error(`fail to execute adb devices`) | ||
} | ||
console.log(`you can parse your devices info here`) | ||
@@ -38,0 +38,0 @@ callback(null, result) |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
2
7231112
37