UNPKG

tmrw-audit

Version:

tmrw audit: Your escape hatch from the cloud cage.

45 lines (44 loc) 1.7 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.scanCodebase = scanCodebase; const globby_1 = require("globby"); const analyzer_1 = require("./analyzer"); const dotenv_1 = __importDefault(require("dotenv")); const chalk_1 = __importDefault(require("chalk")); /** * Scans the codebase for relevant files and analyzes them for CLV scoring. * @param rootDir - The root directory of the codebase. * @returns A promise resolving to the scan results. * @throws Error if scanning fails or no files are found. */ async function scanCodebase(rootDir) { dotenv_1.default.config(); console.log('🔍 Scanning your codebase for traps...'); const patterns = process.env.FILE_PATTERNS?.split(',').map((p) => p.trim()) ?? [ '**/*.tf', '**/*.yml', '**/*.yaml', '**/Dockerfile', '**/package.json', '!node_modules/**', '!dist/**', '!build/**', '!vendor/**', ]; try { const files = await (0, globby_1.globby)(patterns, { cwd: rootDir, gitignore: true }); if (!files.length) { throw new Error('No infrastructure files found. The cloud hides, but we’ll find it. Check your .env FILE_PATTERNS.'); } if (process.env.DEBUG === 'true') { console.log(chalk_1.default.dim(`Found ${files.length} files: ${files.join(', ')}`)); } return await (0, analyzer_1.analyzeFiles)(files, rootDir); } catch (err) { throw new Error(`Scanning failed: ${err.message}`); } }