mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-10-16 11:21:37 +08:00
style: move "important" funcs to top of file
This commit is contained in:
parent
c47522eb50
commit
6818b2d54c
@ -15,31 +15,6 @@ import { join as pathJoin} from "path";
|
|||||||
const DIR_NAME = "trilium-data";
|
const DIR_NAME = "trilium-data";
|
||||||
const FOLDER_PERMISSIONS = 0o700;
|
const FOLDER_PERMISSIONS = 0o700;
|
||||||
|
|
||||||
export function getPlatformAppDataDir(platform: ReturnType<typeof os.platform>, ENV_APPDATA_DIR: string | undefined = process.env.APPDATA) {
|
|
||||||
|
|
||||||
switch(true) {
|
|
||||||
case platform === "win32" && !!ENV_APPDATA_DIR:
|
|
||||||
return ENV_APPDATA_DIR;
|
|
||||||
|
|
||||||
case platform === "linux":
|
|
||||||
return `${os.homedir()}/.local/share`;
|
|
||||||
|
|
||||||
case platform === "darwin":
|
|
||||||
return `${os.homedir()}/Library/Application Support`;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// if OS is not recognized
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function createDirIfNotExisting(path: fs.PathLike, permissionMode: fs.Mode = FOLDER_PERMISSIONS) {
|
|
||||||
if (!fs.existsSync(path)) {
|
|
||||||
fs.mkdirSync(path, permissionMode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getTriliumDataDir(dataDirName: string) {
|
export function getTriliumDataDir(dataDirName: string) {
|
||||||
// case A
|
// case A
|
||||||
if (process.env.TRILIUM_DATA_DIR) {
|
if (process.env.TRILIUM_DATA_DIR) {
|
||||||
@ -84,9 +59,35 @@ export function getDataDirs(TRILIUM_DATA_DIR: string) {
|
|||||||
|
|
||||||
Object.freeze(dataDirs);
|
Object.freeze(dataDirs);
|
||||||
return dataDirs;
|
return dataDirs;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPlatformAppDataDir(platform: ReturnType<typeof os.platform>, ENV_APPDATA_DIR: string | undefined = process.env.APPDATA) {
|
||||||
|
|
||||||
|
switch(true) {
|
||||||
|
case platform === "win32" && !!ENV_APPDATA_DIR:
|
||||||
|
return ENV_APPDATA_DIR;
|
||||||
|
|
||||||
|
case platform === "linux":
|
||||||
|
return `${os.homedir()}/.local/share`;
|
||||||
|
|
||||||
|
case platform === "darwin":
|
||||||
|
return `${os.homedir()}/Library/Application Support`;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// if OS is not recognized
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createDirIfNotExisting(path: fs.PathLike, permissionMode: fs.Mode = FOLDER_PERMISSIONS) {
|
||||||
|
if (!fs.existsSync(path)) {
|
||||||
|
fs.mkdirSync(path, permissionMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const TRILIUM_DATA_DIR = getTriliumDataDir(DIR_NAME);
|
const TRILIUM_DATA_DIR = getTriliumDataDir(DIR_NAME);
|
||||||
const dataDirs = getDataDirs(TRILIUM_DATA_DIR);
|
const dataDirs = getDataDirs(TRILIUM_DATA_DIR);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user