This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
55 lines (50 loc) · 1.51 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
47
48
49
50
51
52
53
54
55
require('dotenv').config()
const commandLineArgs = require('command-line-args')
const fs = require('fs-extra')
const { DateTime, Interval } = require('luxon')
const sources = require('./src/sources')
const runner = require('./src/run')
const writer = require('./src/output/files')
const config = require('./config')
const reporter = require('./src/utilities/reporter')()
const startTime = DateTime.local()
const optionDefinitions = [
{ name: 'source', alias: 's', type: String },
{ name: 'clean', alias: 'c', type: Boolean },
]
const options = commandLineArgs(optionDefinitions)
if (options.clean) {
fs.removeSync(config.outputPath)
}
fs.ensureDirSync(config.outputPath)
const run = () => {
runner(
sources(options),
(result) => {
writer(result, config.outputPath)
},
(api, graphQl) => {
if (!options.volunteers) {
fs.writeJsonSync(
`${config.outputPath}openapi.json`,
api.getDefinition(),
{
spaces: 2,
}
)
fs.writeFileSync(`${config.outputPath}schema.graphql`, graphQl.getSdl())
}
reporter.addDataLine('Files written', reporter.getTotal('files'))
const buildTime = Interval.fromDateTimes(startTime, DateTime.local())
reporter.addLine(
`Total run time: ${
buildTime.length('minutes') > 1
? Math.floor(buildTime.length('seconds') / 60)
: 0
} minutes ${Math.round(buildTime.length('seconds') % 60)} seconds`
)
reporter.report()
}
)
}
run()