generated from scaffoldly/github-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsoa.js
45 lines (41 loc) · 1.54 KB
/
tsoa.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint-disable @typescript-eslint/no-var-requires */
const { generateRoutes, generateSpec } = require('tsoa');
const fs = require('fs');
const packageJson = require('./package.json');
const { NODE_ENV } = process.env;
const envVars = NODE_ENV
? JSON.parse(fs.readFileSync(fs.openSync(`.scaffoldly/${NODE_ENV}/env-vars.json`)))
: JSON.parse(fs.readFileSync(fs.openSync(`.scaffoldly/env-vars.json`)));
const services = NODE_ENV
? JSON.parse(fs.readFileSync(fs.openSync(`.scaffoldly/${NODE_ENV}/services.json`)))
: JSON.parse(fs.readFileSync(fs.openSync(`.scaffoldly/services.json`)));
(async () => {
console.log('Generating spec...');
await generateSpec({
basePath: `/${envVars['service-slug']}`,
name: envVars['application-name'],
version: packageJson.version,
description: `To generate a JWT token, go to the <a href="${services['auth-sls-rest-api']['base-url']}/jwt.html" target="_blank">JWT Token Generator</a>`,
entryFile: 'src/app.ts',
noImplicitAdditionalProperties: 'throw-on-extras',
controllerPathGlobs: ['src/**/*Controller*.ts'],
outputDirectory: 'src',
specVersion: 3,
securityDefinitions: {
jwt: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
});
console.log('Generating routes...');
await generateRoutes({
entryFile: 'src/app.ts',
noImplicitAdditionalProperties: 'throw-on-extras',
controllerPathGlobs: ['src/**/*Controller*.ts'],
routesDir: 'src',
authenticationModule: 'src/auth.ts',
noWriteIfUnchanged: true,
});
})();