contensis-cli 1.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/.vscode/launch.json +15 -0
  2. package/README.md +631 -0
  3. package/cli.js +7 -0
  4. package/dist/commands/connect.js +44 -0
  5. package/dist/commands/connect.js.map +7 -0
  6. package/dist/commands/create.js +55 -0
  7. package/dist/commands/create.js.map +7 -0
  8. package/dist/commands/get.js +121 -0
  9. package/dist/commands/get.js.map +7 -0
  10. package/dist/commands/globalOptions.js +139 -0
  11. package/dist/commands/globalOptions.js.map +7 -0
  12. package/dist/commands/import.js +95 -0
  13. package/dist/commands/import.js.map +7 -0
  14. package/dist/commands/index.js +81 -0
  15. package/dist/commands/index.js.map +7 -0
  16. package/dist/commands/list.js +88 -0
  17. package/dist/commands/list.js.map +7 -0
  18. package/dist/commands/login.js +56 -0
  19. package/dist/commands/login.js.map +7 -0
  20. package/dist/commands/push.js +133 -0
  21. package/dist/commands/push.js.map +7 -0
  22. package/dist/commands/remove.js +77 -0
  23. package/dist/commands/remove.js.map +7 -0
  24. package/dist/commands/set.js +55 -0
  25. package/dist/commands/set.js.map +7 -0
  26. package/dist/index.js +32 -0
  27. package/dist/index.js.map +7 -0
  28. package/dist/localisation/en-GB.js +203 -0
  29. package/dist/localisation/en-GB.js.map +7 -0
  30. package/dist/models/AppError.d.js +2 -0
  31. package/dist/models/AppError.d.js.map +7 -0
  32. package/dist/models/Cache.d.js +2 -0
  33. package/dist/models/Cache.d.js.map +7 -0
  34. package/dist/models/JsModules.d.js +2 -0
  35. package/dist/models/JsModules.d.js.map +7 -0
  36. package/dist/providers/CredentialProvider.js +87 -0
  37. package/dist/providers/CredentialProvider.js.map +7 -0
  38. package/dist/providers/SessionCacheProvider.js +91 -0
  39. package/dist/providers/SessionCacheProvider.js.map +7 -0
  40. package/dist/providers/file-provider.js +113 -0
  41. package/dist/providers/file-provider.js.map +7 -0
  42. package/dist/services/ContensisAuthService.js +75 -0
  43. package/dist/services/ContensisAuthService.js.map +7 -0
  44. package/dist/services/ContensisCliService.js +1110 -0
  45. package/dist/services/ContensisCliService.js.map +7 -0
  46. package/dist/shell.js +261 -0
  47. package/dist/shell.js.map +7 -0
  48. package/dist/util/console.printer.js +194 -0
  49. package/dist/util/console.printer.js.map +7 -0
  50. package/dist/util/csv.formatter.js +50 -0
  51. package/dist/util/csv.formatter.js.map +7 -0
  52. package/dist/util/index.js +94 -0
  53. package/dist/util/index.js.map +7 -0
  54. package/dist/util/json.formatter.js +29 -0
  55. package/dist/util/json.formatter.js.map +7 -0
  56. package/dist/util/logger.js +184 -0
  57. package/dist/util/logger.js.map +7 -0
  58. package/dist/util/xml.formatter.js +51 -0
  59. package/dist/util/xml.formatter.js.map +7 -0
  60. package/dist/version.js +29 -0
  61. package/dist/version.js.map +7 -0
  62. package/esbuild.config.js +49 -0
  63. package/headless-setup.sh +7 -0
  64. package/package.json +59 -0
  65. package/patches/inquirer-command-prompt+0.1.0.patch +27 -0
  66. package/src/commands/connect.ts +23 -0
  67. package/src/commands/create.ts +41 -0
  68. package/src/commands/get.ts +139 -0
  69. package/src/commands/globalOptions.ts +126 -0
  70. package/src/commands/import.ts +89 -0
  71. package/src/commands/index.ts +72 -0
  72. package/src/commands/list.ts +90 -0
  73. package/src/commands/login.ts +33 -0
  74. package/src/commands/push.ts +120 -0
  75. package/src/commands/remove.ts +77 -0
  76. package/src/commands/set.ts +40 -0
  77. package/src/index.ts +19 -0
  78. package/src/localisation/en-GB.ts +211 -0
  79. package/src/models/AppError.d.ts +40 -0
  80. package/src/models/Cache.d.ts +25 -0
  81. package/src/models/JsModules.d.ts +1 -0
  82. package/src/providers/CredentialProvider.ts +88 -0
  83. package/src/providers/SessionCacheProvider.ts +74 -0
  84. package/src/providers/file-provider.ts +72 -0
  85. package/src/services/ContensisAuthService.ts +70 -0
  86. package/src/services/ContensisCliService.ts +1390 -0
  87. package/src/shell.ts +250 -0
  88. package/src/util/console.printer.ts +203 -0
  89. package/src/util/csv.formatter.ts +21 -0
  90. package/src/util/index.ts +67 -0
  91. package/src/util/json.formatter.ts +1 -0
  92. package/src/util/logger.ts +165 -0
  93. package/src/util/xml.formatter.ts +20 -0
  94. package/src/version.ts +1 -0
  95. package/tsconfig.json +22 -0
