UNPKG

gitly

Version:

An API to download and/or extract git repositories

35 lines (34 loc) 1.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_fs_1 = require("node:fs"); const node_path_1 = require("node:path"); const exists_1 = __importDefault(require("./exists")); const archive_1 = require("./archive"); const { mkdir } = node_fs_1.promises; /** * Extract a zipped file to the specified destination * @param source The source zipped file * @param destination The path to extract the zipped file * @param options * */ exports.default = async (source, destination, options = {}) => { var _a; const _destination = (0, node_path_1.resolve)(destination); if (await (0, exists_1.default)(source, options)) { try { const filter = ((_a = options.extract) === null || _a === void 0 ? void 0 : _a.filter) ? options.extract.filter : () => true; await mkdir(destination, { recursive: true }); await (0, archive_1.extract)({ strip: 1, filter, file: source, cwd: _destination }); return _destination; // eslint-disable-next-line no-empty } catch (_) { } } return ''; };