why does it include files like public/font-awesome-4.7.0/css/font-awesome.css even…
- User
why does it include files like public/font-awesome-4.7.0/css/font-awesome.css even though "font-awesome-4.7.0" is listed in excludedFolders?
- extension.js
const vscode = require('vscode'); const fs = require('fs'); const path = require('path'); const ignore = require('ignore'); function activate(context) { let disposable = vscode.commands.registerCommand('extension.code2prompt.listCodeBaseFiles', function () { const workspaceFolders = vscode.workspace.workspaceFolders; if (!workspaceFolders) { vscode.window.showErrorMessage('No workspace folder open'); return; } const rootPath = workspaceFolders[0].uri.fsPath; try { // Step 1: Collect all eligible files. const listOfFiles = collectFiles(rootPath); if (listOfFiles.length === 0) { vscode.window.showInformationMessage('No matching files found in the workspace'); } else { // Step 2: Show QuickPick for user selection. vscode.window.showQuickPick(listOfFiles, { canPickMany: true, placeHolder: 'Select files to include in codebase.md', }).then(selectedItems => { if (!selectedItems || selectedItems.length === 0) { vscode.window.showInformationMessage('No files selected'); return; } // Step 3: Generate codebase.md with selected files. const selectedFiles = selectedItems.map(item => item.label); const { totalFiles, outputFileSizeInKB } = generateCodebaseMarkdown(rootPath, selectedFiles); vscode.window.showInformationMessage(`${totalFiles} files have been written to codebase.md (${outputFileSizeInKB.toFixed(2)} kb)`); }); } } catch (error) { vscode.window.showErrorMessage(`Error: ${error.message}`); } }); context.subscriptions.push(disposable); } function collectFiles(rootPath) { const config = vscode.workspace.getConfiguration('code2prompt'); const allowedExtensions = config.get('allowedExtensions'); const excludedFolders = config.get('excludedFolders'); const excludedFiles = config.get('excludedFiles'); const excludedExtensions = config.get('excludedExtensions'); const MAX_FILE_SIZE = config.get('maxFileSize'); const ig = ignore(); if (fs.existsSync(path.join(rootPath, '.gitignore'))) { ig.add(fs.readFileSync(path.join(rootPath, '.gitignore')).toString()); } let listOfFiles = []; function traverseDirectory(dir) { const items = fs.readdirSync(dir); const files = []; const directories = []; for (const item of items) { const itemPath = path.join(dir, item); const stats = fs.statSync(itemPath); const relativePath = path.relative(rootPath, itemPath).replace(/\\/g, '/'); if (ig.ignores(relativePath)) { continue; } if (stats.isDirectory() && (excludedFolders.includes(item) || excludedFolders.some(excluded => itemPath.includes(excluded)))) { continue; } if (stats.isFile()) { if (!excludedFiles.includes(item)) { files.push(item); } } else if (stats.isDirectory()) { directories.push(item); } } files.sort((a, b) => a.localeCompare(b)); directories.sort((a, b) => a.localeCompare(b)); for (const file of files) { const filePath = path.join(dir, file); const ext = path.extname(file); const stats = fs.statSync(filePath); const fileSizeInBytes = stats.size; if (ext === '.css') { const jsFilePath = path.join(dir, `${path.basename(file, '.css')}.scss`); if (fs.existsSync(jsFilePath)) { continue; } } if (allowedExtensions.includes(ext) && !excludedExtensions.some(excluded => file.endsWith(excluded)) && fileSizeInBytes <= MAX_FILE_SIZE) { const relativePath = path.relative(rootPath, filePath).replace(/\\/g, '/'); if (!excludedFolders.some(folder => relativePath.includes(folder))) { listOfFiles.push({ label: relativePath, picked: true, description: `${(fileSizeInBytes / 1024).toFixed(2)} KB` }); } } } for (const directory of directories) { const dirPath = path.join(dir, directory); traverseDirectory(dirPath); } } traverseDirectory(rootPath); return listOfFiles; } function generateCodebaseMarkdown(rootPath, selectedFiles) { let totalFiles = 0; let markdownContent = ''; for (const relativePath of selectedFiles) { const filePath = path.join(rootPath, relativePath); const ext = path.extname(filePath).slice(1); try { const fileContent = fs.readFileSync(filePath, 'utf-8'); markdownContent += `\n- ${relativePath}\n\`\`\`${ext}\n${fileContent}\n\`\`\`\n`; totalFiles++; } catch (error) { vscode.window.showErrorMessage(`Error reading file ${relativePath}: ${error.message}`); } } if (markdownContent.length === 0) { return { totalFiles: 0, outputFileSizeInKB: 0 }; } const outputFile = path.join(rootPath, 'codebase.md'); fs.writeFileSync(outputFile, markdownContent); let outputFileSizeInKB = fs.statSync(outputFile).size / 1024; return { totalFiles, outputFileSizeInKB }; } function deactivate() { } module.exports = { activate, deactivate } - Assistant