1.0.3 • Published 8 months ago

node-project-context v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

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 is 2, max is 10).
  • --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: 1. Determine /home/user/my-node-app as the project root. 2. Create an output directory at /home/user/output. 3. Traverse the source files up to 3 levels deep for dependency resolution. 4. 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:

  1. package.json: Copied from the root directory.
  2. Other Key Files: Files like README.md, matching the default rootFileRegex.
  3. Dependency Analysis: A detailed dependency tree, visualized with madge.
  4. 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.

Author

Ian Baker - Website - Email

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago