|
| 1 | +"use strict"; |
| 2 | +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
| 3 | + if (k2 === undefined) k2 = k; |
| 4 | + var desc = Object.getOwnPropertyDescriptor(m, k); |
| 5 | + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { |
| 6 | + desc = { enumerable: true, get: function() { return m[k]; } }; |
| 7 | + } |
| 8 | + Object.defineProperty(o, k2, desc); |
| 9 | +}) : (function(o, m, k, k2) { |
| 10 | + if (k2 === undefined) k2 = k; |
| 11 | + o[k2] = m[k]; |
| 12 | +})); |
| 13 | +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { |
| 14 | + Object.defineProperty(o, "default", { enumerable: true, value: v }); |
| 15 | +}) : function(o, v) { |
| 16 | + o["default"] = v; |
| 17 | +}); |
| 18 | +var __importStar = (this && this.__importStar) || (function () { |
| 19 | + var ownKeys = function(o) { |
| 20 | + ownKeys = Object.getOwnPropertyNames || function (o) { |
| 21 | + var ar = []; |
| 22 | + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; |
| 23 | + return ar; |
| 24 | + }; |
| 25 | + return ownKeys(o); |
| 26 | + }; |
| 27 | + return function (mod) { |
| 28 | + if (mod && mod.__esModule) return mod; |
| 29 | + var result = {}; |
| 30 | + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); |
| 31 | + __setModuleDefault(result, mod); |
| 32 | + return result; |
| 33 | + }; |
| 34 | +})(); |
| 35 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 36 | +exports.FsUtils = void 0; |
| 37 | +const fs = __importStar(require("fs/promises")); |
| 38 | +const path = __importStar(require("path")); |
| 39 | +class FsUtils { |
| 40 | + static async getFileSize(filePath) { |
| 41 | + const stats = await fs.stat(filePath); |
| 42 | + return stats.size; |
| 43 | + } |
| 44 | + static async createTempDirectoryRecursive(prefix = 'asmx-package') { |
| 45 | + const os = require('os'); |
| 46 | + const tempDir = path.join(os.tmpdir(), `${prefix}-${Date.now()}`); |
| 47 | + await fs.mkdir(tempDir, { recursive: true }); |
| 48 | + return tempDir; |
| 49 | + } |
| 50 | + static async copyDirectoryRecursive(src, dest) { |
| 51 | + await fs.mkdir(dest, { recursive: true }); |
| 52 | + const entries = await fs.readdir(src, { withFileTypes: true }); |
| 53 | + for (const entry of entries) { |
| 54 | + const srcPath = path.join(src, entry.name); |
| 55 | + const destPath = path.join(dest, entry.name); |
| 56 | + if (entry.isDirectory()) { |
| 57 | + await this.copyDirectoryRecursive(srcPath, destPath); |
| 58 | + } |
| 59 | + else { |
| 60 | + await fs.copyFile(srcPath, destPath); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + static async removeDirectoryRecursive(dir) { |
| 65 | + try { |
| 66 | + await fs.rm(dir, { recursive: true, force: true }); |
| 67 | + } |
| 68 | + catch (error) { |
| 69 | + // Ignore errors if the directory does not exist |
| 70 | + } |
| 71 | + } |
| 72 | + static async checkFilePermissions(filePath) { |
| 73 | + try { |
| 74 | + await fs.access(filePath, fs.constants.R_OK); |
| 75 | + const readable = true; |
| 76 | + let writable = false; |
| 77 | + try { |
| 78 | + await fs.access(filePath, fs.constants.W_OK); |
| 79 | + writable = true; |
| 80 | + } |
| 81 | + catch { } |
| 82 | + let executable = false; |
| 83 | + try { |
| 84 | + await fs.access(filePath, fs.constants.X_OK); |
| 85 | + executable = true; |
| 86 | + } |
| 87 | + catch { } |
| 88 | + return { readable, writable, executable }; |
| 89 | + } |
| 90 | + catch { |
| 91 | + return { readable: false, writable: false, executable: false }; |
| 92 | + } |
| 93 | + } |
| 94 | + static async setFilePermissions(filePath, mode) { |
| 95 | + await fs.chmod(filePath, mode); |
| 96 | + } |
| 97 | + static async getAllFiles(dir, excludeDirs = []) { |
| 98 | + const files = []; |
| 99 | + async function scan(currentDir) { |
| 100 | + const entries = await fs.readdir(currentDir, { withFileTypes: true }); |
| 101 | + for (const entry of entries) { |
| 102 | + const fullPath = path.join(currentDir, entry.name); |
| 103 | + if (entry.isDirectory()) { |
| 104 | + const relativePath = path.relative(dir, fullPath); |
| 105 | + if (!excludeDirs.some(exclude => relativePath.startsWith(exclude))) { |
| 106 | + await scan(fullPath); |
| 107 | + } |
| 108 | + } |
| 109 | + else if (entry.isFile()) { |
| 110 | + files.push(fullPath); |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + await scan(dir); |
| 115 | + return files; |
| 116 | + } |
| 117 | +} |
| 118 | +exports.FsUtils = FsUtils; |
0 commit comments