Skip to content

Commit ff44139

Browse files
committed
feat: add -s and -f options to fba-cli go for backend/frontend navigation
`fba-cli go -s` enters the backend directory directly, `fba-cli go -f` enters the frontend directory, instead of the project root. Made-with: Cursor
1 parent a23caac commit ff44139

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/commands/go.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// go.ts — 进入项目目录 (启动子 shell)
22
import chalk from 'chalk'
33
import { existsSync } from 'fs'
4-
import { readGlobalConfig } from '../lib/config.js'
4+
import { readGlobalConfig, getBackendDir, getFrontendDir } from '../lib/config.js'
55
import { t } from '../lib/i18n.js'
66
import { fatal } from '../lib/errors.js'
77
import { getDefaultShell, getShellArgs } from '../lib/platform.js'
88
import { execa } from 'execa'
99

10-
export async function goAction(options: { shell?: string }) {
10+
export async function goAction(options: { shell?: string; s?: boolean; f?: boolean }) {
1111
const config = readGlobalConfig()
1212

1313
if (!config.current) {
@@ -21,17 +21,33 @@ export async function goAction(options: { shell?: string }) {
2121
t('hintRunRemove'),
2222
)
2323
}
24-
// 优先级:命令行 --shell > 全局配置 shell > 平台默认 shell
24+
25+
let targetDir = projectPath
26+
let label = t('goEnteringProject')
27+
28+
if (options.s) {
29+
targetDir = getBackendDir(projectPath)
30+
label = t('goEnteringBackend')
31+
if (!existsSync(targetDir)) {
32+
fatal(`${t('backendDirNotFound')}\n ${t('expectedAt')} ${targetDir}`)
33+
}
34+
} else if (options.f) {
35+
targetDir = getFrontendDir(projectPath)
36+
label = t('goEnteringFrontend')
37+
if (!existsSync(targetDir)) {
38+
fatal(`${t('frontendDirNotFound')}\n ${t('expectedAt')} ${targetDir}`)
39+
}
40+
}
41+
2542
const shell = options.shell || config.shell || getDefaultShell()
2643

27-
console.log(chalk.cyan(`\n 📂 ${t('goEnteringProject')} ${projectPath}`))
44+
console.log(chalk.cyan(`\n 📂 ${label} ${targetDir}`))
2845
console.log(chalk.dim(` ${t('goShell')} ${shell}`))
2946
console.log(chalk.dim(` ${t('goExitHint')}\n`))
3047

31-
// 启动交互式子 shell,CWD 设为项目目录
3248
try {
3349
await execa(shell, getShellArgs(), {
34-
cwd: projectPath,
50+
cwd: targetDir,
3551
stdio: 'inherit',
3652
env: {
3753
...process.env,

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ program
176176
program
177177
.command('go')
178178
.description(t('cmdGo'))
179+
.option('-s', t('optGoServer'))
180+
.option('-f', t('optGoFrontend'))
179181
.option('--shell <shell>', t('optShell'))
180182
.action(async (options) => {
181183
const { goAction } = await import('./commands/go.js')

0 commit comments

Comments
 (0)