From bde29c5684e031732aac79eee839b276fb625a33 Mon Sep 17 00:00:00 2001 From: Mark Wylde Date: Wed, 31 Jul 2024 15:38:58 +0100 Subject: [PATCH 1/3] feat: ignore multi file extensions --- bin/index.js | 71 +++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/bin/index.js b/bin/index.js index 686b1fc..eed8db2 100755 --- a/bin/index.js +++ b/bin/index.js @@ -4,40 +4,49 @@ 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 ignore = ['.next', '.husky', '.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 = '') { - const files = fs.readdirSync(dir, { withFileTypes: true }); - files.forEach(file => { - const ext = file.name.split('.').at(-1); - if (ignore.includes(file.name || (file.name.includes('.') && ignoreExtensions.includes(ext)))) { - return; - } - const filePath = path.join(dir, file.name); - const relativePath = path.join(baseDir, path.relative(dir, filePath)); - if (file.isDirectory()) { - output = listFiles(filePath, dumpContent, output, relativePath); - } 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; +function listFiles(dir, dumpContent = false, output = '', baseDir = '', depth = 0) { + const files = fs.readdirSync(dir, { withFileTypes: true }); + files.forEach((file, index) => { + const fileNameParts = file.name.split('.'); + const ext = fileNameParts.length > 1 ? fileNameParts.slice(-2).join('.') : fileNameParts[fileNameParts.length - 1]; + + if (ignore.includes(file.name) || ignoreExtensions.includes(ext)) { + return; + } + + const filePath = path.join(dir, file.name); + const relativePath = path.join(baseDir, path.relative(dir, filePath)); + const isLast = index === files.length - 1; + const prefix = depth === 0 ? '' : ' '.repeat(depth - 1) + (isLast ? '└─ ' : '├─ '); + + if (file.isDirectory()) { + if (!dumpContent) { + output += `${prefix}${file.name}/\n`; + } + output = listFiles(filePath, dumpContent, output, relativePath, depth + 1); + } else { + if (dumpContent) { + output += `# ${relativePath}\n`; + } else { + output += `${prefix}${file.name}\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 From e4d8f09ed12f6a0ae7f7e398e24c6c79f0e9c967 Mon Sep 17 00:00:00 2001 From: Mark Wylde Date: Wed, 31 Jul 2024 15:39:36 +0100 Subject: [PATCH 2/3] Update index.js --- bin/index.js | 138 ++++++++++++++++++++++++++------------------------- 1 file changed, 70 insertions(+), 68 deletions(-) diff --git a/bin/index.js b/bin/index.js index eed8db2..3d8be30 100755 --- a/bin/index.js +++ b/bin/index.js @@ -5,48 +5,50 @@ import path from 'path'; import minimist from 'minimist'; const ignore = ['.next', '.husky', '.terraform.lock.hcl', '.terraform', '.git', '.DS_Store', 'node_modules', 'package-lock.json', 'coverage']; -const ignoreExtensions = ['png', 'svg', 'jpg', 'jpeg', 'bin']; +const ignoreExtensions = ['png', 'svg', 'jpg', 'jpeg', 'bin', 'stories.tsx']; // Function to list all files recursively function listFiles(dir, dumpContent = false, output = '', baseDir = '', depth = 0) { - const files = fs.readdirSync(dir, { withFileTypes: true }); - files.forEach((file, index) => { - const fileNameParts = file.name.split('.'); - const ext = fileNameParts.length > 1 ? fileNameParts.slice(-2).join('.') : fileNameParts[fileNameParts.length - 1]; - - if (ignore.includes(file.name) || ignoreExtensions.includes(ext)) { - return; - } - - const filePath = path.join(dir, file.name); - const relativePath = path.join(baseDir, path.relative(dir, filePath)); - const isLast = index === files.length - 1; - const prefix = depth === 0 ? '' : ' '.repeat(depth - 1) + (isLast ? '└─ ' : '├─ '); - - if (file.isDirectory()) { - if (!dumpContent) { - output += `${prefix}${file.name}/\n`; - } - output = listFiles(filePath, dumpContent, output, relativePath, depth + 1); - } else { - if (dumpContent) { - output += `# ${relativePath}\n`; - } else { - output += `${prefix}${file.name}\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"; - } + const files = fs.readdirSync(dir, { + withFileTypes: true + }); + files.forEach((file, index) => { + const fileNameParts = file.name.split('.'); + const ext = fileNameParts.length > 1 ? fileNameParts.slice(-2).join('.') : fileNameParts[fileNameParts.length - 1]; + + if (ignore.includes(file.name) || ignoreExtensions.includes(ext)) { + return; + } + + const filePath = path.join(dir, file.name); + const relativePath = path.join(baseDir, path.relative(dir, filePath)); + const isLast = index === files.length - 1; + const prefix = depth === 0 ? '' : ' '.repeat(depth - 1) + (isLast ? '└─ ' : '├─ '); + + if (file.isDirectory()) { + if (!dumpContent) { + output += `${prefix}${file.name}/\n`; + } + output = listFiles(filePath, dumpContent, output, relativePath, depth + 1); + } else { + if (dumpContent) { + output += `# ${relativePath}\n`; + } else { + output += `${prefix}${file.name}\n`; + } + if (dumpContent) { + output += "```\n"; + try { + const content = fs.readFileSync(filePath, 'utf8'); + output += content + "\n"; + } catch (err) { + output += `Error reading file: ${err.message}\n`; } - }); - return output; + output += "```\n\n"; + } + } + }); + return output; } // Parse command line arguments @@ -67,39 +69,39 @@ Options: // Main function function main() { - if (argv.help || argv._.includes('help') || argv._.length === 0) { - console.log(helpMessage); - return; - } + if (argv.help || argv._.includes('help') || argv._.length === 0) { + console.log(helpMessage); + return; + } - const command = argv._[0]; - const directories = argv._.slice(1); + const command = argv._[0]; + const directories = argv._.slice(1); - if (directories.length === 0) { - directories.push(process.cwd()); - } + if (directories.length === 0) { + directories.push(process.cwd()); + } - let output = ''; - - switch (command) { - case 'cat': - case 'ls': - directories.forEach(directory => { - if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) { - console.error(`Error: "${directory}" is not a valid directory.`); - return; - } - const baseName = path.basename(directory); - output += listFiles(directory, command === 'cat', '', baseName); - }); - console.log(output); - if (command === 'cat') { - console.log('File contents dumped to output.txt'); - } - break; - default: - console.log('Invalid command. Use "aitk help" for usage information.'); - } + let output = ''; + + switch (command) { + case 'cat': + case 'ls': + directories.forEach(directory => { + if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) { + console.error(`Error: "${directory}" is not a valid directory.`); + return; + } + const baseName = path.basename(directory); + output += listFiles(directory, command === 'cat', '', baseName); + }); + console.log(output); + if (command === 'cat') { + console.log('File contents dumped to output.txt'); + } + break; + default: + console.log('Invalid command. Use "aitk help" for usage information.'); + } } main(); From 86c73e0afc3142acf883eae67cd4418d43eba092 Mon Sep 17 00:00:00 2001 From: Mark Wylde Date: Wed, 31 Jul 2024 19:06:08 +0100 Subject: [PATCH 3/3] 1.3.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7cd84bf..e44d49d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@markwylde/ai-toolkit", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@markwylde/ai-toolkit", - "version": "1.2.0", + "version": "1.3.0", "license": "MIT", "dependencies": { "minimist": "^1.2.8" diff --git a/package.json b/package.json index 39e4478..3b4a55a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@markwylde/ai-toolkit", "private": false, - "version": "1.2.0", + "version": "1.3.0", "bin": { "aitk": "bin/index.js" },