forked from noxious/server
Renamed files to storage, re-worked datetimeManager, added json help utilities
This commit is contained in:
33
src/utilities/storage.ts
Normal file
33
src/utilities/storage.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import config from './config'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
export function getRootPath(folder: string, ...additionalSegments: string[]) {
|
||||
return path.join(process.cwd(), folder, ...additionalSegments)
|
||||
}
|
||||
|
||||
export function getAppPath(folder: string, ...additionalSegments: string[]) {
|
||||
const baseDir = config.ENV === 'development' ? 'src' : 'dist'
|
||||
return path.join(process.cwd(), baseDir, folder, ...additionalSegments)
|
||||
}
|
||||
|
||||
export function getPublicPath(folder: string, ...additionalSegments: string[]) {
|
||||
return path.join(process.cwd(), 'public', folder, ...additionalSegments)
|
||||
}
|
||||
|
||||
export function doesPathExist(path: string) {
|
||||
try {
|
||||
fs.accessSync(path, fs.constants.F_OK);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function createDir(path: string) {
|
||||
try {
|
||||
fs.mkdirSync(path, { recursive: true });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user