Merge pull request #109 from Lifeforge-app/fix/hardcoded-links

fix: hardcoded file directory
This commit is contained in:
Melvin Chia
2026-03-25 15:01:30 +08:00
committed by GitHub
5 changed files with 45 additions and 29 deletions

View File

@@ -0,0 +1,29 @@
import path from 'path'
/**
* Gets the project root directory name from a file path.
* Supports both app modules (/apps/) and core modules (/server/).
*/
export default function getProjectRootDir(
filePath: string
): string | undefined {
// For app modules: /path/to/projectRoot/apps/moduleId/server/...
const appsIndex = filePath.indexOf('/apps/')
if (appsIndex !== -1) {
const pathBeforeApps = filePath.substring(0, appsIndex)
return path.basename(pathBeforeApps)
} else {
// For core modules: /path/to/projectRoot/server/src/...
const serverIndex = filePath.indexOf('/server/')
if (serverIndex !== -1) {
const pathBeforeServer = filePath.substring(0, serverIndex)
return path.basename(pathBeforeServer)
}
}
return undefined
}

View File

@@ -1,3 +1,5 @@
import getProjectRootDir from './extractProjectRoot'
export default function getCallerModuleId():
| { source: 'app' | 'core'; id: string }
| undefined {
@@ -17,8 +19,14 @@ export default function getCallerModuleId():
if (!filePath) return undefined
// Try external app module: /apps/{moduleId}/server/
const appMatch = filePath.match(/lifeforge\/apps\/([^/]+)\/server\//)
const projectRoot = getProjectRootDir(filePath)
if (!projectRoot) return undefined
// Try external app module: /{projectRoot}/apps/{moduleId}/server/
const appMatch = filePath.match(
new RegExp(`${projectRoot}\\/apps\\/([^/]+)\\/server\\/`)
)
if (appMatch)
return {
@@ -27,10 +35,10 @@ export default function getCallerModuleId():
}
// Try core module:
// - /lifeforge/server/src/lib/{coreModuleId}/
// - /lifeforge/server/src/core/{coreModuleId}/
// - /{projectRoot}/server/src/lib/{coreModuleId}/
// - /{projectRoot}/server/src/core/{coreModuleId}/
const coreMatch = filePath.match(
/lifeforge\/server\/src\/(?:lib|core)\/([^/]+)\//
new RegExp(`${projectRoot}\\/server\\/src\\/(?:lib|core)\\/([^/]+)\\/`)
)
if (coreMatch)

View File

@@ -1,20 +0,0 @@
import { coreLogger } from '@functions/logging'
import path from 'path'
/**
* Ensures the root directory name is 'lifeforge'.
* Exits the process if the root directory name is not 'lifeforge'.
*/
export default function ensureRootName(): void {
const projectRoot = path.basename(
path.resolve(import.meta.dirname.split('server')[0])
)
if (projectRoot !== 'lifeforge') {
coreLogger.error(
`Project root directory must be named 'lifeforge', but found '${projectRoot}'. Please rename the root directory.`
)
process.exit(1)
}
}

View File

@@ -10,7 +10,6 @@ import { LocaleService } from '@functions/initialization/localeService'
import traceRouteStack from '@functions/initialization/traceRouteStack'
import { LOG_LEVELS, type LogLevel, coreLogger } from '@functions/logging'
import createSocketServer from '@functions/socketio/createSocketServer'
import ensureRootName from '@functions/utils/ensureRootName'
import app from './core/app'
@@ -57,7 +56,6 @@ function startServer(server: ReturnType<typeof createServer>): void {
async function main(): Promise<void> {
LocaleService.validateAndLoad()
ensureRootName()
ensureDirectories()
ensureCredentials()
await checkDB()

View File

@@ -4,6 +4,7 @@ import getPBInstance from '@/utils/pocketbase'
import { cleanupOldMigrations } from '../functions/migration-generation/cleanupOldMigrations'
import stageMigration from '../functions/migration-generation/stageMigrations'
import { importSchemaModules } from '../utils'
import chalk from 'chalk'
/**
* Command handler for generating database migrations
@@ -29,9 +30,9 @@ export async function generateMigrationsHandler(
killPB?.()
logger.success('Migrations generated successfully')
logger.success(`Migrations generated successfully for module ${chalk.green(targetModule ? `${targetModule}` : 'all modules')}`)
} catch (error) {
logger.error('Migration script failed')
logger.error(`Migration script failed for module ${chalk.red(targetModule ? `${targetModule}` : 'all modules')}.`)
logger.debug(`Error details: ${error}`)
killPB?.()