-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
46 lines (41 loc) · 1.04 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
44
45
46
#!/usr/bin/env node
import arg from 'arg'
import fs from 'fs'
import { overlayFiles } from './src/overlay.js'
function showHelp () {
console.log('Usage: overlayjs --openapi FILEPATH --overlay FILEPATH')
console.log(' use --help to see this help')
}
// Function to read the version from package.json
function showVersion () {
const packageJsonPath = './package.json'
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
console.log(packageJson.version)
}
try {
const args = arg({
'--openapi': String,
'--overlay': String,
'--version': Boolean,
'--help': Boolean
})
if (args['--version']) {
showVersion()
process.exit(0)
}
if (args['--overlay'] && args['--openapi']) {
const openapiFile = args['--openapi']
const overlayFile = args['--overlay']
const spec = overlayFiles(openapiFile, overlayFile)
console.log(spec)
} else {
showHelp()
}
} catch (err) {
if (err.code === 'ARG_UNKNOWN_OPTION') {
console.warn(err.message)
showHelp()
} else {
throw err
}
}