Skip to content

Commit 2732c89

Browse files
committed
feat(cli): add options to specify redoc options
1 parent 7ee1ab2 commit 2732c89

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

cli/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Options = {
2121
output?: string;
2222
title?: string;
2323
templateFileName?: string;
24+
redocOptions?: object;
2425
};
2526

2627
const BUNDLES_DIR = dirname(require.resolve('redoc'));
@@ -60,6 +61,7 @@ yargs
6061
ssr: argv.ssr,
6162
watch: argv.watch,
6263
templateFileName: argv.template,
64+
redocOptions: argv.options || {},
6365
});
6466
} catch (e) {
6567
console.log(e.stack);
@@ -104,6 +106,7 @@ yargs
104106
cdn: argv.cdn,
105107
title: argv.title,
106108
templateFileName: argv.template,
109+
redocOptions: argv.options || {},
107110
});
108111
} catch (e) {
109112
console.log(e.message);
@@ -115,6 +118,9 @@ yargs
115118
describe: 'Path to handlebars page template, see https://git.io/vxZ3V for the example ',
116119
type: 'string',
117120
})
121+
.options('options', {
122+
describe: 'ReDoc options, use dot notation, e.g. options.nativeScrollbars',
123+
})
118124
.demandCommand().argv;
119125

120126
async function serve(port: number, pathToSpec: string, options: Options = {}) {
@@ -188,13 +194,13 @@ async function bundle(pathToSpec, options: Options = {}) {
188194
async function getPageHTML(
189195
spec: any,
190196
pathToSpec: string,
191-
{ ssr, cdn, title, templateFileName }: Options,
197+
{ ssr, cdn, title, templateFileName, redocOptions = {} }: Options,
192198
) {
193199
let html, css, state;
194200
let redocStandaloneSrc;
195201
if (ssr) {
196202
console.log('Prerendering docs');
197-
const store = await createStore(spec, pathToSpec);
203+
const store = await createStore(spec, pathToSpec, redocOptions);
198204
const sheet = new ServerStyleSheet();
199205
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
200206
css = sheet.getStyleTags();
@@ -207,15 +213,17 @@ async function getPageHTML(
207213

208214
templateFileName = templateFileName ? templateFileName : join(__dirname, './template.hbs');
209215
const template = compile(readFileSync(templateFileName).toString());
210-
console.log(readFileSync(templateFileName).toString());
211-
debugger;
212216
return template({
213217
redocHTML: `
214218
<script>
215219
${(ssr && `const __redoc_state = ${JSON.stringify(state)};`) || ''}
216220
document.addEventListener('DOMContentLoaded', function() {
217221
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+
};
219227
});
220228
</script>
221229
<div id="redoc">${(ssr && html) || ''}</div>`,

0 commit comments

Comments
 (0)