UNPKG

@geek-fun/serverlessinsight

Version:

Full life cycle cross providers serverless application management for your fast-growing business.

37 lines (36 loc) 1.71 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractZipFile = void 0; const jszip_1 = __importDefault(require("jszip")); const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); const node_os_1 = __importDefault(require("node:os")); const extractZipFile = async (zipPath) => { const zipData = node_fs_1.default.readFileSync(zipPath); const zip = await jszip_1.default.loadAsync(zipData); const tempDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'si-function-')); for (const [relativePath, file] of Object.entries(zip.files)) { if (file.dir) { node_fs_1.default.mkdirSync(node_path_1.default.join(tempDir, relativePath), { recursive: true }); } else { const content = await file.async('nodebuffer'); const filePath = node_path_1.default.join(tempDir, relativePath); node_fs_1.default.mkdirSync(node_path_1.default.dirname(filePath), { recursive: true }); node_fs_1.default.writeFileSync(filePath, content); } } // Check if there's a single root directory in the zip const entries = node_fs_1.default.readdirSync(tempDir); if (entries.length === 1) { const singleEntry = node_path_1.default.join(tempDir, entries[0]); if (node_fs_1.default.statSync(singleEntry).isDirectory()) { return singleEntry; } } return tempDir; }; exports.extractZipFile = extractZipFile;