@redocly/cli 1.0.0-beta.128 → 1.0.0-beta.130
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/lib/__tests__/commands/build-docs.test.js +1 -1
- package/lib/__tests__/commands/bundle.test.js +18 -17
- package/lib/__tests__/commands/join.test.js +9 -8
- package/lib/__tests__/commands/lint.test.js +40 -20
- package/lib/__tests__/commands/push-region.test.js +3 -2
- package/lib/__tests__/commands/push.test.js +94 -55
- package/lib/__tests__/fetch-with-timeout.test.d.ts +1 -0
- package/lib/__tests__/fetch-with-timeout.test.js +38 -0
- package/lib/__tests__/utils.test.js +131 -40
- package/lib/__tests__/wrapper.test.d.ts +1 -0
- package/lib/__tests__/wrapper.test.js +57 -0
- package/lib/commands/build-docs/index.d.ts +2 -1
- package/lib/commands/build-docs/index.js +1 -2
- package/lib/commands/bundle.d.ts +10 -4
- package/lib/commands/bundle.js +4 -8
- package/lib/commands/join.d.ts +6 -3
- package/lib/commands/join.js +1 -2
- package/lib/commands/lint.d.ts +13 -6
- package/lib/commands/lint.js +9 -17
- package/lib/commands/login.d.ts +5 -3
- package/lib/commands/login.js +2 -2
- package/lib/commands/preview-docs/index.d.ts +4 -2
- package/lib/commands/preview-docs/index.js +11 -4
- package/lib/commands/push.d.ts +11 -6
- package/lib/commands/push.js +40 -22
- package/lib/commands/split/index.d.ts +4 -2
- package/lib/commands/stats.d.ts +7 -4
- package/lib/commands/stats.js +1 -2
- package/lib/fetch-with-timeout.d.ts +2 -0
- package/lib/fetch-with-timeout.js +25 -0
- package/lib/index.js +70 -22
- package/lib/types.d.ts +11 -8
- package/lib/update-version-notifier.d.ts +1 -0
- package/lib/update-version-notifier.js +8 -7
- package/lib/utils.d.ts +23 -2
- package/lib/utils.js +113 -11
- package/lib/wrapper.d.ts +4 -0
- package/lib/wrapper.js +52 -0
- package/package.json +9 -7
package/lib/commands/push.d.ts
CHANGED
|
@@ -1,29 +1,34 @@
|
|
|
1
1
|
import { Config, Region } from '@redocly/openapi-core';
|
|
2
|
-
declare
|
|
2
|
+
export declare const DESTINATION_REGEX: RegExp;
|
|
3
|
+
export declare type PushOptions = {
|
|
3
4
|
api?: string;
|
|
4
5
|
destination?: string;
|
|
5
6
|
branchName?: string;
|
|
6
7
|
upsert?: boolean;
|
|
7
|
-
'
|
|
8
|
+
'job-id'?: string;
|
|
8
9
|
'batch-size'?: number;
|
|
9
10
|
region?: Region;
|
|
10
11
|
'skip-decorator'?: string[];
|
|
11
12
|
public?: boolean;
|
|
12
13
|
files?: string[];
|
|
14
|
+
organization?: string;
|
|
15
|
+
config?: string;
|
|
13
16
|
};
|
|
14
|
-
export declare function handlePush(argv:
|
|
17
|
+
export declare function handlePush(argv: PushOptions, config: Config): Promise<void>;
|
|
15
18
|
export declare function getDestinationProps(destination: string | undefined, organization: string | undefined): {
|
|
16
19
|
organizationId: string | undefined;
|
|
17
20
|
name: string | undefined;
|
|
18
21
|
version: string | undefined;
|
|
19
22
|
};
|
|
20
|
-
declare type BarePushArgs = Omit<
|
|
21
|
-
maybeApiOrDestination?: string;
|
|
23
|
+
declare type BarePushArgs = Omit<PushOptions, 'destination' | 'branchName'> & {
|
|
22
24
|
maybeDestination?: string;
|
|
23
25
|
maybeBranchName?: string;
|
|
24
26
|
branch?: string;
|
|
27
|
+
destination?: string;
|
|
25
28
|
};
|
|
26
|
-
export declare const transformPush: (callback: typeof handlePush) => ({ maybeApiOrDestination, maybeDestination, maybeBranchName, branch, ...rest }: BarePushArgs
|
|
29
|
+
export declare const transformPush: (callback: typeof handlePush) => ({ api: maybeApiOrDestination, maybeDestination, maybeBranchName, branch, "batch-id": batchId, "job-id": jobId, ...rest }: BarePushArgs & {
|
|
30
|
+
'batch-id'?: string;
|
|
31
|
+
}, config: Config) => Promise<void>;
|
|
27
32
|
export declare function getApiRoot({ name, version, config: { apis }, }: {
|
|
28
33
|
name: string;
|
|
29
34
|
version: string;
|
package/lib/commands/push.js
CHANGED
|
@@ -20,7 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.getApiRoot = exports.transformPush = exports.getDestinationProps = exports.handlePush = void 0;
|
|
23
|
+
exports.getApiRoot = exports.transformPush = exports.getDestinationProps = exports.handlePush = exports.DESTINATION_REGEX = void 0;
|
|
24
24
|
const fs = require("fs");
|
|
25
25
|
const path = require("path");
|
|
26
26
|
const node_fetch_1 = require("node-fetch");
|
|
@@ -31,10 +31,9 @@ const openapi_core_1 = require("@redocly/openapi-core");
|
|
|
31
31
|
const utils_1 = require("../utils");
|
|
32
32
|
const login_1 = require("./login");
|
|
33
33
|
const DEFAULT_VERSION = 'latest';
|
|
34
|
-
|
|
35
|
-
function handlePush(argv) {
|
|
34
|
+
exports.DESTINATION_REGEX = /^(@(?<organizationId>[\w\-\s]+)\/)?(?<name>[^@]*)@(?<version>[\w\.\-]+)$/;
|
|
35
|
+
function handlePush(argv, config) {
|
|
36
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const config = yield utils_1.loadConfigAndHandleErrors({ region: argv.region, files: argv.files });
|
|
38
37
|
const client = new openapi_core_1.RedoclyClient(config.region);
|
|
39
38
|
const isAuthorized = yield client.isAuthorizedWithRedoclyByRegion();
|
|
40
39
|
if (!isAuthorized) {
|
|
@@ -43,21 +42,27 @@ function handlePush(argv) {
|
|
|
43
42
|
}
|
|
44
43
|
const startedAt = perf_hooks_1.performance.now();
|
|
45
44
|
const { destination, branchName, upsert } = argv;
|
|
46
|
-
const
|
|
45
|
+
const jobId = argv['job-id'];
|
|
47
46
|
const batchSize = argv['batch-size'];
|
|
48
|
-
if (destination && !DESTINATION_REGEX.test(destination)) {
|
|
49
|
-
utils_1.exitWithError(`Destination argument value is not valid, please use the right format: ${colorette_1.yellow('
|
|
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>')}`);
|
|
50
49
|
}
|
|
51
|
-
const
|
|
50
|
+
const destinationProps = getDestinationProps(destination, config.organization);
|
|
51
|
+
const organizationId = argv.organization || destinationProps.organizationId;
|
|
52
|
+
const { name, version } = destinationProps;
|
|
52
53
|
if (!organizationId) {
|
|
53
|
-
return utils_1.exitWithError(`No organization provided, please use
|
|
54
|
+
return utils_1.exitWithError(`No organization provided, please use --organization option or specify the 'organization' field in the config file.`);
|
|
54
55
|
}
|
|
55
56
|
const api = argv.api || (name && version && getApiRoot({ name, version, config }));
|
|
56
57
|
if (name && version && !api) {
|
|
57
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
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
// Ensure that a destination for the api is provided.
|
|
61
|
+
if (!name && api) {
|
|
62
|
+
return utils_1.exitWithError(`No destination provided, please use --destination option to provide destination.`);
|
|
63
|
+
}
|
|
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.`);
|
|
61
66
|
}
|
|
62
67
|
if (batchSize && batchSize < 2) {
|
|
63
68
|
utils_1.exitWithError(`The ${colorette_1.blue(`batch-size`)} option value is not valid, please use the integer bigger than 1.`);
|
|
@@ -109,7 +114,7 @@ function handlePush(argv) {
|
|
|
109
114
|
branch: branchName,
|
|
110
115
|
isUpsert: upsert,
|
|
111
116
|
isPublic: argv['public'],
|
|
112
|
-
batchId:
|
|
117
|
+
batchId: jobId,
|
|
113
118
|
batchSize: batchSize,
|
|
114
119
|
});
|
|
115
120
|
}
|
|
@@ -118,8 +123,7 @@ function handlePush(argv) {
|
|
|
118
123
|
utils_1.exitWithError(`Organization ${colorette_1.blue(organizationId)} not found`);
|
|
119
124
|
}
|
|
120
125
|
if (error.message === 'API_VERSION_NOT_FOUND') {
|
|
121
|
-
utils_1.exitWithError(`The definition version ${colorette_1.blue(name
|
|
122
|
-
`);
|
|
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`);
|
|
123
127
|
}
|
|
124
128
|
throw error;
|
|
125
129
|
}
|
|
@@ -230,7 +234,7 @@ function hashFiles(filePaths) {
|
|
|
230
234
|
}
|
|
231
235
|
function parseDestination(destination) {
|
|
232
236
|
var _a;
|
|
233
|
-
return (_a = destination === null || destination === void 0 ? void 0 : destination.match(DESTINATION_REGEX)) === null || _a === void 0 ? void 0 : _a.groups;
|
|
237
|
+
return (_a = destination === null || destination === void 0 ? void 0 : destination.match(exports.DESTINATION_REGEX)) === null || _a === void 0 ? void 0 : _a.groups;
|
|
234
238
|
}
|
|
235
239
|
function getDestinationProps(destination, organization) {
|
|
236
240
|
const groups = destination && parseDestination(destination);
|
|
@@ -246,15 +250,29 @@ function getDestinationProps(destination, organization) {
|
|
|
246
250
|
}
|
|
247
251
|
}
|
|
248
252
|
exports.getDestinationProps = getDestinationProps;
|
|
249
|
-
const transformPush = (callback) => (_a) => {
|
|
250
|
-
var { maybeApiOrDestination, maybeDestination, maybeBranchName, branch } = _a, rest = __rest(_a, ["
|
|
253
|
+
const transformPush = (callback) => (_a, config) => {
|
|
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
|
+
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`));
|
|
257
|
+
}
|
|
251
258
|
if (maybeBranchName) {
|
|
252
|
-
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
|
|
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'));
|
|
260
|
+
}
|
|
261
|
+
let apiFile, destination;
|
|
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'));
|
|
264
|
+
apiFile = maybeApiOrDestination;
|
|
265
|
+
destination = maybeDestination;
|
|
266
|
+
}
|
|
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'));
|
|
269
|
+
destination = maybeApiOrDestination;
|
|
270
|
+
}
|
|
271
|
+
else if (maybeApiOrDestination && !exports.DESTINATION_REGEX.test(maybeApiOrDestination)) {
|
|
272
|
+
apiFile = maybeApiOrDestination;
|
|
253
273
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return callback(Object.assign(Object.assign({}, rest), { destination,
|
|
257
|
-
api, branchName: branch !== null && branch !== void 0 ? branch : maybeBranchName }));
|
|
274
|
+
destination = rest.destination || destination;
|
|
275
|
+
return callback(Object.assign(Object.assign({}, rest), { destination, api: apiFile, branchName: branch !== null && branch !== void 0 ? branch : maybeBranchName, 'job-id': jobId || batchId }), config);
|
|
258
276
|
};
|
|
259
277
|
exports.transformPush = transformPush;
|
|
260
278
|
function getApiRoot({ name, version, config: { apis }, }) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Oas3PathItem, Referenced } from './types';
|
|
2
|
-
export declare
|
|
2
|
+
export declare type SplitOptions = {
|
|
3
3
|
api: string;
|
|
4
4
|
outDir: string;
|
|
5
5
|
separator: string;
|
|
6
|
-
|
|
6
|
+
config?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function handleSplit(argv: SplitOptions): Promise<void>;
|
|
7
9
|
declare function iteratePathItems(pathItems: Record<string, Referenced<Oas3PathItem>> | undefined, openapiDir: string, outDir: string, componentsFiles: object, pathSeparator: string, codeSamplesPathPrefix?: string): void;
|
|
8
10
|
export { iteratePathItems };
|
package/lib/commands/stats.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Config } from '@redocly/openapi-core';
|
|
2
|
+
import type { OutputFormat } from '@redocly/openapi-core';
|
|
3
|
+
export declare type StatsOptions = {
|
|
3
4
|
api?: string;
|
|
4
|
-
format:
|
|
5
|
-
|
|
5
|
+
format: OutputFormat;
|
|
6
|
+
config?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function handleStats(argv: StatsOptions, config: Config): Promise<void>;
|
package/lib/commands/stats.js
CHANGED
|
@@ -52,9 +52,8 @@ function printStats(statsAccumulator, api, format) {
|
|
|
52
52
|
break;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
function handleStats(argv) {
|
|
55
|
+
function handleStats(argv, config) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const config = yield utils_1.loadConfigAndHandleErrors({ configPath: argv.config });
|
|
58
57
|
const [{ path }] = yield utils_1.getFallbackApisOrExit(argv.api ? [argv.api] : [], config);
|
|
59
58
|
const externalRefResolver = new openapi_core_1.BaseResolver(config.resolve);
|
|
60
59
|
const { bundle: document } = yield openapi_core_1.bundle({ config, ref: path });
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const node_fetch_1 = require("node-fetch");
|
|
13
|
+
const TIMEOUT = 3000;
|
|
14
|
+
exports.default = (url, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
if (!global.AbortController) {
|
|
16
|
+
return node_fetch_1.default(url, options);
|
|
17
|
+
}
|
|
18
|
+
const controller = new AbortController();
|
|
19
|
+
const timeout = setTimeout(() => {
|
|
20
|
+
controller.abort();
|
|
21
|
+
}, TIMEOUT);
|
|
22
|
+
const res = yield node_fetch_1.default(url, Object.assign({ signal: controller.signal }, options));
|
|
23
|
+
clearTimeout(timeout);
|
|
24
|
+
return res;
|
|
25
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -24,12 +24,13 @@ const bundle_1 = require("./commands/bundle");
|
|
|
24
24
|
const login_1 = require("./commands/login");
|
|
25
25
|
const build_docs_1 = require("./commands/build-docs");
|
|
26
26
|
const update_version_notifier_1 = require("./update-version-notifier");
|
|
27
|
-
const
|
|
27
|
+
const wrapper_1 = require("./wrapper");
|
|
28
|
+
const update_version_notifier_2 = require("./update-version-notifier");
|
|
28
29
|
update_version_notifier_1.cacheLatestVersion();
|
|
29
30
|
yargs
|
|
30
|
-
.version('version', 'Show version number.', version)
|
|
31
|
+
.version('version', 'Show version number.', update_version_notifier_2.version)
|
|
31
32
|
.help('help', 'Show help.')
|
|
32
|
-
.parserConfiguration({ 'greedy-arrays': false })
|
|
33
|
+
.parserConfiguration({ 'greedy-arrays': false, 'camel-case-expansion': false })
|
|
33
34
|
.command('stats [api]', 'Gathering statistics for a document.', (yargs) => yargs.positional('api', { type: 'string' }).option({
|
|
34
35
|
config: { description: 'Specify path to the config file.', type: 'string' },
|
|
35
36
|
format: {
|
|
@@ -39,7 +40,7 @@ yargs
|
|
|
39
40
|
},
|
|
40
41
|
}), (argv) => {
|
|
41
42
|
process.env.REDOCLY_CLI_COMMAND = 'stats';
|
|
42
|
-
stats_1.handleStats(argv);
|
|
43
|
+
wrapper_1.commandWrapper(stats_1.handleStats)(argv);
|
|
43
44
|
})
|
|
44
45
|
.command('split [api]', 'Split definition into a multi-file structure.', (yargs) => yargs
|
|
45
46
|
.positional('api', {
|
|
@@ -58,10 +59,15 @@ yargs
|
|
|
58
59
|
type: 'string',
|
|
59
60
|
default: '_',
|
|
60
61
|
},
|
|
62
|
+
config: {
|
|
63
|
+
description: 'Specify path to the config file.',
|
|
64
|
+
requiresArg: true,
|
|
65
|
+
type: 'string',
|
|
66
|
+
},
|
|
61
67
|
})
|
|
62
68
|
.demandOption('api'), (argv) => {
|
|
63
69
|
process.env.REDOCLY_CLI_COMMAND = 'split';
|
|
64
|
-
split_1.handleSplit(argv);
|
|
70
|
+
wrapper_1.commandWrapper(split_1.handleSplit)(argv);
|
|
65
71
|
})
|
|
66
72
|
.command('join [apis...]', 'Join definitions [experimental].', (yargs) => yargs
|
|
67
73
|
.positional('apis', {
|
|
@@ -98,21 +104,53 @@ yargs
|
|
|
98
104
|
type: 'string',
|
|
99
105
|
default: 'openapi.yaml',
|
|
100
106
|
},
|
|
107
|
+
config: {
|
|
108
|
+
description: 'Specify path to the config file.',
|
|
109
|
+
requiresArg: true,
|
|
110
|
+
type: 'string',
|
|
111
|
+
},
|
|
101
112
|
}), (argv) => {
|
|
102
113
|
process.env.REDOCLY_CLI_COMMAND = 'join';
|
|
103
|
-
join_1.handleJoin(argv
|
|
114
|
+
wrapper_1.commandWrapper(join_1.handleJoin)(argv);
|
|
104
115
|
})
|
|
105
|
-
.command('push [
|
|
106
|
-
.
|
|
116
|
+
.command('push [api] [maybeDestination] [maybeBranchName]', 'Push an API definition to the Redocly API registry.', (yargs) => yargs
|
|
117
|
+
.usage('push [api]')
|
|
118
|
+
.positional('api', { type: 'string' })
|
|
107
119
|
.positional('maybeDestination', { type: 'string' })
|
|
108
|
-
.
|
|
120
|
+
.hide('maybeDestination')
|
|
121
|
+
.hide('maybeBranchName')
|
|
109
122
|
.option({
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
organization: {
|
|
124
|
+
description: 'Name of the organization to push to.',
|
|
125
|
+
type: 'string',
|
|
126
|
+
alias: 'o',
|
|
127
|
+
},
|
|
128
|
+
destination: {
|
|
129
|
+
description: 'API name and version in the format `name@version`.',
|
|
130
|
+
type: 'string',
|
|
131
|
+
alias: 'd',
|
|
132
|
+
},
|
|
133
|
+
branch: {
|
|
134
|
+
description: 'Branch name to push to.',
|
|
135
|
+
type: 'string',
|
|
136
|
+
alias: 'b',
|
|
137
|
+
},
|
|
138
|
+
upsert: {
|
|
139
|
+
description: "Create the specified API version if it doesn't exist, update if it does exist.",
|
|
140
|
+
type: 'boolean',
|
|
141
|
+
alias: 'u',
|
|
142
|
+
},
|
|
112
143
|
'batch-id': {
|
|
113
144
|
description: 'Specifies the ID of the CI job that the current push will be associated with.',
|
|
114
145
|
type: 'string',
|
|
115
146
|
requiresArg: true,
|
|
147
|
+
deprecated: true,
|
|
148
|
+
hidden: true,
|
|
149
|
+
},
|
|
150
|
+
'job-id': {
|
|
151
|
+
description: 'Specifies the ID of the CI job that the current push will be associated with.',
|
|
152
|
+
type: 'string',
|
|
153
|
+
requiresArg: true,
|
|
116
154
|
},
|
|
117
155
|
'batch-size': {
|
|
118
156
|
description: 'Specifies the total number of CI jobs planned to be pushed.',
|
|
@@ -135,10 +173,13 @@ yargs
|
|
|
135
173
|
type: 'string',
|
|
136
174
|
},
|
|
137
175
|
})
|
|
176
|
+
.deprecateOption('batch-id', 'use --job-id')
|
|
177
|
+
.deprecateOption('maybeDestination')
|
|
178
|
+
.implies('job-id', 'batch-size')
|
|
138
179
|
.implies('batch-id', 'batch-size')
|
|
139
|
-
.implies('batch-size', '
|
|
180
|
+
.implies('batch-size', 'job-id'), (argv) => {
|
|
140
181
|
process.env.REDOCLY_CLI_COMMAND = 'push';
|
|
141
|
-
push_1.transformPush(push_1.handlePush)(argv);
|
|
182
|
+
wrapper_1.commandWrapper(push_1.transformPush(push_1.handlePush))(argv);
|
|
142
183
|
})
|
|
143
184
|
.command('lint [apis...]', 'Lint definition.', (yargs) => yargs.positional('apis', { array: true, type: 'string', demandOption: true }).option({
|
|
144
185
|
format: {
|
|
@@ -191,7 +232,7 @@ yargs
|
|
|
191
232
|
},
|
|
192
233
|
}), (argv) => {
|
|
193
234
|
process.env.REDOCLY_CLI_COMMAND = 'lint';
|
|
194
|
-
lint_1.handleLint(argv
|
|
235
|
+
wrapper_1.commandWrapper(lint_1.handleLint)(argv);
|
|
195
236
|
})
|
|
196
237
|
.command('bundle [apis...]', 'Bundle definition.', (yargs) => yargs.positional('apis', { array: true, type: 'string', demandOption: true }).options({
|
|
197
238
|
output: { type: 'string', alias: 'o' },
|
|
@@ -267,7 +308,7 @@ yargs
|
|
|
267
308
|
},
|
|
268
309
|
}), (argv) => {
|
|
269
310
|
process.env.REDOCLY_CLI_COMMAND = 'bundle';
|
|
270
|
-
bundle_1.handleBundle(argv
|
|
311
|
+
wrapper_1.commandWrapper(bundle_1.handleBundle)(argv);
|
|
271
312
|
})
|
|
272
313
|
.command('login', 'Login to the Redocly API registry with an access token.', (yargs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
273
314
|
return yargs.options({
|
|
@@ -280,16 +321,23 @@ yargs
|
|
|
280
321
|
alias: 'r',
|
|
281
322
|
choices: types_1.regionChoices,
|
|
282
323
|
},
|
|
324
|
+
config: {
|
|
325
|
+
description: 'Specify path to the config file.',
|
|
326
|
+
requiresArg: true,
|
|
327
|
+
type: 'string',
|
|
328
|
+
},
|
|
283
329
|
});
|
|
284
330
|
}), (argv) => {
|
|
285
331
|
process.env.REDOCLY_CLI_COMMAND = 'login';
|
|
286
|
-
login_1.handleLogin(argv);
|
|
332
|
+
wrapper_1.commandWrapper(login_1.handleLogin)(argv);
|
|
287
333
|
})
|
|
288
|
-
.command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
334
|
+
.command('logout', 'Clear your stored credentials for the Redocly API registry.', (yargs) => yargs, (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
289
335
|
process.env.REDOCLY_CLI_COMMAND = 'logout';
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
336
|
+
yield wrapper_1.commandWrapper(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
337
|
+
const client = new openapi_core_1.RedoclyClient();
|
|
338
|
+
client.logout();
|
|
339
|
+
process.stdout.write('Logged out from the Redocly account. ✋\n');
|
|
340
|
+
}))(argv);
|
|
293
341
|
}))
|
|
294
342
|
.command('preview-docs [api]', 'Preview API reference docs for the specified definition.', (yargs) => yargs.positional('api', { type: 'string' }).options({
|
|
295
343
|
port: {
|
|
@@ -329,7 +377,7 @@ yargs
|
|
|
329
377
|
},
|
|
330
378
|
}), (argv) => {
|
|
331
379
|
process.env.REDOCLY_CLI_COMMAND = 'preview-docs';
|
|
332
|
-
preview_docs_1.previewDocs(argv);
|
|
380
|
+
wrapper_1.commandWrapper(preview_docs_1.previewDocs)(argv);
|
|
333
381
|
})
|
|
334
382
|
.command('build-docs [api]', 'build definition into an HTML file', (yargs) => yargs
|
|
335
383
|
.positional('api', { type: 'string' })
|
|
@@ -377,7 +425,7 @@ yargs
|
|
|
377
425
|
return true;
|
|
378
426
|
}), (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
379
427
|
process.env.REDOCLY_CLI_COMMAND = 'build-docs';
|
|
380
|
-
build_docs_1.handlerBuildCommand(argv);
|
|
428
|
+
wrapper_1.commandWrapper(build_docs_1.handlerBuildCommand)(argv);
|
|
381
429
|
}))
|
|
382
430
|
.completion('completion', 'Generate completion script.')
|
|
383
431
|
.demandCommand(1)
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import type { BundleOutputFormat,
|
|
1
|
+
import type { BundleOutputFormat, Region, Config } from '@redocly/openapi-core';
|
|
2
|
+
import type { LintOptions } from './commands/lint';
|
|
3
|
+
import type { BundleOptions } from './commands/bundle';
|
|
4
|
+
import type { JoinOptions } from './commands/join';
|
|
5
|
+
import type { LoginOptions } from './commands/login';
|
|
6
|
+
import type { PushOptions } from './commands/push';
|
|
7
|
+
import type { StatsOptions } from './commands/stats';
|
|
8
|
+
import type { SplitOptions } from './commands/split';
|
|
9
|
+
import type { PreviewDocsOptions } from './commands/preview-docs';
|
|
10
|
+
import type { BuildDocsArgv } from './commands/build-docs/types';
|
|
2
11
|
export declare type Totals = {
|
|
3
12
|
errors: number;
|
|
4
13
|
warnings: number;
|
|
@@ -11,13 +20,7 @@ export declare type Entrypoint = {
|
|
|
11
20
|
export declare const outputExtensions: readonly BundleOutputFormat[];
|
|
12
21
|
export declare type OutputExtensions = 'json' | 'yaml' | 'yml' | undefined;
|
|
13
22
|
export declare const regionChoices: readonly Region[];
|
|
14
|
-
export declare type
|
|
15
|
-
apis: string[];
|
|
16
|
-
'max-problems'?: number;
|
|
17
|
-
extends?: string[];
|
|
18
|
-
config?: string;
|
|
19
|
-
format: OutputFormat;
|
|
20
|
-
};
|
|
23
|
+
export declare type CommandOptions = StatsOptions | SplitOptions | JoinOptions | PushOptions | LintOptions | BundleOptions | LoginOptions | PreviewDocsOptions | BuildDocsArgv;
|
|
21
24
|
export declare type Skips = {
|
|
22
25
|
'skip-rule'?: string[];
|
|
23
26
|
'skip-decorator'?: string[];
|
|
@@ -8,16 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var _a;
|
|
11
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.cacheLatestVersion = exports.notifyUpdateCliVersion = void 0;
|
|
13
|
+
exports.cacheLatestVersion = exports.notifyUpdateCliVersion = exports.name = exports.version = void 0;
|
|
13
14
|
const os_1 = require("os");
|
|
14
15
|
const path_1 = require("path");
|
|
15
16
|
const fs_1 = require("fs");
|
|
16
17
|
const semver_1 = require("semver");
|
|
17
|
-
const
|
|
18
|
+
const fetch_with_timeout_1 = require("./fetch-with-timeout");
|
|
18
19
|
const colorette_1 = require("colorette");
|
|
19
20
|
const utils_1 = require("./utils");
|
|
20
|
-
|
|
21
|
+
_a = require('../package.json'), exports.version = _a.version, exports.name = _a.name;
|
|
21
22
|
const VERSION_CACHE_FILE = 'redocly-cli-version';
|
|
22
23
|
const SPACE_TO_BORDER = 4;
|
|
23
24
|
const INTERVAL_TO_CHECK = 1000 * 60 * 60 * 12;
|
|
@@ -28,8 +29,8 @@ const notifyUpdateCliVersion = () => {
|
|
|
28
29
|
}
|
|
29
30
|
try {
|
|
30
31
|
const latestVersion = fs_1.readFileSync(path_1.join(os_1.tmpdir(), VERSION_CACHE_FILE)).toString();
|
|
31
|
-
if (isNewVersionAvailable(version, latestVersion)) {
|
|
32
|
-
renderUpdateBanner(version, latestVersion);
|
|
32
|
+
if (isNewVersionAvailable(exports.version, latestVersion)) {
|
|
33
|
+
renderUpdateBanner(exports.version, latestVersion);
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
catch (e) {
|
|
@@ -40,7 +41,7 @@ exports.notifyUpdateCliVersion = notifyUpdateCliVersion;
|
|
|
40
41
|
const isNewVersionAvailable = (current, latest) => semver_1.compare(current, latest) < 0;
|
|
41
42
|
const getLatestVersion = (packageName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
43
|
const latestUrl = `http://registry.npmjs.org/${packageName}/latest`;
|
|
43
|
-
const response = yield
|
|
44
|
+
const response = yield fetch_with_timeout_1.default(latestUrl);
|
|
44
45
|
const info = yield response.json();
|
|
45
46
|
return info.version;
|
|
46
47
|
});
|
|
@@ -48,7 +49,7 @@ const cacheLatestVersion = () => {
|
|
|
48
49
|
if (!isNeedToBeCached() || SHOULD_NOT_NOTIFY) {
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
|
-
getLatestVersion(name)
|
|
52
|
+
getLatestVersion(exports.name)
|
|
52
53
|
.then((version) => {
|
|
53
54
|
const lastCheckFile = path_1.join(os_1.tmpdir(), VERSION_CACHE_FILE);
|
|
54
55
|
fs_1.writeFileSync(lastCheckFile, version);
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BundleOutputFormat, StyleguideConfig, RawConfig, Region, Config, Oas3Definition, Oas2Definition } from '@redocly/openapi-core';
|
|
2
|
-
import { Totals, Entrypoint, ConfigApis } from './types';
|
|
2
|
+
import { Totals, Entrypoint, ConfigApis, CommandOptions } from './types';
|
|
3
|
+
import { Arguments } from 'yargs';
|
|
3
4
|
export declare function getFallbackApisOrExit(argsApis: string[] | undefined, config: ConfigApis): Promise<Entrypoint[]>;
|
|
4
5
|
export declare function getExecutionTime(startedAt: number): string;
|
|
5
6
|
export declare function printExecutionTime(commandName: string, startedAt: number, api: string): void;
|
|
@@ -17,6 +18,8 @@ export declare function readYaml(filename: string): unknown;
|
|
|
17
18
|
export declare function writeYaml(data: any, filename: string, noRefs?: boolean): void;
|
|
18
19
|
export declare function pluralize(label: string, num: number): string;
|
|
19
20
|
export declare function handleError(e: Error, ref: string): void;
|
|
21
|
+
export declare class HandledError extends Error {
|
|
22
|
+
}
|
|
20
23
|
export declare function printLintTotals(totals: Totals, definitionsCount: number): void;
|
|
21
24
|
export declare function printConfigLintTotals(totals: Totals): void;
|
|
22
25
|
export declare function getOutputFileName(entrypoint: string, entries: number, output?: string, ext?: BundleOutputFormat): {
|
|
@@ -35,7 +38,25 @@ export declare function loadConfigAndHandleErrors(options?: {
|
|
|
35
38
|
processRawConfig?: (rawConfig: RawConfig) => void | Promise<void>;
|
|
36
39
|
files?: string[];
|
|
37
40
|
region?: Region;
|
|
38
|
-
}): Promise<Config>;
|
|
41
|
+
}): Promise<Config | void>;
|
|
39
42
|
export declare function sortTopLevelKeysForOas(document: Oas3Definition | Oas2Definition): Oas3Definition | Oas2Definition;
|
|
40
43
|
export declare function checkIfRulesetExist(rules: typeof StyleguideConfig.prototype.rules): void;
|
|
41
44
|
export declare function cleanColors(input: string): string;
|
|
45
|
+
export declare function sendTelemetry(argv: Arguments | undefined, exit_code: ExitCode, has_config: boolean | undefined): Promise<void>;
|
|
46
|
+
export declare type ExitCode = 0 | 1 | 2;
|
|
47
|
+
export declare type Analytics = {
|
|
48
|
+
event: string;
|
|
49
|
+
event_time: string;
|
|
50
|
+
logged_in: boolean;
|
|
51
|
+
command: string | number;
|
|
52
|
+
arguments: Record<string, unknown>;
|
|
53
|
+
node_version: string;
|
|
54
|
+
version: string;
|
|
55
|
+
exit_code: ExitCode;
|
|
56
|
+
environment?: string;
|
|
57
|
+
environment_ci?: string;
|
|
58
|
+
raw_input: string;
|
|
59
|
+
has_config?: boolean;
|
|
60
|
+
};
|
|
61
|
+
export declare function cleanArgs(args: CommandOptions): Record<string, unknown>;
|
|
62
|
+
export declare function cleanRawInput(argv: string[]): string;
|