mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 01:54:08 +03:00
chore: fix cli declarations
This commit is contained in:
parent
2cdfcd25cd
commit
f31cf3534c
35
cli/index.ts
35
cli/index.ts
|
@ -13,7 +13,7 @@ import * as zlib from 'zlib';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';
|
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';
|
||||||
|
|
||||||
import {watch} from 'chokidar';
|
import { watch } from 'chokidar';
|
||||||
import { createReadStream, existsSync, readFileSync, ReadStream, writeFileSync } from 'fs';
|
import { createReadStream, existsSync, readFileSync, ReadStream, writeFileSync } from 'fs';
|
||||||
import * as mkdirp from 'mkdirp';
|
import * as mkdirp from 'mkdirp';
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ interface Options {
|
||||||
cdn?: boolean;
|
cdn?: boolean;
|
||||||
output?: string;
|
output?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
port?: number;
|
||||||
templateFileName?: string;
|
templateFileName?: string;
|
||||||
templateOptions?: any;
|
templateOptions?: any;
|
||||||
redocOptions?: any;
|
redocOptions?: any;
|
||||||
|
@ -62,16 +63,16 @@ YargsParser.command(
|
||||||
return yargs;
|
return yargs;
|
||||||
},
|
},
|
||||||
async argv => {
|
async argv => {
|
||||||
const config = {
|
const config: Options = {
|
||||||
ssr: argv.ssr,
|
ssr: argv.ssr as boolean,
|
||||||
watch: argv.watch,
|
watch: argv.watch as boolean,
|
||||||
templateFileName: argv.template,
|
templateFileName: argv.template as string,
|
||||||
templateOptions: argv.templateOptions || {},
|
templateOptions: argv.templateOptions || {},
|
||||||
redocOptions: argv.options || {},
|
redocOptions: argv.options || {},
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await serve(argv.port, argv.spec, config);
|
await serve(argv.port as number, argv.spec as string, config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
handleError(e);
|
handleError(e);
|
||||||
}
|
}
|
||||||
|
@ -108,12 +109,12 @@ YargsParser.command(
|
||||||
return yargs;
|
return yargs;
|
||||||
},
|
},
|
||||||
async argv => {
|
async argv => {
|
||||||
const config = {
|
const config: Options = {
|
||||||
ssr: true,
|
ssr: true,
|
||||||
output: argv.o,
|
output: argv.o as string,
|
||||||
cdn: argv.cdn,
|
cdn: argv.cdn as boolean,
|
||||||
title: argv.title,
|
title: argv.title as string,
|
||||||
templateFileName: argv.template,
|
templateFileName: argv.template as string,
|
||||||
templateOptions: argv.templateOptions || {},
|
templateOptions: argv.templateOptions || {},
|
||||||
redocOptions: argv.options || {},
|
redocOptions: argv.options || {},
|
||||||
};
|
};
|
||||||
|
@ -132,7 +133,8 @@ YargsParser.command(
|
||||||
type: 'string',
|
type: 'string',
|
||||||
})
|
})
|
||||||
.options('templateOptions', {
|
.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', {
|
.options('options', {
|
||||||
describe: 'ReDoc options, use dot notation, e.g. options.nativeScrollbars',
|
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');
|
log('Updated successfully');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error while updating: ', e.message);
|
console.error('Error while updating: ', e.message);
|
||||||
}})
|
}
|
||||||
|
})
|
||||||
.on('error', error => console.error(`Watcher error: ${error}`))
|
.on('error', error => console.error(`Watcher error: ${error}`))
|
||||||
.on('ready', () => log(`👀 Watching ${pathToSpecDirectory} for changes...`));
|
.on('ready', () => log(`👀 Watching ${pathToSpecDirectory} for changes...`));
|
||||||
}
|
}
|
||||||
|
@ -247,13 +250,13 @@ async function getPageHTML(
|
||||||
ssr
|
ssr
|
||||||
? 'hydrate(__redoc_state, container);'
|
? 'hydrate(__redoc_state, container);'
|
||||||
: `init("spec.json", ${JSON.stringify(redocOptions)}, container)`
|
: `init("spec.json", ${JSON.stringify(redocOptions)}, container)`
|
||||||
};
|
};
|
||||||
|
|
||||||
</script>`,
|
</script>`,
|
||||||
redocHead: ssr
|
redocHead: ssr
|
||||||
? (cdn
|
? (cdn
|
||||||
? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>'
|
? '<script src="https://unpkg.com/redoc@next/bundles/redoc.standalone.js"></script>'
|
||||||
: `<script>${redocStandaloneSrc}</script>`) + css
|
: `<script>${redocStandaloneSrc}</script>`) + css
|
||||||
: '<script src="redoc.standalone.js"></script>',
|
: '<script src="redoc.standalone.js"></script>',
|
||||||
title,
|
title,
|
||||||
templateOptions,
|
templateOptions,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user