11#!/usr/bin/env node
22/* tslint:disable:no-implicit-dependencies */
3- import * as React from 'react' ;
4- import * as updateNotifier from 'update-notifier' ;
3+ import { createElement } from 'react' ;
54import { renderToString } from 'react-dom/server' ;
65import { ServerStyleSheet } from 'styled-components' ;
76
@@ -10,6 +9,7 @@ import { createServer, IncomingMessage, ServerResponse } from 'http';
109import { dirname , join , resolve , extname as getExtName } from 'path' ;
1110
1211import * as zlib from 'zlib' ;
12+ import * as boxen from 'boxen' ;
1313
1414// @ts -ignore
1515import { createStore , loadAndBundleSpec , Redoc } from 'redoc' ;
@@ -66,6 +66,14 @@ export const mimeTypes = {
6666
6767const BUNDLES_DIR = dirname ( require . resolve ( 'redoc' ) ) ;
6868
69+ const boxenOptions = {
70+ title : 'DEPRECATED' ,
71+ titleAlignment : 'center' ,
72+ padding : 1 ,
73+ margin : 1 ,
74+ borderColor : 'red' ,
75+ } as boxen . Options ;
76+
6977const builderForBuildCommand = yargs => {
7078 yargs . positional ( 'spec' , {
7179 describe : 'path or URL to your spec' ,
@@ -112,7 +120,6 @@ const handlerForBuildCommand = async (argv: any) => {
112120 } ;
113121
114122 try {
115- notifyUpdateCliVersion ( ) ;
116123 await bundle ( argv . spec , config ) ;
117124 } catch ( e ) {
118125 handleError ( e ) ;
@@ -121,7 +128,7 @@ const handlerForBuildCommand = async (argv: any) => {
121128
122129YargsParser . command (
123130 'serve <spec>' ,
124- 'start the server' ,
131+ 'start the server [deprecated] ' ,
125132 yargs => {
126133 yargs . positional ( 'spec' , {
127134 describe : 'path or URL to your spec' ,
@@ -176,38 +183,38 @@ YargsParser.command(
176183 } ;
177184
178185 try {
179- notifyUpdateCliVersion ( ) ;
180186 await serve ( argv . host as string , argv . port as number , argv . spec as string , config ) ;
181187 } catch ( e ) {
182188 handleError ( e ) ;
183189 }
184190 } ,
185191 [
186192 res => {
187- console . log (
188- `\n⚠️ This command is deprecated. Use "npx @redocly/cli preview-docs petstore.yaml"\n` ,
189- ) ;
193+ console . log ( `
194+ ${ boxen (
195+ 'This package is deprecated.\n\nUse `npx @redocly/cli preview-docs <api>` instead.' ,
196+ boxenOptions ,
197+ ) } `) ;
190198 return res ;
191199 } ,
192200 ] ,
201+ true ,
193202)
194203 . command (
195204 'build <spec>' ,
196- 'build definition into zero-dependency HTML-file' ,
205+ 'build definition into zero-dependency HTML-file [deprecated] ' ,
197206 builderForBuildCommand ,
198207 handlerForBuildCommand ,
208+ [ notifyDeprecation ] ,
209+ true ,
199210 )
200211 . command (
201212 'bundle <spec>' ,
202213 'bundle spec into zero-dependency HTML-file [deprecated]' ,
203214 builderForBuildCommand ,
204215 handlerForBuildCommand ,
205- [
206- res => {
207- console . log ( `\n⚠️ This command is deprecated. Use "build" command instead.\n` ) ;
208- return res ;
209- } ,
210- ] ,
216+ [ notifyDeprecation ] ,
217+ true ,
211218 )
212219 . demandCommand ( )
213220 . options ( 't' , {
@@ -344,7 +351,7 @@ async function getPageHTML(
344351 const store = await createStore ( spec , specUrl , redocOptions ) ;
345352 const sheet = new ServerStyleSheet ( ) ;
346353 // @ts -ignore
347- html = renderToString ( sheet . collectStyles ( React . createElement ( Redoc , { store } ) ) ) ;
354+ html = renderToString ( sheet . collectStyles ( createElement ( Redoc , { store } ) ) ) ;
348355 css = sheet . getStyleTags ( ) ;
349356 state = await store . toJS ( ) ;
350357
@@ -472,15 +479,12 @@ function getObjectOrJSON(options) {
472479 }
473480}
474481
475- function notifyUpdateCliVersion ( ) {
476- const pkg = require ( './package.json' ) ;
477- const notifier = updateNotifier ( {
478- pkg,
479- updateCheckInterval : 0 ,
480- shouldNotifyInNpmScript : true ,
481- } ) ;
482- notifier . notify ( {
483- message :
484- 'Run `{updateCommand}` to update.\nChangelog: https://github.com/Redocly/redoc/releases/tag/{latestVersion}' ,
485- } ) ;
482+ function notifyDeprecation ( res : YargsParser . Arguments ) : YargsParser . Arguments {
483+ console . log (
484+ boxen (
485+ 'This package is deprecated.\n\nUse `npx @redocly/cli build-docs <api>` instead.' ,
486+ boxenOptions ,
487+ ) ,
488+ ) ;
489+ return res ;
486490}
0 commit comments