forked from COVID19Tracking/covid-public-api-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (62 loc) · 1.9 KB
/
index.js
File metadata and controls
67 lines (62 loc) · 1.9 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
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 bigQueryRunner = require('./src/run/bigquery')
const writer = require('./src/output/files')
const config = require('./config')
const bigquery = require('./src/run/bigquery')
const reporter = require('./src/utilities/reporter')()
const startTime = DateTime.local()
const optionDefinitions = [
{ name: 'source', alias: 's', type: String },
{ name: 'clean', alias: 'c', type: Boolean },
{ name: 'bigquery', alias: 'b', type: Boolean },
{ name: 'volunteers', alias: 'v', type: Boolean },
]
const options = commandLineArgs(optionDefinitions)
if (options.clean) {
fs.removeSync(config.outputPath)
}
fs.ensureDirSync(config.outputPath)
const run = () => {
if (!options.volunteers) {
bigQueryRunner(config, (result) => {
reporter.addDataLine('BigQuery tables written', result.length)
})
}
if (options.bigquery) {
return
}
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()