From eb096b69be52568fc581027161c7d0c4b26c56c1 Mon Sep 17 00:00:00 2001 From: AlexVarchuk Date: Mon, 21 Mar 2022 17:21:02 +0200 Subject: [PATCH] fix: rename bandle command and add deprecate notice (#1935) Co-authored-by: Roman Hotsiy --- cli/index.ts | 127 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 52 deletions(-) diff --git a/cli/index.ts b/cli/index.ts index e9042707..9f6d764d 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -59,7 +59,58 @@ export const mimeTypes = { const BUNDLES_DIR = dirname(require.resolve('redoc')); -/* tslint:disable-next-line */ +const builderForBuildCommand = yargs => { + yargs.positional('spec', { + describe: 'path or URL to your spec', + }); + + yargs.option('o', { + describe: 'Output file', + alias: 'output', + type: 'string', + default: 'redoc-static.html', + }); + + yargs.options('title', { + describe: 'Page Title', + type: 'string', + }); + + yargs.options('disableGoogleFont', { + describe: 'Disable Google Font', + type: 'boolean', + default: false, + }); + + yargs.option('cdn', { + describe: 'Do not include ReDoc source code into html page, use link to CDN instead', + type: 'boolean', + default: false, + }); + + yargs.demandOption('spec'); + return yargs; +}; + +const handlerForBuildCommand = async (argv: any) => { + const config = { + ssr: true, + output: argv.o as string, + cdn: argv.cdn as boolean, + title: argv.title as string, + disableGoogleFont: argv.disableGoogleFont as boolean, + templateFileName: argv.template as string, + templateOptions: argv.templateOptions || {}, + redocOptions: getObjectOrJSON(argv.options), + }; + + try { + await bundle(argv.spec, config); + } catch (e) { + handleError(e); + } +}; + YargsParser.command( 'serve ', 'start the server', @@ -122,60 +173,32 @@ YargsParser.command( handleError(e); } }, + [ + res => { + console.log( + `\n⚠️ This command is deprecated. Use "npx @redocly/openapi-cli preview-docs petstore.yaml"\n`, + ); + return res; + }, + ], ) + .command( + 'build ', + 'build definition into zero-dependency HTML-file', + builderForBuildCommand, + handlerForBuildCommand, + ) .command( 'bundle ', - 'bundle spec into zero-dependency HTML-file', - yargs => { - yargs.positional('spec', { - describe: 'path or URL to your spec', - }); - - yargs.option('o', { - describe: 'Output file', - alias: 'output', - type: 'string', - default: 'redoc-static.html', - }); - - yargs.options('title', { - describe: 'Page Title', - type: 'string', - }); - - yargs.options('disableGoogleFont', { - describe: 'Disable Google Font', - type: 'boolean', - default: false, - }); - - yargs.option('cdn', { - describe: 'Do not include ReDoc source code into html page, use link to CDN instead', - type: 'boolean', - default: false, - }); - - yargs.demandOption('spec'); - return yargs; - }, - async (argv: any) => { - const config = { - ssr: true, - output: argv.o as string, - cdn: argv.cdn as boolean, - title: argv.title as string, - disableGoogleFont: argv.disableGoogleFont as boolean, - templateFileName: argv.template as string, - templateOptions: argv.templateOptions || {}, - redocOptions: getObjectOrJSON(argv.options), - }; - - try { - await bundle(argv.spec, config); - } catch (e) { - handleError(e); - } - }, + 'bundle spec into zero-dependency HTML-file [deprecated]', + builderForBuildCommand, + handlerForBuildCommand, + [ + res => { + console.log(`\n⚠️ This command is deprecated. Use "build" command instead.\n`); + return res; + }, + ], ) .demandCommand() .options('t', {