Skip to content

Commit 2ae7e08

Browse files
feat: add deprecation label to redoc-cli (#2172)
--------- Co-authored-by: Adam Altman <[email protected]>
1 parent 53c83b4 commit 2ae7e08

File tree

6 files changed

+63
-1282
lines changed

6 files changed

+63
-1282
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Refer to the Redocly's documentation for more information on these products:
8484
- [Simple integration with `create-react-app`](https://redocly.com/docs/redoc/quickstart/react/)
8585

8686
[Example repo](https://github.com/APIs-guru/create-react-app-redoc)
87-
- [Command-line interface to bundle your docs into a **zero-dependency** HTML file](https://redoc.ly/docs/redoc/quickstart/cli/)
87+
- [Command-line interface to bundle your docs into a **zero-dependency** HTML file](https://redocly.com/docs/cli/commands/build-docs/)
8888
- Neat **interactive** documentation for nested objects <br>
8989
![](docs/images/nested-demo.gif)
9090

cli/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# redoc-cli
22

3+
**DEPRECATED: this package is deprecated. Use `npx @redocly/cli build-docs <api>` instead.**
4+
35
**[ReDoc](https://github.com/Redocly/redoc)'s Command Line Interface**
46

57
## Installation

cli/index.ts

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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';
54
import { renderToString } from 'react-dom/server';
65
import { ServerStyleSheet } from 'styled-components';
76

@@ -10,6 +9,7 @@ import { createServer, IncomingMessage, ServerResponse } from 'http';
109
import { dirname, join, resolve, extname as getExtName } from 'path';
1110

1211
import * as zlib from 'zlib';
12+
import * as boxen from 'boxen';
1313

1414
// @ts-ignore
1515
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';
@@ -66,6 +66,14 @@ export const mimeTypes = {
6666

6767
const 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+
6977
const 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

122129
YargsParser.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

Comments
 (0)