@redocly/cli 1.20.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,13 +37,13 @@ import type {
37
37
  Referenced,
38
38
  } from './types';
39
39
  import type { CommandArgs } from '../../wrapper';
40
+ import type { VerifyConfigOptions } from '../../types';
40
41
 
41
42
  export type SplitOptions = {
42
43
  api: string;
43
44
  outDir: string;
44
45
  separator: string;
45
- config?: string;
46
- };
46
+ } & VerifyConfigOptions;
47
47
 
48
48
  export async function handleSplit({ argv, collectSpecData }: CommandArgs<SplitOptions>) {
49
49
  const startedAt = performance.now();
@@ -13,7 +13,6 @@ import {
13
13
  } from '@redocly/openapi-core';
14
14
  import { getFallbackApisOrExit, printExecutionTime } from '../utils/miscellaneous';
15
15
 
16
- import type { CommandArgs } from '../wrapper';
17
16
  import type {
18
17
  StatsAccumulator,
19
18
  StatsName,
@@ -21,6 +20,8 @@ import type {
21
20
  OutputFormat,
22
21
  StyleguideConfig,
23
22
  } from '@redocly/openapi-core';
23
+ import type { CommandArgs } from '../wrapper';
24
+ import type { VerifyConfigOptions } from '../types';
24
25
 
25
26
  const statsAccumulator: StatsAccumulator = {
26
27
  refs: { metric: '🚗 References', total: 0, color: 'red', items: new Set() },
@@ -89,8 +90,7 @@ function printStats(
89
90
  export type StatsOptions = {
90
91
  api?: string;
91
92
  format: OutputFormat;
92
- config?: string;
93
- };
93
+ } & VerifyConfigOptions;
94
94
 
95
95
  export async function handleStats({ argv, config, collectSpecData }: CommandArgs<StatsOptions>) {
96
96
  const [{ path }] = await getFallbackApisOrExit(argv.api ? [argv.api] : [], config);
@@ -0,0 +1,19 @@
1
+ import { spawn } from 'child_process';
2
+
3
+ import type { CommandArgs } from '../wrapper';
4
+ import type { VerifyConfigOptions } from '../types';
5
+
6
+ export type TranslationsOptions = {
7
+ locale: string;
8
+ 'project-dir'?: string;
9
+ } & VerifyConfigOptions;
10
+
11
+ export const handleTranslations = async ({ argv }: CommandArgs<TranslationsOptions>) => {
12
+ process.stdout.write(`\nLaunching translate using NPX.\n\n`);
13
+ const npxExecutableName = process.platform === 'win32' ? 'npx.cmd' : 'npx';
14
+ spawn(
15
+ npxExecutableName,
16
+ ['-y', '@redocly/realm', 'translate', argv.locale, `-d=${argv['project-dir']}`],
17
+ { stdio: 'inherit' }
18
+ );
19
+ };
package/src/index.ts CHANGED
@@ -21,6 +21,8 @@ import {
21
21
  } from './utils/update-version-notifier';
22
22
  import { commandWrapper } from './wrapper';
23
23
  import { previewProject } from './commands/preview-project';
24
+ import { handleTranslations } from './commands/translations';
25
+ import { handleEject } from './commands/eject';
24
26
  import { PRODUCT_PLANS } from './commands/preview-project/constants';
25
27
  import { commonPushHandler } from './commands/push';
26
28
 
@@ -29,6 +31,7 @@ import type { OutputFormat, RuleSeverity } from '@redocly/openapi-core';
29
31
  import type { BuildDocsArgv } from './commands/build-docs/types';
30
32
  import type { PushStatusOptions } from './cms/commands/push-status';
31
33
  import type { PushArguments } from './types';
34
+ import type { EjectOptions } from './commands/eject';
32
35
 
33
36
  if (!('replaceAll' in String.prototype)) {
34
37
  require('core-js/actual/string/replace-all');
@@ -228,6 +231,11 @@ yargs
228
231
  type: 'boolean',
229
232
  default: false,
230
233
  },
234
+ 'lint-config': {
235
+ description: 'Severity level for config file linting.',
236
+ choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
237
+ default: 'warn' as RuleSeverity,
238
+ },
231
239
  }),
232
240
  (argv) => {
233
241
  process.env.REDOCLY_CLI_COMMAND = 'push-status';
@@ -642,18 +650,32 @@ yargs
642
650
  default: 'enterprise',
643
651
  },
644
652
  port: {
653
+ alias: 'p',
645
654
  type: 'number',
646
655
  description: 'Preview port.',
647
656
  default: 4000,
648
657
  },
649
- 'source-dir': {
650
- alias: 'd',
658
+ 'project-dir': {
659
+ alias: ['d', 'source-dir'],
651
660
  type: 'string',
652
- description: 'Project directory.',
661
+ description:
662
+ 'Specifies the project content directory. The default value is the directory where the command is executed.',
653
663
  default: '.',
654
664
  },
665
+ 'lint-config': {
666
+ description: 'Severity level for config file linting.',
667
+ choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
668
+ default: 'warn' as RuleSeverity,
669
+ },
655
670
  }),
656
671
  (argv) => {
672
+ if (process.argv.some((arg) => arg.startsWith('--source-dir'))) {
673
+ process.stderr.write(
674
+ colors.red(
675
+ 'Option --source-dir is deprecated and will be removed soon. Use --project-dir instead.\n'
676
+ )
677
+ );
678
+ }
657
679
  commandWrapper(previewProject)(argv);
658
680
  }
659
681
  )
