import { log } from './log.js'; /** * Returns valid db schema */ export const dbSchema = (userList) => { return { version: '1.0.0', userList, } } /** * Returns valid user schema */ export const userSchema = (entry) => { return { lastError: entry.lastError, lastUpdated: entry.lastUpdated, pastUsernames: entry.pastUsernames, } } /** * Creates db at the specified directory * @param {string} directory the directory the db.json file will be stored in */ export const createDb = async (directory) => { log(ctx, 'Grabbing existing directories'); const children = await getChildDirectories(directory); const db = dbSchema(Object.fromEntries(children.map(e => [e, userSchema({})]))); log(ctx, 'Writing database'); await writeFile(`${directory}/db.json`, JSON.stringify(db, null, 2)); log(ctx, 'Writing complete!'); }