-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 1.2 KB
/
index.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
const { generateService, getSchema } = require('openapi2typescript-temp')
const path = require('path')
const fs = require('fs')
const pkgDir = require('pkg-dir')
const FILE_NAME = '.openapi-gen.js'
;(async () => {
const rootDir = await pkgDir(process.cwd())
const oJsonPath = path.join(rootDir, FILE_NAME)
fs.access(oJsonPath, fs.constants.R_OK, (err) => {
if (err) {
console.log(`[error] ${oJsonPath} not exists;`)
process.exit(1)
}
console.log(`[openapi4cli] get the file: ${oJsonPath}`)
const openAPIConfig = require(oJsonPath)
openAPIConfig.forEach((item) => {
const serversPath = path.join(
rootDir,
item.serversPath || 'src/services'
)
const mockFolder = item.mockFolder
? path.join(
rootDir,
typeof item.mockFolder === 'boolean'
? 'src/mock'
: item.mockFolder
)
: undefined
generateService({
...item,
serversPath,
mockFolder,
})
})
})
})()