Skip to content

Commit 2e63595

Browse files
yuWormclaude
andcommitted
feat: support legacy project structure in add command
Old FBA projects use the backend repo as the project root with frontend as a subdirectory. Detect this layout as a fallback when no backend subdir is found, storing backend_name as "." so all downstream path joins work correctly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b087d01 commit 2e63595

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/commands/add.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ function detectProject(projectDir: string): DetectResult {
135135
}
136136
}
137137

138+
// fallback: 项目根目录本身就是后端(老项目结构)
139+
if (!result.backendName && isBackendDir(projectDir)) {
140+
result.backendName = ".";
141+
const { dbType } = parseBackendEnv(projectDir);
142+
result.dbType = dbType;
143+
}
144+
138145
// 检测基础设施
139146
const infraDir = join(projectDir, "infra");
140147
if (existsSync(infraDir) && statSync(infraDir).isDirectory()) {
@@ -198,9 +205,13 @@ export async function addAction() {
198205
}
199206

200207
// 4. 展示探测结果
208+
const backendDisplayName =
209+
detected.backendName === "."
210+
? `${basename(projectDir)} ${chalk.dim("(project root)")}`
211+
: detected.backendName;
201212
clack.log.step(t("addConfirmDetected"));
202213
clack.log.info(
203-
`${chalk.bold(t("addBackendDetected"))}: ${chalk.green(detected.backendName)}`,
214+
`${chalk.bold(t("addBackendDetected"))}: ${chalk.green(backendDisplayName)}`,
204215
);
205216
clack.log.info(
206217
`${chalk.bold(t("addFrontendDetected"))}: ${chalk.green(detected.frontendName)}`,
@@ -298,7 +309,7 @@ export async function addAction() {
298309
clack.note(
299310
[
300311
`${chalk.bold(t("addProjectName"))}: ${projectName}`,
301-
`${chalk.bold(t("addBackendDetected"))}: ${detected.backendName}`,
312+
`${chalk.bold(t("addBackendDetected"))}: ${backendDisplayName}`,
302313
`${chalk.bold(t("addFrontendDetected"))}: ${detected.frontendName}`,
303314
`${chalk.bold(t("addDbTypeDetected"))}: ${dbType}`,
304315
`${chalk.bold(t("serverPort"))}: ${serverPort}`,

0 commit comments

Comments
 (0)