npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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 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