Skip to content

Commit

Permalink
Update README.md to reflect changes in project structure and file con…
Browse files Browse the repository at this point in the history
…tents; replaced 'utils.ts' with 'example.js' and added a simple example code snippet. Removed redundant text in the contributing section for clarity.
  • Loading branch information
alwalxed committed Dec 21, 2024
1 parent 17290b9 commit 47fef13
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ The output JSON file contains two main sections:

```json
{
"project_structure": ["utils.ts"],
"project_structure": ["example.js"],
"file_contents": {
"utils.ts": {
"content": "import fs from \"fs\";\nimport path from \"path\";\n\nexport function loadGitignore(directory: string): string[] {\n const gitignorePath = path.join(directory, \".gitignore\");\n if (!fs.existsSync(gitignorePath)) return [];\n\n const gitignoreContent = fs.readFileSync(gitignorePath, \"utf-8\");\n return gitignoreContent\n .split(\"\\n\")\n .filter((line) => line && !line.startsWith(\"#\"))\n .map((line) => line.trim());\n}\n\nexport function getAllFiles(\n dirPath: string,\n ignoredFiles: string[],\n arrayOfFiles: string[] = [],\n): string[] {\n const files = fs.readdirSync(dirPath);\n\n files.forEach((file) => {\n const fullPath = path.join(dirPath, file);\n\n if (ignoredFiles.some((ignored) => fullPath.includes(ignored))) return;\n\n if (fs.statSync(fullPath).isDirectory()) {\n arrayOfFiles = getAllFiles(fullPath, ignoredFiles, arrayOfFiles);\n } else {\n arrayOfFiles.push(fullPath);\n }\n });\n\n return arrayOfFiles;\n}\n\ninterface FileContent {\n content: string;\n extension: string;\n}\n\ninterface AIContext {\n project_structure: string[];\n file_contents: {\n [key: string]: FileContent;\n };\n}\n\nexport function generateAIFriendlyOutput(\n directory: string,\n outputFile: string,\n selectedFiles: string[],\n): void {\n if (selectedFiles.length === 0) {\n throw new Error(\"No files selected for output generation.\");\n }\n\n const context: AIContext = {\n project_structure: [],\n file_contents: {},\n };\n\n selectedFiles.forEach((file) => {\n const relativePath = path.relative(directory, file);\n\n try {\n const fileContent = fs.readFileSync(file, \"utf-8\");\n\n context.project_structure.push(relativePath);\n\n context.file_contents[relativePath] = {\n content: fileContent,\n extension: path.extname(file).slice(1) // Remove the leading dot\n };\n } catch (error) {\n console.warn(`Warning: Unable to read file ${file}. It will be skipped.`);\n }\n });\n\n if (Object.keys(context.file_contents).length === 0) {\n throw new Error(\"No valid files could be read for output generation.\");\n }\n\n fs.writeFileSync(outputFile, JSON.stringify(context, null, 2), \"utf-8\");\n}",
"extension": "ts"
"example.js": {
"content": "console.log('Hello, World!');",
"extension": "js"
}
}
}
```

## Contributing

We welcome contributions! Submit issues or pull requests to help improve this tool.
Submit issues or pull requests to help improve this tool.

## License

Expand Down

0 comments on commit 47fef13

Please sign in to comment.