This README will guide you through setting up and running a Node.js script that generates a directory tree or analyzes the codebase of your project using the OpenRouter API.
Before running this project, ensure that you have the following installed:
- Node.js: Download Node.js
- VS Code (for Windows and Mac): Download VS Code
- Alternatively, Xcode for Mac users if preferred: Download Xcode
- Clone or download the code file.
- Open the project folder in your preferred editor (VS Code or Xcode).
- Open VS Code and go to the
File > Open Foldermenu to select your project directory. - Open a terminal within VS Code by selecting
Terminal > New Terminal.
- Open Xcode and select
File > Opento navigate to the project folder. - Use the terminal within Xcode, or you can use your macOS terminal.
In your terminal, run the following command to install the required packages:
npm installThis script interacts with the OpenRouter API, and to run it successfully, you need to configure some environment variables.
- Create a
.envfile in the root directory of your project. - Add the following keys to the
.envfile and replaceYOUR_API_KEYwith the actual API key.
OPENROUTER_API_KEY=YOUR_API_KEY
YOUR_SITE_URL=your-site-url (optional)
YOUR_SITE_NAME=your-site-name (optional)
The OPENROUTER_API_KEY is required for the analysis feature. If this is not configured correctly, the script will exit with an error.
You can run the script in two modes:
- Generate a directory tree.
- Analyze the codebase and send it to the OpenRouter API.
To generate a text-based directory structure of your project:
- Open the terminal in your project directory.
- Run the following command:
node codeSummary.mjsThis will create a .txt file in your project folder containing the directory tree.
To analyze the codebase and send the results to the OpenRouter API:
- Ensure you have set your
OPENROUTER_API_KEYin the.envfile. - Run the following command:
node codeSummary.mjsThis will analyze your codebase by sending file contents to the OpenRouter API. A detailed report will be generated and saved as a .txt file in your project folder.
-
Error: OPENROUTER_API_KEY is not set in the .env file.
- Make sure you have created a
.envfile in the root directory of the project and added theOPENROUTER_API_KEYvariable with a valid API key.
- Make sure you have created a
-
Wrong file type
- You might need to change the extension of the codesummary file to
.mjsor.cjsdepending on your environment.
- You might need to change the extension of the codesummary file to
-
Command Not Found
- Ensure that
nodeis installed correctly. You can verify this by runningnode -vin the terminal. If Node.js is not installed, download and install it from here.
- Ensure that
This script helps you analyze your project by generating a structured directory tree or sending the codebase for analysis to an API. It can be extended or modified to support other features as well.
For more information on the OpenRouter API, visit the official OpenRouter Documentation.