28 lines
666 B
JavaScript
28 lines
666 B
JavaScript
import { writeFile } from 'fs/promises';
|
|
|
|
import { getArg } from './args.js';
|
|
import { getChildren } from './io.js';
|
|
import { error, log } from './log.js';
|
|
|
|
const ctx = 'initDb.js';
|
|
|
|
const initDb = async () => {
|
|
log(ctx, 'Grabbing existing directories');
|
|
let directory = '';
|
|
try {
|
|
directory = getArg('path');
|
|
} catch (err) {
|
|
error(ctx, err);
|
|
return;
|
|
}
|
|
const children = await getChildren(directory);
|
|
const db = children.map(child => ({
|
|
'user': child,
|
|
'lastUpdated': 'never',
|
|
}));
|
|
log(ctx, 'Writing database');
|
|
await writeFile(`${directory}/db.json`, JSON.stringify(db, null, 2));
|
|
log(ctx, 'Writing complete!');
|
|
};
|
|
|
|
initDb();
|