@redocly/cli 1.25.14 → 1.26.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.
- package/CHANGELOG.md +21 -0
- package/lib/__tests__/commands/bundle.test.js +1 -1
- package/lib/__tests__/commands/join.test.js +24 -1
- package/lib/__tests__/utils.test.js +62 -1
- package/lib/commands/eject.js +15 -5
- package/lib/commands/join.js +6 -5
- package/lib/commands/preview-project/index.js +8 -2
- package/lib/commands/translations.js +12 -2
- package/lib/index.js +11 -3
- package/lib/utils/miscellaneous.js +1 -1
- package/lib/utils/platform.d.ts +16 -0
- package/lib/utils/platform.js +34 -0
- package/package.json +2 -2
- package/src/__tests__/commands/bundle.test.ts +1 -1
- package/src/__tests__/commands/join.test.ts +35 -2
- package/src/__tests__/utils.test.ts +72 -1
- package/src/commands/eject.ts +18 -5
- package/src/commands/join.ts +8 -7
- package/src/commands/preview-project/index.ts +9 -3
- package/src/commands/translations.ts +17 -4
- package/src/index.ts +89 -81
- package/src/utils/miscellaneous.ts +1 -1
- package/src/utils/platform.ts +31 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'child_process';
|
|
2
|
+
import { getPlatformSpawnArgs, sanitizeLocale, sanitizePath } from '../utils/platform';
|
|
2
3
|
|
|
3
4
|
import type { CommandArgs } from '../wrapper';
|
|
4
5
|
import type { VerifyConfigOptions } from '../types';
|
|
@@ -10,10 +11,22 @@ export type TranslationsOptions = {
|
|
|
10
11
|
|
|
11
12
|
export const handleTranslations = async ({ argv }: CommandArgs<TranslationsOptions>) => {
|
|
12
13
|
process.stdout.write(`\nLaunching translate using NPX.\n\n`);
|
|
13
|
-
const npxExecutableName
|
|
14
|
-
|
|
14
|
+
const { npxExecutableName, sanitize, shell } = getPlatformSpawnArgs();
|
|
15
|
+
|
|
16
|
+
const projectDir = sanitize(argv['project-dir'], sanitizePath);
|
|
17
|
+
const locale = sanitize(argv.locale, sanitizeLocale);
|
|
18
|
+
|
|
19
|
+
const child = spawn(
|
|
15
20
|
npxExecutableName,
|
|
16
|
-
['-y', '@redocly/realm', 'translate',
|
|
17
|
-
{
|
|
21
|
+
['-y', '@redocly/realm', 'translate', locale, `-d=${projectDir}`],
|
|
22
|
+
{
|
|
23
|
+
stdio: 'inherit',
|
|
24
|
+
shell,
|
|
25
|
+
}
|
|
18
26
|
);
|
|
27
|
+
|
|
28
|
+
child.on('error', (error) => {
|
|
29
|
+
process.stderr.write(`Translate launch failed: ${error.message}`);
|
|
30
|
+
throw new Error(`Translate launch failed.`);
|
|
31
|
+
});
|
|
19
32
|
};
|
package/src/index.ts
CHANGED
|
@@ -473,86 +473,94 @@ yargs
|
|
|
473
473
|
'bundle [apis...]',
|
|
474
474
|
'Bundle a multi-file API description to a single file.',
|
|
475
475
|
(yargs) =>
|
|
476
|
-
yargs
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
476
|
+
yargs
|
|
477
|
+
.positional('apis', { array: true, type: 'string', demandOption: true })
|
|
478
|
+
.options({
|
|
479
|
+
output: {
|
|
480
|
+
type: 'string',
|
|
481
|
+
description: 'Output file or folder for inline APIs.',
|
|
482
|
+
alias: 'o',
|
|
483
|
+
},
|
|
484
|
+
ext: {
|
|
485
|
+
description: 'Bundle file extension.',
|
|
486
|
+
requiresArg: true,
|
|
487
|
+
choices: outputExtensions,
|
|
488
|
+
},
|
|
489
|
+
'skip-preprocessor': {
|
|
490
|
+
description: 'Ignore certain preprocessors.',
|
|
491
|
+
array: true,
|
|
492
|
+
type: 'string',
|
|
493
|
+
},
|
|
494
|
+
'skip-decorator': {
|
|
495
|
+
description: 'Ignore certain decorators.',
|
|
496
|
+
array: true,
|
|
497
|
+
type: 'string',
|
|
498
|
+
},
|
|
499
|
+
dereferenced: {
|
|
500
|
+
alias: 'd',
|
|
501
|
+
type: 'boolean',
|
|
502
|
+
description: 'Produce a fully dereferenced bundle.',
|
|
503
|
+
},
|
|
504
|
+
force: {
|
|
505
|
+
alias: 'f',
|
|
506
|
+
type: 'boolean',
|
|
507
|
+
description: 'Produce bundle output even when errors occur.',
|
|
508
|
+
},
|
|
509
|
+
config: {
|
|
510
|
+
description: 'Path to the config file.',
|
|
511
|
+
type: 'string',
|
|
512
|
+
},
|
|
513
|
+
metafile: {
|
|
514
|
+
description: 'Produce metadata about the bundle',
|
|
515
|
+
type: 'string',
|
|
516
|
+
},
|
|
517
|
+
extends: {
|
|
518
|
+
description: 'Override extends configurations (defaults or config file settings).',
|
|
519
|
+
requiresArg: true,
|
|
520
|
+
array: true,
|
|
521
|
+
type: 'string',
|
|
522
|
+
hidden: true,
|
|
523
|
+
},
|
|
524
|
+
'remove-unused-components': {
|
|
525
|
+
description: 'Remove unused components.',
|
|
526
|
+
type: 'boolean',
|
|
527
|
+
default: false,
|
|
528
|
+
},
|
|
529
|
+
'keep-url-references': {
|
|
530
|
+
description: 'Keep absolute url references.',
|
|
531
|
+
type: 'boolean',
|
|
532
|
+
alias: 'k',
|
|
533
|
+
},
|
|
534
|
+
'lint-config': {
|
|
535
|
+
description: 'Severity level for config file linting.',
|
|
536
|
+
choices: ['warn', 'error', 'off'] as ReadonlyArray<RuleSeverity>,
|
|
537
|
+
default: 'warn' as RuleSeverity,
|
|
538
|
+
},
|
|
539
|
+
format: {
|
|
540
|
+
hidden: true,
|
|
541
|
+
deprecated: true,
|
|
542
|
+
},
|
|
543
|
+
lint: {
|
|
544
|
+
hidden: true,
|
|
545
|
+
deprecated: true,
|
|
546
|
+
},
|
|
547
|
+
'skip-rule': {
|
|
548
|
+
hidden: true,
|
|
549
|
+
deprecated: true,
|
|
550
|
+
array: true,
|
|
551
|
+
type: 'string',
|
|
552
|
+
},
|
|
553
|
+
'max-problems': {
|
|
554
|
+
hidden: true,
|
|
555
|
+
deprecated: true,
|
|
556
|
+
},
|
|
557
|
+
})
|
|
558
|
+
.check((argv) => {
|
|
559
|
+
if (argv.output && (!argv.apis || argv.apis.length === 0)) {
|
|
560
|
+
throw new Error('At least one inline API must be specified when using --output.');
|
|
561
|
+
}
|
|
562
|
+
return true;
|
|
563
|
+
}),
|
|
556
564
|
(argv) => {
|
|
557
565
|
const DEPRECATED_OPTIONS = ['lint', 'format', 'skip-rule', 'max-problems'];
|
|
558
566
|
const LINT_AND_BUNDLE_DOCUMENTATION_LINK =
|
|
@@ -778,7 +786,7 @@ yargs
|
|
|
778
786
|
})
|
|
779
787
|
.check((argv: any) => {
|
|
780
788
|
if (argv.theme && !argv.theme?.openapi)
|
|
781
|
-
throw Error('Invalid option: theme.openapi not set');
|
|
789
|
+
throw Error('Invalid option: theme.openapi not set.');
|
|
782
790
|
return true;
|
|
783
791
|
}),
|
|
784
792
|
async (argv) => {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes the input path by removing invalid characters.
|
|
3
|
+
*/
|
|
4
|
+
export const sanitizePath = (input: string): string => {
|
|
5
|
+
return input.replace(/[^a-zA-Z0-9 ._\-:\\/@]/g, '');
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sanitizes the input locale (ex. en-US) by removing invalid characters.
|
|
10
|
+
*/
|
|
11
|
+
export const sanitizeLocale = (input: string): string => {
|
|
12
|
+
return input.replace(/[^a-zA-Z0-9@._-]/g, '');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves platform-specific arguments and utilities.
|
|
17
|
+
*/
|
|
18
|
+
export function getPlatformSpawnArgs() {
|
|
19
|
+
const isWindowsPlatform = process.platform === 'win32';
|
|
20
|
+
const npxExecutableName = isWindowsPlatform ? 'npx.cmd' : 'npx';
|
|
21
|
+
|
|
22
|
+
const sanitizeIfWindows = (input: string | undefined, sanitizer: (input: string) => string) => {
|
|
23
|
+
if (isWindowsPlatform && input) {
|
|
24
|
+
return sanitizer(input);
|
|
25
|
+
} else {
|
|
26
|
+
return input || '';
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return { npxExecutableName, sanitize: sanitizeIfWindows, shell: isWindowsPlatform };
|
|
31
|
+
}
|