@@ -21,6 +21,7 @@ type Options = {
21
21
output ? : string ;
22
22
title ? : string ;
23
23
templateFileName ? : string ;
24
+ redocOptions ? : object ;
24
25
} ;
25
26
26
27
const BUNDLES_DIR = dirname ( require . resolve ( 'redoc' ) ) ;
60
61
ssr : argv . ssr ,
61
62
watch : argv . watch ,
62
63
templateFileName : argv . template ,
64
+ redocOptions : argv . options || { } ,
63
65
} ) ;
64
66
} catch ( e ) {
65
67
console . log ( e . stack ) ;
@@ -104,6 +106,7 @@ yargs
104
106
cdn : argv . cdn ,
105
107
title : argv . title ,
106
108
templateFileName : argv . template ,
109
+ redocOptions : argv . options || { } ,
107
110
} ) ;
108
111
} catch ( e ) {
109
112
console . log ( e . message ) ;
@@ -115,6 +118,9 @@ yargs
115
118
describe : 'Path to handlebars page template, see https://git.io/vxZ3V for the example ' ,
116
119
type : 'string' ,
117
120
} )
121
+ . options ( 'options' , {
122
+ describe : 'ReDoc options, use dot notation, e.g. options.nativeScrollbars' ,
123
+ } )
118
124
. demandCommand ( ) . argv ;
119
125
120
126
async function serve ( port : number , pathToSpec : string , options : Options = { } ) {
@@ -188,13 +194,13 @@ async function bundle(pathToSpec, options: Options = {}) {
188
194
async function getPageHTML (
189
195
spec : any ,
190
196
pathToSpec : string ,
191
- { ssr, cdn, title, templateFileName } : Options ,
197
+ { ssr, cdn, title, templateFileName, redocOptions = { } } : Options ,
192
198
) {
193
199
let html , css , state ;
194
200
let redocStandaloneSrc ;
195
201
if ( ssr ) {
196
202
console . log ( 'Prerendering docs' ) ;
197
- const store = await createStore ( spec , pathToSpec ) ;
203
+ const store = await createStore ( spec , pathToSpec , redocOptions ) ;
198
204
const sheet = new ServerStyleSheet ( ) ;
199
205
html = renderToString ( sheet . collectStyles ( React . createElement ( Redoc , { store } ) ) ) ;
200
206
css = sheet . getStyleTags ( ) ;
@@ -207,15 +213,17 @@ async function getPageHTML(
207
213
208
214
templateFileName = templateFileName ? templateFileName : join ( __dirname , './template.hbs' ) ;
209
215
const template = compile ( readFileSync ( templateFileName ) . toString ( ) ) ;
210
- console . log ( readFileSync ( templateFileName ) . toString ( ) ) ;
211
- debugger ;
212
216
return template ( {
213
217
redocHTML : `
214
218
<script>
215
219
${ ( ssr && `const __redoc_state = ${ JSON . stringify ( state ) } ;` ) || '' }
216
220
document.addEventListener('DOMContentLoaded', function() {
217
221
var container = document.getElementById('redoc');
218
- Redoc.${ ssr ? 'hydrate(__redoc_state, container);' : 'init("spec.json", {}, container)' } ;
222
+ Redoc.${
223
+ ssr
224
+ ? 'hydrate(__redoc_state, container);'
225
+ : `init("spec.json", ${ JSON . stringify ( redocOptions ) } , container)`
226
+ } ;
219
227
});
220
228
</script>
221
229
<div id="redoc">${ ( ssr && html ) || '' } </div>` ,
0 commit comments