11// go.ts — 进入项目目录 (启动子 shell)
22import chalk from 'chalk'
33import { existsSync } from 'fs'
4- import { readGlobalConfig } from '../lib/config.js'
4+ import { readGlobalConfig , getBackendDir , getFrontendDir } from '../lib/config.js'
55import { t } from '../lib/i18n.js'
66import { fatal } from '../lib/errors.js'
77import { getDefaultShell , getShellArgs } from '../lib/platform.js'
88import { 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 ,
0 commit comments