-
Notifications
You must be signed in to change notification settings - Fork 2
/
fileCheck.js
51 lines (45 loc) · 1.26 KB
/
fileCheck.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
44
45
46
47
48
49
50
51
// This module checks for required files and create them if they aren't present.
import * as fs from "fs/promises";
import { createPromptDB } from "./promptQueue.js";
export default async function checkForFileSystem() {
try {
await checkForAPI();
} catch (err) {
if (err.errno === -17) {
console.log("API.json already exists.");
} else {
console.log("Unknown error opening or creating API.json. Err: " + err);
// throw err;
}
}
try {
await checkForPromptQueue();
} catch (err) {
console.log("Unknown error creating promptDB. Err: " + err);
}
try {
await checkForQuotesDB();
} catch (err) {
if (err.errno === -17) {
console.log("quotesDB.json already exists!");
} else {
console.log(
"Unknown error opening or creating quotesDB.json. Err: " + err
);
// throw err;
}
}
}
// Check for api.json, if it doesn't exist, make it.
async function checkForAPI() {
await fs.open("./data/api.json", "wx");
}
// Check for prompts DB; if it doesn't exist, make it.
async function checkForPromptQueue() {
await createPromptDB();
return true;
}
// Check for quotesDB.json, if it doesn't exist, make it.
async function checkForQuotesDB() {
await fs.open("./data/quotesDB.json", "wx");
}