feat(cli): add title option to bundle

This commit is contained in:
Roman Hotsiy 2018-03-20 10:21:05 +02:00
parent d3779bfd40
commit bb8a6784c2
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -18,6 +18,7 @@ type Options = {
watch?: boolean; watch?: boolean;
cdn?: boolean; cdn?: boolean;
output?: string; output?: string;
title?: string;
}; };
const BUNDLES_DIR = dirname(require.resolve('redoc')); const BUNDLES_DIR = dirname(require.resolve('redoc'));
@ -74,6 +75,12 @@ yargs
default: 'redoc-static.html', default: 'redoc-static.html',
}); });
yargs.options('title', {
describe: 'Page Title',
type: 'string',
default: 'ReDoc documentation',
});
yargs.option('cdn', { yargs.option('cdn', {
describe: 'Do not include ReDoc source code into html page, use link to CDN instead', describe: 'Do not include ReDoc source code into html page, use link to CDN instead',
type: 'boolean', type: 'boolean',
@ -85,7 +92,7 @@ yargs
}, },
async argv => { async argv => {
try { try {
await bundle(argv.spec, { ssr: true, output: argv.o, cdn: argv.cdn }); await bundle(argv.spec, { ssr: true, output: argv.o, cdn: argv.cdn, title: argv.title });
} catch (e) { } catch (e) {
console.log(e.message); console.log(e.message);
} }
@ -161,7 +168,7 @@ async function bundle(pathToSpec, options: Options = {}) {
); );
} }
async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options) { async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn, title }: Options) {
let html, css, state; let html, css, state;
let redocStandaloneSrc; let redocStandaloneSrc;
if (ssr) { if (ssr) {
@ -181,7 +188,7 @@ async function getPageHTML(spec: any, pathToSpec: string, { ssr, cdn }: Options)
<html> <html>
<head> <head>
<meta charset="utf8" /> <meta charset="utf8" />
<title>ReDoc</title> <title>${title}</title>
<!-- needed for adaptive design --> <!-- needed for adaptive design -->
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<style> <style>