print-project
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -8,3 +8,3 @@ "use strict"; | ||
"*.env", "*.bak", "*.tmp", "*.swp", ".eslintcache", ".yarn", ".yarnrc", ".yarn.lock", | ||
".editorconfig", ".npmrc", ".babelrc", ".nyc_output", ".cache", | ||
".editorconfig", ".npmrc", ".babelrc", ".nyc_output", ".cache, project-print.txt", | ||
]; |
@@ -39,3 +39,4 @@ #!/usr/bin/env node | ||
const useDefaultIgnore = program.opts().ignoreDefault; | ||
const patterns = useDefaultIgnore ? [...constants_1.defaultIgnorePatterns, ...userPatterns] : userPatterns; | ||
let patterns = useDefaultIgnore ? [...constants_1.defaultIgnorePatterns, ...userPatterns] : userPatterns; | ||
patterns.push("project-print.txt"); | ||
console.log("Start Path:", startPath); | ||
@@ -42,0 +43,0 @@ console.log("Patterns:", patterns); |
{ | ||
"name": "print-project", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "A simple CLI tool to print the project tree structure and file contents", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -244,2 +244,396 @@ File structure: | ||
You can use either `print-project` or `pprint` to run the tool: | ||
```bash | ||
print-project <startPath> [ignorePatterns] | ||
``` | ||
or | ||
```bash | ||
pprint <startPath> [ignorePatterns] | ||
``` | ||
### Using Default Ignore Patterns | ||
To use the default ignore patterns, add the `--ignore-default` flag: | ||
```bash | ||
print-project <startPath> --ignore-default | ||
``` | ||
You can also combine default patterns with your own: | ||
```bash | ||
print-project <startPath> "your,custom,patterns" --ignore-default | ||
``` | ||
### Default Ignore Patterns | ||
The following patterns are ignored by default when using the `--ignore-default` flag: | ||
``` | ||
node_modules,*.log,dist,coverage,documentation,.prettierrc,.gitignore,dist,scripts,.serverless,.idea,.git,.DS_Store,.husky,package-lock.json | ||
``` | ||
### Examples | ||
- **Print all files and directories**: | ||
```bash | ||
print-project ./src | ||
``` | ||
or | ||
```bash | ||
pprint ./src | ||
``` | ||
- **Ignore specific patterns**: | ||
```bash | ||
print-project ./src "node_modules,*.log,dist,coverage" | ||
``` | ||
or | ||
```bash | ||
pprint ./src "node_modules,*.log,dist,coverage" | ||
``` | ||
- **Use default ignore patterns**: | ||
```bash | ||
print-project ./src --ignore-default | ||
``` | ||
or | ||
```bash | ||
pprint ./src --ignore-default | ||
``` | ||
- **Use default ignore patterns and add custom ones**: | ||
```bash | ||
print-project ./src "*.tmp,*.bak" --ignore-default | ||
``` | ||
or | ||
```bash | ||
pprint ./src "*.tmp,*.bak" --ignore-default | ||
``` | ||
## Features | ||
- **Directory Scanning**: Recursively scans the provided directory path. | ||
- **Ignore Patterns**: Supports glob patterns to exclude specific files or directories from the output. | ||
- **Default Ignore Patterns**: Provides a set of commonly ignored patterns for convenience. | ||
- **Output Generation**: Creates a text file `project-print.txt` in the current working directory containing: | ||
- The structured list of non-ignored files and directories. | ||
- The content of non-empty files. | ||
- **Command Alias**: Can be run using either `print-project` or `pprint` for convenience. | ||
## How It Works | ||
1. Parses the command line arguments for the starting directory path and ignore patterns. | ||
2. Scans the specified directory, applying the ignore patterns to filter out unwanted files or directories. | ||
3. Builds a tree structure of the directory and captures file content. | ||
4. Outputs the directory structure and file content into `project-print.txt`. | ||
## Output File Format | ||
The output `project-print.txt` includes: | ||
- **File Structure**: A tree showing the organization of files and directories. | ||
- **Project Print**: Actual content of non-empty files within the project directory. | ||
## License | ||
This project is licensed under the MIT License - see the LICENSE file for details. | ||
## Contributing | ||
Contributions are welcome. Please open an issue first to discuss what you would like to change, or directly submit a | ||
pull request. | ||
jest.config.js: | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
package.json: | ||
{ | ||
"name": "print-project", | ||
"version": "1.0.7", | ||
"description": "A simple CLI tool to print the project tree structure and file contents", | ||
"main": "dist/index.js", | ||
"bin": { | ||
"print-project": "./dist/index.js", | ||
"pprint": "./dist/index.js" | ||
}, | ||
"types": "dist/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/nitaiaharoni1/print-project.git" | ||
}, | ||
"keywords": [], | ||
"scripts": { | ||
"build": "tsc", | ||
"start": "ts-node src/index.ts", | ||
"bump": "npm version patch", | ||
"package": "npm run build && npm run bump && npm publish" | ||
}, | ||
"author": "Nitai Aharoni", | ||
"license": "MIT", | ||
"dependencies": { | ||
"commander": "^12.1.0" | ||
}, | ||
"devDependencies": { | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.0.4" | ||
} | ||
} | ||
project-print.txt: | ||
File structure: | ||
.eslintrc.json | ||
.npmignore | ||
LICENSE | ||
README.md | ||
jest.config.js | ||
package.json | ||
project-print.txt | ||
src | ||
src/constants.ts | ||
src/index.ts | ||
tsconfig.json | ||
Project print: | ||
.eslintrc.json: | ||
{ | ||
"root": true, | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module", | ||
"project": "./tsconfig.json" | ||
}, | ||
"ignorePatterns": [ | ||
"node_modules/", | ||
"dist/", | ||
"build/", | ||
"coverage/", | ||
"public/" | ||
], | ||
"extends": [ | ||
"standard-with-typescript", | ||
"eslint:all", | ||
"prettier", | ||
"plugin:import/errors", | ||
"plugin:import/warnings", | ||
"plugin:import/typescript" | ||
], | ||
"plugins": [ | ||
"prettier", | ||
"sort-keys-fix", | ||
"sort-imports-es6-autofix" | ||
], | ||
"rules": { | ||
"line-comment-position": "off", | ||
"import/no-unresolved": "off", | ||
"no-return-await": "off", | ||
"@typescript-eslint/restrict-template-expressions": "off", | ||
"no-continue": "off", | ||
"max-params": [ | ||
"error", | ||
4 | ||
], | ||
"no-underscore-dangle": "off", | ||
"init-declarations": "off", | ||
"sort-keys-fix/sort-keys-fix": "error", | ||
"no-inline-comments": "off", | ||
"no-console": [ | ||
"error", | ||
{ | ||
"allow": [ | ||
"debug", | ||
"warn", | ||
"error" | ||
] | ||
} | ||
], | ||
"no-undefined": "off", | ||
"no-undef": "off", | ||
"@typescript-eslint/no-this-alias": "off", | ||
"func-names": "off", | ||
"consistent-this": "off", | ||
"no-invalid-this": "off", | ||
"prefer-named-capture-group": "off", | ||
"@typescript-eslint/no-confusing-void-expression": "off", | ||
"@typescript-eslint/await-thenable": "off", | ||
"@typescript-eslint/no-misused-promises": "off", | ||
"sort-imports": "off", | ||
"no-magic-numbers": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"no-ternary": "off", | ||
"max-statements": [ | ||
"error", | ||
50 | ||
], | ||
"id-length": "off", | ||
"sort-imports-es6-autofix/sort-imports-es6": [ | ||
2, | ||
{ | ||
"ignoreCase": false, | ||
"ignoreMemberSort": false, | ||
"memberSyntaxSortOrder": [ | ||
"none", | ||
"all", | ||
"multiple", | ||
"single" | ||
] | ||
} | ||
], | ||
"no-shadow": "off", | ||
"no-param-reassign": "off", | ||
"no-nested-ternary": "off", | ||
"guard-for-in": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/consistent-type-imports": "off", | ||
"class-methods-use-this": "off", | ||
"@typescript-eslint/no-floating-promises": "off", | ||
"@typescript-eslint/strict-boolean-expressions": "off", | ||
"@typescript-eslint/restrict-plus-operands": "off", | ||
"multiline-comment-style": "off", | ||
"require-jsdoc": "off", | ||
"no-warning-comments": "off", | ||
"capitalized-comments": "off", | ||
"func-style": "off", | ||
"max-lines-per-function": [ | ||
"error", | ||
{ | ||
"max": 100, | ||
"skipBlankLines": true, | ||
"skipComments": true | ||
} | ||
], | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"singleQuote": true, | ||
"printWidth": 180, | ||
"trailingComma": "all", | ||
"bracketSpacing": true, | ||
"bracketSameLine": true, | ||
"quoteProps": "as-needed", | ||
"jsxSingleQuote": true, | ||
"jsxBracketSameLine": false, | ||
"jsxBracketSpacing": true | ||
} | ||
], | ||
"no-use-before-define": "off" | ||
} | ||
} | ||
.npmignore: | ||
# .npmignore | ||
# Ignore the node_modules directory | ||
node_modules/ | ||
# Ignore the build and dist directories | ||
build/ | ||
dist/ | ||
# Ignore any .log files | ||
*.log | ||
# Ignore any .env files | ||
*.env | ||
# Ignore any .DS_Store files (macOS metadata) | ||
.DS_Store | ||
# Ignore the .git directory | ||
.git/ | ||
# Ignore the .gitignore file | ||
.gitignore | ||
# Ignore any editor configuration files | ||
.editorconfig | ||
.vscode/ | ||
# Ignore any test files and directories | ||
test/ | ||
__tests__/ | ||
# Ignore any documentation files | ||
docs/ | ||
README.md | ||
LICENSE | ||
LICENSE: | ||
The MIT License (MIT) | ||
Copyright (c) 2023 Nitai Aharoni | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
README.md: | ||
# Print-Project | ||
The `print-project` command-line tool scans a specified directory and generates a report including the tree structure | ||
and content of files that do not match given ignore patterns. It is useful for documenting or analyzing the file layout | ||
of projects, especially in development environments. | ||
## Installation | ||
You can install `print-project` using npm: | ||
```bash | ||
npm install -g print-project | ||
``` | ||
Ensure you have Node.js installed on your machine to use this package. | ||
## Usage | ||
After installation, the `print-project` tool can be run from the command line. | ||
### Basic Command | ||
```bash | ||
print-project <startPath> [ignorePatterns] | ||
``` | ||
- `<startPath>`: Required. The path to the directory you want to scan. | ||
e.g., `/path/to/project` | ||
- `[ignorePatterns]`: Optional. A comma-separated list of glob patterns to ignore files and directories. | ||
e.g., `"node_modules,*.log,dist,coverage"` | ||
### Command Aliases | ||
You can use either `print-project` or `pp` to run the tool: | ||
@@ -524,1 +918,128 @@ | ||
src/constants.ts: | ||
export const defaultIgnorePatterns: string[] = [ | ||
"node_modules", "*.log", "dist", "coverage", "documentation", ".prettierrc", ".gitignore", "dist", | ||
"scripts", ".serverless", ".idea", ".git", ".DS_Store", ".husky", "package-lock.json", ".vscode", | ||
"*.env", "*.bak", "*.tmp", "*.swp", ".eslintcache", ".yarn", ".yarnrc", ".yarn.lock", | ||
".editorconfig", ".npmrc", ".babelrc", ".nyc_output", ".cache", | ||
]; | ||
src/index.ts: | ||
#!/usr/bin/env node | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import { Command } from "commander"; | ||
import { defaultIgnorePatterns } from "./constants"; | ||
let projectPrint: string = ""; | ||
let treeStructure: Record<string, any> = {}; | ||
let treeStructureString: string = ""; | ||
const program = new Command(); | ||
program.argument("<startPath>", "Starting directory path").argument("[ignorePatterns]", "Comma-separated list of patterns to ignore").option("--ignore-default", "Use default ignore patterns").parse(process.argv); | ||
const startPath: string | undefined = program.args[0] && path.resolve(program.args[0]); | ||
const userPatterns: string[] = program.args[1] ? program.args[1].split(",").filter(Boolean).map(pattern => pattern.trim()) : []; | ||
const useDefaultIgnore: boolean = program.opts().ignoreDefault; | ||
const patterns: string[] = useDefaultIgnore ? [...defaultIgnorePatterns, ...userPatterns] : userPatterns; | ||
console.log("Start Path:", startPath); | ||
console.log("Patterns:", patterns); | ||
function isIgnored(filePath: string, patterns: string[]): boolean { | ||
try { | ||
return patterns.some(pattern => { | ||
const parsedPattern = pattern.replace(/\./g, "\\.").replace(/\*/g, ".*"); | ||
const regex = new RegExp(parsedPattern); | ||
return regex.test(filePath); | ||
}); | ||
} catch (e) { | ||
console.error(`Failed to check if ignored: ${filePath}`, e); | ||
return false; | ||
} | ||
} | ||
function readDirectory(dirPath: string, patterns: string[] = [], treeStructure: Record<string, any> = {}, currentPath: string = ""): void { | ||
try { | ||
const dirents = fs.readdirSync(dirPath, { withFileTypes: true }); | ||
dirents.forEach((dirent) => { | ||
const fullPath = path.relative(process.cwd(), path.join(dirPath, dirent.name)).replace(/\\/g, "/"); | ||
if (isIgnored(fullPath, patterns)) { | ||
return; | ||
} | ||
const relativePath = path.join(currentPath, dirent.name).replace(/\\/g, "/"); | ||
if (dirent.isDirectory()) { | ||
treeStructure[relativePath] = {}; | ||
readDirectory(path.join(dirPath, dirent.name), patterns, treeStructure[relativePath], relativePath); | ||
} else if (dirent.isFile()) { | ||
treeStructure[relativePath] = {}; | ||
const content = fs.readFileSync(path.join(dirPath, dirent.name), "utf8"); | ||
if (content.length > 0) { | ||
projectPrint += `${fullPath}:\n${content}\n\n`; | ||
} | ||
} | ||
}); | ||
} catch (e) { | ||
console.error(`Failed to read directory: ${dirPath}`, e); | ||
} | ||
} | ||
function buildTreeStructure(tree: Record<string, any>, indent: string = ""): void { | ||
for (const key in tree) { | ||
treeStructureString += indent + key + "\n"; | ||
if (typeof tree[key] === "object" && Object.keys(tree[key]).length > 0) { | ||
buildTreeStructure(tree[key], indent + " "); | ||
} | ||
} | ||
} | ||
function main(): void { | ||
if (!startPath) { | ||
console.error("Starting directory path is required."); | ||
process.exit(1); | ||
} | ||
console.log(`Starting directory read from ${startPath}`); | ||
console.log(`Ignoring: ${patterns.join(", ")}`); | ||
console.log(`Using default ignore: ${useDefaultIgnore}`); | ||
readDirectory(startPath, patterns, treeStructure); | ||
console.log("\nNon-ignored file structure:\n"); | ||
buildTreeStructure(treeStructure); | ||
console.log(treeStructureString); | ||
const finalContents = `File structure:\n${treeStructureString}\n\nProject print:\n${projectPrint}`; | ||
fs.writeFileSync("project-print.txt", finalContents); | ||
console.log(`\nProject print size: ${(projectPrint.length / 1024).toFixed(2)}KB`); | ||
} | ||
main(); | ||
tsconfig.json: | ||
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"outDir": "dist", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"lib": [ | ||
"ES2016", | ||
"DOM" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} | ||
@@ -5,3 +5,3 @@ export const defaultIgnorePatterns: string[] = [ | ||
"*.env", "*.bak", "*.tmp", "*.swp", ".eslintcache", ".yarn", ".yarnrc", ".yarn.lock", | ||
".editorconfig", ".npmrc", ".babelrc", ".nyc_output", ".cache", | ||
".editorconfig", ".npmrc", ".babelrc", ".nyc_output", ".cache, project-print.txt", | ||
]; |
@@ -19,3 +19,4 @@ #!/usr/bin/env node | ||
const patterns: string[] = useDefaultIgnore ? [...defaultIgnorePatterns, ...userPatterns] : userPatterns; | ||
let patterns: string[] = useDefaultIgnore ? [...defaultIgnorePatterns, ...userPatterns] : userPatterns; | ||
patterns.push("project-print.txt"); | ||
@@ -22,0 +23,0 @@ console.log("Start Path:", startPath); |
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
66781
698