UNPKG

sui-direct

Version:

Decentralized version control system on SUI blockchain

86 lines (85 loc) 3.45 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.zipFolderIgnoringGitignore = zipFolderIgnoringGitignore; exports.extractZipToFolder = extractZipToFolder; const ignore_1 = __importDefault(require("ignore")); const zip_lib_1 = require("zip-lib"); const zipLib = __importStar(require("zip-lib")); const path_1 = require("path"); const fs_1 = require("fs"); async function zipFolderIgnoringGitignore(folderPath, password) { const gitignorePath = (0, path_1.join)(folderPath, ".gitignore"); let ig = (0, ignore_1.default)(); if ((0, fs_1.existsSync)(gitignorePath)) { ig = (0, ignore_1.default)().add((0, fs_1.readFileSync)(gitignorePath, "utf-8")); } function walkDir(dir) { return (0, fs_1.readdirSync)(dir).flatMap((file) => { const filePath = (0, path_1.join)(dir, file); const relativePath = (0, path_1.relative)(folderPath, filePath); if (ig.ignores(relativePath)) return []; const stat = (0, fs_1.statSync)(filePath); return stat.isDirectory() ? walkDir(filePath) : [filePath]; }); } const zip = new zip_lib_1.Zip(); const filesToZip = walkDir(folderPath); for (const filePath of filesToZip) { zip.addFile(filePath, (0, path_1.relative)(folderPath, filePath)); } const zipName = `direct-${Date.now()}.zip`; await zip.archive(zipName); return { name: zipName, }; } async function extractZipToFolder(zipPath, extractPath, password) { // Create the extraction directory if it doesn't exist if (!(0, fs_1.existsSync)(extractPath)) { (0, fs_1.mkdirSync)(extractPath, { recursive: true }); } try { // Use the zipLib.extract method (zip-lib's extract function) await zipLib.extract(zipPath, extractPath); } catch (error) { throw new Error(`Failed to extract zip file: ${error}`); } }