first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+38
View File
@@ -0,0 +1,38 @@
# adb-driver
[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
## usage
sample1
```javascript
const adbDriver = require('adb-driver')
const { execADBCommand } = adbDriver
execADBCommand(`adb devices`).then(result => {
if (result instanceof Error) {
console.error(`fail to execute adb devices`)
return
}
console.info(`you can parse your devices info here: ${result}`)
})
```
sample2
```javascript
const adbDriver = require('adb-driver')
const { execADBCommand } = adbDriver
async function getDevices(callback) {
const result = await execADBCommand(`adb devices`)
if (result instanceof Error) {
console.error(`fail to execute adb devices`)
return callback(result)
}
console.log(`you can parse your devices info here`)
callback(null, result)
}
```
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
export declare const ADB_BINARY_FILE: {
[key: string]: string;
};
export declare function isSystemAdbAvailable(): boolean;
export declare function execADBCommand(command: string, option?: object): Promise<any>;
+36
View File
@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const child_process_1 = require("child_process");
const which = require("which");
const base = path.resolve(__dirname, '..', 'bin');
exports.ADB_BINARY_FILE = {
win32: path.resolve(base, 'window/adb.exe'),
darwin: path.resolve(base, 'mac/adb'),
linux: path.resolve(base, 'linux/adb'),
};
function isSystemAdbAvailable() {
return !!which.sync('adb', { nothrow: true });
}
exports.isSystemAdbAvailable = isSystemAdbAvailable;
let systemAdbExist = isSystemAdbAvailable();
function execADBCommand(command, option) {
let execCmd = command;
if (!systemAdbExist) {
let cmd = command.split(' ');
const binFile = exports.ADB_BINARY_FILE[process.platform];
cmd[0] = `"${binFile}"`;
execCmd = cmd.join(' ');
}
return new Promise((resolve, reject) => {
child_process_1.exec(execCmd, option || { stdio: 'inherit' }, (err, stdout, stderr) => {
if (err) {
reject(err);
}
resolve(stdout);
});
}).catch(err => {
return err;
});
}
exports.execADBCommand = execADBCommand;
+50
View File
@@ -0,0 +1,50 @@
{
"name": "adb-driver",
"version": "0.1.8",
"description": "A ADB(Android Debugging Bridge) command executor",
"files": [
"build",
"bin"
],
"main": "build/AdbDriver.js",
"license": "MIT",
"author": "cangpeng<dustyface@163.com>",
"scripts": {
"start": "tsc -w",
"clean": "rimraf build",
"format": "prettier \"{examples,lib,script,test}/**/*.{js,ts}\" \"*.yml\" --write",
"test": "jest",
"build": "npm run clean && tsc -p ./tsconfig.json"
},
"jest": {
"testEnvironment": "node",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testMatch": [
"**/?(*.)(spec|test).(ts|tsx|js)",
"**/__tests__/*.(ts|tsx|js)",
"**/test/*.(ts|tsx|js)"
]
},
"devDependencies": {
"@types/jest": "23.3.11",
"@types/node": "10.12.18",
"@types/which": "^1.3.1",
"jest": "23.6.0",
"prettier": "1.15.3",
"rimraf": "2.6.3",
"ts-jest": "23.10.5",
"ts-node": "6.0.0",
"typescript": "3.2.4"
},
"dependencies": {
"which": "^1.3.1"
},
"gitHead": "58b25bdcf3334eb1dcd0f10329d327697086d203"
}