Files
XCDesktop/api/config/index.ts

48 lines
1.1 KiB
TypeScript

import path from 'path'
import { fileURLToPath } from 'url'
import os from 'os'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
export const config = {
get projectRoot(): string {
if (__dirname.includes('app.asar')) {
return path.resolve(__dirname, '..').replace('app.asar', 'app.asar.unpacked')
}
return path.resolve(__dirname, '../../')
},
get notebookRoot(): string {
return process.env.NOTEBOOK_ROOT
? path.resolve(process.env.NOTEBOOK_ROOT)
: path.join(this.projectRoot, 'notebook')
},
get tempRoot(): string {
return path.join(os.tmpdir(), 'xcdesktop_uploads')
},
get serverPort(): number {
return parseInt(process.env.PORT || '3001', 10)
},
get isVercel(): boolean {
return !!process.env.VERCEL
},
get isElectron(): boolean {
return __dirname.includes('app.asar')
},
get isDev(): boolean {
return !this.isElectron && !this.isVercel
},
}
export const PATHS = {
get PROJECT_ROOT() { return config.projectRoot },
get NOTEBOOK_ROOT() { return config.notebookRoot },
get TEMP_ROOT() { return config.tempRoot },
}