@@ -7,18 +7,6 @@ import { createBuild, createDev, info } from './commands/index.js'
7
7
8
8
const require = createRequire ( import . meta. url )
9
9
10
- /**
11
- * Wrap raw command to catch errors and exit process
12
- */
13
- const wrapCommand = ( cmd : ( ...args : any [ ] ) => Promise < void > ) : typeof cmd => {
14
- const wrappedCommand : typeof cmd = ( ...args ) =>
15
- cmd ( ...args ) . catch ( ( err ) => {
16
- console . error ( chalk . red ( err . stack ) )
17
- process . exit ( 1 )
18
- } )
19
- return wrappedCommand
20
- }
21
-
22
10
/**
23
11
* Vuepress cli
24
12
*/
@@ -47,7 +35,7 @@ export const cli = (defaultAppConfig: Partial<AppConfig> = {}): void => {
47
35
. option ( '--open' , 'Open browser when ready' )
48
36
. option ( '--debug' , 'Enable debug mode' )
49
37
. option ( '--no-watch' , 'Disable watching page and config files' )
50
- . action ( wrapCommand ( createDev ( defaultAppConfig ) ) )
38
+ . action ( createDev ( defaultAppConfig ) )
51
39
52
40
// register `build` command
53
41
program
@@ -62,12 +50,20 @@ export const cli = (defaultAppConfig: Partial<AppConfig> = {}): void => {
62
50
. option ( '--clean-temp' , 'Clean the temporary files before build' )
63
51
. option ( '--clean-cache' , 'Clean the cache files before build' )
64
52
. option ( '--debug' , 'Enable debug mode' )
65
- . action ( wrapCommand ( createBuild ( defaultAppConfig ) ) )
53
+ . action ( createBuild ( defaultAppConfig ) )
66
54
67
55
// register `info` command
68
- program
69
- . command ( 'info' , 'Display environment information' )
70
- . action ( wrapCommand ( info ) )
56
+ program . command ( 'info' , 'Display environment information' ) . action ( info )
57
+
58
+ program . parse ( process . argv , { run : false } )
71
59
72
- program . parse ( process . argv )
60
+ // run command or fallback to help messages
61
+ if ( program . matchedCommand ) {
62
+ program . runMatchedCommand ( ) . catch ( ( err ) => {
63
+ console . error ( chalk . red ( err . stack ) )
64
+ process . exit ( 1 )
65
+ } )
66
+ } else {
67
+ program . outputHelp ( )
68
+ }
73
69
}
0 commit comments