Skip to content

Commit

Permalink
chore: fix cli declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 11, 2019
1 parent 2cdfcd2 commit f31cf35
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as zlib from 'zlib';
// @ts-ignore
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';

import {watch} from 'chokidar';
import { watch } from 'chokidar';
import { createReadStream, existsSync, readFileSync, ReadStream, writeFileSync } from 'fs';
import * as mkdirp from 'mkdirp';

Expand All @@ -25,6 +25,7 @@ interface Options {
cdn?: boolean;
output?: string;
title?: string;
port?: number;
templateFileName?: string;
templateOptions?: any;
redocOptions?: any;
Expand Down Expand Up @@ -62,16 +63,16 @@ YargsParser.command(
return yargs;
},
async argv => {
const config = {
ssr: argv.ssr,
watch: argv.watch,
templateFileName: argv.template,
const config: Options = {
ssr: argv.ssr as boolean,
watch: argv.watch as boolean,
templateFileName: argv.template as string,
templateOptions: argv.templateOptions || {},
redocOptions: argv.options || {},
};

try {
await serve(argv.port, argv.spec, config);
await serve(argv.port as number, argv.spec as string, config);
} catch (e) {
handleError(e);
}
Expand Down Expand Up @@ -108,12 +109,12 @@ YargsParser.command(
return yargs;
},
async argv => {
const config = {
const config: Options = {
ssr: true,
output: argv.o,
cdn: argv.cdn,
title: argv.title,
templateFileName: argv.template,
output: argv.o as string,
cdn: argv.cdn as boolean,
title: argv.title as string,
templateFileName: argv.template as string,
templateOptions: argv.templateOptions || {},
redocOptions: argv.options || {},
};
Expand All @@ -132,7 +133,8 @@ YargsParser.command(
type: 'string',
})
.options('templateOptions', {
describe: 'Additional options that you want pass to template. Use dot notation, e.g. templateOptions.metaDescription',
describe:
'Additional options that you want pass to template. Use dot notation, e.g. templateOptions.metaDescription',
})
.options('options', {
describe: 'ReDoc options, use dot notation, e.g. options.nativeScrollbars',
Expand Down Expand Up @@ -190,7 +192,8 @@ async function serve(port: number, pathToSpec: string, options: Options = {}) {
log('Updated successfully');
} catch (e) {
console.error('Error while updating: ', e.message);
}})
}
})
.on('error', error => console.error(`Watcher error: ${error}`))
.on('ready', () => log(`👀 Watching ${pathToSpecDirectory} for changes...`));
}
Expand Down Expand Up @@ -247,13 +250,13 @@ async function getPageHTML(
ssr
? 'hydrate(__redoc_state, container);'
: `init("spec.json", ${JSON.stringify(redocOptions)}, container)`
};
};
</script>`,
redocHead: ssr
? (cdn
? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>'
: `<script>${redocStandaloneSrc}</script>`) + css
? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>'
: `<script>${redocStandaloneSrc}</script>`) + css
: '<script src="redoc.standalone.js"></script>',
title,
templateOptions,
Expand Down

0 comments on commit f31cf35

Please sign in to comment.