node-project-context
v1.0.3
Published
A tool to extract dependencies from Node.js files
Downloads
5
Readme
Node Project Context
Overview
This project, Node Project Context, provides a utility that extracts information about a Node.js project structure, gathering details about the file system, key files, and dependencies. This tool can be useful for creating a summarized context to pass to AI models or for general project analysis.
Features
- Root Directory Identification: Automatically determines the root directory of a Node.js project by searching for a
package.json
file. - File System Overview: Creates a detailed YAML representation of the project’s file system, excluding unnecessary directories like
node_modules
or.git
. - Dependency Analysis: Generates a dependency graph of the project's source files, leveraging madge.
- Output Management: Writes the output to a specified directory, allowing easy access to summarized project information.
Installation
To install this tool globally, run:
npm install -g node-project-context
This will install all necessary dependencies, including madge
, globally, allowing you to use the tool as a CLI.
Usage
Once installed globally, you can use the tool by running:
node-project-context [options]
Command-Line Arguments
[projectRoot]
: The path to the project root directory. Defaults to the current working directory if not provided.--outputTo [outputDir]
: The directory where the output should be written. Defaults to~/Downloads/<project-name>-context
.--source [sourceFilePath]
: Adds specific source files that are relevant for generating the context.--sourceRegex [regexPattern]
: Matches files that should be included in the context output. Cannot be used together with--source
.--depth [number]
: The number of levels of imports to include in the output (default is2
, max is10
).--rootFileRegex [regexPattern]
: Matches files in the root of the project that should be included in the output (defaults to files matching(config|setup|setting|webpack|babel|vite|readme)
).
Example
Suppose you want to generate a context overview of a project located at /home/user/my-node-app
. Run:
node-project-context /home/user/my-node-app --outputTo /home/user/output --depth 3
This command will:
- Determine
/home/user/my-node-app
as the project root. - Create an output directory at
/home/user/output
. - Traverse the source files up to 3 levels deep for dependency resolution.
- Output a file tree representation in
file-tree.yaml
at the destination.
Detailed Example
Let's consider an example project directory structure as follows:
my-node-app/
|-- package.json
|-- index.js
|-- src/
|-- app.js
|-- utils.js
|-- README.md
Generated Output
Running node-project-context my-node-app
will create an output directory containing:
package.json
: Copied from the root directory.Other Key Files: Files like
README.md
, matching the defaultrootFileRegex
.Dependency Analysis: A detailed dependency tree, visualized with madge.
file-tree.yaml
: Provides a representation of the file system in the form of:files: - README.md - index.js - package.json - src: files: - app.js - utils.js
Development and Contribution
This project can be extended to add more file analysis features, such as more advanced dependency handling or integrating with popular CI/CD tools. Contributions are welcome!
License
This project is licensed under ISC.