forked from c19k/website-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.js
29 lines (24 loc) · 950 Bytes
/
publish.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
const moment = require('moment')
const fs = require('fs')
const path = require('path')
const _ = require('lodash')
// Creates a symlink to the latest version of the data (which can be served)
const publish = () => {
// Add 540 = UTC+9 for JST.
const dateString = moment().utcOffset(540).format('YYYY-MM-DD')
for (let dir of ['patient_data', 'summary', 'kpi']) {
let files = fs.readdirSync(path.join('.', 'docs', dir))
let sorted = _.reverse(_.sortBy(_.filter(files, v => { return v.startsWith('2020')})))
if (sorted.length > 0) {
let latest = sorted[0]
let latestDestPath = path.join('.', 'docs', dir, latest)
let latestPath = path.join('.', 'docs', dir, 'latest.json')
fs.unlink(latestPath, err => {
// deliberately ignore err.
console.log(`Symlink to ${latest} from ${latestPath}`)
fs.symlinkSync(latest, latestPath)
})
}
}
}
publish()