@@ -32,7 +32,7 @@ const BUNDLES_DIR = dirname(require.resolve('redoc'));
32
32
33
33
/* tslint:disable-next-line */
34
34
YargsParser . command (
35
- 'serve [ spec] ' ,
35
+ 'serve < spec> ' ,
36
36
'start the server' ,
37
37
yargs => {
38
38
yargs . positional ( 'spec' , {
@@ -60,16 +60,22 @@ YargsParser.command(
60
60
return yargs ;
61
61
} ,
62
62
async argv => {
63
- await serve ( argv . port , argv . spec , {
63
+ const config = {
64
64
ssr : argv . ssr ,
65
65
watch : argv . watch ,
66
66
templateFileName : argv . template ,
67
67
redocOptions : argv . options || { } ,
68
- } ) ;
68
+ } ;
69
+
70
+ try {
71
+ await serve ( argv . port , argv . spec , config ) ;
72
+ } catch ( e ) {
73
+ handleError ( e ) ;
74
+ }
69
75
} ,
70
76
)
71
77
. command (
72
- 'bundle [ spec] ' ,
78
+ 'bundle < spec> ' ,
73
79
'bundle spec into zero-dependency HTML-file' ,
74
80
yargs => {
75
81
yargs . positional ( 'spec' , {
@@ -99,16 +105,22 @@ YargsParser.command(
99
105
return yargs ;
100
106
} ,
101
107
async argv => {
102
- await bundle ( argv . spec , {
108
+ const config = {
103
109
ssr : true ,
104
110
output : argv . o ,
105
111
cdn : argv . cdn ,
106
112
title : argv . title ,
107
113
templateFileName : argv . template ,
108
114
redocOptions : argv . options || { } ,
109
- } ) ;
115
+ } ;
116
+
117
+ try {
118
+ await bundle ( argv . spec , config ) ;
119
+ } catch ( e ) {
120
+ handleError ( e ) ;
121
+ }
110
122
} ,
111
- )
123
+ )
112
124
. demandCommand ( )
113
125
. options ( 't' , {
114
126
alias : 'template' ,
@@ -117,10 +129,6 @@ YargsParser.command(
117
129
} )
118
130
. options ( 'options' , {
119
131
describe : 'ReDoc options, use dot notation, e.g. options.nativeScrollbars' ,
120
- } )
121
- . fail ( ( message , error ) => {
122
- console . log ( error . stack ) ;
123
- process . exit ( 1 ) ;
124
132
} ) . argv ;
125
133
126
134
async function serve ( port : number , pathToSpec : string , options : Options = { } ) {
@@ -229,13 +237,13 @@ async function getPageHTML(
229
237
ssr
230
238
? 'hydrate(__redoc_state, container);'
231
239
: `init("spec.json", ${ JSON . stringify ( redocOptions ) } , container)`
232
- } ;
240
+ } ;
233
241
234
242
</script>` ,
235
243
redocHead : ssr
236
244
? ( cdn
237
- ? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>'
238
- : `<script>${ redocStandaloneSrc } </script>` ) + css
245
+ ? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>'
246
+ : `<script>${ redocStandaloneSrc } </script>` ) + css
239
247
: '<script src="redoc.standalone.js"></script>' ,
240
248
title,
241
249
} ) ;
@@ -296,3 +304,8 @@ function isURL(str: string): boolean {
296
304
function escapeUnicode ( str ) {
297
305
return str . replace ( / \u2028 | \u2029 / g, m => '\\u202' + ( m === '\u2028' ? '8' : '9' ) ) ;
298
306
}
307
+
308
+ function handleError ( error : Error ) {
309
+ console . error ( error . stack ) ;
310
+ process . exit ( 1 ) ;
311
+ }
0 commit comments