dockugen
Version:
Auto-generate API documentation for Node.js apps - Zero config, multi-framework support
348 lines (257 loc) ⢠6.87 kB
Markdown
> Auto-generate API documentation for Node.js apps - **Zero config, multi-framework support!**
DockuGen adalah package Node.js yang otomatis mendeteksi dan generate dokumentasi API dari kode aplikasi Anda tanpa perlu memodifikasi kode yang sudah ada.
- š **Auto-detection** - Otomatis detect framework dan route
- š **Zero Config** - Tidak perlu config file
- š± **Multi Framework** - Support Express, Fastify, Koa, Hapi, dll
- š **Multiple Formats** - Swagger, Markdown, Postman, HTML
- ā” **Super Fast** - Generate docs dalam hitungan detik
- šÆ **Smart Parsing** - Otomatis detect parameter dan middleware
```bash
npm install -g dockugen
npm install --save-dev dockugen
```
```bash
dockugen
dockugen --out ./docs
dockugen --format swagger
dockugen --verbose
```
Setelah menjalankan `dockugen`, Anda akan mendapatkan:
```
api-docs/
āāā swagger.json
āāā api.md
āāā postman.json
āāā index.html
```
- ā
**Express.js** - `app.get('/path', handler)`
- ā
**Fastify** - `fastify.get('/path', handler)`
- ā
**Koa** - `app.get('/path', handler)`
- ā
**Hapi** - `server.route()`
- ā
**Restify** - `server.get('/path', handler)`
- ā
**Native Node.js** - `http.createServer()`
```javascript
// app.js
const express = require('express');
const app = express();
app.get('/users', (req, res) => {
res.json({ users: [] });
});
app.post('/users', (req, res) => {
res.json({ message: 'User created' });
});
app.get('/users/:id', (req, res) => {
res.json({ user: { id: req.params.id } });
});
app.listen(3000);
```
Jalankan:
```bash
dockugen
```
Hasil:
- ā
Auto-detect Express framework
- ā
Auto-detect 3 routes
- ā
Auto-detect parameter `:id`
- ā
Generate Swagger, Markdown, Postman, HTML
```javascript
// server.js
const fastify = require('fastify')();
fastify.get('/api/health', async (request, reply) => {
return { status: 'OK' };
});
fastify.post('/api/users', async (request, reply) => {
return { message: 'User created' };
});
fastify.listen(3000);
```
Jalankan:
```bash
swagjs
```
```bash
dockugen [options]
Options:
-o, --out <dir> Output directory (default: ./api-docs)
-f, --format <format> Output format: swagger, markdown, postman, html, all (default: all)
-s, --src <dir> Source directory to scan (default: auto-detect)
-v, --verbose Verbose output
-h, --help Display help
-V, --version Display version
```
## š CI/CD Integration
### GitHub Actions
```yaml
name: Generate API Docs
on: [push, pull_request]
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- run: npm install -g dockugen
- run: dockugen --out ./docs
- name: Commit docs
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add docs/
git commit -m "Update API documentation" || exit 0
git push
```
### GitLab CI
```yaml
generate_docs:
stage: build
image: node:16
script:
- npm install -g dockugen
- dockugen --out ./docs
artifacts:
paths:
- docs/
```
### Package.json Scripts
```json
{
"scripts": {
"docs": "dockugen",
"docs:watch": "dockugen --watch",
"docs:swagger": "dockugen --format swagger"
}
}
```
DockuGen otomatis detect struktur project:
```
project/
āāā src/ ā
Auto-detect
āāā app/ ā
Auto-detect
āāā routes/ ā
Auto-detect
āāā controllers/ ā
Auto-detect
āāā api/ ā
Auto-detect
āāā lib/ ā
Auto-detect
```
Otomatis detect berbagai pattern route:
```javascript
// Express
app.get('/users', handler); // ā
GET /users
router.post('/users', handler); // ā
POST /users
// Fastify
fastify.get('/api/health', handler); // ā
GET /api/health
// Koa
app.put('/users/:id', handler); // ā
PUT /users/:id
// Generic
server.get('/status', handler); // ā
GET /status
```
```json
{
"openapi": "3.0.0",
"paths": {
"/users": {
"get": {
"summary": "GET /users",
"tags": ["app"],
"responses": {
"200": {
"description": "Successful response"
}
}
}
}
}
}
```
```markdown
- **Method**: `GET`
- **File**: `app.js`
- **Line**: `5`
- **Framework**: `express`
```
```javascript
const { SimpleScanner } = require('dockugen');
const scanner = new SimpleScanner();
const routes = scanner.scan({
out: './custom-docs',
format: 'swagger'
});
console.log(`Found ${routes.length} routes`);
```
```bash
dockugen --out ./my-docs
```
```bash
dockugen --format swagger
dockugen --format markdown
dockugen --format postman
dockugen --format html
```
DockuGen tidak memerlukan config file! Semua otomatis:
- ā
**Framework Detection** - Auto dari package.json
- ā
**Source Directory** - Auto detect folder structure
- ā
**Route Patterns** - Auto detect semua pattern
- ā
**Output Formats** - Generate semua format sekaligus
1. **No routes found**
- Pastikan file JavaScript/TypeScript ada di folder yang benar
- Check apakah route menggunakan pattern yang standard
2. **Permission denied**
- Pastikan folder output bisa di-write
- Gunakan `sudo` jika perlu
3. **Framework not detected**
- Pastikan dependencies ada di package.json
- Check versi Node.js (minimal 14.0.0)
```bash
dockugen --verbose
```
1. Fork repository
2. Create feature branch
3. Commit changes
4. Push to branch
5. Create Pull Request
MIT License - lihat [LICENSE](LICENSE) file untuk detail.
- Terinspirasi dari [Swaggo](https://github.com/swaggo/swag) untuk Go
- Dibuat dengan ā¤ļø untuk komunitas Node.js
---
**DockuGen** - Zero config, multi-framework support! š