-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-resources.js
More file actions
30 lines (24 loc) · 922 Bytes
/
build-resources.js
File metadata and controls
30 lines (24 loc) · 922 Bytes
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
// only do the thing when called directly (node this-script)
if (require.main === module) {
Promise.resolve().then(buildResources)
}
module.exports = buildResources
async function buildResources () {
const debug = require('debug')('prefix-server')
const path = require('path')
const fs = require('fs')
const { promisify } = require('util')
const zlib = require('zlib')
const writeFile = promisify(fs.writeFile)
const gzip = promisify(zlib.gzip)
debug('preparing API data')
const { prepareData } = require('./api/utils')
const dataFiles = await prepareData()
const fileNames = Object.entries(dataFiles)
for (const [keyName, data] of fileNames) {
const extraFilePath = path.resolve(__dirname, `./api/datafiles/${keyName}.json.gz`)
const compressed = await gzip(JSON.stringify(data))
await writeFile(extraFilePath, compressed)
debug(`wrote API data to ${extraFilePath}`)
}
}