@@ -764,6 +786,77 @@ yargs
764
786
  commandWrapper(handlerBuildCommand)(argv as Arguments<BuildDocsArgv>);
765
787
  }
766
788
  )
789
+ .command(
790
+ 'translate <locale>',
791
+ 'Creates or updates translations.yaml files and fills them with missing built-in translations and translations from the redocly.yaml and sidebars.yaml files.',
792
+ (yargs) =>
793
+ yargs
794
+ .positional('locale', {
795
+ description:
796
+ 'Locale code to generate translations for, or `all` for all current project locales.',
797
+ type: 'string',
798
+ demandOption: true,
799
+ })
800
+ .options({
801
+ 'project-dir': {
802
+ alias: 'd',
803
+ type: 'string',
804
+ description:
805
+ 'Specifies the project content directory. The default value is the directory where the command is executed.',
806
+ default: '.',
807
+ },
808
+ 'lint-config': {
809
+ description: 'Severity level for config file linting.',
810
+ choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
811
+ default: 'warn' as RuleSeverity,
812
+ },
813
+ }),
814
+ (argv) => {
815
+ process.env.REDOCLY_CLI_COMMAND = 'translate';
816
+ commandWrapper(handleTranslations)(argv);
817
+ }
818
+ )
819
+ .command(
820
+ 'eject <type> <path>',
821
+ 'Helper function to eject project elements for customization.',
822
+ (yargs) =>
823
+ yargs
824
+ .positional('type', {
825
+ description:
826
+ 'Specifies what type of project element to eject. Currently, it could be only `component`.',
827
+ demandOption: true,
828
+ choices: ['component'],
829
+ })
830
+ .positional('path', {
831
+ description: 'Filepath to a component or filepath with glob pattern.',
832
+ type: 'string',
833
+ demandOption: true,
834
+ })
835
+ .options({
836
+ 'project-dir': {
837
+ alias: 'd',
838
+ type: 'string',
839
+ description:
840
+ 'Specifies the project content directory. The default value is the directory where the command is executed.',
841
+ default: '.',
842
+ },
843
+ force: {
844
+ alias: 'f',
845
+ type: 'boolean',
846
+ description:
847
+ 'Skips the "overwrite existing" confirmation when ejecting a component that is already ejected in the destination.',
848
+ },
849
+ 'lint-config': {
850
+ description: 'Severity level for config file linting.',
851
+ choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
852
+ default: 'warn' as RuleSeverity,
853
+ },
854
+ }),
855
+ (argv) => {
856
+ process.env.REDOCLY_CLI_COMMAND = 'eject';
857
+ commandWrapper(handleEject)(argv as Arguments<EjectOptions>);
858
+ }
859
+ )
767
860
  .completion('completion', 'Generate autocomplete script for `redocly` command.')
768
861
  .demandCommand(1)
769
862
  .middleware([notifyUpdateCliVersion])
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BundleOutputFormat, Region, Config } from '@redocly/openapi-core';
1
+ import type { BundleOutputFormat, Region, Config, RuleSeverity } from '@redocly/openapi-core';
2
2
  import type { ArgumentsCamelCase } from 'yargs';
3
3
  import type { LintOptions } from './commands/lint';
4
4
  import type { BundleOptions } from './commands/bundle';
@@ -12,6 +12,8 @@ import type { BuildDocsArgv } from './commands/build-docs/types';
12
12
  import type { PushOptions as CMSPushOptions } from './cms/commands/push';
13
13
  import type { PushStatusOptions } from './cms/commands/push-status';
14
14
  import type { PreviewProjectOptions } from './commands/preview-project/types';
15
+ import type { TranslationsOptions } from './commands/translations';
16
+ import type { EjectOptions } from './commands/eject';
15
17
 
16
18
  export type Totals = {
17
19
  errors: number;
@@ -37,12 +39,13 @@ export type CommandOptions =
37
39
  | PreviewDocsOptions
38
40
  | BuildDocsArgv
39
41
  | PushStatusOptions
40
- | VerifyConfigOptions
41
- | PreviewProjectOptions;
42
+ | PreviewProjectOptions
43
+ | TranslationsOptions
44
+ | EjectOptions;
42
45
 
43
46
  export type VerifyConfigOptions = {
44
47
  config?: string;
45
- 'lint-config'?: 'warning' | 'error' | 'off';
48
+ 'lint-config'?: RuleSeverity;
46
49
  };
47
50
 
48
51
  export type Skips = {