New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

print-project

Package Overview
Dependencies
Maintainers
0
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

print-project - npm Package Compare versions

Comparing version 1.0.18 to 1.0.19

45

dist/index.js

@@ -60,19 +60,20 @@ #!/usr/bin/env node

const regex = new RegExp(regexPattern, "i");
console.log(`Checking ${filePath} against pattern: ${pattern} (regex: ${regex})`);
const matches = regex.test(filePath);
console.log(`Match result: ${matches}`);
return matches;
return regex.test(filePath);
});
}
function shouldIncludeFile(filePath, ignorePatterns, includePatterns) {
console.log(`\nChecking file: ${filePath}`);
// If there are include patterns and file matches one, include it regardless of ignore patterns
if (includePatterns.length > 0) {
const isIncluded = matchesPattern(filePath, includePatterns);
console.log(`Include pattern match: ${isIncluded}`);
return isIncluded;
// First check if the file matches any include patterns
const isIncluded = includePatterns.length > 0 ? matchesPattern(filePath, includePatterns) : true;
// If the file doesn't match include patterns (when they exist), exclude it
if (!isIncluded) {
return false;
}
// Otherwise, exclude if it matches ignore patterns
// If the file matches include patterns (or there are no include patterns)
// AND doesn't match ignore patterns, include it
const isIgnored = matchesPattern(filePath, ignorePatterns);
console.log(`Ignore pattern match: ${isIgnored}`);
// Special case: if the file matches both include and ignore patterns,
// prioritize the include pattern
if (includePatterns.length > 0 && isIncluded) {
return true;
}
return !isIgnored;

@@ -82,21 +83,14 @@ }

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, "/");
console.log(`\nProcessing: ${fullPath}`);
if (dirent.isDirectory()) {
console.log(`${fullPath} is a directory`);
// If directory matches ignore pattern AND doesn't match include pattern, skip it
const shouldIgnoreDir = matchesPattern(fullPath, ignorePatterns) &&
(!includePatterns.length || !matchesPattern(fullPath, includePatterns));
if (shouldIgnoreDir) {
console.log(`Skipping ignored directory: ${fullPath}`);
return;
// For directories, check if they should be included based on patterns
const shouldIncludeDir = shouldIncludeFile(fullPath, ignorePatterns, includePatterns);
if (shouldIncludeDir) {
treeStructure[fullPath] = {};
readDirectory(path.join(dirPath, dirent.name), ignorePatterns, includePatterns, treeStructure[fullPath], fullPath);
}
treeStructure[fullPath] = {};
readDirectory(path.join(dirPath, dirent.name), ignorePatterns, includePatterns, treeStructure[fullPath], fullPath);
}
else if (dirent.isFile()) {
console.log(`${fullPath} is a file`);
if (shouldIncludeFile(fullPath, ignorePatterns, includePatterns)) {

@@ -107,3 +101,2 @@ treeStructure[fullPath] = {};

projectPrint += `${fullPath}:\n${content}\n\n`;
console.log(`Added ${fullPath} to project print`);
}

@@ -136,5 +129,3 @@ }

readDirectory(startPath, ignorePatterns, includePatterns, treeStructure);
console.log("\nProcessed file structure:\n");
buildTreeStructure(treeStructure);
console.log(treeStructureString);
const finalContents = `File structure:\n${treeStructureString}\n\nProject print:\n${projectPrint}`;

@@ -141,0 +132,0 @@ fs.writeFileSync("project-print.txt", finalContents);

2

package.json
{
"name": "print-project",
"version": "1.0.18",
"version": "1.0.19",
"description": "A simple CLI tool to print the project tree structure and file contents",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -43,6 +43,3 @@ #!/usr/bin/env node

const regex = new RegExp(regexPattern, "i");
console.log(`Checking ${filePath} against pattern: ${pattern} (regex: ${regex})`);
const matches = regex.test(filePath);
console.log(`Match result: ${matches}`);
return matches;
return regex.test(filePath);
});

@@ -52,14 +49,20 @@ }

function shouldIncludeFile(filePath: string, ignorePatterns: string[], includePatterns: string[]): boolean {
console.log(`\nChecking file: ${filePath}`);
// First check if the file matches any include patterns
const isIncluded = includePatterns.length > 0 ? matchesPattern(filePath, includePatterns) : true;
// If there are include patterns and file matches one, include it regardless of ignore patterns
if (includePatterns.length > 0) {
const isIncluded = matchesPattern(filePath, includePatterns);
console.log(`Include pattern match: ${isIncluded}`);
return isIncluded;
// If the file doesn't match include patterns (when they exist), exclude it
if (!isIncluded) {
return false;
}
// Otherwise, exclude if it matches ignore patterns
// If the file matches include patterns (or there are no include patterns)
// AND doesn't match ignore patterns, include it
const isIgnored = matchesPattern(filePath, ignorePatterns);
console.log(`Ignore pattern match: ${isIgnored}`);
// Special case: if the file matches both include and ignore patterns,
// prioritize the include pattern
if (includePatterns.length > 0 && isIncluded) {
return true;
}
return !isIgnored;

@@ -70,3 +73,2 @@ }

try {
console.log(`\nReading directory: ${dirPath}`);
const dirents = fs.readdirSync(dirPath, { withFileTypes: true });

@@ -76,25 +78,18 @@

const fullPath = path.relative(process.cwd(), path.join(dirPath, dirent.name)).replace(/\\/g, "/");
console.log(`\nProcessing: ${fullPath}`);
if (dirent.isDirectory()) {
console.log(`${fullPath} is a directory`);
// If directory matches ignore pattern AND doesn't match include pattern, skip it
const shouldIgnoreDir = matchesPattern(fullPath, ignorePatterns) &&
(!includePatterns.length || !matchesPattern(fullPath, includePatterns));
// For directories, check if they should be included based on patterns
const shouldIncludeDir = shouldIncludeFile(fullPath, ignorePatterns, includePatterns);
if (shouldIgnoreDir) {
console.log(`Skipping ignored directory: ${fullPath}`);
return;
if (shouldIncludeDir) {
treeStructure[fullPath] = {};
readDirectory(
path.join(dirPath, dirent.name),
ignorePatterns,
includePatterns,
treeStructure[fullPath],
fullPath
);
}
treeStructure[fullPath] = {};
readDirectory(
path.join(dirPath, dirent.name),
ignorePatterns,
includePatterns,
treeStructure[fullPath],
fullPath
);
} else if (dirent.isFile()) {
console.log(`${fullPath} is a file`);
if (shouldIncludeFile(fullPath, ignorePatterns, includePatterns)) {

@@ -105,3 +100,2 @@ treeStructure[fullPath] = {};

projectPrint += `${fullPath}:\n${content}\n\n`;
console.log(`Added ${fullPath} to project print`);
}

@@ -137,5 +131,3 @@ }

readDirectory(startPath, ignorePatterns, includePatterns, treeStructure);
console.log("\nProcessed file structure:\n");
buildTreeStructure(treeStructure);
console.log(treeStructureString);

@@ -147,2 +139,2 @@ const finalContents = `File structure:\n${treeStructureString}\n\nProject print:\n${projectPrint}`;

main();
main();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc