-
Notifications
You must be signed in to change notification settings - Fork 12
/
file-paths.js
45 lines (36 loc) · 1.22 KB
/
file-paths.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
import os from 'os';
import fs from 'fs';
import path from 'path';
export class FilePaths {
constructor(logger, appFolderName) {
if (!appFolderName) throw new Error('FilePaths: application folder name not specified');
this.appFolderName = appFolderName;
const appFolderPath = this.appFolderPath();
if (!fs.existsSync(appFolderPath)) {
try {
fs.mkdirSync(appFolderPath);
} catch(e) {
logger.logError(`error while creating directory ${appFolderPath} \n ${e}`);
}
logger.logInfo(`created folder ${appFolderPath}`);
}else {
logger.logInfo(`using folder ${appFolderPath}`);
}
}
appFolderPath() {
const documentsPath = path.join(os.homedir(), "Documents");
return path.join(documentsPath, this.appFolderName);
}
dbFilePath() {
return path.join(this.appFolderPath(), 'database.db');
}
csvFilePath() {
return path.join(this.appFolderPath(), 'Courses.csv');
}
settingsPath() {
return path.join(this.appFolderPath(), 'settings.json');
}
logsPath() {
return path.join(this.appFolderPath(), 'logs.txt');
}
}