contensis-cli 1.0.0-beta.51 → 1.0.0-beta.52
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/package.json +1 -1
- package/dist/commands/connect.js +0 -44
- package/dist/commands/connect.js.map +0 -7
- package/dist/commands/create.js +0 -75
- package/dist/commands/create.js.map +0 -7
- package/dist/commands/diff.js +0 -57
- package/dist/commands/diff.js.map +0 -7
- package/dist/commands/get.js +0 -170
- package/dist/commands/get.js.map +0 -7
- package/dist/commands/globalOptions.js +0 -144
- package/dist/commands/globalOptions.js.map +0 -7
- package/dist/commands/import.js +0 -121
- package/dist/commands/import.js.map +0 -7
- package/dist/commands/index.js +0 -89
- package/dist/commands/index.js.map +0 -7
- package/dist/commands/list.js +0 -99
- package/dist/commands/list.js.map +0 -7
- package/dist/commands/login.js +0 -56
- package/dist/commands/login.js.map +0 -7
- package/dist/commands/push.js +0 -137
- package/dist/commands/push.js.map +0 -7
- package/dist/commands/release.js +0 -47
- package/dist/commands/release.js.map +0 -7
- package/dist/commands/remove.js +0 -79
- package/dist/commands/remove.js.map +0 -7
- package/dist/commands/set.js +0 -96
- package/dist/commands/set.js.map +0 -7
- package/dist/index.js +0 -32
- package/dist/index.js.map +0 -7
- package/dist/localisation/en-GB.js +0 -253
- package/dist/localisation/en-GB.js.map +0 -7
- package/dist/models/AppError.d.js +0 -2
- package/dist/models/AppError.d.js.map +0 -7
- package/dist/models/Cache.d.js +0 -2
- package/dist/models/Cache.d.js.map +0 -7
- package/dist/models/JsModules.d.js +0 -2
- package/dist/models/JsModules.d.js.map +0 -7
- package/dist/providers/CredentialProvider.js +0 -116
- package/dist/providers/CredentialProvider.js.map +0 -7
- package/dist/providers/SessionCacheProvider.js +0 -111
- package/dist/providers/SessionCacheProvider.js.map +0 -7
- package/dist/providers/file-provider.js +0 -117
- package/dist/providers/file-provider.js.map +0 -7
- package/dist/services/ContensisAuthService.js +0 -75
- package/dist/services/ContensisAuthService.js.map +0 -7
- package/dist/services/ContensisCliService.js +0 -1374
- package/dist/services/ContensisCliService.js.map +0 -7
- package/dist/shell.js +0 -278
- package/dist/shell.js.map +0 -7
- package/dist/util/console.printer.js +0 -317
- package/dist/util/console.printer.js.map +0 -7
- package/dist/util/csv.formatter.js +0 -50
- package/dist/util/csv.formatter.js.map +0 -7
- package/dist/util/index.js +0 -97
- package/dist/util/index.js.map +0 -7
- package/dist/util/json.formatter.js +0 -29
- package/dist/util/json.formatter.js.map +0 -7
- package/dist/util/logger.js +0 -216
- package/dist/util/logger.js.map +0 -7
- package/dist/util/xml.formatter.js +0 -51
- package/dist/util/xml.formatter.js.map +0 -7
- package/dist/version.js +0 -29
- package/dist/version.js.map +0 -7
|
@@ -1,1374 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to2, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to2, key) && key !== except)
|
|
16
|
-
__defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to2;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
var ContensisCliService_exports = {};
|
|
26
|
-
__export(ContensisCliService_exports, {
|
|
27
|
-
cliCommand: () => cliCommand,
|
|
28
|
-
default: () => ContensisCliService_default
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(ContensisCliService_exports);
|
|
31
|
-
var import_fs = __toESM(require("fs"));
|
|
32
|
-
var import_path = __toESM(require("path"));
|
|
33
|
-
var import_node_fetch = __toESM(require("node-fetch"));
|
|
34
|
-
var import_inquirer = __toESM(require("inquirer"));
|
|
35
|
-
var import_await_to_js = __toESM(require("await-to-js"));
|
|
36
|
-
var import_chalk = __toESM(require("chalk"));
|
|
37
|
-
var import_util = require("../util");
|
|
38
|
-
var import_SessionCacheProvider = __toESM(require("../providers/SessionCacheProvider"));
|
|
39
|
-
var import_ContensisAuthService = __toESM(require("./ContensisAuthService"));
|
|
40
|
-
var import_CredentialProvider = __toESM(require("../providers/CredentialProvider"));
|
|
41
|
-
var import_logger = require("../util/logger");
|
|
42
|
-
var import_en_GB = require("../localisation/en-GB");
|
|
43
|
-
var import_migratortron = require("migratortron");
|
|
44
|
-
var import_csv = require("../util/csv.formatter");
|
|
45
|
-
var import_xml = require("../util/xml.formatter");
|
|
46
|
-
var import_json = require("../util/json.formatter");
|
|
47
|
-
var import_console = require("../util/console.printer");
|
|
48
|
-
var import_file_provider = require("../providers/file-provider");
|
|
49
|
-
let insecurePasswordWarningShown = false;
|
|
50
|
-
class ContensisCli {
|
|
51
|
-
static quit = (error) => {
|
|
52
|
-
process.removeAllListeners("exit");
|
|
53
|
-
const exitCode = error ? 1 : 0;
|
|
54
|
-
process.exit(exitCode);
|
|
55
|
-
};
|
|
56
|
-
command;
|
|
57
|
-
format;
|
|
58
|
-
output;
|
|
59
|
-
session;
|
|
60
|
-
contensis;
|
|
61
|
-
contensisOpts;
|
|
62
|
-
currentProject;
|
|
63
|
-
sourceAlias;
|
|
64
|
-
targetEnv;
|
|
65
|
-
urls;
|
|
66
|
-
log = import_logger.Logger;
|
|
67
|
-
messages = import_en_GB.LogMessages;
|
|
68
|
-
verb;
|
|
69
|
-
noun;
|
|
70
|
-
thirdArg;
|
|
71
|
-
get cache() {
|
|
72
|
-
return this.session.Get();
|
|
73
|
-
}
|
|
74
|
-
get currentEnv() {
|
|
75
|
-
return this.cache.currentEnvironment || "";
|
|
76
|
-
}
|
|
77
|
-
set currentEnv(currentEnvironment) {
|
|
78
|
-
this.session.Update({ currentEnvironment });
|
|
79
|
-
}
|
|
80
|
-
get env() {
|
|
81
|
-
const currentEnvironment = this.currentEnv;
|
|
82
|
-
const environments = this.cache.environments || {};
|
|
83
|
-
if (!currentEnvironment)
|
|
84
|
-
return {};
|
|
85
|
-
else if (!!environments[currentEnvironment])
|
|
86
|
-
return environments[currentEnvironment];
|
|
87
|
-
else {
|
|
88
|
-
return {
|
|
89
|
-
history: [],
|
|
90
|
-
lastUserId: "",
|
|
91
|
-
projects: [],
|
|
92
|
-
versionStatus: "latest"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
get contentTypes() {
|
|
97
|
-
var _a;
|
|
98
|
-
return (_a = this.contensis) == null ? void 0 : _a.models.contentTypes();
|
|
99
|
-
}
|
|
100
|
-
get components() {
|
|
101
|
-
var _a;
|
|
102
|
-
return (_a = this.contensis) == null ? void 0 : _a.models.components();
|
|
103
|
-
}
|
|
104
|
-
get models() {
|
|
105
|
-
var _a;
|
|
106
|
-
return (_a = this.contensis) == null ? void 0 : _a.models.contentModels();
|
|
107
|
-
}
|
|
108
|
-
constructor(args, outputOpts, contensisOpts = {}) {
|
|
109
|
-
const [exe, script, verb = "", noun = "", ...restArgs] = args;
|
|
110
|
-
this.verb = verb == null ? void 0 : verb.toLowerCase();
|
|
111
|
-
this.noun = noun == null ? void 0 : noun.toLowerCase();
|
|
112
|
-
this.thirdArg = restArgs == null ? void 0 : restArgs[0];
|
|
113
|
-
const commandText = `${this.verb} ${this.noun} ${restArgs ? restArgs.join(" ") : ""}`.trim();
|
|
114
|
-
this.session = new import_SessionCacheProvider.default();
|
|
115
|
-
this.contensisOpts = contensisOpts;
|
|
116
|
-
this.format = outputOpts == null ? void 0 : outputOpts.format;
|
|
117
|
-
this.output = (outputOpts == null ? void 0 : outputOpts.output) && import_path.default.join(process.cwd(), outputOpts.output);
|
|
118
|
-
const currentEnvironment = (outputOpts == null ? void 0 : outputOpts.alias) || this.currentEnv;
|
|
119
|
-
const environments = this.cache.environments || {};
|
|
120
|
-
this.currentEnv = currentEnvironment;
|
|
121
|
-
const env = this.env;
|
|
122
|
-
if (outputOpts == null ? void 0 : outputOpts.projectId)
|
|
123
|
-
env.currentProject = outputOpts.projectId;
|
|
124
|
-
if (outputOpts == null ? void 0 : outputOpts.user)
|
|
125
|
-
env.lastUserId = outputOpts.user;
|
|
126
|
-
if (outputOpts == null ? void 0 : outputOpts.password)
|
|
127
|
-
env.passwordFallback = outputOpts.password;
|
|
128
|
-
if (outputOpts == null ? void 0 : outputOpts.clientId)
|
|
129
|
-
env.lastUserId = outputOpts.clientId;
|
|
130
|
-
if (outputOpts == null ? void 0 : outputOpts.sharedSecret)
|
|
131
|
-
env.passwordFallback = outputOpts.sharedSecret;
|
|
132
|
-
this.currentProject = (env == null ? void 0 : env.currentProject) || "null";
|
|
133
|
-
this.sourceAlias = (outputOpts == null ? void 0 : outputOpts.sourceAlias) || currentEnvironment;
|
|
134
|
-
if (currentEnvironment) {
|
|
135
|
-
this.urls = (0, import_util.url)(currentEnvironment, (env == null ? void 0 : env.currentProject) || "website");
|
|
136
|
-
}
|
|
137
|
-
this.command = {
|
|
138
|
-
commandText,
|
|
139
|
-
createdDate: new Date().toISOString(),
|
|
140
|
-
createdUserId: env == null ? void 0 : env.lastUserId
|
|
141
|
-
};
|
|
142
|
-
if (currentEnvironment) {
|
|
143
|
-
env.history = [this.command];
|
|
144
|
-
if (commandText) {
|
|
145
|
-
environments[currentEnvironment] = env;
|
|
146
|
-
this.session.Update({
|
|
147
|
-
currentEnvironment,
|
|
148
|
-
environments,
|
|
149
|
-
history: [commandText]
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
PrintEnvironments = () => {
|
|
155
|
-
const { log, messages } = this;
|
|
156
|
-
const { currentEnvironment, environments = {} } = this.cache;
|
|
157
|
-
const envKeys = Object.keys(environments);
|
|
158
|
-
log.success(messages.envs.found(envKeys.length));
|
|
159
|
-
this.HandleFormattingAndOutput(envKeys, () => {
|
|
160
|
-
for (const env of envKeys) {
|
|
161
|
-
console.log(` - ${currentEnvironment === env ? "* " : ""}${env}`);
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
if (envKeys.length === 0 || !currentEnvironment) {
|
|
165
|
-
log.help(messages.envs.tip());
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
Connect = async (environment) => {
|
|
169
|
-
var _a;
|
|
170
|
-
const { log, messages, session } = this;
|
|
171
|
-
if (environment) {
|
|
172
|
-
this.currentEnv = environment;
|
|
173
|
-
this.urls = (0, import_util.url)(environment, "website");
|
|
174
|
-
const [fetchErr, response] = await (0, import_await_to_js.default)((0, import_node_fetch.default)(this.urls.cms));
|
|
175
|
-
if (response && (response == null ? void 0 : response.status) < 400) {
|
|
176
|
-
log.success(messages.connect.connected(environment));
|
|
177
|
-
session.UpdateEnv(this.env, environment);
|
|
178
|
-
if ((_a = this.env) == null ? void 0 : _a.lastUserId) {
|
|
179
|
-
await this.PrintProjects();
|
|
180
|
-
} else {
|
|
181
|
-
log.warning(messages.projects.noList());
|
|
182
|
-
log.help(messages.connect.tip());
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
log.error(
|
|
186
|
-
messages.connect.unreachable(this.urls.cms, (response == null ? void 0 : response.status) || 0)
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
} else {
|
|
190
|
-
log.error(messages.connect.noEnv());
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
ConnectContensis = async ({ commit = false } = {}) => {
|
|
194
|
-
var _a, _b, _c;
|
|
195
|
-
if (!this.contensis) {
|
|
196
|
-
const { contensisOpts, currentEnv, env, log, messages } = this;
|
|
197
|
-
const userId = env == null ? void 0 : env.lastUserId;
|
|
198
|
-
const isGuidId = userId && (0, import_util.isUuid)(userId);
|
|
199
|
-
if (currentEnv && userId) {
|
|
200
|
-
const credentials = await this.GetCredentials(
|
|
201
|
-
userId,
|
|
202
|
-
env.passwordFallback
|
|
203
|
-
);
|
|
204
|
-
const cachedPassword = (_a = credentials == null ? void 0 : credentials.current) == null ? void 0 : _a.password;
|
|
205
|
-
if (cachedPassword) {
|
|
206
|
-
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
207
|
-
{
|
|
208
|
-
...contensisOpts,
|
|
209
|
-
source: {
|
|
210
|
-
url: ((_b = this.urls) == null ? void 0 : _b.cms) || "",
|
|
211
|
-
username: !isGuidId ? userId : void 0,
|
|
212
|
-
password: !isGuidId ? cachedPassword : void 0,
|
|
213
|
-
clientId: isGuidId ? userId : void 0,
|
|
214
|
-
sharedSecret: isGuidId ? cachedPassword : void 0,
|
|
215
|
-
project: (env == null ? void 0 : env.currentProject) || "",
|
|
216
|
-
assetHostname: (_c = this.urls) == null ? void 0 : _c.previewWeb
|
|
217
|
-
},
|
|
218
|
-
concurrency: typeof contensisOpts.concurrency !== "undefined" ? contensisOpts.concurrency : 3,
|
|
219
|
-
outputProgress: true
|
|
220
|
-
},
|
|
221
|
-
!commit
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
} else {
|
|
225
|
-
if (!currentEnv)
|
|
226
|
-
log.help(messages.connect.help());
|
|
227
|
-
if (!userId)
|
|
228
|
-
log.help(messages.connect.tip());
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return this.contensis;
|
|
232
|
-
};
|
|
233
|
-
ConnectContensisImport = async ({
|
|
234
|
-
commit = false,
|
|
235
|
-
fromFile,
|
|
236
|
-
importDataType
|
|
237
|
-
}) => {
|
|
238
|
-
var _a, _b, _c, _d, _e, _f;
|
|
239
|
-
const source = fromFile ? "file" : "contensis";
|
|
240
|
-
const fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
241
|
-
if (typeof fileData === "string")
|
|
242
|
-
throw new Error(`Import file format must be of type JSON`);
|
|
243
|
-
const { contensisOpts, currentEnv, env, log, messages, sourceAlias } = this;
|
|
244
|
-
const environments = this.cache.environments || {};
|
|
245
|
-
const sourceEnvironment = environments[sourceAlias || ""] || {};
|
|
246
|
-
const sourceCms = "source" in contensisOpts && contensisOpts.source || {};
|
|
247
|
-
const sourceUserId = sourceCms.clientId || sourceCms.username || sourceEnvironment.lastUserId;
|
|
248
|
-
const sourceProjectId = sourceCms.project || sourceEnvironment.currentProject || "website";
|
|
249
|
-
const isSourceGuidId = sourceUserId && (0, import_util.isUuid)(sourceUserId);
|
|
250
|
-
const sourceUrls = (0, import_util.url)(sourceAlias || "", sourceProjectId);
|
|
251
|
-
const sourcePassword = sourceCms.sharedSecret || sourceCms.password || sourceEnvironment.passwordFallback;
|
|
252
|
-
const targetUserId = env == null ? void 0 : env.lastUserId;
|
|
253
|
-
const isTargetGuidId = targetUserId && (0, import_util.isUuid)(targetUserId);
|
|
254
|
-
if (sourceUserId && currentEnv && targetUserId) {
|
|
255
|
-
const sourceCredentials = await this.GetCredentials(
|
|
256
|
-
sourceUserId,
|
|
257
|
-
sourcePassword,
|
|
258
|
-
sourceAlias,
|
|
259
|
-
false
|
|
260
|
-
);
|
|
261
|
-
const cachedSourcePassword = (_a = sourceCredentials == null ? void 0 : sourceCredentials.current) == null ? void 0 : _a.password;
|
|
262
|
-
const targetCredentials = await this.GetCredentials(
|
|
263
|
-
targetUserId,
|
|
264
|
-
env.passwordFallback
|
|
265
|
-
);
|
|
266
|
-
const cachedTargetPassword = (_b = targetCredentials == null ? void 0 : targetCredentials.current) == null ? void 0 : _b.password;
|
|
267
|
-
if (cachedSourcePassword && cachedTargetPassword) {
|
|
268
|
-
if (source === "file" || importDataType === "user-input") {
|
|
269
|
-
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
270
|
-
{
|
|
271
|
-
concurrency: 3,
|
|
272
|
-
outputProgress: true,
|
|
273
|
-
...contensisOpts,
|
|
274
|
-
target: {
|
|
275
|
-
url: ((_c = this.urls) == null ? void 0 : _c.cms) || "",
|
|
276
|
-
username: !isTargetGuidId ? targetUserId : void 0,
|
|
277
|
-
password: !isTargetGuidId ? cachedTargetPassword : void 0,
|
|
278
|
-
clientId: isTargetGuidId ? targetUserId : void 0,
|
|
279
|
-
sharedSecret: isTargetGuidId ? cachedTargetPassword : void 0,
|
|
280
|
-
targetProjects: [env.currentProject || ""],
|
|
281
|
-
assetHostname: (_d = this.urls) == null ? void 0 : _d.previewWeb
|
|
282
|
-
},
|
|
283
|
-
...importDataType ? { [importDataType]: fileData } : {}
|
|
284
|
-
},
|
|
285
|
-
!commit
|
|
286
|
-
);
|
|
287
|
-
} else if (source === "contensis") {
|
|
288
|
-
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
289
|
-
{
|
|
290
|
-
concurrency: 3,
|
|
291
|
-
outputProgress: true,
|
|
292
|
-
...contensisOpts,
|
|
293
|
-
source: {
|
|
294
|
-
url: sourceUrls.cms || "",
|
|
295
|
-
username: !isSourceGuidId ? sourceUserId : void 0,
|
|
296
|
-
password: !isSourceGuidId ? cachedSourcePassword : void 0,
|
|
297
|
-
clientId: isSourceGuidId ? sourceUserId : void 0,
|
|
298
|
-
sharedSecret: isSourceGuidId ? cachedSourcePassword : void 0,
|
|
299
|
-
project: sourceProjectId,
|
|
300
|
-
assetHostname: sourceUrls.previewWeb
|
|
301
|
-
},
|
|
302
|
-
target: {
|
|
303
|
-
url: ((_e = this.urls) == null ? void 0 : _e.cms) || "",
|
|
304
|
-
username: !isTargetGuidId ? targetUserId : void 0,
|
|
305
|
-
password: !isTargetGuidId ? cachedTargetPassword : void 0,
|
|
306
|
-
clientId: isTargetGuidId ? targetUserId : void 0,
|
|
307
|
-
sharedSecret: isTargetGuidId ? cachedTargetPassword : void 0,
|
|
308
|
-
targetProjects: [env.currentProject || ""],
|
|
309
|
-
assetHostname: (_f = this.urls) == null ? void 0 : _f.previewWeb
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
!commit
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
} else {
|
|
317
|
-
if (!currentEnv)
|
|
318
|
-
log.help(messages.connect.help());
|
|
319
|
-
if (!targetUserId)
|
|
320
|
-
log.help(messages.connect.tip());
|
|
321
|
-
}
|
|
322
|
-
return this.contensis;
|
|
323
|
-
};
|
|
324
|
-
GetCredentials = async (userId, password, currentEnv = this.currentEnv, saveCurrentEnv = true) => {
|
|
325
|
-
const { log, messages } = this;
|
|
326
|
-
if (userId) {
|
|
327
|
-
const [credentialError, credentials] = await new import_CredentialProvider.default(
|
|
328
|
-
{ userId, alias: currentEnv },
|
|
329
|
-
password
|
|
330
|
-
).Init();
|
|
331
|
-
if (credentialError && !credentials.current) {
|
|
332
|
-
log.error(credentialError);
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
if (credentials.remarks.secure !== true) {
|
|
336
|
-
if (!insecurePasswordWarningShown) {
|
|
337
|
-
log.warning(messages.login.insecurePassword());
|
|
338
|
-
insecurePasswordWarningShown = true;
|
|
339
|
-
}
|
|
340
|
-
} else {
|
|
341
|
-
const env = this.cache.environments[currentEnv];
|
|
342
|
-
env.passwordFallback = void 0;
|
|
343
|
-
this.session.UpdateEnv(env, currentEnv, saveCurrentEnv);
|
|
344
|
-
}
|
|
345
|
-
return credentials;
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
Login = async (userId, {
|
|
349
|
-
password = (0, import_util.isPassword)(this.env.passwordFallback),
|
|
350
|
-
promptPassword = true,
|
|
351
|
-
sharedSecret = (0, import_util.isSharedSecret)(this.env.passwordFallback),
|
|
352
|
-
silent = false,
|
|
353
|
-
attempt = 1
|
|
354
|
-
} = {}) => {
|
|
355
|
-
var _a, _b, _c, _d;
|
|
356
|
-
let inputPassword = password || sharedSecret;
|
|
357
|
-
const { log, messages } = this;
|
|
358
|
-
if (userId) {
|
|
359
|
-
const { currentEnv, env } = this;
|
|
360
|
-
if (currentEnv) {
|
|
361
|
-
const credentials = await this.GetCredentials(userId, inputPassword);
|
|
362
|
-
if (credentials) {
|
|
363
|
-
const cachedPassword = (0, import_util.isPassword)((_a = credentials.current) == null ? void 0 : _a.password);
|
|
364
|
-
const cachedSecret = (0, import_util.isSharedSecret)((_b = credentials.current) == null ? void 0 : _b.password);
|
|
365
|
-
if (!cachedPassword && !cachedSecret && promptPassword) {
|
|
366
|
-
({ inputPassword } = await import_inquirer.default.prompt([
|
|
367
|
-
{
|
|
368
|
-
type: "password",
|
|
369
|
-
message: messages.login.passwordPrompt(currentEnv, userId),
|
|
370
|
-
name: "inputPassword",
|
|
371
|
-
mask: "*",
|
|
372
|
-
prefix: void 0
|
|
373
|
-
}
|
|
374
|
-
]));
|
|
375
|
-
}
|
|
376
|
-
if (inputPassword || cachedPassword || cachedSecret) {
|
|
377
|
-
const authService = new import_ContensisAuthService.default({
|
|
378
|
-
username: userId,
|
|
379
|
-
password: inputPassword || cachedPassword,
|
|
380
|
-
projectId: (env == null ? void 0 : env.currentProject) || "website",
|
|
381
|
-
rootUrl: ((_c = this.urls) == null ? void 0 : _c.cms) || "",
|
|
382
|
-
clientId: userId,
|
|
383
|
-
clientSecret: sharedSecret || cachedSecret
|
|
384
|
-
});
|
|
385
|
-
const [authError, bearerToken] = await (0, import_await_to_js.default)(
|
|
386
|
-
authService.BearerToken()
|
|
387
|
-
);
|
|
388
|
-
if (bearerToken) {
|
|
389
|
-
env.authToken = bearerToken;
|
|
390
|
-
env.lastUserId = userId;
|
|
391
|
-
env.passwordFallback = credentials.remarks.secure !== true ? (_d = credentials.current) == null ? void 0 : _d.password : void 0;
|
|
392
|
-
this.session.UpdateEnv(env);
|
|
393
|
-
if (inputPassword)
|
|
394
|
-
await credentials.Save(inputPassword);
|
|
395
|
-
if (sharedSecret)
|
|
396
|
-
await credentials.Save(sharedSecret);
|
|
397
|
-
if (!silent) {
|
|
398
|
-
import_logger.Logger.success(messages.login.success(currentEnv, userId));
|
|
399
|
-
await this.PrintProjects();
|
|
400
|
-
}
|
|
401
|
-
} else if (authError) {
|
|
402
|
-
import_logger.Logger.error(authError.toString());
|
|
403
|
-
env.authToken = "";
|
|
404
|
-
env.lastUserId = "";
|
|
405
|
-
env.passwordFallback = void 0;
|
|
406
|
-
this.session.UpdateEnv(env);
|
|
407
|
-
if ((cachedPassword || cachedSecret) && credentials.remarks.secure) {
|
|
408
|
-
await credentials.Delete();
|
|
409
|
-
return await this.Login(userId, { password, sharedSecret });
|
|
410
|
-
} else {
|
|
411
|
-
throw new Error(messages.login.failed(currentEnv, userId));
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return env.authToken;
|
|
415
|
-
} else {
|
|
416
|
-
import_logger.Logger.error(messages.login.passwordPrompt());
|
|
417
|
-
if (attempt < 2)
|
|
418
|
-
return await this.Login(userId, { attempt: attempt + 1 });
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
} else {
|
|
422
|
-
import_logger.Logger.error(messages.login.noEnv());
|
|
423
|
-
}
|
|
424
|
-
} else {
|
|
425
|
-
import_logger.Logger.error(messages.login.noUserId());
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
PrintContensisVersion = async () => {
|
|
429
|
-
const { log, messages } = this;
|
|
430
|
-
const contensis = await this.ConnectContensis();
|
|
431
|
-
if (contensis) {
|
|
432
|
-
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
433
|
-
contensis.projects.GetSourceProjects()
|
|
434
|
-
);
|
|
435
|
-
if (Array.isArray(projects)) {
|
|
436
|
-
this.HandleFormattingAndOutput(
|
|
437
|
-
contensis.contensisVersion,
|
|
438
|
-
() => log.raw(log.highlightText(contensis.contensisVersion))
|
|
439
|
-
);
|
|
440
|
-
}
|
|
441
|
-
if (projectsErr) {
|
|
442
|
-
log.error(messages.projects.noList());
|
|
443
|
-
log.error(projectsErr.message);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
PrintProjects = async () => {
|
|
448
|
-
const { currentProject, log, messages, session } = this;
|
|
449
|
-
const contensis = await this.ConnectContensis();
|
|
450
|
-
if (contensis) {
|
|
451
|
-
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
452
|
-
contensis.projects.GetSourceProjects()
|
|
453
|
-
);
|
|
454
|
-
if (Array.isArray(projects)) {
|
|
455
|
-
const nextCurrentProject = currentProject && currentProject !== "null" ? currentProject : projects.some((p) => p.id === "website") ? "website" : void 0;
|
|
456
|
-
session.UpdateEnv({
|
|
457
|
-
projects: projects.map((p) => p.id),
|
|
458
|
-
currentProject: nextCurrentProject
|
|
459
|
-
});
|
|
460
|
-
log.success(messages.projects.list());
|
|
461
|
-
log.raw("");
|
|
462
|
-
this.HandleFormattingAndOutput(projects, () => {
|
|
463
|
-
for (const project of projects.sort(
|
|
464
|
-
(a, b) => a.id.localeCompare(b.id)
|
|
465
|
-
)) {
|
|
466
|
-
let color;
|
|
467
|
-
try {
|
|
468
|
-
color = import_chalk.default.keyword(project.color);
|
|
469
|
-
} catch (ex) {
|
|
470
|
-
color = import_chalk.default.white;
|
|
471
|
-
}
|
|
472
|
-
console.log(
|
|
473
|
-
`${nextCurrentProject === project.id ? `>> ${log.boldText(color(project.id))}` : ` ${color(project.id)}`} ${log.infoText(
|
|
474
|
-
`[${project.supportedLanguages.map(
|
|
475
|
-
(l) => l === project.primaryLanguage ? `*${log.boldText(l)}` : l
|
|
476
|
-
).join(" ")}]`
|
|
477
|
-
)}`
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
if (!this.SetProject(nextCurrentProject))
|
|
482
|
-
log.warning(messages.projects.tip());
|
|
483
|
-
}
|
|
484
|
-
if (projectsErr) {
|
|
485
|
-
log.error(messages.projects.noList());
|
|
486
|
-
log.error(projectsErr.message);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
PrintProject = async (projectId = this.currentProject) => {
|
|
491
|
-
const { log, messages, session } = this;
|
|
492
|
-
const contensis = await this.ConnectContensis();
|
|
493
|
-
if (contensis) {
|
|
494
|
-
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
495
|
-
contensis.projects.GetSourceProjects()
|
|
496
|
-
);
|
|
497
|
-
const foundProject = projects == null ? void 0 : projects.find(
|
|
498
|
-
(p) => p.id.toLowerCase() === projectId.toLowerCase()
|
|
499
|
-
);
|
|
500
|
-
if (foundProject) {
|
|
501
|
-
log.raw("");
|
|
502
|
-
this.HandleFormattingAndOutput(foundProject, log.object);
|
|
503
|
-
}
|
|
504
|
-
if (projectsErr) {
|
|
505
|
-
log.error(messages.projects.noList());
|
|
506
|
-
log.error(projectsErr.message);
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
SetProject = (projectId = "website") => {
|
|
511
|
-
const { env, log, messages, session } = this;
|
|
512
|
-
let nextProjectId;
|
|
513
|
-
if ((env == null ? void 0 : env.projects.length) > 0 && (env == null ? void 0 : env.lastUserId)) {
|
|
514
|
-
nextProjectId = env.projects.find(
|
|
515
|
-
(p) => p.toLowerCase() === projectId.toLowerCase()
|
|
516
|
-
);
|
|
517
|
-
if (nextProjectId) {
|
|
518
|
-
env.currentProject = nextProjectId;
|
|
519
|
-
session.UpdateEnv(env);
|
|
520
|
-
log.success(messages.projects.set(projectId));
|
|
521
|
-
log.raw("");
|
|
522
|
-
} else {
|
|
523
|
-
log.error(messages.projects.failedSet(projectId));
|
|
524
|
-
}
|
|
525
|
-
} else {
|
|
526
|
-
log.warning(messages.projects.noList());
|
|
527
|
-
log.help(messages.connect.tip());
|
|
528
|
-
}
|
|
529
|
-
return nextProjectId;
|
|
530
|
-
};
|
|
531
|
-
SetVersion = (versionStatus) => {
|
|
532
|
-
const { env, log, messages, session } = this;
|
|
533
|
-
if (!["latest", "published"].includes(versionStatus)) {
|
|
534
|
-
log.error(messages.version.invalid(versionStatus));
|
|
535
|
-
return false;
|
|
536
|
-
}
|
|
537
|
-
if (!env) {
|
|
538
|
-
log.help(messages.version.noEnv());
|
|
539
|
-
return false;
|
|
540
|
-
}
|
|
541
|
-
if ((env == null ? void 0 : env.projects.length) > 0 && (env == null ? void 0 : env.lastUserId)) {
|
|
542
|
-
session.UpdateEnv({ versionStatus });
|
|
543
|
-
log.success(messages.version.set(this.currentEnv, versionStatus));
|
|
544
|
-
return true;
|
|
545
|
-
} else {
|
|
546
|
-
log.warning(messages.projects.noList());
|
|
547
|
-
log.help(messages.connect.tip());
|
|
548
|
-
return false;
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
HydrateContensis = async () => {
|
|
552
|
-
const { log } = this;
|
|
553
|
-
const contensis = await this.ConnectContensis();
|
|
554
|
-
if (contensis) {
|
|
555
|
-
const [contensisErr, models] = await (0, import_await_to_js.default)(
|
|
556
|
-
contensis.models.HydrateContensisRepositories()
|
|
557
|
-
);
|
|
558
|
-
if (contensisErr) {
|
|
559
|
-
log.error(contensisErr.message);
|
|
560
|
-
return contensisErr;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
PrintApiKeys = async () => {
|
|
565
|
-
const { currentEnv, log, messages } = this;
|
|
566
|
-
const contensis = await this.ConnectContensis();
|
|
567
|
-
if (contensis) {
|
|
568
|
-
const [keysErr, apiKeys] = await contensis.apiKeys.GetKeys();
|
|
569
|
-
if (Array.isArray(apiKeys)) {
|
|
570
|
-
log.success(messages.keys.list(currentEnv));
|
|
571
|
-
this.HandleFormattingAndOutput(apiKeys, () => {
|
|
572
|
-
for (const {
|
|
573
|
-
id,
|
|
574
|
-
sharedSecret,
|
|
575
|
-
name,
|
|
576
|
-
description,
|
|
577
|
-
dateModified,
|
|
578
|
-
modifiedBy
|
|
579
|
-
} of apiKeys) {
|
|
580
|
-
console.log(
|
|
581
|
-
` - ${name}${description ? ` (${description})` : ""} [${dateModified.toString().substring(0, 10)} ${modifiedBy}]`
|
|
582
|
-
);
|
|
583
|
-
console.log(` ${id}`);
|
|
584
|
-
console.log(` ${sharedSecret}`);
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
if (keysErr) {
|
|
589
|
-
log.error(messages.keys.noList(currentEnv));
|
|
590
|
-
log.error((0, import_json.jsonFormatter)(keysErr));
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
CreateApiKey = async (name, description) => {
|
|
595
|
-
const { currentEnv, log, messages } = this;
|
|
596
|
-
const contensis = await this.ConnectContensis();
|
|
597
|
-
if (contensis) {
|
|
598
|
-
const [err, key] = await contensis.apiKeys.CreateKey(name, description);
|
|
599
|
-
if (key) {
|
|
600
|
-
log.success(messages.keys.created(currentEnv, name));
|
|
601
|
-
console.log(
|
|
602
|
-
` - ${key.name}${key.description ? ` (${key.description})` : ""} [${key.dateModified.toString().substring(0, 10)} ${key.modifiedBy}]`
|
|
603
|
-
);
|
|
604
|
-
console.log(` - id: ${key.id}`);
|
|
605
|
-
console.log(` - sharedSecret: ${key.sharedSecret}`);
|
|
606
|
-
}
|
|
607
|
-
console.log("");
|
|
608
|
-
if (err) {
|
|
609
|
-
log.error(messages.keys.failedCreate(currentEnv, name), err);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
RemoveApiKey = async (id) => {
|
|
614
|
-
const { currentEnv, log, messages } = this;
|
|
615
|
-
const contensis = await this.ConnectContensis({ commit: true });
|
|
616
|
-
if (contensis) {
|
|
617
|
-
const [err, key] = await contensis.apiKeys.RemoveKey(id);
|
|
618
|
-
if (!err) {
|
|
619
|
-
log.success(messages.keys.removed(currentEnv, id));
|
|
620
|
-
console.log("");
|
|
621
|
-
} else {
|
|
622
|
-
log.error(messages.keys.failedRemove(currentEnv, id), err);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
CreateProject = async (project) => {
|
|
627
|
-
const { currentEnv, log, messages } = this;
|
|
628
|
-
const contensis = await this.ConnectContensis();
|
|
629
|
-
if (contensis) {
|
|
630
|
-
const [err, created] = await contensis.projects.CreateProject(project);
|
|
631
|
-
if (created) {
|
|
632
|
-
log.success(messages.projects.created(currentEnv, project.id));
|
|
633
|
-
this.HandleFormattingAndOutput(created, () => {
|
|
634
|
-
this.SetProject(project.id);
|
|
635
|
-
this.PrintProjects();
|
|
636
|
-
});
|
|
637
|
-
return project.id;
|
|
638
|
-
}
|
|
639
|
-
if (err) {
|
|
640
|
-
log.error(messages.projects.failedCreate(currentEnv, project.id), err);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
};
|
|
644
|
-
UpdateProject = async (project) => {
|
|
645
|
-
const { currentEnv, currentProject, log, messages } = this;
|
|
646
|
-
const contensis = await this.ConnectContensis();
|
|
647
|
-
if (contensis) {
|
|
648
|
-
const [err, updated] = await contensis.projects.UpdateProject({
|
|
649
|
-
id: currentProject,
|
|
650
|
-
...project
|
|
651
|
-
});
|
|
652
|
-
if (updated) {
|
|
653
|
-
log.success(messages.projects.updated(currentEnv, currentProject));
|
|
654
|
-
this.HandleFormattingAndOutput(updated, log.object);
|
|
655
|
-
return updated.id;
|
|
656
|
-
}
|
|
657
|
-
if (err) {
|
|
658
|
-
log.error(
|
|
659
|
-
messages.projects.failedUpdate(currentEnv, currentProject),
|
|
660
|
-
err
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
};
|
|
665
|
-
GetContentTypes = async () => {
|
|
666
|
-
const { currentProject, log, messages } = this;
|
|
667
|
-
let err;
|
|
668
|
-
if (!this.contensis)
|
|
669
|
-
err = await this.HydrateContensis();
|
|
670
|
-
if (err)
|
|
671
|
-
log.error(messages.models.noList(currentProject));
|
|
672
|
-
if (!this.contensis)
|
|
673
|
-
log.warning(messages.models.noList(currentProject));
|
|
674
|
-
return this.contensis;
|
|
675
|
-
};
|
|
676
|
-
PrintContentModels = async (modelIds = []) => {
|
|
677
|
-
const { currentProject, log, messages } = this;
|
|
678
|
-
const contensis = await this.GetContentTypes();
|
|
679
|
-
if (contensis) {
|
|
680
|
-
const { models, contentTypes = [], components = [] } = this;
|
|
681
|
-
const returnModels = (modelIds == null ? void 0 : modelIds.length) ? models == null ? void 0 : models.filter(
|
|
682
|
-
(m) => modelIds.some((id) => id.toLowerCase() === m.id.toLowerCase())
|
|
683
|
-
) : void 0;
|
|
684
|
-
const contentTypeIds = Array.from(
|
|
685
|
-
/* @__PURE__ */ new Set([
|
|
686
|
-
...(returnModels || models || []).map((m) => m.id),
|
|
687
|
-
...(returnModels || models || []).map((m) => {
|
|
688
|
-
var _a, _b;
|
|
689
|
-
return ((_b = (_a = m.dependencies) == null ? void 0 : _a.contentTypes) == null ? void 0 : _b.map((c) => c[0])) || [];
|
|
690
|
-
}).flat()
|
|
691
|
-
])
|
|
692
|
-
);
|
|
693
|
-
const componentIds = Array.from(
|
|
694
|
-
new Set(
|
|
695
|
-
(returnModels || models || []).map((m) => {
|
|
696
|
-
var _a, _b;
|
|
697
|
-
return ((_b = (_a = m.dependencies) == null ? void 0 : _a.components) == null ? void 0 : _b.map((c) => c[0])) || [];
|
|
698
|
-
}).flat()
|
|
699
|
-
)
|
|
700
|
-
);
|
|
701
|
-
const contentModelBackup = [
|
|
702
|
-
...contentTypes.filter((c) => contentTypeIds.includes(c.id)),
|
|
703
|
-
...components.filter((c) => componentIds.includes(c.id))
|
|
704
|
-
];
|
|
705
|
-
if (Array.isArray(returnModels)) {
|
|
706
|
-
log.success(messages.models.list(currentProject));
|
|
707
|
-
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
708
|
-
for (const model of returnModels) {
|
|
709
|
-
log.raw("");
|
|
710
|
-
log.object(model);
|
|
711
|
-
}
|
|
712
|
-
log.raw("");
|
|
713
|
-
});
|
|
714
|
-
} else {
|
|
715
|
-
log.success(
|
|
716
|
-
messages.models.get(currentProject, (models == null ? void 0 : models.length.toString()) || "0")
|
|
717
|
-
);
|
|
718
|
-
log.raw("");
|
|
719
|
-
if (models == null ? void 0 : models.length) {
|
|
720
|
-
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
721
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
722
|
-
for (const model of models) {
|
|
723
|
-
const components2 = ((_a = model.components) == null ? void 0 : _a.length) || 0;
|
|
724
|
-
const contentTypes2 = ((_b = model.contentTypes) == null ? void 0 : _b.length) || 0;
|
|
725
|
-
const dependencies = (((_d = (_c = model.dependencies) == null ? void 0 : _c.components) == null ? void 0 : _d.length) || 0) + (((_f = (_e = model.dependencies) == null ? void 0 : _e.contentTypes) == null ? void 0 : _f.length) || 0);
|
|
726
|
-
const dependencyOf = (((_h = (_g = model.dependencyOf) == null ? void 0 : _g.components) == null ? void 0 : _h.length) || 0) + (((_j = (_i = model.dependencyOf) == null ? void 0 : _i.contentTypes) == null ? void 0 : _j.length) || 0);
|
|
727
|
-
const hasAny = components2 + contentTypes2 + dependencies + dependencyOf;
|
|
728
|
-
log.raw(
|
|
729
|
-
` - ${log.highlightText(log.boldText(model.id))} ${hasAny ? log.infoText(
|
|
730
|
-
`{ ${components2 ? `components: ${components2}, ` : ""}${contentTypes2 ? `contentTypes: ${contentTypes2}, ` : ""}${dependencies ? `references: ${dependencies}, ` : ""}${dependencyOf ? `required by: ${dependencyOf}` : ""} }`
|
|
731
|
-
) : ""}`
|
|
732
|
-
);
|
|
733
|
-
}
|
|
734
|
-
log.raw("");
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
ImportContentModels = async ({
|
|
741
|
-
commit,
|
|
742
|
-
fromFile
|
|
743
|
-
}) => {
|
|
744
|
-
const { currentProject, log, messages } = this;
|
|
745
|
-
const fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
746
|
-
if (typeof fileData === "string")
|
|
747
|
-
throw new Error(`Import file format must be of type JSON`);
|
|
748
|
-
const contensis = await this.ConnectContensisImport({
|
|
749
|
-
commit,
|
|
750
|
-
fromFile,
|
|
751
|
-
importDataType: "models"
|
|
752
|
-
});
|
|
753
|
-
if (contensis) {
|
|
754
|
-
log.line();
|
|
755
|
-
if (contensis.isPreview) {
|
|
756
|
-
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
757
|
-
} else {
|
|
758
|
-
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
759
|
-
}
|
|
760
|
-
const [migrateErr, result] = await contensis.MigrateContentModels();
|
|
761
|
-
if (migrateErr)
|
|
762
|
-
(0, import_logger.logError)(migrateErr);
|
|
763
|
-
else
|
|
764
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
765
|
-
if (!commit) {
|
|
766
|
-
log.raw(log.boldText(`
|
|
767
|
-
Content types:`));
|
|
768
|
-
if (!result.contentTypes)
|
|
769
|
-
log.info(`- None returned
|
|
770
|
-
`);
|
|
771
|
-
else
|
|
772
|
-
(0, import_console.printModelMigrationAnalysis)(this, result.contentTypes);
|
|
773
|
-
log.raw(log.boldText(`
|
|
774
|
-
Components:`));
|
|
775
|
-
if (!result.components)
|
|
776
|
-
log.info(`- None returned
|
|
777
|
-
`);
|
|
778
|
-
else
|
|
779
|
-
(0, import_console.printModelMigrationAnalysis)(this, result.components);
|
|
780
|
-
} else {
|
|
781
|
-
const migrateResult = result;
|
|
782
|
-
log.raw(log.boldText(`
|
|
783
|
-
Content types:`));
|
|
784
|
-
(0, import_console.printModelMigrationResult)(
|
|
785
|
-
this,
|
|
786
|
-
migrateResult[currentProject].contentTypes
|
|
787
|
-
);
|
|
788
|
-
log.raw(log.boldText(`
|
|
789
|
-
Components:`));
|
|
790
|
-
(0, import_console.printModelMigrationResult)(
|
|
791
|
-
this,
|
|
792
|
-
migrateResult[currentProject].components
|
|
793
|
-
);
|
|
794
|
-
}
|
|
795
|
-
});
|
|
796
|
-
} else {
|
|
797
|
-
log.warning(messages.models.noList(currentProject));
|
|
798
|
-
log.help(messages.connect.tip());
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
PrintContentTypes = async () => {
|
|
802
|
-
const { currentProject, log, messages } = this;
|
|
803
|
-
await this.GetContentTypes();
|
|
804
|
-
if (this.contensis) {
|
|
805
|
-
const { contentTypes } = this;
|
|
806
|
-
if (Array.isArray(contentTypes)) {
|
|
807
|
-
log.success(messages.contenttypes.list(currentProject));
|
|
808
|
-
this.HandleFormattingAndOutput(contentTypes, () => {
|
|
809
|
-
var _a;
|
|
810
|
-
for (const contentType of contentTypes) {
|
|
811
|
-
const fieldsLength = ((_a = contentType.fields) == null ? void 0 : _a.length) || 0;
|
|
812
|
-
console.log(
|
|
813
|
-
` - ${contentType.id} [${fieldsLength} field${fieldsLength !== 1 ? "s" : ""}]`
|
|
814
|
-
);
|
|
815
|
-
}
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
PrintContentType = async (contentTypeId) => {
|
|
821
|
-
const { currentProject, log, messages } = this;
|
|
822
|
-
await this.GetContentTypes();
|
|
823
|
-
if (this.contensis) {
|
|
824
|
-
const { contentTypes } = this;
|
|
825
|
-
if (Array.isArray(contentTypes)) {
|
|
826
|
-
const contentType = contentTypes.find(
|
|
827
|
-
(c) => c.id.toLowerCase() === contentTypeId.toLowerCase()
|
|
828
|
-
);
|
|
829
|
-
if (contentType) {
|
|
830
|
-
log.success(
|
|
831
|
-
messages.contenttypes.get(currentProject, contentType.id)
|
|
832
|
-
);
|
|
833
|
-
this.HandleFormattingAndOutput(contentType, log.object);
|
|
834
|
-
} else {
|
|
835
|
-
log.error(
|
|
836
|
-
messages.contenttypes.failedGet(currentProject, contentTypeId)
|
|
837
|
-
);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
RemoveContentTypes = async (contentTypeIds, commit = false) => {
|
|
843
|
-
const { currentProject, log, messages } = this;
|
|
844
|
-
const contensis = await this.ConnectContensisImport({
|
|
845
|
-
commit,
|
|
846
|
-
importDataType: "user-input"
|
|
847
|
-
});
|
|
848
|
-
if (contensis) {
|
|
849
|
-
const [err, result] = await contensis.DeleteContentTypes(contentTypeIds);
|
|
850
|
-
if (err) {
|
|
851
|
-
log.error(
|
|
852
|
-
messages.contenttypes.failedRemove(
|
|
853
|
-
currentProject,
|
|
854
|
-
contentTypeIds.join('", "')
|
|
855
|
-
),
|
|
856
|
-
err
|
|
857
|
-
);
|
|
858
|
-
} else {
|
|
859
|
-
log.success(
|
|
860
|
-
messages.contenttypes.removed(
|
|
861
|
-
currentProject,
|
|
862
|
-
contentTypeIds.join('", "'),
|
|
863
|
-
!contensis.isPreview
|
|
864
|
-
)
|
|
865
|
-
);
|
|
866
|
-
this.HandleFormattingAndOutput(
|
|
867
|
-
result,
|
|
868
|
-
() => log.object((0, import_json.jsonFormatter)(result))
|
|
869
|
-
);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
ImportContentTypes = async ({
|
|
874
|
-
commit,
|
|
875
|
-
fromFile
|
|
876
|
-
}, contentTypeIds = []) => {
|
|
877
|
-
const { currentProject, log, messages } = this;
|
|
878
|
-
let fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
879
|
-
if (typeof fileData === "string")
|
|
880
|
-
throw new Error(`Import file format must be of type JSON`);
|
|
881
|
-
if (!Array.isArray(fileData))
|
|
882
|
-
fileData = [fileData];
|
|
883
|
-
const contensis = await this.ConnectContensisImport({
|
|
884
|
-
commit,
|
|
885
|
-
importDataType: fromFile ? "user-input" : void 0
|
|
886
|
-
});
|
|
887
|
-
if (contensis) {
|
|
888
|
-
for (const contentType of fileData) {
|
|
889
|
-
contentType.projectId = currentProject;
|
|
890
|
-
delete contentType.uuid;
|
|
891
|
-
const [err, created, createStatus] = await contensis.models.targetRepos[currentProject].repo.UpsertContentType(false, contentType);
|
|
892
|
-
if (err)
|
|
893
|
-
log.error(err.message, err);
|
|
894
|
-
if (createStatus) {
|
|
895
|
-
log.success(
|
|
896
|
-
messages.contenttypes.created(
|
|
897
|
-
currentProject,
|
|
898
|
-
contentType.id,
|
|
899
|
-
createStatus
|
|
900
|
-
)
|
|
901
|
-
);
|
|
902
|
-
this.HandleFormattingAndOutput(contentType, () => {
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
};
|
|
908
|
-
DiffModels = async ({
|
|
909
|
-
fromFile
|
|
910
|
-
}, modelIds = []) => {
|
|
911
|
-
const { log } = this;
|
|
912
|
-
let fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
913
|
-
if (typeof fileData === "string")
|
|
914
|
-
throw new Error(`Import file format must be of type JSON`);
|
|
915
|
-
if (!Array.isArray(fileData))
|
|
916
|
-
fileData = [fileData];
|
|
917
|
-
const contensis = await this.ConnectContensisImport({
|
|
918
|
-
fromFile,
|
|
919
|
-
importDataType: "models"
|
|
920
|
-
});
|
|
921
|
-
if (contensis) {
|
|
922
|
-
const [err, result] = await (0, import_await_to_js.default)(
|
|
923
|
-
contensis.models.Diff(fileData.length ? fileData : modelIds)
|
|
924
|
-
);
|
|
925
|
-
if (err)
|
|
926
|
-
log.error(err.message, err);
|
|
927
|
-
if (result)
|
|
928
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
929
|
-
var _a;
|
|
930
|
-
log.success(
|
|
931
|
-
`Queried models ${log.infoText(
|
|
932
|
-
`"${(_a = result.query.modelIds) == null ? void 0 : _a.join(", ")}"`
|
|
933
|
-
)}
|
|
934
|
-
`
|
|
935
|
-
);
|
|
936
|
-
log.raw(log.boldText(`Content types:`));
|
|
937
|
-
if (!result.contentTypes)
|
|
938
|
-
log.info(`- None returned
|
|
939
|
-
`);
|
|
940
|
-
else
|
|
941
|
-
(0, import_console.printModelMigrationAnalysis)(this, result.contentTypes);
|
|
942
|
-
log.raw(log.boldText(`Components:`));
|
|
943
|
-
if (!result.components)
|
|
944
|
-
log.info(`- None returned
|
|
945
|
-
`);
|
|
946
|
-
else
|
|
947
|
-
(0, import_console.printModelMigrationAnalysis)(this, result.components);
|
|
948
|
-
});
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
PrintComponents = async () => {
|
|
952
|
-
const { currentProject, log, messages } = this;
|
|
953
|
-
await this.GetContentTypes();
|
|
954
|
-
if (this.contensis) {
|
|
955
|
-
const { components } = this;
|
|
956
|
-
if (Array.isArray(components)) {
|
|
957
|
-
log.success(messages.components.list(currentProject));
|
|
958
|
-
this.HandleFormattingAndOutput(components, () => {
|
|
959
|
-
var _a;
|
|
960
|
-
for (const component of components) {
|
|
961
|
-
const fieldsLength = ((_a = component.fields) == null ? void 0 : _a.length) || 0;
|
|
962
|
-
console.log(
|
|
963
|
-
` - ${component.id} [${fieldsLength} field${fieldsLength !== 1 ? "s" : ""}]`
|
|
964
|
-
);
|
|
965
|
-
}
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
};
|
|
970
|
-
PrintComponent = async (componentId) => {
|
|
971
|
-
const { currentProject, log, messages } = this;
|
|
972
|
-
await this.GetContentTypes();
|
|
973
|
-
if (this.contensis) {
|
|
974
|
-
const { components } = this;
|
|
975
|
-
if (Array.isArray(components)) {
|
|
976
|
-
const component = components.find(
|
|
977
|
-
(c) => c.id.toLowerCase() === componentId.toLowerCase()
|
|
978
|
-
);
|
|
979
|
-
if (component) {
|
|
980
|
-
log.success(messages.components.get(currentProject, component.id));
|
|
981
|
-
this.HandleFormattingAndOutput(component, log.object);
|
|
982
|
-
} else {
|
|
983
|
-
log.error(messages.components.failedGet(currentProject, componentId));
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
RemoveComponents = async (componentIds, commit = false) => {
|
|
989
|
-
const { currentProject, log, messages } = this;
|
|
990
|
-
const contensis = await this.ConnectContensisImport({
|
|
991
|
-
commit,
|
|
992
|
-
importDataType: "user-input"
|
|
993
|
-
});
|
|
994
|
-
if (contensis) {
|
|
995
|
-
const [err, result] = await contensis.DeleteContentTypes(
|
|
996
|
-
void 0,
|
|
997
|
-
componentIds
|
|
998
|
-
);
|
|
999
|
-
if (err) {
|
|
1000
|
-
log.error(
|
|
1001
|
-
messages.components.failedRemove(
|
|
1002
|
-
currentProject,
|
|
1003
|
-
componentIds.join('", "')
|
|
1004
|
-
),
|
|
1005
|
-
err
|
|
1006
|
-
);
|
|
1007
|
-
} else {
|
|
1008
|
-
log.success(
|
|
1009
|
-
messages.components.removed(
|
|
1010
|
-
currentProject,
|
|
1011
|
-
componentIds.join('", "'),
|
|
1012
|
-
!contensis.isPreview
|
|
1013
|
-
)
|
|
1014
|
-
);
|
|
1015
|
-
this.HandleFormattingAndOutput(
|
|
1016
|
-
result,
|
|
1017
|
-
() => log.info((0, import_json.jsonFormatter)(result))
|
|
1018
|
-
);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
};
|
|
1022
|
-
ImportComponents = async ({
|
|
1023
|
-
commit,
|
|
1024
|
-
fromFile
|
|
1025
|
-
}, componentIds = []) => {
|
|
1026
|
-
const { currentProject, log, messages } = this;
|
|
1027
|
-
let fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
1028
|
-
if (typeof fileData === "string")
|
|
1029
|
-
throw new Error(`Import file format must be of type JSON`);
|
|
1030
|
-
if (!Array.isArray(fileData))
|
|
1031
|
-
fileData = [fileData];
|
|
1032
|
-
const contensis = await this.ConnectContensisImport({
|
|
1033
|
-
commit,
|
|
1034
|
-
importDataType: fromFile ? "user-input" : void 0
|
|
1035
|
-
});
|
|
1036
|
-
if (contensis) {
|
|
1037
|
-
for (const component of fileData) {
|
|
1038
|
-
component.projectId = currentProject;
|
|
1039
|
-
delete component.uuid;
|
|
1040
|
-
const [err, created, createStatus] = await contensis.models.targetRepos[currentProject].repo.UpsertComponent(false, component);
|
|
1041
|
-
if (err)
|
|
1042
|
-
log.error(err.message, err);
|
|
1043
|
-
if (createStatus) {
|
|
1044
|
-
log.success(
|
|
1045
|
-
messages.components.created(
|
|
1046
|
-
currentProject,
|
|
1047
|
-
component.id,
|
|
1048
|
-
createStatus
|
|
1049
|
-
)
|
|
1050
|
-
);
|
|
1051
|
-
this.HandleFormattingAndOutput(component, () => {
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
};
|
|
1057
|
-
RemoveEntries = async (commit = false) => {
|
|
1058
|
-
var _a, _b, _c;
|
|
1059
|
-
const { currentEnv, log, messages } = this;
|
|
1060
|
-
const contensis = await this.ConnectContensisImport({
|
|
1061
|
-
commit,
|
|
1062
|
-
importDataType: "user-input"
|
|
1063
|
-
});
|
|
1064
|
-
if (contensis) {
|
|
1065
|
-
if (contensis.isPreview) {
|
|
1066
|
-
console.log(log.successText(` -- PREVIEW -- `));
|
|
1067
|
-
} else {
|
|
1068
|
-
console.log(log.warningText(` *** COMMITTING DELETE *** `));
|
|
1069
|
-
}
|
|
1070
|
-
const [err, result] = await contensis.DeleteEntries();
|
|
1071
|
-
if (result)
|
|
1072
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
1073
|
-
(0, import_console.printMigrateResult)(this, result, { action: "delete" });
|
|
1074
|
-
});
|
|
1075
|
-
if (!err && (!commit && ((_a = Object.values(result.entriesToMigrate)) == null ? void 0 : _a[0].totalCount) > 0 || commit && ((_b = result.migrateResult) == null ? void 0 : _b.deleted))) {
|
|
1076
|
-
log.success(messages.entries.removed(currentEnv, commit));
|
|
1077
|
-
if (!commit)
|
|
1078
|
-
log.help(messages.entries.commitTip());
|
|
1079
|
-
} else {
|
|
1080
|
-
log.error(messages.entries.failedRemove(currentEnv), err);
|
|
1081
|
-
if (!((_c = Object.values(result.entriesToMigrate)) == null ? void 0 : _c[0].totalCount))
|
|
1082
|
-
log.help(messages.entries.notFound(currentEnv));
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
};
|
|
1086
|
-
GetEntries = async ({
|
|
1087
|
-
withDependents = false
|
|
1088
|
-
}) => {
|
|
1089
|
-
const { currentProject, log, messages } = this;
|
|
1090
|
-
const contensis = await this.ConnectContensis();
|
|
1091
|
-
if (contensis) {
|
|
1092
|
-
log.line();
|
|
1093
|
-
const entries = await contensis.GetEntries({ withDependents });
|
|
1094
|
-
this.HandleFormattingAndOutput(
|
|
1095
|
-
entries,
|
|
1096
|
-
() => {
|
|
1097
|
-
var _a;
|
|
1098
|
-
return (0, import_migratortron.logEntriesTable)(
|
|
1099
|
-
entries,
|
|
1100
|
-
currentProject,
|
|
1101
|
-
(_a = contensis.payload.query) == null ? void 0 : _a.fields
|
|
1102
|
-
);
|
|
1103
|
-
}
|
|
1104
|
-
);
|
|
1105
|
-
} else {
|
|
1106
|
-
log.warning(messages.models.noList(currentProject));
|
|
1107
|
-
log.help(messages.connect.tip());
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
ImportEntries = async ({
|
|
1111
|
-
commit,
|
|
1112
|
-
fromFile
|
|
1113
|
-
}) => {
|
|
1114
|
-
const { currentProject, log, messages } = this;
|
|
1115
|
-
const contensis = await this.ConnectContensisImport({
|
|
1116
|
-
commit,
|
|
1117
|
-
fromFile,
|
|
1118
|
-
importDataType: "entries"
|
|
1119
|
-
});
|
|
1120
|
-
if (contensis) {
|
|
1121
|
-
log.line();
|
|
1122
|
-
if (contensis.isPreview) {
|
|
1123
|
-
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
1124
|
-
} else {
|
|
1125
|
-
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
1126
|
-
}
|
|
1127
|
-
const [migrateErr, migrateResult] = await contensis.MigrateEntries();
|
|
1128
|
-
if (migrateErr)
|
|
1129
|
-
(0, import_logger.logError)(migrateErr);
|
|
1130
|
-
else
|
|
1131
|
-
this.HandleFormattingAndOutput(migrateResult, () => {
|
|
1132
|
-
(0, import_console.printMigrateResult)(this, migrateResult);
|
|
1133
|
-
});
|
|
1134
|
-
} else {
|
|
1135
|
-
log.warning(messages.models.noList(currentProject));
|
|
1136
|
-
log.help(messages.connect.tip());
|
|
1137
|
-
}
|
|
1138
|
-
};
|
|
1139
|
-
PrintWebhookSubscriptions = async (subscriptionIds, name) => {
|
|
1140
|
-
const { currentEnv, log, messages } = this;
|
|
1141
|
-
const contensis = await this.ConnectContensis();
|
|
1142
|
-
if (contensis) {
|
|
1143
|
-
const [webhooksErr, webhooks] = await contensis.subscriptions.webhooks.GetSubscriptions();
|
|
1144
|
-
const filteredResults = typeof name === "string" ? webhooks == null ? void 0 : webhooks.filter(
|
|
1145
|
-
(w) => {
|
|
1146
|
-
var _a;
|
|
1147
|
-
return (_a = w.name) == null ? void 0 : _a.toLowerCase().includes(name.toLowerCase());
|
|
1148
|
-
}
|
|
1149
|
-
) : Array.isArray(subscriptionIds) ? webhooks == null ? void 0 : webhooks.filter((w) => subscriptionIds == null ? void 0 : subscriptionIds.some((id) => id === w.id)) : webhooks;
|
|
1150
|
-
if (Array.isArray(filteredResults)) {
|
|
1151
|
-
this.HandleFormattingAndOutput(filteredResults, () => {
|
|
1152
|
-
log.success(messages.webhooks.list(currentEnv));
|
|
1153
|
-
for (const {
|
|
1154
|
-
id,
|
|
1155
|
-
description,
|
|
1156
|
-
method,
|
|
1157
|
-
name: name2,
|
|
1158
|
-
version,
|
|
1159
|
-
url: url2
|
|
1160
|
-
} of filteredResults) {
|
|
1161
|
-
console.log(
|
|
1162
|
-
` - ${name2}${description ? ` (${description})` : ""} [${version.modified.toString().substring(0, 10)} ${version.modifiedBy}]`
|
|
1163
|
-
);
|
|
1164
|
-
console.log(` ${id}`);
|
|
1165
|
-
console.log(` [${method}] ${url2}`);
|
|
1166
|
-
}
|
|
1167
|
-
console.log("");
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
if (webhooksErr) {
|
|
1171
|
-
log.error(messages.webhooks.noList(currentEnv));
|
|
1172
|
-
log.error((0, import_json.jsonFormatter)(webhooksErr));
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
PrintBlocks = async () => {
|
|
1177
|
-
const { currentEnv, env, log, messages } = this;
|
|
1178
|
-
const contensis = await this.ConnectContensis();
|
|
1179
|
-
if (contensis) {
|
|
1180
|
-
const [err, blocks] = await contensis.blocks.GetBlocks();
|
|
1181
|
-
if (Array.isArray(blocks)) {
|
|
1182
|
-
this.HandleFormattingAndOutput(blocks, () => {
|
|
1183
|
-
log.success(messages.blocks.list(currentEnv, env.currentProject));
|
|
1184
|
-
for (const {
|
|
1185
|
-
id,
|
|
1186
|
-
description,
|
|
1187
|
-
branches,
|
|
1188
|
-
liveVersion,
|
|
1189
|
-
madeLive,
|
|
1190
|
-
versionsSinceLive
|
|
1191
|
-
} of blocks) {
|
|
1192
|
-
console.log(
|
|
1193
|
-
` - ${id}${description ? ` (${description})` : ""}${madeLive ? ` [${madeLive.toString().substring(0, 10)} v${liveVersion}]` : ""}${versionsSinceLive ? log.warningText(` +${versionsSinceLive}`) : ""}`
|
|
1194
|
-
);
|
|
1195
|
-
for (const branch of branches)
|
|
1196
|
-
console.log(
|
|
1197
|
-
log.infoText(` [${branch.id}]: ${branch.status}`)
|
|
1198
|
-
);
|
|
1199
|
-
}
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
if (err) {
|
|
1203
|
-
log.error(messages.blocks.noList(currentEnv));
|
|
1204
|
-
log.error((0, import_json.jsonFormatter)(err));
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
};
|
|
1208
|
-
PrintBlockVersions = async (blockId, branch, version) => {
|
|
1209
|
-
const { currentEnv, env, log, messages } = this;
|
|
1210
|
-
const contensis = await this.ConnectContensis();
|
|
1211
|
-
if (contensis) {
|
|
1212
|
-
const [err, blocks] = await contensis.blocks.GetBlockVersions(
|
|
1213
|
-
blockId,
|
|
1214
|
-
branch,
|
|
1215
|
-
version
|
|
1216
|
-
);
|
|
1217
|
-
if (blocks) {
|
|
1218
|
-
this.HandleFormattingAndOutput(blocks, () => {
|
|
1219
|
-
log.success(
|
|
1220
|
-
messages.blocks.get(blockId, currentEnv, env.currentProject)
|
|
1221
|
-
);
|
|
1222
|
-
for (const block of blocks)
|
|
1223
|
-
(0, import_console.printBlockVersion)(
|
|
1224
|
-
this,
|
|
1225
|
-
block,
|
|
1226
|
-
!version ? {
|
|
1227
|
-
showImage: false,
|
|
1228
|
-
showSource: true,
|
|
1229
|
-
showStaticPaths: false,
|
|
1230
|
-
showStatus: false
|
|
1231
|
-
} : void 0
|
|
1232
|
-
);
|
|
1233
|
-
});
|
|
1234
|
-
}
|
|
1235
|
-
if (err) {
|
|
1236
|
-
log.error(messages.blocks.noList(currentEnv, env.currentProject));
|
|
1237
|
-
log.error((0, import_json.jsonFormatter)(err));
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
|
-
PushBlock = async (block) => {
|
|
1242
|
-
const { currentEnv, env, log, messages } = this;
|
|
1243
|
-
log.info(
|
|
1244
|
-
messages.blocks.tryPush(
|
|
1245
|
-
block.id,
|
|
1246
|
-
block.source.branch,
|
|
1247
|
-
currentEnv,
|
|
1248
|
-
env.currentProject
|
|
1249
|
-
)
|
|
1250
|
-
);
|
|
1251
|
-
console.log((0, import_json.jsonFormatter)(block));
|
|
1252
|
-
const contensis = await this.ConnectContensis();
|
|
1253
|
-
if (contensis) {
|
|
1254
|
-
const [err, blockVersion] = await contensis.blocks.PushBlockVersion(
|
|
1255
|
-
block
|
|
1256
|
-
);
|
|
1257
|
-
if (!err) {
|
|
1258
|
-
log.success(
|
|
1259
|
-
messages.blocks.pushed(
|
|
1260
|
-
block.id,
|
|
1261
|
-
block.source.branch,
|
|
1262
|
-
currentEnv,
|
|
1263
|
-
env.currentProject
|
|
1264
|
-
)
|
|
1265
|
-
);
|
|
1266
|
-
}
|
|
1267
|
-
if (blockVersion) {
|
|
1268
|
-
this.HandleFormattingAndOutput(blockVersion, () => {
|
|
1269
|
-
(0, import_console.printBlockVersion)(this, blockVersion);
|
|
1270
|
-
});
|
|
1271
|
-
}
|
|
1272
|
-
if (err)
|
|
1273
|
-
throw new Error(
|
|
1274
|
-
messages.blocks.failedPush(block.id, currentEnv, env.currentProject)
|
|
1275
|
-
);
|
|
1276
|
-
}
|
|
1277
|
-
};
|
|
1278
|
-
ReleaseBlock = async (blockId, version) => {
|
|
1279
|
-
const { currentEnv, env, log, messages } = this;
|
|
1280
|
-
const contensis = await this.ConnectContensis();
|
|
1281
|
-
if (contensis) {
|
|
1282
|
-
const [err, blockVersion] = await contensis.blocks.BlockAction(
|
|
1283
|
-
blockId,
|
|
1284
|
-
"release",
|
|
1285
|
-
version
|
|
1286
|
-
);
|
|
1287
|
-
if (blockVersion) {
|
|
1288
|
-
this.HandleFormattingAndOutput(blockVersion, () => {
|
|
1289
|
-
log.success(
|
|
1290
|
-
messages.blocks.released(blockId, currentEnv, env.currentProject)
|
|
1291
|
-
);
|
|
1292
|
-
(0, import_console.printBlockVersion)(this, blockVersion);
|
|
1293
|
-
});
|
|
1294
|
-
}
|
|
1295
|
-
if (err) {
|
|
1296
|
-
log.error(
|
|
1297
|
-
messages.blocks.failedRelease(blockId, currentEnv, env.currentProject)
|
|
1298
|
-
);
|
|
1299
|
-
log.error((0, import_json.jsonFormatter)(err));
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
};
|
|
1303
|
-
PrintBlockLogs = async (blockId, branch, version, dataCenter) => {
|
|
1304
|
-
const { currentEnv, env, log, messages } = this;
|
|
1305
|
-
const contensis = await this.ConnectContensis();
|
|
1306
|
-
if (contensis) {
|
|
1307
|
-
log.success(
|
|
1308
|
-
messages.blocks.getLogs(blockId, branch, currentEnv, env.currentProject)
|
|
1309
|
-
);
|
|
1310
|
-
const [err, blockLogs] = await contensis.blocks.GetBlockLogs({
|
|
1311
|
-
blockId,
|
|
1312
|
-
branchId: branch,
|
|
1313
|
-
version,
|
|
1314
|
-
dataCenter
|
|
1315
|
-
});
|
|
1316
|
-
if (blockLogs) {
|
|
1317
|
-
this.HandleFormattingAndOutput(blockLogs, () => {
|
|
1318
|
-
console.log(
|
|
1319
|
-
` - ${blockId} ${branch} ${Number(version) ? `v${version}` : version} [${dataCenter}]`
|
|
1320
|
-
);
|
|
1321
|
-
log.line();
|
|
1322
|
-
console.log(log.infoText(blockLogs));
|
|
1323
|
-
log.line();
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
if (err) {
|
|
1327
|
-
log.error(
|
|
1328
|
-
messages.blocks.failedGetLogs(blockId, currentEnv, env.currentProject)
|
|
1329
|
-
);
|
|
1330
|
-
log.error((0, import_json.jsonFormatter)(err));
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
1334
|
-
HandleFormattingAndOutput = (obj, logFn) => {
|
|
1335
|
-
const { format, log, messages, output } = this;
|
|
1336
|
-
if (!format) {
|
|
1337
|
-
logFn(obj);
|
|
1338
|
-
} else if (format === "csv") {
|
|
1339
|
-
log.raw("");
|
|
1340
|
-
log.raw(log.infoText((0, import_csv.csvFormatter)(obj)));
|
|
1341
|
-
} else if (format === "xml") {
|
|
1342
|
-
log.raw("");
|
|
1343
|
-
log.raw(log.infoText((0, import_xml.xmlFormatter)(obj)));
|
|
1344
|
-
} else if (format === "json") {
|
|
1345
|
-
log.raw("");
|
|
1346
|
-
log.raw(log.infoText((0, import_json.jsonFormatter)(obj)));
|
|
1347
|
-
}
|
|
1348
|
-
log.raw("");
|
|
1349
|
-
if (output) {
|
|
1350
|
-
let writeString = "";
|
|
1351
|
-
if (format === "csv") {
|
|
1352
|
-
writeString = (0, import_csv.csvFormatter)(obj);
|
|
1353
|
-
} else if (format === "xml") {
|
|
1354
|
-
writeString = (0, import_xml.xmlFormatter)(obj);
|
|
1355
|
-
} else
|
|
1356
|
-
writeString = (0, import_json.jsonFormatter)(obj);
|
|
1357
|
-
if (writeString) {
|
|
1358
|
-
import_fs.default.writeFileSync(output, writeString);
|
|
1359
|
-
log.success(messages.app.fileOutput(format, output));
|
|
1360
|
-
} else {
|
|
1361
|
-
log.info(messages.app.noFileOutput());
|
|
1362
|
-
}
|
|
1363
|
-
}
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
const cliCommand = (commandArgs, outputOpts = {}, contensisOpts = {}) => {
|
|
1367
|
-
return new ContensisCli(["", "", ...commandArgs], outputOpts, contensisOpts);
|
|
1368
|
-
};
|
|
1369
|
-
var ContensisCliService_default = ContensisCli;
|
|
1370
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1371
|
-
0 && (module.exports = {
|
|
1372
|
-
cliCommand
|
|
1373
|
-
});
|
|
1374
|
-
//# sourceMappingURL=ContensisCliService.js.map
|