Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add deprecation label to redoc-cli #2172

Merged
merged 11 commits into from
Mar 6, 2023
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Refer to the Redocly's documentation for more information on these products:
- [Simple integration with `create-react-app`](https://redoc.ly/docs/redoc/quickstart/react/)

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

Expand Down
2 changes: 2 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# redoc-cli

**DEPRECATED: this package is deprecated now, please use `@redocly/cli build-docs <api>` instead.**
AlexVarchuk marked this conversation as resolved.
Show resolved Hide resolved

**[ReDoc](https://github.com/Redocly/redoc)'s Command Line Interface**

## Installation
Expand Down
62 changes: 35 additions & 27 deletions cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env node
/* tslint:disable:no-implicit-dependencies */
import * as React from 'react';
import * as updateNotifier from 'update-notifier';
import { createElement } from 'react';
import { renderToString } from 'react-dom/server';
import { ServerStyleSheet } from 'styled-components';

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

import * as zlib from 'zlib';
import * as boxen from 'boxen';

// @ts-ignore
import { createStore, loadAndBundleSpec, Redoc } from 'redoc';
Expand Down Expand Up @@ -112,7 +112,6 @@ const handlerForBuildCommand = async (argv: any) => {
};

try {
notifyUpdateCliVersion();
await bundle(argv.spec, config);
} catch (e) {
handleError(e);
Expand All @@ -121,7 +120,7 @@ const handlerForBuildCommand = async (argv: any) => {

YargsParser.command(
'serve <spec>',
'start the server',
'start the server [deprecated]',
yargs => {
yargs.positional('spec', {
describe: 'path or URL to your spec',
Expand Down Expand Up @@ -176,38 +175,44 @@ YargsParser.command(
};

try {
notifyUpdateCliVersion();
await serve(argv.host as string, argv.port as number, argv.spec as string, config);
} catch (e) {
handleError(e);
}
},
[
res => {
console.log(
`\n⚠️ This command is deprecated. Use "npx @redocly/cli preview-docs petstore.yaml"\n`,
);
console.log(`
${boxen(
'This package is deprecated now.\n\nPlease use `@redocly/cli preview-docs <api>` instead.',
AlexVarchuk marked this conversation as resolved.
Show resolved Hide resolved
{
title: 'DEPRECATED',
titleAlignment: 'center',
padding: 1,
margin: 1,
borderColor: 'red',
},
)}`);
return res;
},
],
true,
)
.command(
'build <spec>',
'build definition into zero-dependency HTML-file',
'build definition into zero-dependency HTML-file [deprecated]',
builderForBuildCommand,
handlerForBuildCommand,
[notifyDeprecation],
true,
)
.command(
'bundle <spec>',
'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;
},
],
[notifyDeprecation],
true,
)
.demandCommand()
.options('t', {
Expand Down Expand Up @@ -344,7 +349,7 @@ async function getPageHTML(
const store = await createStore(spec, specUrl, redocOptions);
const sheet = new ServerStyleSheet();
// @ts-ignore
html = renderToString(sheet.collectStyles(React.createElement(Redoc, { store })));
html = renderToString(sheet.collectStyles(createElement(Redoc, { store })));
css = sheet.getStyleTags();
state = await store.toJS();

Expand Down Expand Up @@ -472,15 +477,18 @@ function getObjectOrJSON(options) {
}
}

function notifyUpdateCliVersion() {
const pkg = require('./package.json');
const notifier = updateNotifier({
pkg,
updateCheckInterval: 0,
shouldNotifyInNpmScript: true,
});
notifier.notify({
message:
'Run `{updateCommand}` to update.\nChangelog: https://github.com/Redocly/redoc/releases/tag/{latestVersion}',
});
function notifyDeprecation(res: YargsParser.Arguments): YargsParser.Arguments {
console.log(
boxen(
'This package is deprecated now.\n\nPlease use `@redocly/cli build-docs <api>` instead.',
AlexVarchuk marked this conversation as resolved.
Show resolved Hide resolved
{
title: 'DEPRECATED',
titleAlignment: 'center',
padding: 1,
margin: 1,
borderColor: 'red',
},
),
);
return res;
}
Loading