UNPKG

projex

Version:
48 lines (47 loc) 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInformation = exports.getManifestContent = exports.getManifestsContent = exports.getFilesInCurrentDirectory = void 0; const path_1 = require("path"); const logger_1 = require("../logger"); const fs = require('fs'); const path = require('path'); let manifests = []; // Método que retorna los archivos en el directorio actual const getFilesInCurrentDirectory = (srcpath) => { return fs.readdirSync(srcpath).map((file) => path.join(srcpath, file)); }; exports.getFilesInCurrentDirectory = getFilesInCurrentDirectory; // Método que retorna un array con los directorios encontrados // Método que permite traer el contenido de todos los directorios indicados const getManifestsContent = async (files) => { await files.forEach(async (file) => { await (0, exports.getInformation)((0, path_1.resolve)(file)); }); return manifests; }; exports.getManifestsContent = getManifestsContent; // Método que permite traer el contenido de un solo directorio const getManifestContent = async (directory) => { await (0, exports.getInformation)((0, path_1.resolve)(directory)); return manifests[0]; }; exports.getManifestContent = getManifestContent; // Metodo que trae el contenido de un directorio indicado const getInformation = async (dir) => { try { if (fs.existsSync(`${dir}/manifest.json`)) { let result = await JSON.parse(fs.readFileSync(`${dir}/manifest.json`, 'utf8')); if (result) { result.path = dir; manifests.push(result); } } else { logger_1.log.debug(`manifest.json not found in directory: ${dir}`); } } catch (error) { logger_1.log.debug(`Error reading the manifest file in directory: ${dir}. Please check the file content.`); } }; exports.getInformation = getInformation;