Skip to content

Commit b161f9e

Browse files
committed
v1.0.16
1 parent ea5a0e9 commit b161f9e

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

.defaultignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.env
44
.git
55
.gitignore
6+
.gitattributes
67
vendor
78
node_modules
89
*.lock

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "llm-prepare",
3-
"version": "1.0.15",
3+
"version": "1.0.16",
44
"description": "llm-prepare converts complex project directory structures and files into a single flat file or a set of flat files, facilitating processing using In-Context Learning (ICL) prompts.",
55
"author": "Sam Estrin",
66
"license": "MIT",

src/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async function main(argv) {
101101
let layoutIncluded = false;
102102

103103
if ("show-default-ignore" in argv) {
104-
await showDefaultIgnore();
104+
await showDefaultIgnore(argv);
105105
return;
106106
} else if ("show-prompts" in argv) {
107107
const open = (await import("open")).default;
@@ -116,7 +116,6 @@ async function main(argv) {
116116
);
117117

118118
const ig = await readIgnoreFiles(argv["path"], argv["default-ignore"], argv);
119-
120119
const {
121120
layout: updatedLayout,
122121
singleFileOutput,

src/utils/errorHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ function handleError(error) {
99
if (!process.env.ENV && false) {
1010
console.error(`Unhandled error: ${error.message}`);
1111
} else {
12-
console.log(`${error.message}`);
13-
console.log(` at ${error.stack}`);
12+
console.error(`${error.message}`);
13+
console.error(` at ${error.stack}`);
1414
}
1515
}
1616

src/utils/ignoreUtils.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// utils/ignoreUtils.js
2+
13
const ignore = require("ignore");
24
const fs = require("fs-extra");
35
const path = require("path");
@@ -17,8 +19,8 @@ async function readIgnoreFiles(dir, defaultIgnorePath = false, argv) {
1719
const ig = ignore();
1820

1921
if (!defaultIgnorePath)
20-
defaultIgnorePath = path.join(__dirname, ".defaultignore");
21-
22+
defaultIgnorePath = path.join(__dirname, "../../.defaultignore");
23+
console.log(defaultIgnorePath);
2224
// Attempt to load .defaultignore with specific error handling
2325
try {
2426
if (await fileExists(defaultIgnorePath)) {
@@ -86,6 +88,9 @@ async function readIgnoreFiles(dir, defaultIgnorePath = false, argv) {
8688
}
8789
}
8890

91+
// Debugging: Log the ignore patterns
92+
//console.log("Ignore patterns loaded:", ig._rules);
93+
8994
return ig;
9095
}
9196

@@ -107,10 +112,11 @@ function filterIgnoreContent(content) {
107112
* Shows the contents of the default ignore file configured in the system.
108113
* This function reads the content of the specified default ignore file and prints it to the console.
109114
*
115+
* @param {object} argv - Command-line arguments that might affect ignore rules.
110116
* @returns {Promise<void>} A promise that resolves when the operation is complete.
111117
* @throws {Error} If there is an error reading the default ignore file.
112118
*/
113-
async function showDefaultIgnore() {
119+
async function showDefaultIgnore(argv) {
114120
const defaultIgnorePath =
115121
argv["default-ignore"] || path.join(__dirname, ".defaultignore");
116122
try {

src/utils/processDirectory.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,31 @@ async function processDirectory(
3434
let layout = depth === 0 && !layoutIncluded ? `/${baseDir}\n` : "";
3535
let singleFileOutput = [];
3636
const entries = await fs.readdir(dir);
37-
const notIgnoredEntries = ig.filter(entries).sort();
3837

39-
for (let i = 0; i < notIgnoredEntries.length; i++) {
40-
const entry = notIgnoredEntries[i];
38+
// Map entries to their relative paths for filtering
39+
const relativePaths = entries.map((entry) =>
40+
path.relative(baseDir, path.join(dir, entry)),
41+
);
42+
43+
// Filter entries using ignore rules
44+
const filteredEntries = entries
45+
.filter((entry, index) => !ig.ignores(relativePaths[index]))
46+
.sort();
47+
48+
for (let i = 0; i < filteredEntries.length; i++) {
49+
const entry = filteredEntries[i];
4150
const entryPath = path.join(dir, entry);
4251
const stats = await fs.stat(entryPath);
4352

44-
let prefix = computePrefix(
45-
depth,
46-
lastItemStack,
47-
i,
48-
notIgnoredEntries.length,
49-
);
53+
let prefix = computePrefix(depth, lastItemStack, i, filteredEntries.length);
5054

5155
if (stats.isDirectory()) {
5256
const childResult = await processDirectory(
5357
entryPath,
5458
baseDir,
5559
ig,
5660
depth + 1,
57-
lastItemStack.concat(i === notIgnoredEntries.length - 1),
61+
lastItemStack.concat(i === filteredEntries.length - 1),
5862
filePattern,
5963
layoutIncluded,
6064
argv,

0 commit comments

Comments
 (0)