Notes/src/services/resource_dir.ts

30 lines
805 B
TypeScript
Raw Normal View History

import log from "./log.js";
import path from "path";
import fs from "fs";
2017-12-27 16:44:15 -05:00
2024-07-19 00:18:35 +03:00
import { fileURLToPath } from "url";
export const RESOURCE_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
2017-12-27 16:44:15 -05:00
2023-06-30 11:18:34 +02:00
// where the "trilium" executable is
const ELECTRON_APP_ROOT_DIR = path.resolve(RESOURCE_DIR, "../..");
const DB_INIT_DIR = path.resolve(RESOURCE_DIR, "db");
2017-12-27 16:44:15 -05:00
if (!fs.existsSync(DB_INIT_DIR)) {
log.error(`Could not find DB initialization directory: ${DB_INIT_DIR}`);
2017-12-27 16:44:15 -05:00
process.exit(1);
}
const MIGRATIONS_DIR = path.resolve(DB_INIT_DIR, "migrations");
2017-12-27 16:44:15 -05:00
if (!fs.existsSync(MIGRATIONS_DIR)) {
log.error(`Could not find migration directory: ${MIGRATIONS_DIR}`);
2017-12-27 16:44:15 -05:00
process.exit(1);
}
export default {
2017-12-27 16:44:15 -05:00
RESOURCE_DIR,
MIGRATIONS_DIR,
DB_INIT_DIR,
2023-02-17 16:44:04 +01:00
ELECTRON_APP_ROOT_DIR
2022-12-30 17:10:07 +01:00
};