UNPKG

logkitten

Version:

Stream Android and iOS logs without Android Studio or Console.app, with programmatic Node.js API for log analysis.

47 lines (46 loc) 1.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAdbPath = getAdbPath; exports.getSdkRoot = getSdkRoot; exports.run = run; exports.spawnLogcatProcess = spawnLogcatProcess; var _child_process = require("child_process"); var _path = _interopRequireDefault(require("path")); var _errors = require("../errors"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function run({ adbPath, deviceId }) { const execPath = getAdbPath(adbPath); return spawnLogcatProcess(execPath, deviceId); } function getSdkRoot() { var _process$env$ANDROID_; return (_process$env$ANDROID_ = process.env.ANDROID_SDK_ROOT) !== null && _process$env$ANDROID_ !== void 0 ? _process$env$ANDROID_ : process.env.ANDROID_HOME; } function getAdbPath(customPath) { if (customPath) { return _path.default.resolve(customPath); } const sdkRoot = getSdkRoot(); return sdkRoot ? `${sdkRoot}/platform-tools/adb` : 'adb'; } function spawnLogcatProcess(adbPath, deviceId) { const baseArgs = deviceId ? ['-s', deviceId] : []; try { (0, _child_process.execFileSync)(adbPath, [...baseArgs, 'logcat', '-c']); } catch (error) { throw new _errors.CodeError(_errors.ERR_ANDROID_CANNOT_CLEAN_LOGCAT_BUFFER, error.message); } try { return (0, _child_process.spawn)(adbPath, [...baseArgs, 'logcat', '-v', 'epoch,uid,threadtime,usec,printable,year,zone'], { stdio: 'pipe' }); } catch (error) { throw new _errors.CodeError(_errors.ERR_ANDROID_CANNOT_START_LOGCAT, error.message); } } //# sourceMappingURL=runner.js.map