From e2f311e8a7945b83ecebd5aa4b6f9be2ca6116d1 Mon Sep 17 00:00:00 2001 From: Julian Rabe Date: Tue, 2 Jun 2020 12:28:12 +0200 Subject: [PATCH] feat: Add parameter to change output file name (#24) Co-authored-by: Lukasz Gornicki --- README.md | 7 ++++++- hooks/output-filename.js | 10 ++++++++++ package.json | 9 ++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 hooks/output-filename.js diff --git a/README.md b/README.md index a74d9d574..c3cb1cdd9 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ If you don't have the AsyncAPI Generator installed, you can install it like this ``` npm install -g @asyncapi/generator ``` +## Supported parameters + +|Name|Description|Required|Default|Example| +|---|---|---|---| +|outFilename|The filename of the output file.|No|`asyncapi.md`|`index.md`| ## Development @@ -40,4 +45,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d -This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! \ No newline at end of file +This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! diff --git a/hooks/output-filename.js b/hooks/output-filename.js new file mode 100644 index 000000000..2e88f1cdf --- /dev/null +++ b/hooks/output-filename.js @@ -0,0 +1,10 @@ +const fs = require('fs'); + +module.exports = { + 'generate:after': generator => { + if(generator.templateParams.outFilename !== 'asyncapi.md') { + fs.renameSync(`${generator.targetDir}/asyncapi.md`, + `${generator.targetDir}/${generator.templateParams.outFilename}`); + } + } +} diff --git a/package.json b/package.json index 74f45cea2..d5a0b8228 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,13 @@ "generator": ">=0.50.0 <2.0.0", "filters": [ "@asyncapi/generator-filters" - ] + ], + "parameters": { + "outFilename": { + "description": "The name of the output markdown file", + "default": "asyncapi.md", + "required": false + } + } } }