forked from trackawesomelist/trackawesomelist-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-db.ts
25 lines (24 loc) · 746 Bytes
/
init-db.ts
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
import {
getDbIndexFilePath,
getDbMetaFilePath,
writeJSONFile,
} from "./util.ts";
import log from "./log.ts";
import dbInitMeta from "./db-meta-init.json" assert { type: "json" };
export default async function initDb() {
const dbMetaFilePath = getDbMetaFilePath();
const dbIndexFilePath = getDbIndexFilePath();
if (!await Deno.stat(dbMetaFilePath).catch(() => false)) {
log.info("db meta not found, auto init");
// copy db-meta-init.json
await writeJSONFile(dbMetaFilePath, dbInitMeta);
}
if (!await Deno.stat(dbIndexFilePath).catch(() => false)) {
log.info("db index not found, auto init");
// copy db-meta-init.json
await writeJSONFile(dbIndexFilePath, {});
}
}
if (import.meta.main) {
initDb();
}