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 Folder
menu to select your project directory. - Open a terminal within VS Code by selecting
Terminal > New Terminal
.
- Open Xcode and select
File > Open
to 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 install
This script interacts with the OpenRouter API, and to run it successfully, you need to configure some environment variables.
- Create a
.env
file in the root directory of your project. - Add the following keys to the
.env
file and replaceYOUR_API_KEY
with 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.mjs
This 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_KEY
in the.env
file. - Run the following command:
node codeSummary.mjs
This 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
.env
file in the root directory of the project and added theOPENROUTER_API_KEY
variable 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
.mjs
or.cjs
depending on your environment.
- You might need to change the extension of the codesummary file to
-
Command Not Found
- Ensure that
node
is installed correctly. You can verify this by runningnode -v
in 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.