-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8b434e6
Showing
5 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# AI Toolkit (aitk) | ||
|
||
AI Toolkit is a command-line utility for listing and dumping file contents in a directory structure, designed to assist with AI-related tasks. | ||
|
||
## Installation | ||
|
||
To install the AI Toolkit globally, run: | ||
|
||
```bash | ||
npm install -g @markwylde/ai-toolkit | ||
``` | ||
|
||
## Usage | ||
|
||
```bash | ||
aitk [command] [directory] | ||
``` | ||
|
||
### Commands | ||
|
||
- `cat`: Dump all file contents into a text file | ||
- `ls`: Show a recursive directory tree of all files | ||
- `help`: Show the help message | ||
|
||
### Options | ||
|
||
- `--help`: Show help message | ||
|
||
## Examples | ||
|
||
1. List all files in the current directory: | ||
```bash | ||
aitk ls | ||
``` | ||
|
||
2. Dump contents of all files in a specific directory: | ||
```bash | ||
aitk cat | ||
``` | ||
|
||
3. Show help message: | ||
```bash | ||
aitk help | ||
``` | ||
|
||
## Features | ||
|
||
- Recursively lists files in a directory | ||
- Ignores specified files and directories (e.g., `.git`, `node_modules`) | ||
- Ignores files with specific extensions (e.g., `png`, `svg`, `jpg`) | ||
- Dumps file contents with file paths as headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env node | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
import minimist from 'minimist'; | ||
|
||
const ignore = ['.terraform.lock.hcl', '.terraform', '.git', '.DS_Store', 'node_modules', 'package-lock.json', 'coverage']; | ||
const ignoreExtensions = ['png', 'svg', 'jpg', 'jpeg', 'bin']; | ||
|
||
// Function to list all files recursively | ||
function listFiles(dir, dumpContent = false, output = '', baseDir = dir) { | ||
const files = fs.readdirSync(dir, { withFileTypes: true }); | ||
files.forEach(file => { | ||
const ext = file.name.split('.').at(-1); | ||
if (ignore.includes(file.name) || ignoreExtensions.includes(ext)) { | ||
return; | ||
} | ||
const filePath = path.join(dir, file.name); | ||
const relativePath = path.relative(baseDir, filePath); | ||
if (file.isDirectory()) { | ||
output = listFiles(filePath, dumpContent, output, baseDir); | ||
} else { | ||
if (dumpContent) { | ||
output += `# ${relativePath}\n`; | ||
} else { | ||
output += `- ${relativePath}\n`; | ||
} | ||
if (dumpContent) { | ||
output += "```\n"; | ||
try { | ||
const content = fs.readFileSync(filePath, 'utf8'); | ||
output += content + "\n"; | ||
} catch (err) { | ||
output += `Error reading file: ${err.message}\n`; | ||
} | ||
output += "```\n\n"; | ||
} | ||
} | ||
}); | ||
return output; | ||
} | ||
|
||
// Parse command line arguments | ||
const argv = minimist(process.argv.slice(2)); | ||
|
||
// Help message | ||
const helpMessage = ` | ||
Usage: aitk [command] [directory] | ||
Commands: | ||
cat Dump all file contents into a text file | ||
ls Show a recursive directory tree of all files | ||
help Show this help message | ||
Options: | ||
--help Show help message | ||
`; | ||
|
||
// Main function | ||
function main() { | ||
if (argv.help || argv._.includes('help') || argv._.length === 0) { | ||
console.log(helpMessage); | ||
return; | ||
} | ||
|
||
const command = argv._[0]; | ||
const directory = argv._[1] || process.cwd(); | ||
|
||
if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) { | ||
console.error(`Error: "${directory}" is not a valid directory.`); | ||
return; | ||
} | ||
|
||
let output = ''; | ||
|
||
switch (command) { | ||
case 'cat': | ||
output = listFiles(directory, true); | ||
console.log(output); | ||
console.log('File contents dumped to output.txt'); | ||
break; | ||
case 'ls': | ||
output = listFiles(directory, false); | ||
console.log(output); | ||
break; | ||
default: | ||
console.log('Invalid command. Use "aitk help" for usage information.'); | ||
} | ||
} | ||
|
||
main(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "ai-toolkit", | ||
"version": "1.0.0", | ||
"bin": { | ||
"aitk": "bin/index.js" | ||
}, | ||
"type": "module", | ||
"main": "bin/index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"files": [ | ||
"bin" | ||
], | ||
"keywords": [], | ||
"author": { | ||
"email": "[email protected]", | ||
"name": "Mark Wylde", | ||
"url": "https://markwylde.com" | ||
}, | ||
"license": "MIT", | ||
"description": "A set of utilities for working with ai tools", | ||
"dependencies": { | ||
"minimist": "^1.2.8" | ||
} | ||
} |