Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frankhereford/discovery-day-winter-2023
discovery-day-winter-2023
https://github.com/frankhereford/discovery-day-winter-2023
Last synced: 21 days ago
JSON representation
discovery-day-winter-2023
- Host: GitHub
- URL: https://github.com/frankhereford/discovery-day-winter-2023
- Owner: frankhereford
- Created: 2023-12-08T21:07:28.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-10T19:29:52.000Z (about 1 year ago)
- Last Synced: 2024-11-09T06:40:57.222Z (2 months ago)
- Language: JavaScript
- Size: 88.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 📚 The Documentarian
## Overview
This Node.js script enhances a JavaScript file by optionally removing comments, adding comments from OpenAI, and formatting the code with Prettier. It uses several Node.js modules, including `fs`, `prettier`, `yargs`, `@babel/parser`, `@babel/traverse`, `@babel/generator`, and `OpenAI`.## Prerequisites
- Node.js
- npm (Node Package Manager)## Installation
1. Clone or download this repository.
2. Navigate to the directory containing the script.
3. Run `npm install` to install the required dependencies.## Usage
The script is executed with the following command: `node [script-name] --file [path-to-js-file] [options]`### Options
- `--file, -f`: Path to the JavaScript file to process (required).
- `--clear-comments, -c`: Remove all comments from the file before processing.
- `--openai-comments, -o`: Fetch and add comments from OpenAI.
- `--header, -h`: Fetch and add a summary header from OpenAI.
- `--prettier, -p`: Run Prettier on the output.## How it Works
1. **Parsing and Traversing the AST**: The script parses the JavaScript file into an Abstract Syntax Tree (AST), traverses it, and identifies nodes (e.g., functions, classes) to be processed.
2. **Comment Manipulation**: If `-c` is used, it removes all comments. If `-o` is used, it fetches comments for specific code snippets from OpenAI and inserts them into the AST.
3. **Summary Header**: If `-h` is selected, it fetches a summary of the file from OpenAI and adds it as a header comment.
4. **Formatting**: If `-p` is used, the script formats the modified file using Prettier.## Error Handling
The script includes error handling for file existence, read/write operations, and API interactions.## Note
Ensure that your OpenAI API key is correctly configured in your environment variables for the script to interact with OpenAI services.## License
The Unlicense