-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlistMissingScreenshots.js
43 lines (36 loc) · 1.12 KB
/
listMissingScreenshots.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
const fs = require('fs/promises')
const path = require('path')
const getJsonForType = async type =>
JSON.parse((await fs.readFile(`${type}/data.json`)).toString())
const checkIfScreenshotExists = datum =>
fs.stat(path.join(__dirname, datum.image))
const addMissingScreenshotPath = async (acc, datum) =>
(await acc).concat(datum.image)
const handleErrorAndReturnAcc = (acc, e, datum) => {
switch (e.code) {
case 'ENOENT':
return addMissingScreenshotPath(acc, datum)
case 'ERR_INVALID_ARG_TYPE':
return acc
default:
console.error(`Unexpected error:`, e)
return acc
}
}
const collectPathsToMissingScreenshots = data =>
data.reduce(async (acc, datum) => {
try {
await checkIfScreenshotExists(datum)
return acc
} catch (e) {
return handleErrorAndReturnAcc(acc, e, datum)
}
}, [])
async function main(type) {
const data = await getJsonForType(type)
const pathsToMissingScreenshots = await collectPathsToMissingScreenshots(data)
console.log('Screenshots that are missing for', type)
console.table(pathsToMissingScreenshots)
}
main('Animals')
main('Loot')