-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
179 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fsPromises from 'fs/promises'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
export async function createDoc(projectName, template) { | ||
const SOURCE_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), '../', `templates/swagger/${template}`); | ||
const TARGET_PATH = path.join(process.cwd(), projectName); | ||
|
||
try { | ||
await fsPromises.cp(SOURCE_PATH, TARGET_PATH, { recursive: true, force: true }); | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import inquirer from 'inquirer'; | ||
|
||
export default async function printDocs() { | ||
const iq = await inquirer.prompt({ | ||
name: 'apiDoc', | ||
type: 'confirm', | ||
message: 'Do you want to use swagger for API documentation?', | ||
default: false, | ||
}); | ||
|
||
return iq.apiDoc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import express from 'express'; | ||
import dotenv from 'dotenv'; | ||
import cors from 'cors'; | ||
|
||
import swaggerUi from 'swagger-ui-express'; | ||
import swaggerDocument from '../apidoc.json'; | ||
|
||
import routes from './routes/index'; | ||
|
||
dotenv.config(); | ||
|
||
const app = express(); | ||
const PORT = process.env.PORT ?? 8000; | ||
|
||
app.use(cors()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
|
||
app.use(`/api`, routes); | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server is running on port ${PORT}`); | ||
}); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import swaggerAutogen from 'swagger-autogen'; | ||
|
||
const doc = { | ||
info: { | ||
title: 'Gen Express CLI', | ||
description: 'Gen Express CLI API Documentation', | ||
}, | ||
host: 'localhost:8000/api', | ||
}; | ||
|
||
const outputFile = './apidoc.json'; | ||
const routes = ['./src/routes/index.js']; | ||
|
||
/* NOTE: If you are using the express Router, you must pass in the 'routes' only the | ||
root file where the route starts, such as index.js, app.js, routes.js, etc ... */ | ||
|
||
swaggerAutogen()(outputFile, routes, doc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import express from 'express'; | ||
import dotenv from 'dotenv'; | ||
import cors from 'cors'; | ||
|
||
import swaggerUi from 'swagger-ui-express'; | ||
import swaggerDocument from '../apidoc.json'; | ||
|
||
import routes from './routes/index'; | ||
|
||
dotenv.config(); | ||
|
||
const app = express(); | ||
const PORT = process.env.PORT ?? 8000; | ||
|
||
app.use(cors()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
|
||
app.use(`/api`, routes); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Server is running on port ${PORT}`); | ||
}); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import swaggerAutogen from 'swagger-autogen'; | ||
|
||
const doc = { | ||
info: { | ||
title: 'Gen Express CLI', | ||
description: 'Gen Express CLI API Documentation', | ||
}, | ||
host: 'localhost:8000/api', | ||
}; | ||
|
||
const outputFile = './apidoc.json'; | ||
const routes = ['./src/routes/index.ts']; | ||
|
||
/* NOTE: If you are using the express Router, you must pass in the 'routes' only the | ||
root file where the route starts, such as index.js, app.js, routes.js, etc ... */ | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
swaggerAutogen()(outputFile, routes, doc); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters