@redocly/cli 1.3.0 → 1.4.1

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +15 -7
  3. package/lib/__mocks__/@redocly/openapi-core.d.ts +1 -0
  4. package/lib/__mocks__/@redocly/openapi-core.js +4 -3
  5. package/lib/__mocks__/utils.d.ts +2 -0
  6. package/lib/__mocks__/utils.js +3 -1
  7. package/lib/__tests__/commands/build-docs.test.js +2 -2
  8. package/lib/__tests__/commands/bundle.test.js +7 -7
  9. package/lib/__tests__/commands/join.test.js +25 -18
  10. package/lib/__tests__/commands/lint.test.js +15 -15
  11. package/lib/__tests__/commands/push-region.test.js +2 -2
  12. package/lib/__tests__/commands/push.test.js +30 -30
  13. package/lib/__tests__/fetch-with-timeout.test.js +2 -2
  14. package/lib/__tests__/utils.test.js +63 -32
  15. package/lib/__tests__/wrapper.test.js +3 -3
  16. package/lib/assert-node-version.js +1 -1
  17. package/lib/commands/build-docs/index.js +9 -9
  18. package/lib/commands/build-docs/types.d.ts +2 -2
  19. package/lib/commands/build-docs/utils.js +10 -10
  20. package/lib/commands/bundle.d.ts +1 -1
  21. package/lib/commands/bundle.js +25 -25
  22. package/lib/commands/join.d.ts +1 -1
  23. package/lib/commands/join.js +49 -48
  24. package/lib/commands/lint.d.ts +1 -1
  25. package/lib/commands/lint.js +22 -22
  26. package/lib/commands/login.d.ts +1 -1
  27. package/lib/commands/login.js +3 -3
  28. package/lib/commands/preview-docs/index.d.ts +1 -1
  29. package/lib/commands/preview-docs/index.js +7 -7
  30. package/lib/commands/preview-docs/preview-server/hot.js +19 -2
  31. package/lib/commands/preview-docs/preview-server/preview-server.js +15 -14
  32. package/lib/commands/preview-docs/preview-server/server.d.ts +3 -1
  33. package/lib/commands/preview-docs/preview-server/server.js +2 -2
  34. package/lib/commands/push.d.ts +2 -2
  35. package/lib/commands/push.js +31 -31
  36. package/lib/commands/split/__tests__/index.test.js +9 -9
  37. package/lib/commands/split/index.d.ts +2 -2
  38. package/lib/commands/split/index.js +41 -40
  39. package/lib/commands/split/types.d.ts +2 -2
  40. package/lib/commands/split/types.js +2 -2
  41. package/lib/commands/stats.d.ts +1 -1
  42. package/lib/commands/stats.js +9 -9
  43. package/lib/fetch-with-timeout.js +5 -2
  44. package/lib/index.js +11 -12
  45. package/lib/types.d.ts +6 -6
  46. package/lib/update-version-notifier.js +18 -18
  47. package/lib/utils.d.ts +6 -3
  48. package/lib/utils.js +66 -38
  49. package/lib/wrapper.js +5 -5
  50. package/package.json +4 -3
  51. package/src/__mocks__/@redocly/openapi-core.ts +1 -0
  52. package/src/__mocks__/utils.ts +2 -0
  53. package/src/__tests__/commands/join.test.ts +37 -7
  54. package/src/__tests__/utils.test.ts +45 -1
  55. package/src/commands/join.ts +8 -3
  56. package/src/commands/preview-docs/preview-server/hot.js +19 -2
  57. package/src/commands/preview-docs/preview-server/preview-server.ts +6 -4
  58. package/src/commands/preview-docs/preview-server/server.ts +2 -2
  59. package/src/commands/split/__tests__/index.test.ts +14 -5
  60. package/src/commands/split/index.ts +25 -17
  61. package/src/fetch-with-timeout.ts +3 -0
  62. package/src/index.ts +0 -1
  63. package/src/utils.ts +40 -1
  64. package/tsconfig.tsbuildinfo +1 -1
