All files / util init-util.js

93.33% Statements 14/15
0% Branches 0/1
100% Functions 1/1
93.33% Lines 14/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211x 1x 1x 1x   1x 1x 1x       1x 1x 1x 1x 1x 1x       1x
const fs = require('fs');
const path = require('path');
const { access, readFile } = require('fs').promises;
const { buildImageRecords } = require('./image-util');
 
const initData = async (db, dir = 'init') => {
    try {
        await access(path.join(dir, 'data.json'), fs.constants.R_OK)
    } catch (e) {
        return
    }
    const data = await readFile(path.join(dir, 'data.json'), 'utf-8')
    const json = JSON.parse(data);
    for (let record of json.records) {
        console.log(`\t${record.name}`);
        const records = await buildImageRecords(path.join(dir, record.image), record.profiles);
        db.add(records);
    }
}
 
module.exports = { initData }