mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
refactor(data_dir): pass DIR_NAME as argument to getTriliumDir
makes it a bit cleaner and easier to test in the future, as it is one thing less that'd need mocking :-)
This commit is contained in:
parent
e021c0cd0e
commit
c47522eb50
@ -40,7 +40,7 @@ function createDirIfNotExisting(path: fs.PathLike, permissionMode: fs.Mode = FOL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTriliumDataDir() {
|
export function getTriliumDataDir(dataDirName: string) {
|
||||||
// case A
|
// case A
|
||||||
if (process.env.TRILIUM_DATA_DIR) {
|
if (process.env.TRILIUM_DATA_DIR) {
|
||||||
createDirIfNotExisting(process.env.TRILIUM_DATA_DIR);
|
createDirIfNotExisting(process.env.TRILIUM_DATA_DIR);
|
||||||
@ -48,7 +48,7 @@ export function getTriliumDataDir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// case B
|
// case B
|
||||||
const homePath = pathJoin(os.homedir(), DIR_NAME);
|
const homePath = pathJoin(os.homedir(), dataDirName);
|
||||||
if (fs.existsSync(homePath)) {
|
if (fs.existsSync(homePath)) {
|
||||||
return homePath;
|
return homePath;
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ export function getTriliumDataDir() {
|
|||||||
// case C
|
// case C
|
||||||
const platformAppDataDir = getPlatformAppDataDir(os.platform(), process.env.APPDATA);
|
const platformAppDataDir = getPlatformAppDataDir(os.platform(), process.env.APPDATA);
|
||||||
if (platformAppDataDir && fs.existsSync(platformAppDataDir)) {
|
if (platformAppDataDir && fs.existsSync(platformAppDataDir)) {
|
||||||
const appDataDirPath = pathJoin(platformAppDataDir, DIR_NAME);
|
const appDataDirPath = pathJoin(platformAppDataDir, dataDirName);
|
||||||
createDirIfNotExisting(appDataDirPath);
|
createDirIfNotExisting(appDataDirPath);
|
||||||
return appDataDirPath;
|
return appDataDirPath;
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ export function getDataDirs(TRILIUM_DATA_DIR: string) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const TRILIUM_DATA_DIR = getTriliumDataDir();
|
const TRILIUM_DATA_DIR = getTriliumDataDir(DIR_NAME);
|
||||||
const dataDirs = getDataDirs(TRILIUM_DATA_DIR);
|
const dataDirs = getDataDirs(TRILIUM_DATA_DIR);
|
||||||
|
|
||||||
export default dataDirs;
|
export default dataDirs;
|
Loading…
x
Reference in New Issue
Block a user