From 87d0d8793e09a67fa08fbab7181e10281e2a232f Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Thu, 17 Mar 2022 18:09:09 +0200 Subject: [PATCH 1/5] fix: rename bandle command and add deprecate notice --- cli/index.ts | 122 +++++++++++++++++++++++++++++---------------------- 1 file changed, 69 insertions(+), 53 deletions(-) diff --git a/cli/index.ts b/cli/index.ts index 10e82b2cc1..82ea739a99 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -10,7 +10,6 @@ import { dirname, join, resolve } from 'path'; import * as zlib from 'zlib'; -// @ts-ignore import { createStore, loadAndBundleSpec, Redoc } from 'redoc'; import { watch } from 'chokidar'; @@ -41,7 +40,58 @@ interface Options { 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', @@ -105,59 +155,25 @@ YargsParser.command( } }, ) + .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 to create zero-dependency HTML-file from the definition.⚠️\n`, + ); + return res; + }, + ], ) .demandCommand() .options('t', { From 8a60f97e34bceda65f723dbe2d360caa6b10cafb Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Thu, 17 Mar 2022 18:14:20 +0200 Subject: [PATCH 2/5] chore: return ts-ignore --- cli/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/index.ts b/cli/index.ts index 82ea739a99..e92a2bad62 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -10,6 +10,7 @@ import { dirname, join, resolve } from 'path'; import * as zlib from 'zlib'; +// @ts-ignore import { createStore, loadAndBundleSpec, Redoc } from 'redoc'; import { watch } from 'chokidar'; From d34b0e641b8e1d5420b826467e4d523e46c88890 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Mon, 21 Mar 2022 13:07:33 +0200 Subject: [PATCH 3/5] chore: add deprecate notice to serve command --- cli/index.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli/index.ts b/cli/index.ts index e92a2bad62..87c3766c96 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -155,6 +155,14 @@ YargsParser.command( handleError(e); } }, + [ + res => { + console.log( + `\n⚠️ This command is deprecated. Use openapi-cli for it: npx @redocly/openapi-cli preview-docs petstore.yaml⚠️\n`, + ); + return res; + }, + ], ) .command( 'build ', From 52280838ee1aef3ee1aa5697f5cfecb44bbdb448 Mon Sep 17 00:00:00 2001 From: AlexVarchuk Date: Mon, 21 Mar 2022 14:29:18 +0200 Subject: [PATCH 4/5] chore: update message Co-authored-by: Roman Hotsiy --- cli/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/index.ts b/cli/index.ts index 87c3766c96..a66ff2b9e1 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -178,7 +178,7 @@ YargsParser.command( [ res => { console.log( - `\n⚠️ This command is deprecated. Use build command to create zero-dependency HTML-file from the definition.⚠️\n`, + `\n⚠️ This command is deprecated. Use "build" command instead.\n`, ); return res; }, From b45a45dde0514845888783fb8a590c1eceab2a32 Mon Sep 17 00:00:00 2001 From: Alex Varchuk Date: Mon, 21 Mar 2022 14:35:01 +0200 Subject: [PATCH 5/5] chore: fix message --- cli/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cli/index.ts b/cli/index.ts index a66ff2b9e1..2ae99e0121 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -158,7 +158,7 @@ YargsParser.command( [ res => { console.log( - `\n⚠️ This command is deprecated. Use openapi-cli for it: npx @redocly/openapi-cli preview-docs petstore.yaml⚠️\n`, + `\n⚠️ This command is deprecated. Use "npx @redocly/openapi-cli preview-docs petstore.yaml"\n`, ); return res; }, @@ -177,9 +177,7 @@ YargsParser.command( handlerForBuildCommand, [ res => { - console.log( - `\n⚠️ This command is deprecated. Use "build" command instead.\n`, - ); + console.log(`\n⚠️ This command is deprecated. Use "build" command instead.\n`); return res; }, ],