print-project
Advanced tools
Comparing version 1.0.11 to 1.0.12
@@ -35,8 +35,3 @@ #!/usr/bin/env node | ||
const program = new commander_1.Command(); | ||
program | ||
.argument("<startPath>", "Starting directory path") | ||
.option("--ignore <patterns>", "Comma-separated list of patterns to ignore") | ||
.option("--include <patterns>", "Comma-separated list of patterns to include") | ||
.option("--ignore-default", "Use default ignore patterns") | ||
.parse(process.argv); | ||
program.argument("<startPath>", "Starting directory path").option("--ignore <patterns>", "Comma-separated list of patterns to ignore").option("--include <patterns>", "Comma-separated list of patterns to include").option("--ignore-default", "Use default ignore patterns").parse(process.argv); | ||
const startPath = program.args[0] && path.resolve(program.args[0]); | ||
@@ -53,17 +48,27 @@ const options = program.opts(); | ||
function matchesPattern(filePath, patterns) { | ||
console.log(`\nChecking patterns for file: ${filePath}`); | ||
return patterns.some(pattern => { | ||
const escapedPattern = pattern | ||
.replace(/[.+^${}()|[\]\\]/g, '\\$&') | ||
.replace(/\*/g, '.*') | ||
.replace(/\?/g, '.'); | ||
const regex = new RegExp(`^${escapedPattern}$|/${escapedPattern}$|/${escapedPattern}/|^${escapedPattern}/`); | ||
return regex.test(filePath); | ||
// Escape special regex characters except * and ? | ||
const escapedPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, "."); | ||
const regex = new RegExp(escapedPattern, "i"); // Added 'i' flag for case-insensitive matching | ||
const matches = regex.test(filePath); | ||
console.log(` Pattern: ${pattern}`); | ||
console.log(` Regex: ${regex}`); | ||
console.log(` Matches: ${matches}`); | ||
return matches; | ||
}); | ||
} | ||
function shouldIncludeFile(filePath, ignorePatterns, includePatterns) { | ||
console.log(`\nEvaluating file: ${filePath}`); | ||
const isIgnored = matchesPattern(filePath, ignorePatterns); | ||
console.log(`Is ignored: ${isIgnored}`); | ||
const isIncluded = includePatterns.length === 0 || matchesPattern(filePath, includePatterns); | ||
console.log(`Is included: ${isIncluded}`); | ||
// If we have include patterns, they take precedence | ||
if (includePatterns.length > 0) { | ||
console.log(`Include patterns exist, returning: ${isIncluded}`); | ||
return isIncluded; | ||
} | ||
// Otherwise, include if not ignored | ||
console.log(`No include patterns, returning: ${!isIgnored}`); | ||
return !isIgnored; | ||
@@ -73,6 +78,11 @@ } | ||
try { | ||
console.log(`\nReading directory: ${dirPath}`); | ||
const dirents = fs.readdirSync(dirPath, { withFileTypes: true }); | ||
dirents.forEach((dirent) => { | ||
const fullPath = path.relative(process.cwd(), path.join(dirPath, dirent.name)).replace(/\\/g, "/"); | ||
if (!shouldIncludeFile(fullPath, ignorePatterns, includePatterns)) { | ||
console.log(`\nProcessing: ${fullPath}`); | ||
const include = shouldIncludeFile(fullPath, ignorePatterns, includePatterns); | ||
console.log(`Should include ${fullPath}: ${include}`); | ||
if (!include) { | ||
console.log(`Skipping ${fullPath}`); | ||
return; | ||
@@ -82,2 +92,3 @@ } | ||
if (dirent.isDirectory()) { | ||
console.log(`${fullPath} is a directory`); | ||
treeStructure[relativePath] = {}; | ||
@@ -87,2 +98,3 @@ readDirectory(path.join(dirPath, dirent.name), ignorePatterns, includePatterns, treeStructure[relativePath], relativePath); | ||
else if (dirent.isFile()) { | ||
console.log(`${fullPath} is a file`); | ||
treeStructure[relativePath] = {}; | ||
@@ -92,2 +104,3 @@ const content = fs.readFileSync(path.join(dirPath, dirent.name), "utf8"); | ||
projectPrint += `${fullPath}:\n${content}\n\n`; | ||
console.log(`Added ${fullPath} to project print`); | ||
} | ||
@@ -94,0 +107,0 @@ } |
{ | ||
"name": "print-project", | ||
"version": "1.0.11", | ||
"version": "1.0.12", | ||
"description": "A simple CLI tool to print the project tree structure and file contents", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -12,8 +12,3 @@ #!/usr/bin/env node | ||
const program = new Command(); | ||
program | ||
.argument("<startPath>", "Starting directory path") | ||
.option("--ignore <patterns>", "Comma-separated list of patterns to ignore") | ||
.option("--include <patterns>", "Comma-separated list of patterns to include") | ||
.option("--ignore-default", "Use default ignore patterns") | ||
.parse(process.argv); | ||
program.argument("<startPath>", "Starting directory path").option("--ignore <patterns>", "Comma-separated list of patterns to ignore").option("--include <patterns>", "Comma-separated list of patterns to include").option("--ignore-default", "Use default ignore patterns").parse(process.argv); | ||
@@ -34,9 +29,16 @@ const startPath: string | undefined = program.args[0] && path.resolve(program.args[0]); | ||
function matchesPattern(filePath: string, patterns: string[]): boolean { | ||
console.log(`\nChecking patterns for file: ${filePath}`); | ||
return patterns.some(pattern => { | ||
const escapedPattern = pattern | ||
.replace(/[.+^${}()|[\]\\]/g, '\\$&') | ||
.replace(/\*/g, '.*') | ||
.replace(/\?/g, '.'); | ||
const regex = new RegExp(`^${escapedPattern}$|/${escapedPattern}$|/${escapedPattern}/|^${escapedPattern}/`); | ||
return regex.test(filePath); | ||
// Escape special regex characters except * and ? | ||
const escapedPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, "."); | ||
const regex = new RegExp(escapedPattern, "i"); // Added 'i' flag for case-insensitive matching | ||
const matches = regex.test(filePath); | ||
console.log(` Pattern: ${pattern}`); | ||
console.log(` Regex: ${regex}`); | ||
console.log(` Matches: ${matches}`); | ||
return matches; | ||
}); | ||
@@ -46,7 +48,18 @@ } | ||
function shouldIncludeFile(filePath: string, ignorePatterns: string[], includePatterns: string[]): boolean { | ||
console.log(`\nEvaluating file: ${filePath}`); | ||
const isIgnored = matchesPattern(filePath, ignorePatterns); | ||
console.log(`Is ignored: ${isIgnored}`); | ||
const isIncluded = includePatterns.length === 0 || matchesPattern(filePath, includePatterns); | ||
console.log(`Is included: ${isIncluded}`); | ||
// If we have include patterns, they take precedence | ||
if (includePatterns.length > 0) { | ||
console.log(`Include patterns exist, returning: ${isIncluded}`); | ||
return isIncluded; | ||
} | ||
// Otherwise, include if not ignored | ||
console.log(`No include patterns, returning: ${!isIgnored}`); | ||
return !isIgnored; | ||
@@ -57,13 +70,24 @@ } | ||
try { | ||
console.log(`\nReading directory: ${dirPath}`); | ||
const dirents = fs.readdirSync(dirPath, { withFileTypes: true }); | ||
dirents.forEach((dirent) => { | ||
const fullPath = path.relative(process.cwd(), path.join(dirPath, dirent.name)).replace(/\\/g, "/"); | ||
if (!shouldIncludeFile(fullPath, ignorePatterns, includePatterns)) { | ||
console.log(`\nProcessing: ${fullPath}`); | ||
const include = shouldIncludeFile(fullPath, ignorePatterns, includePatterns); | ||
console.log(`Should include ${fullPath}: ${include}`); | ||
if (!include) { | ||
console.log(`Skipping ${fullPath}`); | ||
return; | ||
} | ||
const relativePath = path.join(currentPath, dirent.name).replace(/\\/g, "/"); | ||
if (dirent.isDirectory()) { | ||
console.log(`${fullPath} is a directory`); | ||
treeStructure[relativePath] = {}; | ||
readDirectory(path.join(dirPath, dirent.name), ignorePatterns, includePatterns, treeStructure[relativePath], relativePath); | ||
} else if (dirent.isFile()) { | ||
console.log(`${fullPath} is a file`); | ||
treeStructure[relativePath] = {}; | ||
@@ -73,2 +97,3 @@ const content = fs.readFileSync(path.join(dirPath, dirent.name), "utf8"); | ||
projectPrint += `${fullPath}:\n${content}\n\n`; | ||
console.log(`Added ${fullPath} to project print`); | ||
} | ||
@@ -75,0 +100,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23879
479