generate-serverless-files
Version:
This project helps to generate serverless files
92 lines (69 loc) • 2.12 kB
Markdown
This project helps to generate serverless files
This project is inspired by [swagger-jsdoc](https://github.com/Surnet/swagger-jsdoc) and the post of [@dwelch2344](https://github.com/serverless/serverless/issues/4218#issuecomment-361760059)
[](https://www.npmjs.com/package/generate-serverless-files)
```
npm install --save generate-serverless-files
```
It parse the documentation in your files to give them to serverless when you use
```shell script
serverless deploy
```
create a js (```serverless-dynamic.js``` for example) file and put this code :
```javascript
const parse = require("generate-serverless-files");
module.exports = () => {
return parse(["*.ts"]);
}
```
In your main ```serverless.yml``` file import the previously created file
```yaml
service: example
provider:
name: aws
runtime: nodejs12.x
region: eu-west-3
memorySize: 128
timeout: 10
functions: ${file(./serverless-dynamic.js)}
```
in your code, writes the serverless configuration in the documentation
```typescript
import {body, Controller, custom, header, Method, param, query} from "@igloobuster/aws_lambda_middleware/dist/Annotations";
@Controller({exports, json: true, router: new Router(middlewares)})
export class Example {
/**
* @serverless
* getExample:
* handler: routes/Example.getExample
* events:
* - http:
* path: /example
* method: get
*/
@Method()
private async getExample() {
return {Hello: "world"};
}
/**
* @serverless
* postExample:
* handler: routes/Example.postExample
* events:
* - http:
* path: /example
* method: post
*/
@Method()
private async postExample() {
return {Hello: "post to the world"};
}
}
```
All the lines bellow @serverless will be used for the configuration