UNPKG

swagger-auto-generate

Version:

Automatically generate Swagger JSDoc documentation for Express applications

106 lines 3.79 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; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.FileScanner = void 0; const glob_1 = require("glob"); const path = __importStar(require("path")); class FileScanner { constructor(config) { this.config = config; } /** * Scan all input folders for JavaScript and TypeScript files */ async scanFiles() { const allFiles = []; const ignorePatterns = this.getIgnorePatterns(); for (const folder of this.config.inputFolders) { try { const pattern = path.join(folder, '**/*.{js,ts}'); const files = await (0, glob_1.glob)(pattern, { ignore: ignorePatterns, absolute: true, nodir: true, }); allFiles.push(...files); } catch (error) { console.warn(`Warning: Could not scan folder ${folder}:`, error); } } return allFiles.filter(file => { // Additional filtering to exclude test files and node_modules const relativePath = path.relative(process.cwd(), file); return !relativePath.includes('node_modules') && !relativePath.includes('__tests__') && !relativePath.includes('.test.') && !relativePath.includes('.spec.'); }); } /** * Get ignore patterns for file scanning */ getIgnorePatterns() { const defaultPatterns = [ '**/node_modules/**', '**/dist/**', '**/build/**', '**/.git/**', '**/coverage/**', '**/__mocks__/**', '**/*.test.js', '**/*.test.ts', '**/*.spec.js', '**/*.spec.ts', ]; return [...defaultPatterns, ...(this.config.ignorePatterns || [])]; } /** * Check if a file should be processed */ static shouldProcessFile(filePath) { const ext = path.extname(filePath).toLowerCase(); return ext === '.js' || ext === '.ts'; } /** * Get file content as string */ static async readFileContent(filePath) { const fs = await Promise.resolve().then(() => __importStar(require('fs/promises'))); return fs.readFile(filePath, 'utf-8'); } } exports.FileScanner = FileScanner; //# sourceMappingURL=fileScanner.js.map