UNPKG

dockugen

Version:

Auto-generate API documentation for Node.js apps - Zero config, multi-framework support

348 lines (257 loc) • 6.87 kB
# šŸš€ DockuGen > 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. ## ✨ Features - šŸ” **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 ## šŸš€ Quick Start ### Install ```bash # Install globally npm install -g dockugen # Atau install di project npm install --save-dev dockugen ``` ### Usage ```bash # Generate docs (super simple!) dockugen # Output ke folder custom dockugen --out ./docs # Format tertentu dockugen --format swagger # Verbose output dockugen --verbose ``` ## šŸ“ Output Setelah menjalankan `dockugen`, Anda akan mendapatkan: ``` api-docs/ ā”œā”€ā”€ swagger.json # OpenAPI 3.0 specification ā”œā”€ā”€ api.md # Markdown documentation ā”œā”€ā”€ postman.json # Postman collection └── index.html # Beautiful HTML docs ``` ## šŸ”§ Supported Frameworks - āœ… **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()` ## šŸ“ Examples ### Express.js App ```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 ### Fastify App ```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 ``` ## šŸŽÆ CLI Options ```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" } } ``` ## šŸ—ļø Project Structure Detection DockuGen otomatis detect struktur project: ``` project/ ā”œā”€ā”€ src/ āœ… Auto-detect ā”œā”€ā”€ app/ āœ… Auto-detect ā”œā”€ā”€ routes/ āœ… Auto-detect ā”œā”€ā”€ controllers/ āœ… Auto-detect ā”œā”€ā”€ api/ āœ… Auto-detect └── lib/ āœ… Auto-detect ``` ## šŸ” Route Detection 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 ``` ## šŸ“Š Generated Documentation ### Swagger/OpenAPI 3.0 ```json { "openapi": "3.0.0", "paths": { "/users": { "get": { "summary": "GET /users", "tags": ["app"], "responses": { "200": { "description": "Successful response" } } } } } } ``` ### Markdown ```markdown # API Documentation ## GET Routes ### /users - **Method**: `GET` - **File**: `app.js` - **Line**: `5` - **Framework**: `express` ``` ## šŸš€ Advanced Usage ### Programmatic Usage ```javascript const { SimpleScanner } = require('dockugen'); const scanner = new SimpleScanner(); const routes = scanner.scan({ out: './custom-docs', format: 'swagger' }); console.log(`Found ${routes.length} routes`); ``` ### Custom Output Directory ```bash dockugen --out ./my-docs ``` ### Specific Format ```bash # Hanya generate Swagger dockugen --format swagger # Hanya generate Markdown dockugen --format markdown # Hanya generate Postman dockugen --format postman # Hanya generate HTML dockugen --format html ``` ## šŸ”§ Configuration 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 ## šŸ› Troubleshooting ### Common Issues 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) ### Debug Mode ```bash dockugen --verbose ``` ## šŸ¤ Contributing 1. Fork repository 2. Create feature branch 3. Commit changes 4. Push to branch 5. Create Pull Request ## šŸ“„ License MIT License - lihat [LICENSE](LICENSE) file untuk detail. ## šŸ™ Acknowledgments - Terinspirasi dari [Swaggo](https://github.com/swaggo/swag) untuk Go - Dibuat dengan ā¤ļø untuk komunitas Node.js --- **DockuGen** - Zero config, multi-framework support! šŸš€