fix(server,forgeCLI): route and schema template file generation is now run in forgeCLI before starting the server

This commit is contained in:
Melvin Chia
2025-12-30 21:16:22 +08:00
parent 3d73e29b1d
commit 4e0fb0ed5f
5 changed files with 8 additions and 39 deletions

View File

@@ -14,7 +14,7 @@
"type": "module",
"main": "./dist/server.js",
"scripts": {
"dev": "tsx watch --env-file=../env/.env.local ./src/index.ts",
"dev": "echo \"PLEASE USE \"bun forge dev\" INSTEAD\"",
"types": "bun run tsc -b",
"build": "bun build ./src/index.ts --target bun --minify --production --outfile=./dist/server.js",
"start": "NODE_ENV=production bun --env-file=../env/.env.local ./src/index.ts",

View File

@@ -1,34 +0,0 @@
import fs from 'fs'
import path from 'path'
import { LoggingService } from '@functions/logging/loggingService'
const ROOT_DIR = path.resolve(import.meta.dirname.split('core')[0], 'core')
/**
* Initializes the route and schema files.
* Creates the files from templates if they do not exist.
*/
export default function initRouteAndSchemaFiles(): void {
const appRoutesPath = path.resolve(ROOT_DIR, 'routes/app.routes.ts')
const schemaPath = path.resolve(ROOT_DIR, 'schema.ts')
const templatesDir = path.resolve(ROOT_DIR, 'templates')
if (!fs.existsSync(appRoutesPath)) {
LoggingService.info(
'app.routes.ts not found, creating from template...',
'INIT'
)
fs.copyFileSync(path.join(templatesDir, 'example.routes.ts'), appRoutesPath)
}
if (!fs.existsSync(schemaPath)) {
LoggingService.info(
'schema.ts not found, creating from template...',
'INIT'
)
fs.copyFileSync(path.join(templatesDir, 'example.schema.ts'), schemaPath)
}
}

View File

@@ -2,9 +2,7 @@ import fs from 'fs'
import { createServer } from 'node:http'
import checkDB from '@functions/database/dbUtils'
import { ensureKeysExist } from '@functions/encryption'
import ensureCredentials from '@functions/initialization/ensureCredentials'
import initRouteAndSchemaFiles from '@functions/initialization/initRouteAndSchemaFiles'
import { LocaleService } from '@functions/initialization/localeService'
import traceRouteStack from '@functions/initialization/traceRouteStack'
import updateLocaleSubmodules from '@functions/initialization/updateLocaleSubmodules'
@@ -35,7 +33,6 @@ async function main(): Promise<void> {
updateLocaleSubmodules()
LocaleService.validateAndLoad()
ensureRootName()
initRouteAndSchemaFiles()
ensureDirectories()
ensureCredentials()
await checkDB()

View File

@@ -7,6 +7,7 @@ import {
executeCommand,
killExistingProcess
} from '@/utils/helpers'
import initRouteAndSchemaFiles from '@/utils/initRouteAndSchemaFiles'
import CLILoggingService from '@/utils/logging'
/**
@@ -67,7 +68,9 @@ export const SERVICE_COMMANDS: Record<string, ServiceConfig> = {
process.exit(1)
}
return 'bun run dev'
initRouteAndSchemaFiles()
return 'bun tsx watch --env-file=../env/.env.local ./src/index.ts'
},
cwd: 'server'
},

View File

@@ -2,6 +2,7 @@ import fs from 'fs'
import path from 'path'
import CLILoggingService from './logging'
import { generateDatabaseSchemas } from '@/commands/modules/functions'
const ROOT_DIR = path.resolve(
import.meta.dirname.split('tools')[0],
@@ -26,6 +27,8 @@ export default function initRouteAndSchemaFiles(): {
if (!fs.existsSync(schemaPath)) {
CLILoggingService.info('schema.ts not found, creating from template...')
fs.copyFileSync(path.join(templatesDir, 'example.schema.ts'), schemaPath)
generateDatabaseSchemas()
}
return {