@redocly/cli 1.18.1 → 1.19.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 +11 -0
- package/lib/__mocks__/@redocly/openapi-core.d.ts +2 -2
- package/lib/__mocks__/@redocly/openapi-core.js +1 -0
- package/lib/__mocks__/fs.d.ts +0 -1
- package/lib/__mocks__/perf_hooks.d.ts +0 -1
- package/lib/__mocks__/redoc.d.ts +0 -1
- package/lib/__tests__/commands/build-docs.test.js +21 -23
- package/lib/__tests__/commands/bundle.test.js +21 -30
- package/lib/__tests__/commands/join.test.js +101 -70
- package/lib/__tests__/commands/lint.test.js +54 -54
- package/lib/__tests__/commands/push-region.test.js +24 -25
- package/lib/__tests__/commands/push.test.js +269 -170
- package/lib/__tests__/fetch-with-timeout.test.js +3 -12
- package/lib/__tests__/fixtures/config.d.ts +0 -1
- package/lib/__tests__/utils.test.js +32 -37
- package/lib/__tests__/wrapper.test.js +31 -20
- package/lib/cms/api/__tests__/api.client.test.js +29 -38
- package/lib/cms/api/api-client.d.ts +0 -2
- package/lib/cms/api/api-client.js +106 -127
- package/lib/cms/api/api-keys.js +1 -2
- package/lib/cms/api/domains.js +1 -2
- package/lib/cms/commands/__tests__/push-status.test.js +251 -162
- package/lib/cms/commands/__tests__/push.test.js +120 -102
- package/lib/cms/commands/__tests__/utils.test.js +12 -21
- package/lib/cms/commands/push-status.d.ts +3 -2
- package/lib/cms/commands/push-status.js +94 -106
- package/lib/cms/commands/push.d.ts +3 -2
- package/lib/cms/commands/push.js +66 -74
- package/lib/cms/commands/utils.js +20 -34
- package/lib/commands/build-docs/index.d.ts +2 -2
- package/lib/commands/build-docs/index.js +8 -17
- package/lib/commands/build-docs/utils.js +26 -38
- package/lib/commands/bundle.d.ts +2 -2
- package/lib/commands/bundle.js +70 -94
- package/lib/commands/join.d.ts +2 -2
- package/lib/commands/join.js +375 -388
- package/lib/commands/lint.d.ts +2 -2
- package/lib/commands/lint.js +64 -75
- package/lib/commands/login.d.ts +3 -2
- package/lib/commands/login.js +9 -21
- package/lib/commands/preview-docs/index.d.ts +2 -2
- package/lib/commands/preview-docs/index.js +92 -106
- package/lib/commands/preview-docs/preview-server/preview-server.js +64 -76
- package/lib/commands/preview-docs/preview-server/server.d.ts +0 -3
- package/lib/commands/preview-docs/preview-server/server.js +6 -6
- package/lib/commands/preview-project/index.d.ts +2 -1
- package/lib/commands/preview-project/index.js +5 -14
- package/lib/commands/push.d.ts +8 -11
- package/lib/commands/push.js +177 -195
- package/lib/commands/split/__tests__/index.test.js +31 -25
- package/lib/commands/split/index.d.ts +2 -1
- package/lib/commands/split/index.js +20 -33
- package/lib/commands/stats.d.ts +2 -2
- package/lib/commands/stats.js +34 -45
- package/lib/index.js +32 -46
- package/lib/types.d.ts +2 -2
- package/lib/utils/__mocks__/miscellaneous.d.ts +0 -1
- package/lib/utils/fetch-with-timeout.js +7 -12
- package/lib/utils/getCommandNameFromArgs.js +2 -4
- package/lib/utils/js-utils.js +6 -7
- package/lib/utils/miscellaneous.d.ts +4 -1
- package/lib/utils/miscellaneous.js +130 -152
- package/lib/utils/update-version-notifier.js +4 -13
- package/lib/wrapper.d.ts +9 -2
- package/lib/wrapper.js +27 -16
- package/package.json +3 -3
- package/src/__mocks__/@redocly/openapi-core.ts +1 -0
- package/src/__tests__/commands/build-docs.test.ts +5 -4
- package/src/__tests__/commands/join.test.ts +51 -51
- package/src/__tests__/commands/push-region.test.ts +10 -8
- package/src/__tests__/commands/push.test.ts +127 -102
- package/src/__tests__/utils.test.ts +1 -0
- package/src/__tests__/wrapper.test.ts +24 -2
- package/src/cms/commands/__tests__/push-status.test.ts +70 -56
- package/src/cms/commands/__tests__/push.test.ts +30 -24
- package/src/cms/commands/push-status.ts +8 -7
- package/src/cms/commands/push.ts +12 -9
- package/src/commands/build-docs/index.ts +10 -5
- package/src/commands/bundle.ts +14 -6
- package/src/commands/join.ts +6 -2
- package/src/commands/lint.ts +9 -3
- package/src/commands/login.ts +4 -2
- package/src/commands/preview-docs/index.ts +6 -1
- package/src/commands/preview-project/index.ts +5 -4
- package/src/commands/push.ts +13 -15
- package/src/commands/split/__tests__/index.test.ts +17 -6
- package/src/commands/split/index.ts +4 -2
- package/src/commands/stats.ts +4 -2
- package/src/utils/miscellaneous.ts +11 -1
- package/src/wrapper.ts +37 -11
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ReuniteApiClient = void 0;
|
|
13
4
|
const fetch_with_timeout_1 = require("../../utils/fetch-with-timeout");
|
|
@@ -19,134 +10,122 @@ class RemotesApiClient {
|
|
|
19
10
|
this.domain = domain;
|
|
20
11
|
this.apiKey = apiKey;
|
|
21
12
|
}
|
|
22
|
-
getParsedResponse(response) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
throw new Error(responseBody.title || response.statusText);
|
|
29
|
-
});
|
|
13
|
+
async getParsedResponse(response) {
|
|
14
|
+
const responseBody = await response.json();
|
|
15
|
+
if (response.ok) {
|
|
16
|
+
return responseBody;
|
|
17
|
+
}
|
|
18
|
+
throw new Error(responseBody.title || response.statusText);
|
|
30
19
|
}
|
|
31
|
-
getDefaultBranch(organizationId, projectId) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
if (!response) {
|
|
41
|
-
throw new Error(`Failed to get default branch.`);
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
const source = yield this.getParsedResponse(response);
|
|
45
|
-
return source.branchName;
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
throw new Error(`Failed to fetch default branch: ${err.message || 'Unknown error'}`);
|
|
49
|
-
}
|
|
20
|
+
async getDefaultBranch(organizationId, projectId) {
|
|
21
|
+
const response = await (0, fetch_with_timeout_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/source`, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
headers: {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
26
|
+
},
|
|
50
27
|
});
|
|
28
|
+
if (!response) {
|
|
29
|
+
throw new Error(`Failed to get default branch.`);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const source = await this.getParsedResponse(response);
|
|
33
|
+
return source.branchName;
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
throw new Error(`Failed to fetch default branch: ${err.message || 'Unknown error'}`);
|
|
37
|
+
}
|
|
51
38
|
}
|
|
52
|
-
upsert(organizationId, projectId, remote) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}),
|
|
66
|
-
});
|
|
67
|
-
if (!response) {
|
|
68
|
-
throw new Error(`Failed to upsert.`);
|
|
69
|
-
}
|
|
70
|
-
try {
|
|
71
|
-
return yield this.getParsedResponse(response);
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
throw new Error(`Failed to upsert remote: ${err.message || 'Unknown error'}`);
|
|
75
|
-
}
|
|
39
|
+
async upsert(organizationId, projectId, remote) {
|
|
40
|
+
const response = await (0, fetch_with_timeout_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/remotes`, {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
headers: {
|
|
43
|
+
'Content-Type': 'application/json',
|
|
44
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
mountPath: remote.mountPath,
|
|
48
|
+
mountBranchName: remote.mountBranchName,
|
|
49
|
+
type: 'CICD',
|
|
50
|
+
autoMerge: true,
|
|
51
|
+
}),
|
|
76
52
|
});
|
|
53
|
+
if (!response) {
|
|
54
|
+
throw new Error(`Failed to upsert.`);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
return await this.getParsedResponse(response);
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
throw new Error(`Failed to upsert remote: ${err.message || 'Unknown error'}`);
|
|
61
|
+
}
|
|
77
62
|
}
|
|
78
|
-
push(organizationId, projectId, payload, files) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
agent: (0, openapi_core_1.getProxyAgent)(),
|
|
102
|
-
});
|
|
103
|
-
try {
|
|
104
|
-
return yield this.getParsedResponse(response);
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
throw new Error(`Failed to push: ${err.message || 'Unknown error'}`);
|
|
108
|
-
}
|
|
63
|
+
async push(organizationId, projectId, payload, files) {
|
|
64
|
+
const formData = new FormData();
|
|
65
|
+
formData.append('remoteId', payload.remoteId);
|
|
66
|
+
formData.append('commit[message]', payload.commit.message);
|
|
67
|
+
formData.append('commit[author][name]', payload.commit.author.name);
|
|
68
|
+
formData.append('commit[author][email]', payload.commit.author.email);
|
|
69
|
+
formData.append('commit[branchName]', payload.commit.branchName);
|
|
70
|
+
payload.commit.url && formData.append('commit[url]', payload.commit.url);
|
|
71
|
+
payload.commit.namespace && formData.append('commit[namespaceId]', payload.commit.namespace);
|
|
72
|
+
payload.commit.sha && formData.append('commit[sha]', payload.commit.sha);
|
|
73
|
+
payload.commit.repository && formData.append('commit[repositoryId]', payload.commit.repository);
|
|
74
|
+
payload.commit.createdAt && formData.append('commit[createdAt]', payload.commit.createdAt);
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
formData.append(`files[${file.path}]`, file.stream);
|
|
77
|
+
}
|
|
78
|
+
payload.isMainBranch && formData.append('isMainBranch', 'true');
|
|
79
|
+
const response = await (0, node_fetch_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/pushes`, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: {
|
|
82
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
83
|
+
},
|
|
84
|
+
body: formData,
|
|
85
|
+
agent: (0, openapi_core_1.getProxyAgent)(),
|
|
109
86
|
});
|
|
87
|
+
try {
|
|
88
|
+
return await this.getParsedResponse(response);
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
throw new Error(`Failed to push: ${err.message || 'Unknown error'}`);
|
|
92
|
+
}
|
|
110
93
|
}
|
|
111
|
-
getRemotesList(organizationId, projectId, mountPath) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
if (!response) {
|
|
121
|
-
throw new Error(`Failed to get remotes list.`);
|
|
122
|
-
}
|
|
123
|
-
try {
|
|
124
|
-
return yield this.getParsedResponse(response);
|
|
125
|
-
}
|
|
126
|
-
catch (err) {
|
|
127
|
-
throw new Error(`Failed to get remote list: ${err.message || 'Unknown error'}`);
|
|
128
|
-
}
|
|
94
|
+
async getRemotesList(organizationId, projectId, mountPath) {
|
|
95
|
+
const response = await (0, fetch_with_timeout_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/remotes?filter=mountPath:/${mountPath}/`, {
|
|
96
|
+
method: 'GET',
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': 'application/json',
|
|
99
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
100
|
+
},
|
|
129
101
|
});
|
|
102
|
+
if (!response) {
|
|
103
|
+
throw new Error(`Failed to get remotes list.`);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
return await this.getParsedResponse(response);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
throw new Error(`Failed to get remote list: ${err.message || 'Unknown error'}`);
|
|
110
|
+
}
|
|
130
111
|
}
|
|
131
|
-
getPush({ organizationId, projectId, pushId, }) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
if (!response) {
|
|
141
|
-
throw new Error(`Failed to get push status.`);
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
return yield this.getParsedResponse(response);
|
|
145
|
-
}
|
|
146
|
-
catch (err) {
|
|
147
|
-
throw new Error(`Failed to get push status: ${err.message || 'Unknown error'}`);
|
|
148
|
-
}
|
|
112
|
+
async getPush({ organizationId, projectId, pushId, }) {
|
|
113
|
+
const response = await (0, fetch_with_timeout_1.default)(`${this.domain}/api/orgs/${organizationId}/projects/${projectId}/pushes/${pushId}`, {
|
|
114
|
+
method: 'GET',
|
|
115
|
+
headers: {
|
|
116
|
+
'Content-Type': 'application/json',
|
|
117
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
118
|
+
},
|
|
149
119
|
});
|
|
120
|
+
if (!response) {
|
|
121
|
+
throw new Error(`Failed to get push status.`);
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return await this.getParsedResponse(response);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
throw new Error(`Failed to get push status: ${err.message || 'Unknown error'}`);
|
|
128
|
+
}
|
|
150
129
|
}
|
|
151
130
|
}
|
|
152
131
|
class ReuniteApiClient {
|
package/lib/cms/api/api-keys.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getApiKeys =
|
|
3
|
+
exports.getApiKeys = getApiKeys;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const os_1 = require("os");
|
|
6
6
|
const fs_1 = require("fs");
|
|
@@ -21,4 +21,3 @@ function getApiKeys(domain) {
|
|
|
21
21
|
}
|
|
22
22
|
throw new Error('No api key provided, please use environment variable REDOCLY_AUTHORIZATION.');
|
|
23
23
|
}
|
|
24
|
-
exports.getApiKeys = getApiKeys;
|
package/lib/cms/api/domains.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDomain =
|
|
3
|
+
exports.getDomain = getDomain;
|
|
4
4
|
const DEFAULT_DOMAIN = 'https://app.cloud.redocly.com';
|
|
5
5
|
function getDomain() {
|
|
6
6
|
const domain = process.env.REDOCLY_DOMAIN;
|
|
@@ -9,4 +9,3 @@ function getDomain() {
|
|
|
9
9
|
}
|
|
10
10
|
return DEFAULT_DOMAIN;
|
|
11
11
|
}
|
|
12
|
-
exports.getDomain = getDomain;
|