chore: fix cli declarations

This commit is contained in:
Roman Hotsiy 2019-03-11 17:58:23 +02:00
parent 2cdfcd25cd
commit f31cf3534c
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -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';
@ -25,6 +25,7 @@ interface Options {
cdn?: boolean;
output?: string;
title?: string;
port?: number;
templateFileName?: string;
templateOptions?: any;
redocOptions?: any;
@ -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);
}
@ -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 || {},
};
@ -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',
@ -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...`));
}