fix(cli): Further fix on #81

This commit is contained in:
melvinchia3636
2026-01-28 19:17:15 +08:00
parent cde1925db3
commit 6b2ffd09c6
3 changed files with 28 additions and 24 deletions

View File

@@ -10,6 +10,8 @@ import listModules from '../functions/listModules'
interface BuildOptions {
docker?: boolean
buildClient?: boolean
buildServer?: boolean
}
/**
@@ -30,6 +32,10 @@ export async function buildModuleHandler(
const isDocker = options?.docker ?? false
const buildClient = options?.buildClient ?? true
const buildServer = options?.buildServer ?? true
const moduleNames = moduleName
? [normalizePackage(moduleName).fullName]
: Object.keys(modules)
@@ -66,23 +72,27 @@ export async function buildModuleHandler(
}
// Build client
if (hasClient) {
logger.info(`Building ${chalk.blue(shortName)} client...`)
if (hasClient && buildClient) {
if (!isDocker && !process.env.VITE_API_HOST) {
logger.warn(`VITE_API_HOST not set. Skipping local build.`)
} else {
logger.info(`Building ${chalk.blue(shortName)} client...`)
try {
executeCommand('bun run build:client', {
cwd: targetDir,
stdio: 'pipe',
env: isDocker ? { ...process.env, DOCKER_BUILD: 'true' } : undefined
})
clientBuiltCount++
} catch (error) {
logger.error(`Failed to build ${shortName} client: ${error}`)
try {
executeCommand('bun run build:client', {
cwd: targetDir,
stdio: 'pipe',
env: isDocker ? { ...process.env, DOCKER_BUILD: 'true' } : undefined
})
clientBuiltCount++
} catch (error) {
logger.error(`Failed to build ${shortName} client: ${error}`)
}
}
}
// Build server
if (hasServer) {
if (hasServer && buildServer) {
logger.info(`Building ${chalk.blue(shortName)} server...`)
try {

View File

@@ -96,11 +96,11 @@ export async function installModuleHandler(
for (const moduleName of installed) {
logger.debug(`Building ${chalk.blue(moduleName)} bundles...`)
// Build regular dist
// Build regular dist for client and server
await buildModuleHandler(moduleName)
// Build dist-docker
await buildModuleHandler(moduleName, { docker: true })
// Build dist-docker for client only
await buildModuleHandler(moduleName, { docker: true, buildServer: false })
}
// Generate migrations for new modules (skip in Docker environment)

View File

@@ -21,15 +21,9 @@ const envPath = path.resolve(ROOT_DIR, 'env/.env.local')
const dockerEnvPath = path.resolve(ROOT_DIR, 'env/.env.docker')
if (fs.existsSync(envPath)) {
dotenv.config({ path: envPath, quiet: true })
} else if (fs.existsSync(dockerEnvPath)) {
dotenv.config({ path: dockerEnvPath, quiet: true })
} else {
logger.warn(
`Environment file not found at ${envPath}. Continuing without loading environment variables from file.`
)
}
const paths = [envPath, dockerEnvPath].filter(fs.existsSync)
dotenv.config({ path: paths, quiet: true })
// Setup and run CLI
try {