@@ -0,0 +1,1110 @@
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_util = require("../util");
37
+ var import_SessionCacheProvider = __toESM(require("../providers/SessionCacheProvider"));
38
+ var import_ContensisAuthService = __toESM(require("./ContensisAuthService"));
39
+ var import_CredentialProvider = __toESM(require("../providers/CredentialProvider"));
40
+ var import_logger = require("../util/logger");
41
+ var import_en_GB = require("../localisation/en-GB");
42
+ var import_migratortron = require("migratortron");
43
+ var import_csv = require("../util/csv.formatter");
44
+ var import_xml = require("../util/xml.formatter");
45
+ var import_json = require("../util/json.formatter");
46
+ var import_console = require("../util/console.printer");
47
+ var import_file_provider = require("../providers/file-provider");
48
+ class ContensisCli {
49
+ static quit = (error) => {
50
+ process.removeAllListeners("exit");
51
+ const exitCode = error ? 1 : 0;
52
+ console.info(`
53
+ Exiting contensis-cli with exit code: ${exitCode}
54
+ `);
55
+ process.exit(exitCode);
56
+ };
57
+ cache;
58
+ contensis;
59
+ contensisOpts;
60
+ contentTypes;
61
+ components;
62
+ currentEnv;
63
+ currentProject;
64
+ env;
65
+ sourceEnv;
66
+ targetEnv;
67
+ urls;
68
+ command;
69
+ format;
70
+ output;
71
+ log = import_logger.Logger;
72
+ messages = import_en_GB.LogMessages;
73
+ session;
74
+ verb;
75
+ noun;
76
+ thirdArg;
77
+ constructor(args, outputOpts, contensisOpts = {}) {
78
+ const [exe, script, verb = "", noun = "", ...restArgs] = args;
79
+ this.verb = verb == null ? void 0 : verb.toLowerCase();
80
+ this.noun = noun == null ? void 0 : noun.toLowerCase();
81
+ this.thirdArg = restArgs == null ? void 0 : restArgs[0];
82
+ const commandText = `${this.verb} ${this.noun} ${restArgs ? restArgs.join(" ") : ""}`.trim();
83
+ this.session = new import_SessionCacheProvider.default();
84
+ this.cache = this.session.Get();
85
+ this.contensisOpts = contensisOpts;
86
+ this.format = outputOpts == null ? void 0 : outputOpts.format;
87
+ this.output = (outputOpts == null ? void 0 : outputOpts.output) && import_path.default.join(process.cwd(), outputOpts.output);
88
+ const currentEnvironment = (outputOpts == null ? void 0 : outputOpts.alias) || this.cache.currentEnvironment || "";
89
+ const environments = this.cache.environments || {};
90
+ if (!currentEnvironment)
91
+ this.env = {};
92
+ else if (!!environments[currentEnvironment])
93
+ this.env = environments[currentEnvironment];
94
+ else {
95
+ this.env = {
96
+ history: [],
97
+ lastUserId: "",
98
+ projects: [],
99
+ versionStatus: "latest"
100
+ };
101
+ }
102
+ const env = this.env;
103
+ if (outputOpts == null ? void 0 : outputOpts.projectId)
104
+ env.currentProject = outputOpts.projectId;
105
+ if (outputOpts == null ? void 0 : outputOpts.user)
106
+ env.lastUserId = outputOpts.user;
107
+ if (outputOpts == null ? void 0 : outputOpts.password)
108
+ env.passwordFallback = outputOpts.password;
109
+ if (outputOpts == null ? void 0 : outputOpts.clientId)
110
+ env.lastUserId = outputOpts.clientId;
111
+ if (outputOpts == null ? void 0 : outputOpts.sharedSecret)
112
+ env.passwordFallback = outputOpts.sharedSecret;
113
+ this.currentEnv = currentEnvironment;
114
+ this.currentProject = (env == null ? void 0 : env.currentProject) || "null";
115
+ this.sourceEnv = (outputOpts == null ? void 0 : outputOpts.sourceEnv) || currentEnvironment;
116
+ if (currentEnvironment) {
117
+ this.urls = (0, import_util.url)(currentEnvironment, (env == null ? void 0 : env.currentProject) || "website");
118
+ }
119
+ this.command = {
120
+ commandText,
121
+ createdDate: new Date().toISOString(),
122
+ createdUserId: env == null ? void 0 : env.lastUserId
123
+ };
124
+ if (currentEnvironment) {
125
+ env.history = [this.command];
126
+ if (commandText) {
127
+ environments[currentEnvironment] = this.env;
128
+ this.session.Update({
129
+ currentEnvironment,
130
+ environments,
131
+ history: [commandText]
132
+ });
133
+ }
134
+ }
135
+ }
136
+ PrintEnvironments = () => {
137
+ const { log, messages } = this;
138
+ const { currentEnvironment, environments = {} } = this.cache;
139
+ const envKeys = Object.keys(environments);
140
+ log.success(messages.envs.found(envKeys.length));
141
+ this.HandleFormattingAndOutput(envKeys, () => {
142
+ for (const env of envKeys) {
143
+ console.log(` - ${currentEnvironment === env ? "* " : ""}${env}`);
144
+ }
145
+ });
146
+ if (envKeys.length === 0 || !currentEnvironment) {
147
+ log.help(messages.envs.tip());
148
+ }
149
+ };
150
+ Connect = async (environment) => {
151
+ var _a;
152
+ const { cache, log, messages, session } = this;
153
+ if (environment) {
154
+ const envCache = cache.environments[environment];
155
+ if (!envCache)
156
+ cache.environments[environment] = {
157
+ versionStatus: "published",
158
+ history: [],
159
+ lastUserId: "",
160
+ projects: [],
161
+ ...!this.currentEnv ? this.env : {}
162
+ };
163
+ this.env = cache.environments[environment];
164
+ this.currentEnv = environment;
165
+ this.urls = (0, import_util.url)(environment, "website");
166
+ const [fetchErr, response] = await (0, import_await_to_js.default)((0, import_node_fetch.default)(this.urls.cms));
167
+ if (response && (response == null ? void 0 : response.status) < 400) {
168
+ log.success(messages.connect.connected(environment));
169
+ if ((_a = this.env) == null ? void 0 : _a.lastUserId) {
170
+ await this.ConnectContensis();
171
+ await this.PrintProjects();
172
+ } else {
173
+ log.warning(messages.projects.noList());
174
+ log.help(messages.connect.tip());
175
+ }
176
+ session.Update({
177
+ currentEnvironment: environment,
178
+ environments: cache.environments
179
+ });
180
+ } else {
181
+ log.error(
182
+ messages.connect.unreachable(this.urls.cms, (response == null ? void 0 : response.status) || 0)
183
+ );
184
+ }
185
+ } else {
186
+ log.error(messages.connect.noEnv());
187
+ }
188
+ };
189
+ ConnectContensis = async ({ commit = false } = {}) => {
190
+ var _a, _b, _c;
191
+ const { contensisOpts, currentEnv, env, log, messages } = this;
192
+ const userId = env == null ? void 0 : env.lastUserId;
193
+ const isGuidId = userId && (0, import_util.isUuid)(userId);
194
+ if (currentEnv && userId) {
195
+ const [credentialError, credentials] = await new import_CredentialProvider.default(
196
+ {
197
+ userId,
198
+ alias: currentEnv
199
+ },
200
+ env.passwordFallback
201
+ ).Init();
202
+ if (credentialError && !credentials.current) {
203
+ log.error(credentialError);
204
+ return;
205
+ }
206
+ const cachedPassword = (_a = credentials == null ? void 0 : credentials.current) == null ? void 0 : _a.password;
207
+ if (cachedPassword) {
208
+ this.contensis = new import_migratortron.ContensisMigrationService(
209
+ {
210
+ ...contensisOpts,
211
+ source: {
212
+ url: ((_b = this.urls) == null ? void 0 : _b.cms) || "",
213
+ username: !isGuidId ? userId : void 0,
214
+ password: !isGuidId ? cachedPassword : void 0,
215
+ clientId: isGuidId ? userId : void 0,
216
+ sharedSecret: isGuidId ? cachedPassword : void 0,
217
+ project: (env == null ? void 0 : env.currentProject) || "",
218
+ assetHostname: (_c = this.urls) == null ? void 0 : _c.previewWeb
219
+ },
220
+ concurrency: typeof contensisOpts.concurrency !== "undefined" ? contensisOpts.concurrency : 3,
221
+ outputProgress: true
222
+ },
223
+ !commit
224
+ );
225
+ }
226
+ } else {
227
+ if (!currentEnv)
228
+ log.help(messages.connect.help());
229
+ if (!userId)
230
+ log.help(messages.connect.tip());
231
+ }
232
+ };
233
+ ConnectContensisImport = async ({
234
+ commit,
235
+ source,
236
+ fileData,
237
+ fileDataType
238
+ }) => {
239
+ var _a, _b, _c, _d, _e, _f;
240
+ const { contensisOpts, currentEnv, env, log, messages, sourceEnv } = this;
241
+ const environments = this.cache.environments || {};
242
+ const sourceEnvironment = environments[sourceEnv || ""] || {};
243
+ const sourceCms = "source" in contensisOpts && contensisOpts.source || {};
244
+ const sourceUserId = sourceCms.clientId || sourceCms.username || sourceEnvironment.lastUserId;
245
+ const sourceProjectId = sourceCms.project || sourceEnvironment.currentProject || "website";
246
+ const isSourceGuidId = sourceUserId && (0, import_util.isUuid)(sourceUserId);
247
+ const sourceUrls = (0, import_util.url)(sourceEnv || "", sourceProjectId);
248
+ const sourcePassword = sourceCms.sharedSecret || sourceCms.password || sourceEnvironment.passwordFallback;
249
+ const targetUserId = env == null ? void 0 : env.lastUserId;
250
+ const isTargetGuidId = targetUserId && (0, import_util.isUuid)(targetUserId);
251
+ if (sourceUserId && currentEnv && targetUserId) {
252
+ const [sourceCredentialError, sourceCredentials] = await new import_CredentialProvider.default(
253
+ {
254
+ userId: sourceUserId,
255
+ alias: currentEnv
256
+ },
257
+ sourcePassword
258
+ ).Init();
259
+ if (sourceCredentialError && !sourceCredentials.current) {
260
+ (0, import_logger.logError)(sourceCredentialError);
261
+ return;
262
+ }
263
+ const cachedSourcePassword = (_a = sourceCredentials == null ? void 0 : sourceCredentials.current) == null ? void 0 : _a.password;
264
+ const [targetCredentialError, targetCredentials] = await new import_CredentialProvider.default(
265
+ {
266
+ userId: targetUserId,
267
+ alias: currentEnv
268
+ },
269
+ env.passwordFallback
270
+ ).Init();
271
+ if (targetCredentialError && !targetCredentials.current) {
272
+ log.error(targetCredentialError);
273
+ return;
274
+ }
275
+ const cachedTargetPassword = (_b = targetCredentials == null ? void 0 : targetCredentials.current) == null ? void 0 : _b.password;
276
+ if (cachedSourcePassword && cachedTargetPassword) {
277
+ if (source === "file" || source === "input") {
278
+ this.contensis = new import_migratortron.ContensisMigrationService(
279
+ {
280
+ concurrency: 3,
281
+ outputProgress: true,
282
+ ...contensisOpts,
283
+ target: {
284
+ url: ((_c = this.urls) == null ? void 0 : _c.cms) || "",
285
+ username: !isTargetGuidId ? targetUserId : void 0,
286
+ password: !isTargetGuidId ? cachedTargetPassword : void 0,
287
+ clientId: isTargetGuidId ? targetUserId : void 0,
288
+ sharedSecret: isTargetGuidId ? cachedTargetPassword : void 0,
289
+ targetProjects: [env.currentProject || ""],
290
+ assetHostname: (_d = this.urls) == null ? void 0 : _d.previewWeb
291
+ },
292
+ ...fileDataType ? { [fileDataType]: fileData } : {}
293
+ },
294
+ !commit
295
+ );
296
+ }
297
+ if (source === "contensis") {
298
+ this.contensis = new import_migratortron.ContensisMigrationService(
299
+ {
300
+ concurrency: 3,
301
+ outputProgress: true,
302
+ ...contensisOpts,
303
+ source: {
304
+ url: sourceUrls.cms || "",
305
+ username: !isSourceGuidId ? sourceUserId : void 0,
306
+ password: !isSourceGuidId ? cachedSourcePassword : void 0,
307
+ clientId: isSourceGuidId ? sourceUserId : void 0,
308
+ sharedSecret: isSourceGuidId ? cachedSourcePassword : void 0,
309
+ project: sourceProjectId,
310
+ assetHostname: sourceUrls.previewWeb
311
+ },
312
+ target: {
313
+ url: ((_e = this.urls) == null ? void 0 : _e.cms) || "",
314
+ username: !isTargetGuidId ? targetUserId : void 0,
315
+ password: !isTargetGuidId ? cachedTargetPassword : void 0,
316
+ clientId: isTargetGuidId ? targetUserId : void 0,
317
+ sharedSecret: isTargetGuidId ? cachedTargetPassword : void 0,
318
+ targetProjects: [env.currentProject || ""],
319
+ assetHostname: (_f = this.urls) == null ? void 0 : _f.previewWeb
320
+ }
321
+ },
322
+ !commit
323
+ );
324
+ }
325
+ }
326
+ } else {
327
+ if (!currentEnv)
328
+ log.help(messages.connect.help());
329
+ if (!targetUserId)
330
+ log.help(messages.connect.tip());
331
+ }
332
+ };
333
+ Login = async (userId, {
334
+ password = (0, import_util.isPassword)(this.env.passwordFallback),
335
+ promptPassword = true,
336
+ sharedSecret = (0, import_util.isSharedSecret)(this.env.passwordFallback),
337
+ silent = false
338
+ }) => {
339
+ var _a, _b, _c, _d;
340
+ let inputPassword = password;
341
+ const { log, messages } = this;
342
+ if (userId) {
343
+ const { cache, currentEnv, env } = this;
344
+ if (currentEnv) {
345
+ const [credentialError, credentials] = await new import_CredentialProvider.default(
346
+ { userId, alias: currentEnv },
347
+ inputPassword || sharedSecret
348
+ ).Init();
349
+ if (credentialError && !credentials.current) {
350
+ log.error(credentialError);
351
+ return;
352
+ }
353
+ if (credentials.remarks.secure !== true)
354
+ log.warning(messages.login.insecurePassword());
355
+ const cachedPassword = (0, import_util.isPassword)((_a = credentials == null ? void 0 : credentials.current) == null ? void 0 : _a.password);
356
+ const cachedSecret = (0, import_util.isSharedSecret)((_b = credentials == null ? void 0 : credentials.current) == null ? void 0 : _b.password);
357
+ if (!sharedSecret && !inputPassword && !cachedPassword && !cachedSecret && promptPassword) {
358
+ ({ inputPassword } = await import_inquirer.default.prompt([
359
+ {
360
+ type: "password",
361
+ message: messages.login.passwordPrompt(currentEnv, userId),
362
+ name: "inputPassword",
363
+ mask: "*",
364
+ prefix: void 0
365
+ }
366
+ ]));
367
+ }
368
+ if (sharedSecret || cachedSecret || inputPassword || cachedPassword) {
369
+ const authService = new import_ContensisAuthService.default({
370
+ username: userId,
371
+ password: inputPassword || cachedPassword,
372
+ projectId: (env == null ? void 0 : env.currentProject) || "website",
373
+ rootUrl: ((_c = this.urls) == null ? void 0 : _c.cms) || "",
374
+ clientId: userId,
375
+ clientSecret: sharedSecret || cachedSecret
376
+ });
377
+ const [authError, bearerToken] = await (0, import_await_to_js.default)(authService.BearerToken());
378
+ if (bearerToken) {
379
+ env.authToken = bearerToken;
380
+ env.lastUserId = userId;
381
+ env.passwordFallback = credentials.remarks.secure !== true ? (_d = credentials.current) == null ? void 0 : _d.password : void 0;
382
+ if (!silent) {
383
+ import_logger.Logger.success(messages.login.success(currentEnv, userId));
384
+ await this.PrintProjects();
385
+ }
386
+ if (inputPassword)
387
+ await credentials.Save(inputPassword);
388
+ if (sharedSecret)
389
+ await credentials.Save(sharedSecret);
390
+ } else if (authError) {
391
+ import_logger.Logger.error(authError.toString());
392
+ env.authToken = "";
393
+ env.lastUserId = "";
394
+ env.passwordFallback = void 0;
395
+ if ((cachedPassword || cachedSecret) && credentials.remarks.secure) {
396
+ await credentials.Delete();
397
+ return await this.Login(userId, { password, sharedSecret });
398
+ } else {
399
+ throw new Error(messages.login.failed(currentEnv, userId));
400
+ }
401
+ }
402
+ this.session.Update({
403
+ environments: cache.environments
404
+ });
405
+ return env.authToken;
406
+ } else {
407
+ import_logger.Logger.error(messages.login.passwordPrompt(currentEnv, userId));
408
+ }
409
+ } else {
410
+ import_logger.Logger.error(messages.login.noEnv());
411
+ }
412
+ } else {
413
+ import_logger.Logger.error(messages.login.noUserId());
414
+ }
415
+ };
416
+ PrintProjects = async () => {
417
+ const { cache, currentEnv, currentProject, log, messages, session } = this;
418
+ if (!this.contensis)
419
+ await this.ConnectContensis();
420
+ if (this.contensis) {
421
+ const [projectsErr, projects] = await (0, import_await_to_js.default)(
422
+ this.contensis.projects.GetSourceProjects()
423
+ );
424
+ if (Array.isArray(projects)) {
425
+ const currentVals = cache.environments[currentEnv] || {};
426
+ const nextCurrentProject = currentProject && currentProject !== "null" ? currentProject : projects.some((p) => p.id === "website") ? "website" : void 0;
427
+ cache.environments[currentEnv] = {
428
+ ...currentVals,
429
+ projects: projects.map((p) => p.id),
430
+ currentProject: nextCurrentProject
431
+ };
432
+ log.success(messages.projects.list());
433
+ this.HandleFormattingAndOutput(projects, () => {
434
+ for (const project of projects) {
435
+ console.log(
436
+ ` - ${nextCurrentProject === project.id ? "* " : ""}[${project.primaryLanguage}] ${project.id}`
437
+ );
438
+ }
439
+ });
440
+ session.Update({
441
+ environments: cache.environments
442
+ });
443
+ if (nextCurrentProject) {
444
+ this.env = cache.environments[currentEnv];
445
+ this.SetProject(nextCurrentProject);
446
+ }
447
+ }
448
+ if (projectsErr) {
449
+ log.error(messages.projects.noList());
450
+ log.error(projectsErr.message);
451
+ }
452
+ }
453
+ };
454
+ SetProject = async (projectId = "") => {
455
+ const { cache, env, log, messages, session } = this;
456
+ let nextProjectId;
457
+ if ((env == null ? void 0 : env.projects.length) > 0 && (env == null ? void 0 : env.lastUserId)) {
458
+ nextProjectId = env.projects.find(
459
+ (p) => p.toLowerCase() === projectId.toLowerCase()
460
+ );
461
+ if (nextProjectId) {
462
+ env.currentProject = nextProjectId;
463
+ session.Update({
464
+ environments: cache.environments
465
+ });
466
+ log.success(messages.projects.set(projectId));
467
+ } else {
468
+ log.error(messages.projects.failedSet(projectId));
469
+ }
470
+ } else {
471
+ log.warning(messages.projects.noList());
472
+ log.help(messages.connect.tip());
473
+ }
474
+ return nextProjectId;
475
+ };
476
+ SetVersion = async (versionStatus) => {
477
+ const { cache, env, log, messages, session } = this;
478
+ if (!["latest", "published"].includes(versionStatus)) {
479
+ log.error(messages.version.invalid(versionStatus));
480
+ return false;
481
+ }
482
+ if (!env) {
483
+ log.help(messages.version.noEnv());
484
+ return false;
485
+ }
486
+ if ((env == null ? void 0 : env.projects.length) > 0 && (env == null ? void 0 : env.lastUserId)) {
487
+ env.versionStatus = versionStatus;
488
+ session.Update({
489
+ environments: cache.environments
490
+ });
491
+ log.success(messages.version.set(this.currentEnv, versionStatus));
492
+ return true;
493
+ } else {
494
+ log.warning(messages.projects.noList());
495
+ log.help(messages.connect.tip());
496
+ return false;
497
+ }
498
+ };
499
+ HydrateContensis = async () => {
500
+ const { log } = this;
501
+ if (!this.contensis)
502
+ await this.ConnectContensis();
503
+ if (this.contensis) {
504
+ const [contensisErr, models] = await (0, import_await_to_js.default)(
505
+ this.contensis.models.HydrateContensisRepositories()
506
+ );
507
+ if (contensisErr) {
508
+ log.error(contensisErr.message);
509
+ return contensisErr;
510
+ }
511
+ }
512
+ };
513
+ PrintApiKeys = async () => {
514
+ const { currentEnv, log, messages } = this;
515
+ if (!this.contensis)
516
+ await this.ConnectContensis();
517
+ if (this.contensis) {
518
+ const [keysErr, apiKeys] = await this.contensis.apiKeys.GetKeys();
519
+ if (Array.isArray(apiKeys)) {
520
+ log.success(messages.keys.list(currentEnv));
521
+ this.HandleFormattingAndOutput(apiKeys, () => {
522
+ for (const {
523
+ id,
524
+ sharedSecret,
525
+ name,
526
+ description,
527
+ dateModified,
528
+ modifiedBy
529
+ } of apiKeys) {
530
+ console.log(
531
+ ` - ${name}${description ? ` (${description})` : ""} [${dateModified.toString().substring(0, 10)} ${modifiedBy}]`
532
+ );
533
+ console.log(` ${id}`);
534
+ console.log(` ${sharedSecret}`);
535
+ }
536
+ });
537
+ }
538
+ if (keysErr) {
539
+ log.error(messages.keys.noList(currentEnv));
540
+ log.error((0, import_json.jsonFormatter)(keysErr));
541
+ }
542
+ }
543
+ };
544
+ CreateApiKey = async (name, description) => {
545
+ const { currentEnv, log, messages } = this;
546
+ if (!this.contensis)
547
+ await this.ConnectContensis();
548
+ if (this.contensis) {
549
+ const [err, key] = await this.contensis.apiKeys.CreateKey(
550
+ name,
551
+ description
552
+ );
553
+ if (key) {
554
+ log.success(messages.keys.created(currentEnv, name));
555
+ console.log(
556
+ ` - ${key.name}${key.description ? ` (${key.description})` : ""} [${key.dateModified.toString().substring(0, 10)} ${key.modifiedBy}]`
557
+ );
558
+ console.log(` - id: ${key.id}`);
559
+ console.log(` - sharedSecret: ${key.sharedSecret}`);
560
+ }
561
+ console.log("");
562
+ if (err) {
563
+ log.error(messages.keys.failedCreate(currentEnv, name), err);
564
+ }
565
+ }
566
+ };
567
+ RemoveApiKey = async (id) => {
568
+ const { currentEnv, log, messages } = this;
569
+ if (!this.contensis)
570
+ await this.ConnectContensis({ commit: true });
571
+ if (this.contensis) {
572
+ const [err, key] = await this.contensis.apiKeys.RemoveKey(id);
573
+ if (!err) {
574
+ log.success(messages.keys.removed(currentEnv, id));
575
+ console.log("");
576
+ } else {
577
+ log.error(messages.keys.failedRemove(currentEnv, id), err);
578
+ }
579
+ }
580
+ };
581
+ GetContentTypes = async () => {
582
+ const { currentProject, log, messages } = this;
583
+ let err;
584
+ if (!this.contensis)
585
+ err = await this.HydrateContensis();
586
+ if (err)
587
+ log.error(messages.contenttypes.noList(currentProject));
588
+ if (this.contensis) {
589
+ this.contentTypes = this.contensis.models.contentTypes();
590
+ this.components = this.contensis.models.components();
591
+ } else {
592
+ log.warning(messages.contenttypes.noList(currentProject));
593
+ }
594
+ };
595
+ PrintContentTypes = async () => {
596
+ const { currentProject, log, messages } = this;
597
+ await this.GetContentTypes();
598
+ if (this.contensis) {
599
+ const { contentTypes } = this;
600
+ if (Array.isArray(contentTypes)) {
601
+ log.success(messages.contenttypes.list(currentProject));
602
+ this.HandleFormattingAndOutput(contentTypes, () => {
603
+ var _a;
604
+ for (const contentType of contentTypes) {
605
+ const fieldsLength = ((_a = contentType.fields) == null ? void 0 : _a.length) || 0;
606
+ console.log(
607
+ ` - ${contentType.id} [${fieldsLength} field${fieldsLength !== 1 ? "s" : ""}]`
608
+ );
609
+ }
610
+ });
611
+ }
612
+ }
613
+ };
614
+ PrintContentType = async (contentTypeId) => {
615
+ const { currentProject, log, messages } = this;
616
+ await this.GetContentTypes();
617
+ if (this.contensis) {
618
+ const { contentTypes } = this;
619
+ if (Array.isArray(contentTypes)) {
620
+ const contentType = contentTypes.find(
621
+ (c) => c.id.toLowerCase() === contentTypeId.toLowerCase()
622
+ );
623
+ if (contentType) {
624
+ log.success(
625
+ messages.contenttypes.get(currentProject, contentType.id)
626
+ );
627
+ this.HandleFormattingAndOutput(contentType, log.object);
628
+ } else {
629
+ log.error(
630
+ messages.contenttypes.failedGet(currentProject, contentTypeId)
631
+ );
632
+ }
633
+ }
634
+ }
635
+ };
636
+ RemoveContentTypes = async (contentTypeIds, commit = false) => {
637
+ const { currentProject, log, messages } = this;
638
+ if (!this.contensis)
639
+ await this.ConnectContensisImport({
640
+ source: "input",
641
+ commit
642
+ });
643
+ if (this.contensis) {
644
+ const [err, result] = await this.contensis.DeleteContentTypes(
645
+ contentTypeIds
646
+ );
647
+ if (err) {
648
+ log.error(
649
+ messages.contenttypes.failedRemove(
650
+ currentProject,
651
+ contentTypeIds.join('", "')
652
+ ),
653
+ err
654
+ );
655
+ } else {
656
+ log.success(
657
+ messages.contenttypes.removed(
658
+ currentProject,
659
+ contentTypeIds.join('", "'),
660
+ !this.contensis.isPreview
661
+ )
662
+ );
663
+ this.HandleFormattingAndOutput(
664
+ result,
665
+ () => log.object((0, import_json.jsonFormatter)(result))
666
+ );
667
+ }
668
+ }
669
+ };
670
+ ImportContentTypes = async ({
671
+ commit,
672
+ fromFile
673
+ }, contentTypeIds = []) => {
674
+ const { currentProject, log, messages } = this;
675
+ let fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
676
+ if (typeof fileData === "string")
677
+ throw new Error(`Import file format must be of type JSON`);
678
+ if (!Array.isArray(fileData))
679
+ fileData = [fileData];
680
+ await this.ConnectContensisImport({
681
+ commit,
682
+ source: fromFile ? "file" : "contensis"
683
+ });
684
+ if (this.contensis) {
685
+ for (const contentType of fileData) {
686
+ contentType.projectId = currentProject;
687
+ delete contentType.uuid;
688
+ const [err, created, createStatus] = await this.contensis.models.targetRepos[currentProject].repo.UpsertContentType(false, contentType);
689
+ if (err)
690
+ log.error(err.message, err);
691
+ if (createStatus) {
692
+ log.success(
693
+ messages.contenttypes.created(
694
+ currentProject,
695
+ contentType.id,
696
+ createStatus
697
+ )
698
+ );
699
+ this.HandleFormattingAndOutput(contentType, () => {
700
+ });
701
+ }
702
+ }
703
+ }
704
+ };
705
+ PrintComponents = async () => {
706
+ const { currentProject, log, messages } = this;
707
+ await this.GetContentTypes();
708
+ if (this.contensis) {
709
+ const { components } = this;
710
+ if (Array.isArray(components)) {
711
+ log.success(messages.components.list(currentProject));
712
+ this.HandleFormattingAndOutput(components, () => {
713
+ var _a;
714
+ for (const component of components) {
715
+ const fieldsLength = ((_a = component.fields) == null ? void 0 : _a.length) || 0;
716
+ console.log(
717
+ ` - ${component.id} [${fieldsLength} field${fieldsLength !== 1 ? "s" : ""}]`
718
+ );
719
+ }
720
+ });
721
+ }
722
+ }
723
+ };
724
+ PrintComponent = async (componentId) => {
725
+ const { currentProject, log, messages } = this;
726
+ await this.GetContentTypes();
727
+ if (this.contensis) {
728
+ const { components } = this;
729
+ if (Array.isArray(components)) {
730
+ const component = components.find(
731
+ (c) => c.id.toLowerCase() === componentId.toLowerCase()
732
+ );
733
+ if (component) {
734
+ log.success(messages.components.get(currentProject, component.id));
735
+ this.HandleFormattingAndOutput(component, log.object);
736
+ } else {
737
+ log.error(messages.components.failedGet(currentProject, componentId));
738
+ }
739
+ }
740
+ }
741
+ };
742
+ RemoveComponents = async (componentIds, commit = false) => {
743
+ const { currentProject, log, messages } = this;
744
+ if (!this.contensis)
745
+ await this.ConnectContensisImport({
746
+ source: "input",
747
+ commit
748
+ });
749
+ if (this.contensis) {
750
+ const [err, result] = await this.contensis.DeleteContentTypes(
751
+ void 0,
752
+ componentIds
753
+ );
754
+ if (err) {
755
+ log.error(
756
+ messages.components.failedRemove(
757
+ currentProject,
758
+ componentIds.join('", "')
759
+ ),
760
+ err
761
+ );
762
+ } else {
763
+ log.success(
764
+ messages.components.removed(
765
+ currentProject,
766
+ componentIds.join('", "'),
767
+ !this.contensis.isPreview
768
+ )
769
+ );
770
+ this.HandleFormattingAndOutput(
771
+ result,
772
+ () => log.info((0, import_json.jsonFormatter)(result))
773
+ );
774
+ }
775
+ }
776
+ };
777
+ ImportComponents = async ({
778
+ commit,
779
+ fromFile
780
+ }, componentIds = []) => {
781
+ const { currentProject, log, messages } = this;
782
+ let fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
783
+ if (typeof fileData === "string")
784
+ throw new Error(`Import file format must be of type JSON`);
785
+ if (!Array.isArray(fileData))
786
+ fileData = [fileData];
787
+ await this.ConnectContensisImport({
788
+ commit,
789
+ source: fromFile ? "file" : "contensis"
790
+ });
791
+ if (this.contensis) {
792
+ for (const component of fileData) {
793
+ component.projectId = currentProject;
794
+ delete component.uuid;
795
+ const [err, created, createStatus] = await this.contensis.models.targetRepos[currentProject].repo.UpsertComponent(false, component);
796
+ if (err)
797
+ log.error(err.message, err);
798
+ if (createStatus) {
799
+ log.success(
800
+ messages.components.created(
801
+ currentProject,
802
+ component.id,
803
+ createStatus
804
+ )
805
+ );
806
+ this.HandleFormattingAndOutput(component, () => {
807
+ });
808
+ }
809
+ }
810
+ }
811
+ };
812
+ RemoveEntry = async (id, commit = false) => {
813
+ var _a, _b, _c;
814
+ const { currentEnv, log, messages } = this;
815
+ if (!this.contensis)
816
+ await this.ConnectContensisImport({
817
+ source: "input",
818
+ commit
819
+ });
820
+ if (this.contensis) {
821
+ if (this.contensis.isPreview) {
822
+ console.log(log.successText(` -- PREVIEW -- `));
823
+ } else {
824
+ console.log(log.warningText(` *** COMMITTING DELETE *** `));
825
+ }
826
+ const [err, result] = await this.contensis.DeleteEntries();
827
+ if (result)
828
+ this.HandleFormattingAndOutput(result, () => {
829
+ (0, import_console.printMigrateResult)(this, result, { action: "delete" });
830
+ });
831
+ if (!err && (!commit && ((_a = Object.values(result.entriesToMigrate)) == null ? void 0 : _a[0].totalCount) > 0 || commit && ((_b = result.migrateResult) == null ? void 0 : _b.deleted))) {
832
+ log.success(messages.entries.removed(currentEnv, id, commit));
833
+ if (!commit)
834
+ log.help(messages.entries.commitTip());
835
+ } else {
836
+ log.error(messages.entries.failedRemove(currentEnv, id), err);
837
+ if (!((_c = Object.values(result.entriesToMigrate)) == null ? void 0 : _c[0].totalCount))
838
+ log.help(messages.entries.notFound(id));
839
+ }
840
+ }
841
+ };
842
+ GetEntries = async ({
843
+ withDependents = false
844
+ }) => {
845
+ const { currentProject, log, messages } = this;
846
+ await this.ConnectContensis();
847
+ if (this.contensis) {
848
+ log.line();
849
+ const entries = await this.contensis.GetEntries({ withDependents });
850
+ this.HandleFormattingAndOutput(
851
+ entries,
852
+ () => {
853
+ var _a, _b;
854
+ return (0, import_migratortron.logEntriesTable)(
855
+ entries,
856
+ currentProject,
857
+ (_b = (_a = this.contensis) == null ? void 0 : _a.payload.query) == null ? void 0 : _b.fields
858
+ );
859
+ }
860
+ );
861
+ } else {
862
+ log.warning(messages.contenttypes.noList(currentProject));
863
+ log.help(messages.connect.tip());
864
+ }
865
+ };
866
+ ImportEntries = async ({
867
+ commit,
868
+ fromFile
869
+ }) => {
870
+ const { currentProject, log, messages } = this;
871
+ const fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
872
+ if (typeof fileData === "string")
873
+ throw new Error(`Import file format must be of type JSON`);
874
+ await this.ConnectContensisImport({
875
+ commit,
876
+ source: fromFile ? "file" : "contensis",
877
+ fileData,
878
+ fileDataType: "entries"
879
+ });
880
+ if (this.contensis) {
881
+ log.line();
882
+ if (this.contensis.isPreview) {
883
+ console.log(log.successText(` -- IMPORT PREVIEW -- `));
884
+ } else {
885
+ console.log(log.warningText(` *** COMMITTING IMPORT *** `));
886
+ }
887
+ const [migrateErr, migrateResult] = await this.contensis.MigrateEntries();
888
+ if (migrateErr)
889
+ (0, import_logger.logError)(migrateErr);
890
+ else
891
+ this.HandleFormattingAndOutput(migrateResult, () => {
892
+ (0, import_console.printMigrateResult)(this, migrateResult);
893
+ });
894
+ } else {
895
+ log.warning(messages.contenttypes.noList(currentProject));
896
+ log.help(messages.connect.tip());
897
+ }
898
+ };
899
+ PrintWebhookSubscriptions = async (subscriptionIds, name) => {
900
+ const { currentEnv, log, messages } = this;
901
+ if (!this.contensis)
902
+ await this.ConnectContensis();
903
+ if (this.contensis) {
904
+ const [webhooksErr, webhooks] = await this.contensis.subscriptions.webhooks.GetSubscriptions();
905
+ const filteredResults = typeof name === "string" ? webhooks.filter(
906
+ (w) => {
907
+ var _a;
908
+ return (_a = w.name) == null ? void 0 : _a.toLowerCase().includes(name.toLowerCase());
909
+ }
910
+ ) : Array.isArray(subscriptionIds) ? webhooks.filter((w) => subscriptionIds == null ? void 0 : subscriptionIds.some((id) => id === w.id)) : webhooks;
911
+ if (Array.isArray(filteredResults)) {
912
+ this.HandleFormattingAndOutput(filteredResults, () => {
913
+ log.success(messages.webhooks.list(currentEnv));
914
+ for (const {
915
+ id,
916
+ description,
917
+ method,
918
+ name: name2,
919
+ version,
920
+ url: url2
921
+ } of filteredResults) {
922
+ console.log(
923
+ ` - ${name2}${description ? ` (${description})` : ""} [${version.modified.toString().substring(0, 10)} ${version.modifiedBy}]`
924
+ );
925
+ console.log(` ${id}`);
926
+ console.log(` [${method}] ${url2}`);
927
+ }
928
+ console.log("");
929
+ });
930
+ }
931
+ if (webhooksErr) {
932
+ log.error(messages.webhooks.noList(currentEnv));
933
+ log.error((0, import_json.jsonFormatter)(webhooksErr));
934
+ }
935
+ }
936
+ };
937
+ PrintBlocks = async () => {
938
+ const { currentEnv, log, messages } = this;
939
+ if (!this.contensis)
940
+ await this.ConnectContensis();
941
+ if (this.contensis) {
942
+ const [err, blocks] = await this.contensis.blocks.GetBlocks();
943
+ if (Array.isArray(blocks)) {
944
+ this.HandleFormattingAndOutput(blocks, () => {
945
+ log.success(messages.blocks.list(currentEnv));
946
+ for (const {
947
+ id,
948
+ description,
949
+ branches,
950
+ liveVersion,
951
+ madeLive,
952
+ versionsSinceLive
953
+ } of blocks) {
954
+ console.log(
955
+ ` - ${id}${description ? ` (${description})` : ""}${madeLive ? ` [${madeLive.toString().substring(0, 10)} v${liveVersion}]` : ""}${versionsSinceLive ? log.warningText(` +${versionsSinceLive}`) : ""}`
956
+ );
957
+ for (const branch of branches)
958
+ console.log(
959
+ log.infoText(` [${branch.id}]: ${branch.status}`)
960
+ );
961
+ }
962
+ });
963
+ }
964
+ if (err) {
965
+ log.error(messages.blocks.noList(currentEnv));
966
+ log.error((0, import_json.jsonFormatter)(err));
967
+ }
968
+ }
969
+ };
970
+ PrintBlockVersions = async (blockId, branch, version) => {
971
+ const { currentEnv, env, log, messages } = this;
972
+ if (!this.contensis)
973
+ await this.ConnectContensis();
974
+ if (this.contensis) {
975
+ const [err, blocks] = await this.contensis.blocks.GetBlockVersions(
976
+ blockId,
977
+ branch,
978
+ version
979
+ );
980
+ if (blocks) {
981
+ this.HandleFormattingAndOutput(blocks, () => {
982
+ log.success(
983
+ messages.blocks.get(`${currentEnv}:${env.currentProject}`)
984
+ );
985
+ for (const block of blocks)
986
+ (0, import_console.printBlockVersion)(
987
+ this,
988
+ block,
989
+ !version ? {
990
+ showImage: false,
991
+ showSource: true,
992
+ showStaticPaths: false,
993
+ showStatus: false
994
+ } : void 0
995
+ );
996
+ });
997
+ }
998
+ if (err) {
999
+ log.error(messages.blocks.noList(currentEnv, env.currentProject));
1000
+ log.error((0, import_json.jsonFormatter)(err));
1001
+ }
1002
+ }
1003
+ };
1004
+ PushBlock = async (block) => {
1005
+ const { currentEnv, env, log, messages } = this;
1006
+ messages.blocks.tryPush(
1007
+ block.id,
1008
+ block.source.branch,
1009
+ currentEnv,
1010
+ env.currentProject
1011
+ );
1012
+ console.log((0, import_json.jsonFormatter)(block));
1013
+ if (!this.contensis)
1014
+ await this.ConnectContensis();
1015
+ if (this.contensis) {
1016
+ const [err, blockVersion] = await this.contensis.blocks.PushBlockVersion(
1017
+ block
1018
+ );
1019
+ if (!err) {
1020
+ log.success(
1021
+ messages.blocks.pushed(
1022
+ block.id,
1023
+ block.source.branch,
1024
+ currentEnv,
1025
+ env.currentProject
1026
+ )
1027
+ );
1028
+ console.log((0, import_json.jsonFormatter)(blockVersion));
1029
+ }
1030
+ if (blockVersion) {
1031
+ this.HandleFormattingAndOutput(blockVersion, () => {
1032
+ (0, import_console.printBlockVersion)(this, blockVersion);
1033
+ });
1034
+ }
1035
+ if (err)
1036
+ throw new Error(
1037
+ messages.blocks.failedPush(block.id, currentEnv, env.currentProject)
1038
+ );
1039
+ }
1040
+ };
1041
+ PrintBlockLogs = async (blockId, branch, version, dataCenter) => {
1042
+ const { currentEnv, log, messages } = this;
1043
+ if (!this.contensis)
1044
+ await this.ConnectContensis();
1045
+ if (this.contensis) {
1046
+ const [err, blockLogs] = await this.contensis.blocks.GetBlockLogs({
1047
+ blockId,
1048
+ branchId: branch,
1049
+ version,
1050
+ dataCenter
1051
+ });
1052
+ if (blockLogs) {
1053
+ this.HandleFormattingAndOutput(blockLogs, () => {
1054
+ log.success(messages.blocks.list(currentEnv));
1055
+ console.log(
1056
+ ` - ${blockId} ${branch} ${Number(version) ? `v${version}` : version} [${dataCenter}]`
1057
+ );
1058
+ log.line();
1059
+ console.log(log.infoText(blockLogs));
1060
+ log.line();
1061
+ });
1062
+ }
1063
+ if (err) {
1064
+ log.error(messages.blocks.noList(currentEnv));
1065
+ log.error((0, import_json.jsonFormatter)(err));
1066
+ }
1067
+ }
1068
+ };
1069
+ HandleFormattingAndOutput = (obj, logFn) => {
1070
+ const { format, log, messages, output } = this;
1071
+ if (output) {
1072
+ let writeString = "";
1073
+ if (format === "csv") {
1074
+ writeString = (0, import_csv.csvFormatter)(obj);
1075
+ } else if (format === "xml") {
1076
+ writeString = (0, import_xml.xmlFormatter)(obj);
1077
+ } else
1078
+ writeString = (0, import_json.jsonFormatter)(obj);
1079
+ if (writeString) {
1080
+ import_fs.default.writeFileSync(output, writeString);
1081
+ log.success(messages.app.fileOutput(format, output));
1082
+ } else {
1083
+ log.info(messages.app.noFileOutput());
1084
+ }
1085
+ } else {
1086
+ if (!format) {
1087
+ logFn(obj);
1088
+ } else if (format === "csv") {
1089
+ log.raw("");
1090
+ log.raw(log.infoText((0, import_csv.csvFormatter)(obj)));
1091
+ } else if (format === "xml") {
1092
+ log.raw("");
1093
+ log.raw(log.infoText((0, import_xml.xmlFormatter)(obj)));
1094
+ } else if (format === "json") {
1095
+ log.raw("");
1096
+ log.raw(log.infoText((0, import_json.jsonFormatter)(obj)));
1097
+ }
1098
+ log.raw("");
1099
+ }
1100
+ };
1101
+ }
1102
+ const cliCommand = (commandArgs, outputOpts = {}, contensisOpts = {}) => {
1103
+ return new ContensisCli(["", "", ...commandArgs], outputOpts, contensisOpts);
1104
+ };
1105
+ var ContensisCliService_default = ContensisCli;
1106
+ // Annotate the CommonJS export names for ESM import in node:
1107
+ 0 && (module.exports = {
1108
+ cliCommand
1109
+ });
1110
+ //# sourceMappingURL=ContensisCliService.js.map