This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathprep-cds.js
71 lines (58 loc) · 1.93 KB
/
prep-cds.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* Migrate and generate for the given CDS scraper.
*
* Sample call:
*
* node tools-migration/prep-cds.js US/CA/mono-county.js
*/
// Yes, I know this code is very messy!
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
const sourceKey = require('../src/shared/sources/_lib/source-key.js')
function runCommand (command, dirname) {
let raw = ''
try {
raw = execSync(command, { encoding: 'utf-8', cwd: dirname, stdio: 'inherit' })
} catch (err) {
console.log(err)
console.log(err.stack)
process.exit(1)
}
return raw
}
const locPath = process.argv[2]
if (!locPath) {
console.log(`No loc specified, quitting.`)
process.exit(0)
}
const cdsDir = path.join(__dirname, '..', '..', 'coronadatascraper')
const cdsScraper = path.join(cdsDir, 'src', 'shared', 'scrapers', locPath)
if (!fs.existsSync(cdsScraper)) {
console.log(`Missing scraper ${cdsScraper}`)
process.exit(1)
}
const liKey = sourceKey(cdsScraper.replace('scrapers', 'sources').toLowerCase())
// Run the generation in CDS
console.log('got ' + locPath)
console.log('which is sourceKey ' + liKey)
// The cache-migration.js in CDS migrates relative to process.cwd()
// ... but the command is executed from the root dir of CDS, so this
// mess drops the file back into the li directory here.
const cacheMigDest = path.join('..', 'li', 'crawler-cache')
let cmd = ''
runCommand(`rm -rf ${path.join(cacheMigDest, liKey)}`, cdsDir)
cmd = `node tools/generate-v1-cache.js node --dest ${cacheMigDest} --location ${locPath}`
runCommand(cmd, cdsDir)
if (process.platform === 'darwin') {
cmd = `say -v Alex "Done migration"`
runCommand(cmd, cdsDir)
}
const distDest = `zz-dist-${liKey}`
runCommand(`rm -rf ${distDest}`, cdsDir)
cmd = `yarn timeseries --location ${locPath} --writeTo ${distDest}`
runCommand(cmd, cdsDir)
if (process.platform === 'darwin') {
cmd = `say -v Alex "Done timeseries"`
runCommand(cmd, cdsDir)
}