1
1
#!/usr/bin/env node
2
2
/* tslint:disable:no-implicit-dependencies */
3
- import * as React from 'react' ;
4
- import * as updateNotifier from 'update-notifier' ;
3
+ import { createElement } from 'react' ;
5
4
import { renderToString } from 'react-dom/server' ;
6
5
import { ServerStyleSheet } from 'styled-components' ;
7
6
@@ -10,6 +9,7 @@ import { createServer, IncomingMessage, ServerResponse } from 'http';
10
9
import { dirname , join , resolve , extname as getExtName } from 'path' ;
11
10
12
11
import * as zlib from 'zlib' ;
12
+ import * as boxen from 'boxen' ;
13
13
14
14
// @ts -ignore
15
15
import { createStore , loadAndBundleSpec , Redoc } from 'redoc' ;
@@ -66,6 +66,14 @@ export const mimeTypes = {
66
66
67
67
const BUNDLES_DIR = dirname ( require . resolve ( 'redoc' ) ) ;
68
68
69
+ const boxenOptions = {
70
+ title : 'DEPRECATED' ,
71
+ titleAlignment : 'center' ,
72
+ padding : 1 ,
73
+ margin : 1 ,
74
+ borderColor : 'red' ,
75
+ } as boxen . Options ;
76
+
69
77
const builderForBuildCommand = yargs => {
70
78
yargs . positional ( 'spec' , {
71
79
describe : 'path or URL to your spec' ,
@@ -112,7 +120,6 @@ const handlerForBuildCommand = async (argv: any) => {
112
120
} ;
113
121
114
122
try {
115
- notifyUpdateCliVersion ( ) ;
116
123
await bundle ( argv . spec , config ) ;
117
124
} catch ( e ) {
118
125
handleError ( e ) ;
@@ -121,7 +128,7 @@ const handlerForBuildCommand = async (argv: any) => {
121
128
122
129
YargsParser . command (
123
130
'serve <spec>' ,
124
- 'start the server' ,
131
+ 'start the server [deprecated] ' ,
125
132
yargs => {
126
133
yargs . positional ( 'spec' , {
127
134
describe : 'path or URL to your spec' ,
@@ -176,38 +183,38 @@ YargsParser.command(
176
183
} ;
177
184
178
185
try {
179
- notifyUpdateCliVersion ( ) ;
180
186
await serve ( argv . host as string , argv . port as number , argv . spec as string , config ) ;
181
187
} catch ( e ) {
182
188
handleError ( e ) ;
183
189
}
184
190
} ,
185
191
[
186
192
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
+ ) } `) ;
190
198
return res ;
191
199
} ,
192
200
] ,
201
+ true ,
193
202
)
194
203
. command (
195
204
'build <spec>' ,
196
- 'build definition into zero-dependency HTML-file' ,
205
+ 'build definition into zero-dependency HTML-file [deprecated] ' ,
197
206
builderForBuildCommand ,
198
207
handlerForBuildCommand ,
208
+ [ notifyDeprecation ] ,
209
+ true ,
199
210
)
200
211
. command (
201
212
'bundle <spec>' ,
202
213
'bundle spec into zero-dependency HTML-file [deprecated]' ,
203
214
builderForBuildCommand ,
204
215
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 ,
211
218
)
212
219
. demandCommand ( )
213
220
. options ( 't' , {
@@ -344,7 +351,7 @@ async function getPageHTML(
344
351
const store = await createStore ( spec , specUrl , redocOptions ) ;
345
352
const sheet = new ServerStyleSheet ( ) ;
346
353
// @ts -ignore
347
- html = renderToString ( sheet . collectStyles ( React . createElement ( Redoc , { store } ) ) ) ;
354
+ html = renderToString ( sheet . collectStyles ( createElement ( Redoc , { store } ) ) ) ;
348
355
css = sheet . getStyleTags ( ) ;
349
356
state = await store . toJS ( ) ;
350
357
@@ -472,15 +479,12 @@ function getObjectOrJSON(options) {
472
479
}
473
480
}
474
481
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 ;
486
490
}
0 commit comments