fix(scripts): fix schema file retrieval logic

Former-commit-id: 877c2bda6195d16241dba4f35d817905a36f15e0 [formerly e7b48f15b7d808cee94ed90a00a31a3bdcddbc3a] [formerly 4b9b672d57773844a46565f3ad5bbb3b01d6a6e0 [formerly 0f30bcf666bd3a4bb483a23d1d7c36775f007969]]
Former-commit-id: d70f8ced4027e452e36fd37871f8d5246d8efc84 [formerly cc631cd71fef1e37aa287e45ead2d04a14aca1bf]
Former-commit-id: 4842a0581a9526bc8324f49815425b68b6769d09
This commit is contained in:
Melvin Chia
2025-10-05 20:35:11 +08:00
parent 34e9b542f4
commit 17061ca0dc

View File

@@ -22,15 +22,9 @@ interface MigrationResult {
error?: string
}
// Constants
const PATHS = {
ENV_FILE: path.resolve(__dirname, '../env/.env.local'),
MODULES_DIR: path.resolve(__dirname, '../server/src/lib')
} as const
// Environment validation
function validateEnvironment(): Environment {
dotenv.config({ path: PATHS.ENV_FILE })
dotenv.config({ path: path.resolve(__dirname, '../env/.env.local') })
const { PB_DIR } = process.env
@@ -114,7 +108,10 @@ async function cleanupOldMigrations(
async function getSchemaFiles(targetModule?: string): Promise<string[]> {
const { globSync } = await import('glob')
const allSchemas = globSync('./server/src/lib/**/schema.ts')
const allSchemas = globSync([
'./server/src/lib/**/schema.ts',
'./apps/**/server/schema.ts'
])
const filteredSchemas = targetModule
? allSchemas.filter(schemaPath => {
@@ -147,7 +144,13 @@ async function importSchemaModules(
const module = await import(path.resolve(schemaPath))
return {
moduleName: schemaPath.split('/').slice(-2, -1)[0],
moduleName: schemaPath
.split('/')
.slice(0, -1)
.join('/')
.replace(/\/server$/, '')
.split('/')
.pop(),
schema: module.default
}
})