mh-two-thousand-and-two
2024-04-12 3d2ec2fd0578d3ba0a414b0cc4e4a2ae60878596
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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;