bitip/src/backend/utils/paths.ts

49 lines
1.4 KiB
TypeScript

import path from 'path';
import { fileURLToPath } from 'url';
const isProduction = process.env.NODE_ENV === 'production';
const findProjectRoot = (): string => {
// In production (Docker), process.cwd() is /app (project root)
if (isProduction) {
return process.cwd();
}
if (import.meta.url) {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rootPath = path.resolve(__dirname, '../../..');
return rootPath;
}
throw new Error(
'import.meta.url is required in development to resolve project root'
);
};
const projectRootPath = findProjectRoot();
console.log('[paths] Project root resolved:', projectRootPath);
const resolveFilePath = (...relativePath: string[]): string => {
return path.join(projectRootPath, ...relativePath);
};
const envPath = resolveFilePath('.env');
const releaseNotesPath = resolveFilePath('content', 'ReleaseNotes.json');
const overviewPath = resolveFilePath('content', 'Overview.json');
const frontendPrefix = isProduction ? 'dist' : 'src';
const frontendPath = resolveFilePath(frontendPrefix, 'frontend');
const paths = {
projectRoot: projectRootPath,
envFile: envPath,
releaseNotesFile: releaseNotesPath,
overviewFile: overviewPath,
frontendDir: frontendPath,
};
console.log('[paths] App paths resolved:', paths);
export { paths };
export default paths;