@@ -20,7 +20,7 @@ function previewDocs(argv, configFromFile) {
20
20
  let isAuthorizedWithRedocly = false;
21
21
  let redocOptions = {};
22
22
  let config = yield reloadConfig(configFromFile);
23
- const apis = yield utils_1.getFallbackApisOrExit(argv.api ? [argv.api] : [], config);
23
+ const apis = yield (0, utils_1.getFallbackApisOrExit)(argv.api ? [argv.api] : [], config);
24
24
  const api = apis[0];
25
25
  let cachedBundle;
26
26
  const deps = new Set();
@@ -33,7 +33,7 @@ function previewDocs(argv, configFromFile) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
34
  process.stdout.write('\nBundling...\n\n');
35
35
  try {
36
- const { bundle: openapiBundle, problems, fileDependencies, } = yield openapi_core_1.bundle({
36
+ const { bundle: openapiBundle, problems, fileDependencies, } = yield (0, openapi_core_1.bundle)({
37
37
  ref: api.path,
38
38
  config,
39
39
  });
@@ -42,7 +42,7 @@ function previewDocs(argv, configFromFile) {
42
42
  watcher.add([...fileDependencies]);
43
43
  deps.clear();
44
44
  fileDependencies.forEach(deps.add, deps);
45
- const fileTotals = openapi_core_1.getTotals(problems);
45
+ const fileTotals = (0, openapi_core_1.getTotals)(problems);
46
46
  if (fileTotals.errors === 0) {
47
47
  process.stdout.write(fileTotals.errors === 0
48
48
  ? `Created a bundle for ${api.alias || api.path} ${fileTotals.warnings > 0 ? 'with warnings' : 'successfully'}\n`
@@ -51,7 +51,7 @@ function previewDocs(argv, configFromFile) {
51
51
  return openapiBundle.parsed;
52
52
  }
53
53
  catch (e) {
54
- utils_1.handleError(e, api.path);
54
+ (0, utils_1.handleError)(e, api.path);
55
55
  }
56
56
  });
57
57
  }
@@ -62,7 +62,7 @@ function previewDocs(argv, configFromFile) {
62
62
  if (!isAuthorized) {
63
63
  process.stderr.write(`Using Redoc community edition.\nLogin with redocly ${colorette.blue('login')} or use an enterprise license key to preview with the premium docs.\n\n`);
64
64
  }
65
- const hotClients = yield preview_server_1.default(argv.port, argv.host, {
65
+ const hotClients = yield (0, preview_server_1.default)(argv.port, argv.host, {
66
66
  getBundle,
67
67
  getOptions: () => redocOptions,
68
68
  useRedocPro: isAuthorized && !redocOptions.useCommunityEdition,
@@ -97,7 +97,7 @@ function previewDocs(argv, configFromFile) {
97
97
  return __awaiter(this, void 0, void 0, function* () {
98
98
  if (!config) {
99
99
  try {
100
- config = (yield utils_1.loadConfigAndHandleErrors({ configPath: argv.config }));
100
+ config = (yield (0, utils_1.loadConfigAndHandleErrors)({ configPath: argv.config }));
101
101
  }
102
102
  catch (err) {
103
103
  config = new openapi_core_1.Config({ apis: {}, styleguide: {} });
@@ -105,7 +105,7 @@ function previewDocs(argv, configFromFile) {
105
105
  }
106
106
  const redoclyClient = new openapi_core_1.RedoclyClient();
107
107
  isAuthorizedWithRedocly = yield redoclyClient.isAuthorizedWithRedocly();
108
- const resolvedConfig = openapi_core_1.getMergedConfig(config, argv.api);
108
+ const resolvedConfig = (0, openapi_core_1.getMergedConfig)(config, argv.api);
109
109
  const { styleguide } = resolvedConfig;
110
110
  styleguide.skipPreprocessors(argv['skip-preprocessor']);
111
111
  styleguide.skipDecorators(argv['skip-decorator']);
@@ -1,13 +1,29 @@
1
1
  (function run() {
2
2
  const Socket = window.SimpleWebsocket;
3
3
  const port = window.__OPENAPI_CLI_WS_PORT;
4
+ const host = window.__OPENAPI_CLI_WS_HOST;
4
5
 
5
6
  let socket;
6
7
 
7
8
  reconnect();
8
9
 
10
+ function getFormattedHost() {
11
+ // Use localhost when bound to all interfaces
12
+ if (host === '::' || host === '0.0.0.0') {
13
+ return 'localhost';
14
+ }
15
+
16
+ // Other IPv6 addresses must be wrapped in brackets
17
+ if (host.includes('::')) {
18
+ return `[${host}]`;
19
+ }
20
+
21
+ // Otherwise return as-is
22
+ return host;
23
+ }
24
+
9
25
  function reconnect() {
10
- socket = new Socket(`ws://127.0.0.1:${port}`);
26
+ socket = new Socket(`ws://${getFormattedHost()}:${port}`);
11
27
  socket.on('connect', () => {
12
28
  socket.send('{"type": "ping"}');
13
29
  });
@@ -29,13 +45,14 @@
29
45
 
30
46
  socket.on('close', () => {
31
47
  socket.destroy();
32
- console.log('Connection lost, trying to reconnect in 4s');
48
+ console.log('[hot] Connection lost, trying to reconnect in 4s');
33
49
  setTimeout(() => {
34
50
  reconnect();
35
51
  }, 4000);
36
52
  });
37
53
 
38
54
  socket.on('error', () => {
55
+ console.log('[hot] Error connecting to hot reloading server');
39
56
  socket.destroy();
40
57
  });
41
58
  }
@@ -16,18 +16,19 @@ const fs_1 = require("fs");
16
16
  const path = require("path");
17
17
  const server_1 = require("./server");
18
18
  const utils_1 = require("../../../utils");
19
- function getPageHTML(htmlTemplate, redocOptions = {}, useRedocPro, wsPort) {
20
- let templateSrc = fs_1.readFileSync(htmlTemplate, 'utf-8');
19
+ function getPageHTML(htmlTemplate, redocOptions = {}, useRedocPro, wsPort, host) {
20
+ let templateSrc = (0, fs_1.readFileSync)(htmlTemplate, 'utf-8');
21
21
  // fix template for backward compatibility
22
22
  templateSrc = templateSrc
23
23
  .replace(/{?{{redocHead}}}?/, '{{{redocHead}}}')
24
24
  .replace('{{redocBody}}', '{{{redocHTML}}}');
25
- const template = handlebars_1.compile(templateSrc);
25
+ const template = (0, handlebars_1.compile)(templateSrc);
26
26
  return template({
27
27
  redocHead: `
28
28
  <script>
29
29
  window.__REDOC_EXPORT = '${useRedocPro ? 'RedoclyReferenceDocs' : 'Redoc'}';
30
30
  window.__OPENAPI_CLI_WS_PORT = ${wsPort};
31
+ window.__OPENAPI_CLI_WS_HOST = "${host}";
31
32
  </script>
32
33
  <script src="/simplewebsocket.min.js"></script>
33
34
  <script src="/hot.js"></script>
@@ -54,14 +55,14 @@ function startPreviewServer(port, host, { getBundle, getOptions, useRedocPro, })
54
55
  console.time(colorette.dim(`GET ${request.url}`));
55
56
  const { htmlTemplate } = getOptions() || {};
56
57
  if (((_a = request.url) === null || _a === void 0 ? void 0 : _a.endsWith('/')) || path.extname(request.url) === '') {
57
- server_1.respondWithGzip(getPageHTML(htmlTemplate || defaultTemplate, getOptions(), useRedocPro, wsPort), request, response, {
58
+ (0, server_1.respondWithGzip)(getPageHTML(htmlTemplate || defaultTemplate, getOptions(), useRedocPro, wsPort, host), request, response, {
58
59
  'Content-Type': 'text/html',
59
60
  });
60
61
  }
61
62
  else if (request.url === '/openapi.json') {
62
63
  const bundle = yield getBundle();
63
64
  if (bundle === undefined) {
64
- server_1.respondWithGzip(JSON.stringify({
65
+ (0, server_1.respondWithGzip)(JSON.stringify({
65
66
  openapi: '3.0.0',
66
67
  info: {
67
68
  description: '<code> Failed to generate bundle: check out console output for more details </code>',
@@ -72,7 +73,7 @@ function startPreviewServer(port, host, { getBundle, getOptions, useRedocPro, })
72
73
  });
73
74
  }
74
75
  else {
75
- server_1.respondWithGzip(JSON.stringify(bundle), request, response, {
76
+ (0, server_1.respondWithGzip)(JSON.stringify(bundle), request, response, {
76
77
  'Content-Type': 'application/json',
77
78
  });
78
79
  }
@@ -89,8 +90,8 @@ function startPreviewServer(port, host, { getBundle, getOptions, useRedocPro, })
89
90
  if (!filePath) {
90
91
  const basePath = htmlTemplate ? path.dirname(htmlTemplate) : process.cwd();
91
92
  filePath = path.resolve(basePath, `.${request.url}`);
92
- if (!utils_1.isSubdir(basePath, filePath)) {
93
- server_1.respondWithGzip('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
93
+ if (!(0, utils_1.isSubdir)(basePath, filePath)) {
94
+ (0, server_1.respondWithGzip)('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
94
95
  console.timeEnd(colorette.dim(`GET ${request.url}`));
95
96
  return;
96
97
  }
@@ -98,27 +99,27 @@ function startPreviewServer(port, host, { getBundle, getOptions, useRedocPro, })
98
99
  const extname = String(path.extname(filePath)).toLowerCase();
99
100
  const contentType = server_1.mimeTypes[extname] || 'application/octet-stream';
100
101
  try {
101
- server_1.respondWithGzip(yield fs_1.promises.readFile(filePath), request, response, {
102
+ (0, server_1.respondWithGzip)(yield fs_1.promises.readFile(filePath), request, response, {
102
103
  'Content-Type': contentType,
103
104
  });
104
105
  }
105
106
  catch (e) {
106
107
  if (e.code === 'ENOENT') {
107
- server_1.respondWithGzip('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
108
+ (0, server_1.respondWithGzip)('404 Not Found', request, response, { 'Content-Type': 'text/html' }, 404);
108
109
  }
109
110
  else {
110
- server_1.respondWithGzip(`Something went wrong: ${e.code || e.message}...\n`, request, response, {}, 500);
111
+ (0, server_1.respondWithGzip)(`Something went wrong: ${e.code || e.message}...\n`, request, response, {}, 500);
111
112
  }
112
113
  }
113
114
  }
114
115
  console.timeEnd(colorette.dim(`GET ${request.url}`));
115
116
  });
116
- const wsPort = yield get_port_please_1.getPort({ portRange: [32201, 32301] });
117
- const server = server_1.startHttpServer(port, host, handler);
117
+ const wsPort = yield (0, get_port_please_1.getPort)({ port: 32201, portRange: [32201, 32301], host });
118
+ const server = (0, server_1.startHttpServer)(port, host, handler);
118
119
  server.on('listening', () => {
119
120
  process.stdout.write(`\n 🔎 Preview server running at ${colorette.blue(`http://${host}:${port}\n`)}`);
120
121
  });
121
- return server_1.startWsServer(wsPort);
122
+ return (0, server_1.startWsServer)(wsPort, host);
122
123
  });
123
124
  }
124
125
  exports.default = startPreviewServer;
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import * as http from 'http';
3
5
  import { ReadStream } from 'fs';
4
6
  export declare const mimeTypes: {
@@ -20,4 +22,4 @@ export declare const mimeTypes: {
20
22
  };
21
23
  export declare function respondWithGzip(contents: string | Buffer | ReadStream, request: http.IncomingMessage, response: http.ServerResponse, headers?: {}, code?: number): void;
22
24
  export declare function startHttpServer(port: number, host: string, handler: http.RequestListener): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
23
- export declare function startWsServer(port: number): any;
25
+ export declare function startWsServer(port: number, host: string): any;
@@ -58,8 +58,8 @@ function startHttpServer(port, host, handler) {
58
58
  return http.createServer(handler).listen(port, host);
59
59
  }
60
60
  exports.startHttpServer = startHttpServer;
61
- function startWsServer(port) {
62
- const socketServer = new SocketServer({ port, clientTracking: true });
61
+ function startWsServer(port, host) {
62
+ const socketServer = new SocketServer({ port, host, clientTracking: true });
63
63
  socketServer.on('connection', (socket) => {
64
64
  socket.on('data', (data) => {
65
65
  const message = JSON.parse(data);
@@ -1,6 +1,6 @@
1
1
  import { Config, Region } from '@redocly/openapi-core';
2
2
  export declare const DESTINATION_REGEX: RegExp;
3
- export declare type PushOptions = {
3
+ export type PushOptions = {
4
4
  api?: string;
5
5
  destination?: string;
6
6
  branchName?: string;
@@ -20,7 +20,7 @@ export declare function getDestinationProps(destination: string | undefined, org
20
20
  name: string | undefined;
21
21
  version: string | undefined;
22
22
  };
23
- declare type BarePushArgs = Omit<PushOptions, 'destination' | 'branchName'> & {
23
+ type BarePushArgs = Omit<PushOptions, 'destination' | 'branchName'> & {
24
24
  maybeDestination?: string;
25
25
  maybeBranchName?: string;
26
26
  branch?: string;
@@ -37,7 +37,7 @@ function handlePush(argv, config) {
37
37
  const client = new openapi_core_1.RedoclyClient(config.region);
38
38
  const isAuthorized = yield client.isAuthorizedWithRedoclyByRegion();
39
39
  if (!isAuthorized) {
40
- const clientToken = yield login_1.promptClientToken(client.domain);
40
+ const clientToken = yield (0, login_1.promptClientToken)(client.domain);
41
41
  yield client.login(clientToken);
42
42
  }
43
43
  const startedAt = perf_hooks_1.performance.now();
@@ -45,34 +45,34 @@ function handlePush(argv, config) {
45
45
  const jobId = argv['job-id'];
46
46
  const batchSize = argv['batch-size'];
47
47
  if (destination && !exports.DESTINATION_REGEX.test(destination)) {
48
- utils_1.exitWithError(`Destination argument value is not valid, please use the right format: ${colorette_1.yellow('<api-name@api-version>')}`);
48
+ (0, utils_1.exitWithError)(`Destination argument value is not valid, please use the right format: ${(0, colorette_1.yellow)('<api-name@api-version>')}`);
49
49
  }
50
50
  const destinationProps = getDestinationProps(destination, config.organization);
51
51
  const organizationId = argv.organization || destinationProps.organizationId;
52
52
  const { name, version } = destinationProps;
53
53
  if (!organizationId) {
54
- return utils_1.exitWithError(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
54
+ return (0, utils_1.exitWithError)(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
55
55
  }
56
56
  const api = argv.api || (name && version && getApiRoot({ name, version, config }));
57
57
  if (name && version && !api) {
58
- utils_1.exitWithError(`No api found that matches ${colorette_1.blue(`${name}@${version}`)}. Please make sure you have provided the correct data in the config file.`);
58
+ (0, utils_1.exitWithError)(`No api found that matches ${(0, colorette_1.blue)(`${name}@${version}`)}. Please make sure you have provided the correct data in the config file.`);
59
59
  }
60
60
  // Ensure that a destination for the api is provided.
61
61
  if (!name && api) {
62
- return utils_1.exitWithError(`No destination provided, please use --destination option to provide destination.`);
62
+ return (0, utils_1.exitWithError)(`No destination provided, please use --destination option to provide destination.`);
63
63
  }
64
64
  if (jobId && !jobId.trim()) {
65
- utils_1.exitWithError(`The ${colorette_1.blue(`job-id`)} option value is not valid, please avoid using an empty string.`);
65
+ (0, utils_1.exitWithError)(`The ${(0, colorette_1.blue)(`job-id`)} option value is not valid, please avoid using an empty string.`);
66
66
  }
67
67
  if (batchSize && batchSize < 2) {
68
- utils_1.exitWithError(`The ${colorette_1.blue(`batch-size`)} option value is not valid, please use the integer bigger than 1.`);
68
+ (0, utils_1.exitWithError)(`The ${(0, colorette_1.blue)(`batch-size`)} option value is not valid, please use the integer bigger than 1.`);
69
69
  }
70
70
  const apis = api ? { [`${name}@${version}`]: { root: api } } : config.apis;
71
71
  if (!Object.keys(apis).length) {
72
- utils_1.exitWithError(`Api not found. Please make sure you have provided the correct data in the config file.`);
72
+ (0, utils_1.exitWithError)(`Api not found. Please make sure you have provided the correct data in the config file.`);
73
73
  }
74
74
  for (const [apiNameAndVersion, { root: api }] of Object.entries(apis)) {
75
- const resolvedConfig = openapi_core_1.getMergedConfig(config, apiNameAndVersion);
75
+ const resolvedConfig = (0, openapi_core_1.getMergedConfig)(config, apiNameAndVersion);
76
76
  resolvedConfig.styleguide.skipDecorators(argv['skip-decorator']);
77
77
  const [name, version = DEFAULT_VERSION] = apiNameAndVersion.split('@');
78
78
  const encodedName = encodeURIComponent(name);
@@ -81,7 +81,7 @@ function handlePush(argv, config) {
81
81
  const filePaths = [];
82
82
  const filesToUpload = yield collectFilesToUpload(api, resolvedConfig);
83
83
  const filesHash = hashFiles(filesToUpload.files);
84
- process.stdout.write(`Uploading ${filesToUpload.files.length} ${utils_1.pluralize('file', filesToUpload.files.length)}:\n`);
84
+ process.stdout.write(`Uploading ${filesToUpload.files.length} ${(0, utils_1.pluralize)('file', filesToUpload.files.length)}:\n`);
85
85
  let uploaded = 0;
86
86
  for (const file of filesToUpload.files) {
87
87
  const { signedUploadUrl, filePath } = yield client.registryApi.prepareFileUpload({
@@ -96,13 +96,13 @@ function handlePush(argv, config) {
96
96
  rootFilePath = filePath;
97
97
  }
98
98
  filePaths.push(filePath);
99
- process.stdout.write(`Uploading ${file.contents ? 'bundle for ' : ''}${colorette_1.blue(file.filePath)}...`);
99
+ process.stdout.write(`Uploading ${file.contents ? 'bundle for ' : ''}${(0, colorette_1.blue)(file.filePath)}...`);
100
100
  const uploadResponse = yield uploadFileToS3(signedUploadUrl, file.contents || file.filePath);
101
101
  const fileCounter = `(${++uploaded}/${filesToUpload.files.length})`;
102
102
  if (!uploadResponse.ok) {
103
- utils_1.exitWithError(`✗ ${fileCounter}\nFile upload failed\n`);
103
+ (0, utils_1.exitWithError)(`✗ ${fileCounter}\nFile upload failed\n`);
104
104
  }
105
- process.stdout.write(colorette_1.green(`✓ ${fileCounter}\n`));
105
+ process.stdout.write((0, colorette_1.green)(`✓ ${fileCounter}\n`));
106
106
  }
107
107
  process.stdout.write('\n');
108
108
  yield client.registryApi.pushApi({
@@ -120,16 +120,16 @@ function handlePush(argv, config) {
120
120
  }
121
121
  catch (error) {
122
122
  if (error.message === 'ORGANIZATION_NOT_FOUND') {
123
- utils_1.exitWithError(`Organization ${colorette_1.blue(organizationId)} not found`);
123
+ (0, utils_1.exitWithError)(`Organization ${(0, colorette_1.blue)(organizationId)} not found`);
124
124
  }
125
125
  if (error.message === 'API_VERSION_NOT_FOUND') {
126
- utils_1.exitWithError(`The definition version ${colorette_1.blue(`${name}@${version}`)} does not exist in organization ${colorette_1.blue(organizationId)}!\n${colorette_1.yellow('Suggestion:')} please use ${colorette_1.blue('-u')} or ${colorette_1.blue('--upsert')} to create definition.\n\n`);
126
+ (0, utils_1.exitWithError)(`The definition version ${(0, colorette_1.blue)(`${name}@${version}`)} does not exist in organization ${(0, colorette_1.blue)(organizationId)}!\n${(0, colorette_1.yellow)('Suggestion:')} please use ${(0, colorette_1.blue)('-u')} or ${(0, colorette_1.blue)('--upsert')} to create definition.\n\n`);
127
127
  }
128
128
  throw error;
129
129
  }
130
- process.stdout.write(`Definition: ${colorette_1.blue(api)} is successfully pushed to Redocly API Registry \n`);
130
+ process.stdout.write(`Definition: ${(0, colorette_1.blue)(api)} is successfully pushed to Redocly API Registry \n`);
131
131
  }
132
- utils_1.printExecutionTime('push', startedAt, api || `apis in organization ${organizationId}`);
132
+ (0, utils_1.printExecutionTime)('push', startedAt, api || `apis in organization ${organizationId}`);
133
133
  });
134
134
  }
135
135
  exports.handlePush = handlePush;
@@ -151,22 +151,22 @@ function collectFilesToUpload(api, config) {
151
151
  var _a, _b;
152
152
  return __awaiter(this, void 0, void 0, function* () {
153
153
  const files = [];
154
- const [{ path: apiPath }] = yield utils_1.getFallbackApisOrExit([api], config);
154
+ const [{ path: apiPath }] = yield (0, utils_1.getFallbackApisOrExit)([api], config);
155
155
  process.stdout.write('Bundling definition\n');
156
- const { bundle: openapiBundle, problems } = yield openapi_core_1.bundle({
156
+ const { bundle: openapiBundle, problems } = yield (0, openapi_core_1.bundle)({
157
157
  config,
158
158
  ref: apiPath,
159
159
  skipRedoclyRegistryRefs: true,
160
160
  });
161
- const fileTotals = openapi_core_1.getTotals(problems);
161
+ const fileTotals = (0, openapi_core_1.getTotals)(problems);
162
162
  if (fileTotals.errors === 0) {
163
- process.stdout.write(`Created a bundle for ${colorette_1.blue(api)} ${fileTotals.warnings > 0 ? 'with warnings' : ''}\n`);
163
+ process.stdout.write(`Created a bundle for ${(0, colorette_1.blue)(api)} ${fileTotals.warnings > 0 ? 'with warnings' : ''}\n`);
164
164
  }
165
165
  else {
166
- utils_1.exitWithError(`Failed to create a bundle for ${colorette_1.blue(api)}\n`);
166
+ (0, utils_1.exitWithError)(`Failed to create a bundle for ${(0, colorette_1.blue)(api)}\n`);
167
167
  }
168
168
  const fileExt = path.extname(apiPath).split('.').pop();
169
- files.push(getFileEntry(apiPath, utils_1.dumpBundle(openapiBundle.parsed, fileExt)));
169
+ files.push(getFileEntry(apiPath, (0, utils_1.dumpBundle)(openapiBundle.parsed, fileExt)));
170
170
  if (fs.existsSync('package.json')) {
171
171
  files.push(getFileEntry('package.json'));
172
172
  }
@@ -217,8 +217,8 @@ function collectFilesToUpload(api, config) {
217
217
  return {
218
218
  filePath: path.resolve(filename),
219
219
  keyOnS3: config.configFile
220
- ? openapi_core_1.slash(path.relative(path.dirname(config.configFile), filename))
221
- : openapi_core_1.slash(path.basename(filename)),
220
+ ? (0, openapi_core_1.slash)(path.relative(path.dirname(config.configFile), filename))
221
+ : (0, openapi_core_1.slash)(path.basename(filename)),
222
222
  contents: (contents && Buffer.from(contents, 'utf-8')) || undefined,
223
223
  };
224
224
  }
@@ -228,7 +228,7 @@ function getFolder(filePath) {
228
228
  return path.resolve(path.dirname(filePath));
229
229
  }
230
230
  function hashFiles(filePaths) {
231
- const sum = crypto_1.createHash('sha256');
231
+ const sum = (0, crypto_1.createHash)('sha256');
232
232
  filePaths.forEach((file) => sum.update(fs.readFileSync(file.filePath)));
233
233
  return sum.digest('hex');
234
234
  }
@@ -253,19 +253,19 @@ exports.getDestinationProps = getDestinationProps;
253
253
  const transformPush = (callback) => (_a, config) => {
254
254
  var { api: maybeApiOrDestination, maybeDestination, maybeBranchName, branch, 'batch-id': batchId, 'job-id': jobId } = _a, rest = __rest(_a, ["api", "maybeDestination", "maybeBranchName", "branch", 'batch-id', 'job-id']);
255
255
  if (batchId) {
256
- process.stderr.write(colorette_1.yellow(`The ${colorette_1.red('batch-id')} option is deprecated. Please use ${colorette_1.green('job-id')} instead.\n\n`));
256
+ process.stderr.write((0, colorette_1.yellow)(`The ${(0, colorette_1.red)('batch-id')} option is deprecated. Please use ${(0, colorette_1.green)('job-id')} instead.\n\n`));
257
257
  }
258
258
  if (maybeBranchName) {
259
- process.stderr.write(colorette_1.yellow('Deprecation warning: Do not use the third parameter as a branch name. Please use a separate --branch option instead.\n\n'));
259
+ process.stderr.write((0, colorette_1.yellow)('Deprecation warning: Do not use the third parameter as a branch name. Please use a separate --branch option instead.\n\n'));
260
260
  }
261
261
  let apiFile, destination;
262
262
  if (maybeDestination) {
263
- process.stderr.write(colorette_1.yellow('Deprecation warning: Do not use the second parameter as a destination. Please use a separate --destination and --organization instead.\n\n'));
263
+ process.stderr.write((0, colorette_1.yellow)('Deprecation warning: Do not use the second parameter as a destination. Please use a separate --destination and --organization instead.\n\n'));
264
264
  apiFile = maybeApiOrDestination;
265
265
  destination = maybeDestination;
266
266
  }
267
267
  else if (maybeApiOrDestination && exports.DESTINATION_REGEX.test(maybeApiOrDestination)) {
268
- process.stderr.write(colorette_1.yellow('Deprecation warning: Do not use the first parameter as a destination. Please use a separate --destination and --organization options instead.\n\n'));
268
+ process.stderr.write((0, colorette_1.yellow)('Deprecation warning: Do not use the first parameter as a destination. Please use a separate --destination and --organization options instead.\n\n'));
269
269
  destination = maybeApiOrDestination;
270
270
  }
271
271
  else if (maybeApiOrDestination && !exports.DESTINATION_REGEX.test(maybeApiOrDestination)) {
@@ -285,7 +285,7 @@ function uploadFileToS3(url, filePathOrBuffer) {
285
285
  ? fs.statSync(filePathOrBuffer).size
286
286
  : filePathOrBuffer.byteLength;
287
287
  const readStream = typeof filePathOrBuffer === 'string' ? fs.createReadStream(filePathOrBuffer) : filePathOrBuffer;
288
- return node_fetch_1.default(url, {
288
+ return (0, node_fetch_1.default)(url, {
289
289
  method: 'PUT',
290
290
  headers: {
291
291
  'Content-Length': fileSizeInBytes.toString(),
@@ -14,7 +14,7 @@ const path = require("path");
14
14
  const openapiCore = require("@redocly/openapi-core");
15
15
  const colorette_1 = require("colorette");
16
16
  const utils = require('../../../utils');
17
- jest.mock('../../../utils', () => (Object.assign(Object.assign({}, jest.requireActual('../../../utils')), { writeYaml: jest.fn() })));
17
+ jest.mock('../../../utils', () => (Object.assign(Object.assign({}, jest.requireActual('../../../utils')), { writeToFileByExtension: jest.fn() })));
18
18
  jest.mock('@redocly/openapi-core', () => (Object.assign(Object.assign({}, jest.requireActual('@redocly/openapi-core')), { isRef: jest.fn() })));
19
19
  describe('#split', () => {
20
20
  const openapiDir = 'test';
@@ -22,20 +22,20 @@ describe('#split', () => {
22
22
  it('should split the file and show the success message', () => __awaiter(void 0, void 0, void 0, function* () {
23
23
  const filePath = 'packages/cli/src/commands/split/__tests__/fixtures/spec.json';
24
24
  jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
25
- yield index_1.handleSplit({
25
+ yield (0, index_1.handleSplit)({
26
26
  api: filePath,
27
27
  outDir: openapiDir,
28
28
  separator: '_',
29
29
  });
30
30
  expect(process.stderr.write).toBeCalledTimes(2);
31
- expect(process.stderr.write.mock.calls[0][0]).toBe(`🪓 Document: ${colorette_1.blue(filePath)} ${colorette_1.green('is successfully split')}
32
- and all related files are saved to the directory: ${colorette_1.blue(openapiDir)} \n`);
31
+ expect(process.stderr.write.mock.calls[0][0]).toBe(`🪓 Document: ${(0, colorette_1.blue)(filePath)} ${(0, colorette_1.green)('is successfully split')}
32
+ and all related files are saved to the directory: ${(0, colorette_1.blue)(openapiDir)} \n`);
33
33
  expect(process.stderr.write.mock.calls[1][0]).toContain(`${filePath}: split processed in <test>ms`);
34
34
  }));
35
35
  it('should use the correct separator', () => __awaiter(void 0, void 0, void 0, function* () {
36
36
  const filePath = 'packages/cli/src/commands/split/__tests__/fixtures/spec.json';
37
37
  jest.spyOn(utils, 'pathToFilename').mockImplementation(() => 'newFilePath');
38
- yield index_1.handleSplit({
38
+ yield (0, index_1.handleSplit)({
39
39
  api: filePath,
40
40
  outDir: openapiDir,
41
41
  separator: '_',
@@ -47,7 +47,7 @@ describe('#split', () => {
47
47
  const openapi = require('./fixtures/spec.json');
48
48
  jest.spyOn(openapiCore, 'slash').mockImplementation(() => 'paths/test.yaml');
49
49
  jest.spyOn(path, 'relative').mockImplementation(() => 'paths/test.yaml');
50
- index_1.iteratePathItems(openapi.paths, openapiDir, path.join(openapiDir, 'paths'), componentsFiles, '_');
50
+ (0, index_1.iteratePathItems)(openapi.paths, openapiDir, path.join(openapiDir, 'paths'), componentsFiles, '_', undefined, 'yaml');
51
51
  expect(openapiCore.slash).toHaveBeenCalledWith('paths/test.yaml');
52
52
  expect(path.relative).toHaveBeenCalledWith('test', 'test/paths/test.yaml');
53
53
  });
@@ -55,7 +55,7 @@ describe('#split', () => {
55
55
  const openapi = require('./fixtures/webhooks.json');
56
56
  jest.spyOn(openapiCore, 'slash').mockImplementation(() => 'webhooks/test.yaml');
57
57
  jest.spyOn(path, 'relative').mockImplementation(() => 'webhooks/test.yaml');
58
- index_1.iteratePathItems(openapi.webhooks, openapiDir, path.join(openapiDir, 'webhooks'), componentsFiles, 'webhook_');
58
+ (0, index_1.iteratePathItems)(openapi.webhooks, openapiDir, path.join(openapiDir, 'webhooks'), componentsFiles, 'webhook_', undefined, 'yaml');
59
59
  expect(openapiCore.slash).toHaveBeenCalledWith('webhooks/test.yaml');
60
60
  expect(path.relative).toHaveBeenCalledWith('test', 'test/webhooks/test.yaml');
61
61
  });
@@ -63,7 +63,7 @@ describe('#split', () => {
63
63
  const openapi = require('./fixtures/spec.json');
64
64
  jest.spyOn(openapiCore, 'slash').mockImplementation(() => 'webhooks/test.yaml');
65
65
  jest.spyOn(path, 'relative').mockImplementation(() => 'webhooks/test.yaml');
66
- index_1.iteratePathItems(openapi['x-webhooks'], openapiDir, path.join(openapiDir, 'webhooks'), componentsFiles, 'webhook_');
66
+ (0, index_1.iteratePathItems)(openapi['x-webhooks'], openapiDir, path.join(openapiDir, 'webhooks'), componentsFiles, 'webhook_', undefined, 'yaml');
67
67
  expect(openapiCore.slash).toHaveBeenCalledWith('webhooks/test.yaml');
68
68
  expect(path.relative).toHaveBeenCalledWith('test', 'test/webhooks/test.yaml');
69
69
  });
@@ -72,7 +72,7 @@ describe('#split', () => {
72
72
  const fs = require('fs');
73
73
  jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { });
74
74
  jest.spyOn(utils, 'escapeLanguageName');
75
- index_1.iteratePathItems(openapi.paths, openapiDir, path.join(openapiDir, 'paths'), componentsFiles, '_');
75
+ (0, index_1.iteratePathItems)(openapi.paths, openapiDir, path.join(openapiDir, 'paths'), componentsFiles, '_', undefined, 'yaml');
76
76
  expect(utils.escapeLanguageName).nthCalledWith(1, 'C#');
77
77
  expect(utils.escapeLanguageName).nthReturnedWith(1, 'C_sharp');
78
78
  expect(utils.escapeLanguageName).nthCalledWith(2, 'C/AL');
@@ -1,10 +1,10 @@
1
1
  import { Oas3PathItem, Referenced } from './types';
2
- export declare type SplitOptions = {
2
+ export type SplitOptions = {
3
3
  api: string;
4
4
  outDir: string;
5
5
  separator: string;
6
6
  config?: string;
7
7
  };
8
8
  export declare function handleSplit(argv: SplitOptions): Promise<void>;
9
- declare function iteratePathItems(pathItems: Record<string, Referenced<Oas3PathItem>> | undefined, openapiDir: string, outDir: string, componentsFiles: object, pathSeparator: string, codeSamplesPathPrefix?: string): void;
9
+ declare function iteratePathItems(pathItems: Record<string, Referenced<Oas3PathItem>> | undefined, openapiDir: string, outDir: string, componentsFiles: object, pathSeparator: string, codeSamplesPathPrefix: string | undefined, ext: string): void;
10
10
  export { iteratePathItems };