UNPKG

appium-adb

Version:

Android Debug Bridge interface

59 lines 2.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getResourcePath = void 0; exports.unzipFile = unzipFile; const node_path_1 = __importDefault(require("node:path")); const support_1 = require("@appium/support"); const logger_1 = require("../../logger"); const constants_1 = require("./constants"); exports.getResourcePath = support_1.util.memoize(async function getResourcePath(relPath) { const moduleRoot = await getModuleRoot(); const resultPath = node_path_1.default.resolve(moduleRoot, relPath); if (!(await support_1.fs.exists(resultPath))) { throw new Error(`Cannot find the resource '${relPath}' under the '${moduleRoot}' ` + `folder of ${constants_1.MODULE_NAME} Node.js module`); } return resultPath; }); /** * Unzips an archive into the target destination directory. * * @param zipPath - Source zip file path * @param dstRoot - Destination directory. Defaults to zip parent directory */ async function unzipFile(zipPath, dstRoot = node_path_1.default.dirname(zipPath)) { logger_1.log.debug(`Unzipping '${zipPath}' to '${dstRoot}'`); await support_1.zip.assertValidZip(zipPath); await support_1.zip.extractAllTo(zipPath, dstRoot); logger_1.log.debug('Unzip successful'); } const getModuleRoot = support_1.util.memoize(async function getModuleRoot() { let moduleRoot = node_path_1.default.dirname(node_path_1.default.resolve(__filename)); let isAtFsRoot = false; while (!isAtFsRoot) { const manifestPath = node_path_1.default.join(moduleRoot, 'package.json'); try { if (await support_1.fs.exists(manifestPath)) { const manifestContent = await support_1.fs.readFile(manifestPath, 'utf8'); const manifest = JSON.parse(manifestContent); if (manifest.name === constants_1.MODULE_NAME) { return moduleRoot; } } } catch { // Ignore errors and continue searching } const parentDir = node_path_1.default.dirname(moduleRoot); isAtFsRoot = moduleRoot.length <= parentDir.length; moduleRoot = parentDir; } if (isAtFsRoot) { throw new Error(`Cannot find the root folder of the ${constants_1.MODULE_NAME} Node.js module`); } return moduleRoot; }); //# sourceMappingURL=resource.js.map