Skip to content

Commit

Permalink
feat: add the eject and translate commands (#1668)
Browse files Browse the repository at this point in the history
* feat: add the translations command

* feat: add eject command

* Update .changeset/short-panthers-smoke.md

Co-authored-by: Lorna Jane Mitchell <[email protected]>

* Update packages/cli/src/index.ts

Co-authored-by: Lorna Jane Mitchell <[email protected]>

* Update packages/cli/src/index.ts

Co-authored-by: Lorna Jane Mitchell <[email protected]>

* update commands descriptions

* add the -p alias for preivew; update eject/contentDir description

* alighn option naming with the latest Realm changes

* resolve comments

* rename translations to translate

---------

Co-authored-by: Lorna Jane Mitchell <[email protected]>
  • Loading branch information
tatomyr and lornajane authored Aug 23, 2024
1 parent 325aa1d commit 78e0881
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 56 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-panthers-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/cli": minor
---

Added the `eject` and `translate` commands for use with the new Reunite-hosted product family.
22 changes: 11 additions & 11 deletions docs/commands/preview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ This command is for our pre-release products, currently open for early access to
redocly preview
redocly preview --product=revel
redocly preview --product=reef --plan=pro
redocly preview --product=reef --plan=pro --source-dir=./my-docs-project --port=4001
redocly preview --product=reef --plan=pro --project-dir=./my-docs-project --port=4001
```

## Options

| Option | Type | Description |
| ---------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --help | boolean | Show help. |
| --plan | string | Product plan to use in preview. <br/> **Possible values:** `pro`, `enterprise`. The default value is `enterprise`. For more details, see [plans](https://redocly.com/pricing/). |
| --product | string | Name of a product to preview the project with. <br/> **Possible values:** `redoc`, `revel`, `reef`, `realm`, `redoc-revel`, `redoc-reef`, `revel-reef`. <br/> `redoc` is the flagship product for generating API documentation from OpenAPI specifications. <br/> `revel` is a specialized product designed for external API applications. <br/> `reef` is a specialized product designed for internal API needs. <br/> `realm` is a balanced product combining `redoc`, `revel`, and `reef`. <br/> `redoc-revel` is a blended product combining `redoc` and `revel`. <br/> `redoc-reef` is a blended product combining `redoc` and `reef`. <br/> `revel-reef` is a blended product combining `revel` and `reef`. <br/> The default value is autodetected from the project's `package.json` or `realm` is used. |
| --source-dir, -d | string | Path to the project directory. The default value is `.` (current directory). |
| --port | number | The port to run the preview server on. The default value is `4000`. |
| --version | boolean | Show version number. |
| Option | Type | Description |
| ----------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --help | boolean | Show help. |
| --plan | string | Product plan to use in preview. <br/> **Possible values:** `pro`, `enterprise`. The default value is `enterprise`. For more details, see [plans](https://redocly.com/pricing/). |
| --product | string | Name of a product to preview the project with. <br/> **Possible values:** `redoc`, `revel`, `reef`, `realm`, `redoc-revel`, `redoc-reef`, `revel-reef`. <br/> `redoc` is the flagship product for generating API documentation from OpenAPI specifications. <br/> `revel` is a specialized product designed for external API applications. <br/> `reef` is a specialized product designed for internal API needs. <br/> `realm` is a balanced product combining `redoc`, `revel`, and `reef`. <br/> `redoc-revel` is a blended product combining `redoc` and `revel`. <br/> `redoc-reef` is a blended product combining `redoc` and `reef`. <br/> `revel-reef` is a blended product combining `revel` and `reef`. <br/> The default value is autodetected from the project's `package.json` or `realm` is used. |
| --project-dir, -d | string | Path to the project directory. The default value is `.` (current directory). |
| --port, -p | number | The port to run the preview server on. The default value is `4000`. |
| --version | boolean | Show version number. |

## Examples

Expand All @@ -50,10 +50,10 @@ redocly preview --plan=pro

### Specify project directory

By default, the preview command uses the current directory. To specify another directory, provide a path relative to the current directory using the `--source-dir` option:
By default, the preview command uses the current directory. To specify another directory, provide a path relative to the current directory using the `--project-dir` option:

```bash
redocly preview --source-dir=./path/to/my/docs/
redocly preview --project-dir=./path/to/my/docs/
```

### Use custom port for preview
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cms/commands/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ReuniteApiClient, getDomain, getApiKeys } from '../api';

import type { OutputFormat } from '@redocly/openapi-core';
import type { CommandArgs } from '../../wrapper';
import type { VerifyConfigOptions } from '../../types';

export type PushOptions = {
apis?: string[];
Expand All @@ -33,13 +34,12 @@ export type PushOptions = {

'default-branch': string;
domain?: string;
config?: string;
'wait-for-deployment'?: boolean;
'max-execution-time': number;
'continue-on-deploy-failures'?: boolean;
verbose?: boolean;
format?: Extract<OutputFormat, 'stylish'>;
};
} & VerifyConfigOptions;

type FileToUpload = { name: string; path: string };

Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/build-docs/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { VerifyConfigOptions } from '../../types';

export type BuildDocsOptions = {
watch?: boolean;
output?: string;
Expand All @@ -20,5 +22,4 @@ export type BuildDocsArgv = {
theme: {
openapi: string | Record<string, unknown>;
};
config?: string;
};
} & VerifyConfigOptions;
6 changes: 3 additions & 3 deletions packages/cli/src/commands/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ import {
checkForDeprecatedOptions,
} from '../utils/miscellaneous';

import type { OutputExtensions, Skips, Totals } from '../types';
import type { OutputExtensions, Skips, Totals, VerifyConfigOptions } from '../types';
import type { CommandArgs } from '../wrapper';

export type BundleOptions = {
apis?: string[];
extends?: string[];
config?: string;
output?: string;
ext: OutputExtensions;
dereferenced?: boolean;
force?: boolean;
metafile?: string;
'remove-unused-components'?: boolean;
'keep-url-references'?: boolean;
} & Skips;
} & Skips &
VerifyConfigOptions;

export async function handleBundle({
argv,
Expand Down
29 changes: 29 additions & 0 deletions packages/cli/src/commands/eject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { spawn } from 'child_process';

import type { CommandArgs } from '../wrapper';
import type { VerifyConfigOptions } from '../types';

export type EjectOptions = {
type: 'component';
path: string;
'project-dir'?: string;
force: boolean;
} & VerifyConfigOptions;

export const handleEject = async ({ argv }: CommandArgs<EjectOptions>) => {
process.stdout.write(`\nLaunching eject using NPX.\n\n`);
const npxExecutableName = process.platform === 'win32' ? 'npx.cmd' : 'npx';
spawn(
npxExecutableName,
[
'-y',
'@redocly/realm',
'eject',
`${argv.type}`,
`${argv.path}`,
`-d=${argv['project-dir']}`,
argv.force ? `--force=${argv.force}` : '',
],
{ stdio: 'inherit' }
);
};
13 changes: 3 additions & 10 deletions packages/cli/src/commands/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ import { isObject, isString, keysOf } from '../utils/js-utils';
import { COMPONENTS, OPENAPI3_METHOD } from './split/types';
import { crawl, startsWithComponents } from './split';

import type {
Oas3Definition,
Document,
Oas3Tag,
Referenced,
RuleSeverity,
} from '@redocly/openapi-core';
import type { Oas3Definition, Document, Oas3Tag, Referenced } from '@redocly/openapi-core';
import type { BundleResult } from '@redocly/openapi-core/lib/bundle';
import type {
Oas3Parameter,
Expand All @@ -38,6 +32,7 @@ import type {
Oas3_1Definition,
} from '@redocly/openapi-core/lib/typings/openapi';
import type { CommandArgs } from '../wrapper';
import type { VerifyConfigOptions } from '../types';

const Tags = 'tags';
const xTagGroups = 'x-tagGroups';
Expand All @@ -60,9 +55,7 @@ export type JoinOptions = {
'prefix-components-with-info-prop'?: string;
'without-x-tag-groups'?: boolean;
output?: string;
config?: string;
'lint-config'?: RuleSeverity;
};
} & VerifyConfigOptions;

export async function handleJoin({
argv,
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/src/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ import {
import { getCommandNameFromArgs } from '../utils/getCommandNameFromArgs';

import type { Arguments } from 'yargs';
import type { OutputFormat, ProblemSeverity, RuleSeverity } from '@redocly/openapi-core';
import type { OutputFormat, ProblemSeverity } from '@redocly/openapi-core';
import type { RawConfigProcessor } from '@redocly/openapi-core/lib/config';
import type { CommandOptions, Skips, Totals } from '../types';
import type { CommandOptions, Skips, Totals, VerifyConfigOptions } from '../types';
import type { CommandArgs } from '../wrapper';

export type LintOptions = {
apis?: string[];
'max-problems': number;
extends?: string[];
config?: string;
format: OutputFormat;
'generate-ignore-file'?: boolean;
'lint-config'?: RuleSeverity;
} & Omit<Skips, 'skip-decorator'>;
} & Omit<Skips, 'skip-decorator'> &
VerifyConfigOptions;

export async function handleLint({
argv,
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/preview-docs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../../utils/miscellaneous';
import startPreviewServer from './preview-server/preview-server';

import type { Skips } from '../../types';
import type { Skips, VerifyConfigOptions } from '../../types';
import type { CommandArgs } from '../../wrapper';

export type PreviewDocsOptions = {
Expand All @@ -18,7 +18,8 @@ export type PreviewDocsOptions = {
config?: string;
api?: string;
force?: boolean;
} & Omit<Skips, 'skip-rule'>;
} & Omit<Skips, 'skip-rule'> &
VerifyConfigOptions;

export async function previewDocs({
argv,
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/commands/preview-project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import type { CommandArgs } from '../../wrapper';

export const previewProject = async ({ argv }: CommandArgs<PreviewProjectOptions>) => {
const { plan, port } = argv;
const projectDir = argv['source-dir'];
const projectDir = argv['project-dir'];

const product = argv.product || tryGetProductFromPackageJson(projectDir);

if (!isValidProduct(product)) {
process.stderr.write(`Invalid product ${product}`);
throw new Error(`Project preview launch failed`);
process.stderr.write(`Invalid product ${product}.`);
throw new Error(`Project preview launch failed.`);
}

const productName = PRODUCT_NAMES[product];
const packageName = PRODUCT_PACKAGES[product];

process.stdout.write(`\nLaunching preview of ${productName} ${plan} using NPX\n\n`);
process.stdout.write(`\nLaunching preview of ${productName} ${plan} using NPX.\n\n`);

const npxExecutableName = process.platform === 'win32' ? 'npx.cmd' : 'npx';

Expand Down
Loading

1 comment on commit 78e0881

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 77.5% 4739/6115
🟡 Branches 65.84% 1968/2989
🟡 Functions 71.78% 781/1088
🟡 Lines 77.69% 4471/5755

Test suite run success

765 tests passing in 108 suites.

Report generated by 🧪jest coverage report action from 78e0881

Please sign in to comment.