contensis-cli 1.0.0-beta.51 → 1.0.0-beta.53

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 (66) hide show
  1. package/.vscode/launch.json +15 -15
  2. package/README.md +1226 -1226
  3. package/dist/commands/connect.js.map +1 -1
  4. package/dist/commands/create.js.map +1 -1
  5. package/dist/commands/diff.js.map +1 -1
  6. package/dist/commands/get.js.map +1 -1
  7. package/dist/commands/globalOptions.js.map +1 -1
  8. package/dist/commands/import.js.map +1 -1
  9. package/dist/commands/index.js.map +1 -1
  10. package/dist/commands/list.js.map +1 -1
  11. package/dist/commands/login.js.map +1 -1
  12. package/dist/commands/push.js.map +1 -1
  13. package/dist/commands/release.js.map +1 -1
  14. package/dist/commands/remove.js.map +1 -1
  15. package/dist/commands/set.js.map +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/localisation/en-GB.js.map +1 -1
  18. package/dist/providers/CredentialProvider.js.map +1 -1
  19. package/dist/providers/SessionCacheProvider.js.map +1 -1
  20. package/dist/providers/file-provider.js.map +1 -1
  21. package/dist/services/ContensisAuthService.js.map +1 -1
  22. package/dist/services/ContensisCliService.js.map +1 -1
  23. package/dist/shell.js.map +1 -1
  24. package/dist/util/console.printer.js.map +1 -1
  25. package/dist/util/csv.formatter.js.map +1 -1
  26. package/dist/util/index.js.map +1 -1
  27. package/dist/util/json.formatter.js.map +1 -1
  28. package/dist/util/logger.js.map +1 -1
  29. package/dist/util/xml.formatter.js.map +1 -1
  30. package/dist/version.js +1 -1
  31. package/dist/version.js.map +1 -1
  32. package/esbuild.config.js +49 -49
  33. package/headless-setup.sh +6 -6
  34. package/package.json +59 -59
  35. package/src/commands/connect.ts +24 -24
  36. package/src/commands/create.ts +70 -70
  37. package/src/commands/diff.ts +41 -41
  38. package/src/commands/get.ts +214 -214
  39. package/src/commands/globalOptions.ts +127 -127
  40. package/src/commands/import.ts +128 -128
  41. package/src/commands/index.ts +80 -80
  42. package/src/commands/list.ts +116 -116
  43. package/src/commands/login.ts +34 -34
  44. package/src/commands/push.ts +127 -127
  45. package/src/commands/release.ts +32 -32
  46. package/src/commands/remove.ts +85 -85
  47. package/src/commands/set.ts +96 -96
  48. package/src/index.ts +19 -19
  49. package/src/localisation/en-GB.ts +289 -289
  50. package/src/models/AppError.d.ts +40 -40
  51. package/src/models/Cache.d.ts +25 -25
  52. package/src/models/JsModules.d.ts +1 -1
  53. package/src/providers/CredentialProvider.ts +121 -121
  54. package/src/providers/SessionCacheProvider.ts +101 -101
  55. package/src/providers/file-provider.ts +76 -76
  56. package/src/services/ContensisAuthService.ts +70 -70
  57. package/src/services/ContensisCliService.ts +1745 -1745
  58. package/src/shell.ts +270 -270
  59. package/src/util/console.printer.ts +371 -371
  60. package/src/util/csv.formatter.ts +21 -21
  61. package/src/util/index.ts +73 -73
  62. package/src/util/json.formatter.ts +1 -1
  63. package/src/util/logger.ts +234 -234
  64. package/src/util/xml.formatter.ts +20 -20
  65. package/src/version.ts +1 -1
  66. package/tsconfig.json +22 -22
@@ -1,21 +1,21 @@
1
- import { flatten } from 'flat';
2
- import { Parser } from 'json2csv';
3
- import cleaner from 'deep-cleaner';
4
-
5
- const flattenObject = (obj: any) => flatten(cleaner(obj, ['workflow']));
6
-
7
- export const csvFormatter = <T>(entries: T | T[]) => {
8
- // Flatten the passed in object
9
- const flatEntries = [];
10
- if (Array.isArray(entries))
11
- for (const entry of entries) {
12
- flatEntries.push(flattenObject(entry));
13
- }
14
- else flatEntries.push(flattenObject(entries));
15
-
16
- // Parse the flattened object to csv
17
- const json2csvParser = new Parser();
18
- const csv = json2csvParser.parse(flatEntries);
19
-
20
- return csv;
21
- };
1
+ import { flatten } from 'flat';
2
+ import { Parser } from 'json2csv';
3
+ import cleaner from 'deep-cleaner';
4
+
5
+ const flattenObject = (obj: any) => flatten(cleaner(obj, ['workflow']));
6
+
7
+ export const csvFormatter = <T>(entries: T | T[]) => {
8
+ // Flatten the passed in object
9
+ const flatEntries = [];
10
+ if (Array.isArray(entries))
11
+ for (const entry of entries) {
12
+ flatEntries.push(flattenObject(entry));
13
+ }
14
+ else flatEntries.push(flattenObject(entries));
15
+
16
+ // Parse the flattened object to csv
17
+ const json2csvParser = new Parser();
18
+ const csv = json2csvParser.parse(flatEntries);
19
+
20
+ return csv;
21
+ };
package/src/util/index.ts CHANGED
@@ -1,73 +1,73 @@
1
- import mergeWith from 'lodash/mergeWith';
2
- import { Logger } from './logger';
3
- import { LogMessages as enGB } from '../localisation/en-GB.js';
4
-
5
- export const isSharedSecret = (str = '') =>
6
- str.length > 80 && str.split('-').length === 3 ? str : undefined;
7
-
8
- export const isPassword = (str = '') =>
9
- !isSharedSecret(str) ? str : undefined;
10
-
11
- export const tryParse = (str: string) => {
12
- try {
13
- return typeof str === 'object' ? str : JSON.parse(str);
14
- } catch (e) {
15
- return false;
16
- }
17
- };
18
-
19
- export const isJson = (str: string) =>
20
- typeof str === 'object' || !!tryParse(str);
21
-
22
- export const tryStringify = (obj: any) => {
23
- try {
24
- return typeof obj === 'object' ? JSON.stringify(obj) : obj;
25
- } catch (e) {
26
- return obj;
27
- }
28
- };
29
-
30
- export const isUuid = (str: string) => {
31
- // Regular expression to check if string is a valid UUID
32
- const regexExp =
33
- /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
34
-
35
- return regexExp.test(str);
36
- };
37
-
38
- export const url = (alias: string, project: string) => {
39
- const projectAndAlias =
40
- project && project.toLowerCase() !== 'website'
41
- ? `${project.toLowerCase()}-${alias}`
42
- : alias;
43
- return {
44
- api: `https://api-${alias}.cloud.contensis.com`,
45
- cms: `https://cms-${alias}.cloud.contensis.com`,
46
- liveWeb: `https://live-${projectAndAlias}.cloud.contensis.com`,
47
- previewWeb: `https://preview-${projectAndAlias}.cloud.contensis.com`,
48
- iisWeb: `https://iis-live-${projectAndAlias}.cloud.contensis.com`,
49
- iisPreviewWeb: `https://iis-preview-${projectAndAlias}.cloud.contensis.com`,
50
- };
51
- };
52
-
53
- export const Logging = async (language = 'en-GB') => {
54
- const defaultMessages = enGB;
55
- // const { LogMessages: defaultMessages } = await import(
56
- // `../localisation/en-GB.js`
57
- // );
58
- let localisedMessages = defaultMessages;
59
-
60
- if (language === 'en-GB') {
61
- // Using a variable import e.g. `import(`../localisation/${language}.js`);`
62
- // does not play well with packaged executables
63
- // So we have to hard code the import for each language individually
64
- }
65
- return {
66
- messages: mergeWith(
67
- localisedMessages,
68
- defaultMessages,
69
- (v, s) => v || s
70
- ) as typeof defaultMessages,
71
- Log: Logger,
72
- };
73
- };
1
+ import mergeWith from 'lodash/mergeWith';
2
+ import { Logger } from './logger';
3
+ import { LogMessages as enGB } from '../localisation/en-GB.js';
4
+
5
+ export const isSharedSecret = (str = '') =>
6
+ str.length > 80 && str.split('-').length === 3 ? str : undefined;
7
+
8
+ export const isPassword = (str = '') =>
9
+ !isSharedSecret(str) ? str : undefined;
10
+
11
+ export const tryParse = (str: string) => {
12
+ try {
13
+ return typeof str === 'object' ? str : JSON.parse(str);
14
+ } catch (e) {
15
+ return false;
16
+ }
17
+ };
18
+
19
+ export const isJson = (str: string) =>
20
+ typeof str === 'object' || !!tryParse(str);
21
+
22
+ export const tryStringify = (obj: any) => {
23
+ try {
24
+ return typeof obj === 'object' ? JSON.stringify(obj) : obj;
25
+ } catch (e) {
26
+ return obj;
27
+ }
28
+ };
29
+
30
+ export const isUuid = (str: string) => {
31
+ // Regular expression to check if string is a valid UUID
32
+ const regexExp =
33
+ /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
34
+
35
+ return regexExp.test(str);
36
+ };
37
+
38
+ export const url = (alias: string, project: string) => {
39
+ const projectAndAlias =
40
+ project && project.toLowerCase() !== 'website'
41
+ ? `${project.toLowerCase()}-${alias}`
42
+ : alias;
43
+ return {
44
+ api: `https://api-${alias}.cloud.contensis.com`,
45
+ cms: `https://cms-${alias}.cloud.contensis.com`,
46
+ liveWeb: `https://live-${projectAndAlias}.cloud.contensis.com`,
47
+ previewWeb: `https://preview-${projectAndAlias}.cloud.contensis.com`,
48
+ iisWeb: `https://iis-live-${projectAndAlias}.cloud.contensis.com`,
49
+ iisPreviewWeb: `https://iis-preview-${projectAndAlias}.cloud.contensis.com`,
50
+ };
51
+ };
52
+
53
+ export const Logging = async (language = 'en-GB') => {
54
+ const defaultMessages = enGB;
55
+ // const { LogMessages: defaultMessages } = await import(
56
+ // `../localisation/en-GB.js`
57
+ // );
58
+ let localisedMessages = defaultMessages;
59
+
60
+ if (language === 'en-GB') {
61
+ // Using a variable import e.g. `import(`../localisation/${language}.js`);`
62
+ // does not play well with packaged executables
63
+ // So we have to hard code the import for each language individually
64
+ }
65
+ return {
66
+ messages: mergeWith(
67
+ localisedMessages,
68
+ defaultMessages,
69
+ (v, s) => v || s
70
+ ) as typeof defaultMessages,
71
+ Log: Logger,
72
+ };
73
+ };
@@ -1 +1 @@
1
- export const jsonFormatter = <T>(obj: T) => JSON.stringify(obj, null, 2);
1
+ export const jsonFormatter = <T>(obj: T) => JSON.stringify(obj, null, 2);
@@ -1,234 +1,234 @@
1
- /* eslint-disable no-console */
2
- import chalk from 'chalk';
3
- import dateFormat from 'dateformat';
4
- import deepCleaner from 'deep-cleaner';
5
- import ProgressBar from 'progress';
6
- import { tryStringify } from '.';
7
-
8
- type LogMethod = (content: string) => void;
9
- type LogErrorMethod = (content: string, err?: any) => void;
10
- type LogJsonMethod = (content: any, depth?: number, indent?: string) => void;
11
- type LogJsonDepthMethod = (content: any, depth: number) => void;
12
- type LogArrayMethod = (contentArray: string[]) => void;
13
- type LogErrorFunc = (
14
- err: any,
15
- msg?: string,
16
- level?: 'error' | 'critical'
17
- ) => void;
18
-
19
- export class Logger {
20
- static isUserTerminal = !!process.stdout.columns;
21
- static getPrefix = () => {
22
- return Logger.isUserTerminal
23
- ? Logger.infoText(`[cli]`)
24
- : `[${dateFormat(new Date(), 'dd/mm HH:MM:ss')}]`;
25
- };
26
- static errorText = chalk.bold.red;
27
- static warningText = chalk.keyword('orange');
28
- static successText = chalk.keyword('green');
29
- static helpText = chalk.blue;
30
- static highlightText = chalk.yellow;
31
- static infoText = chalk.keyword('grey');
32
- static standardText = chalk.keyword('white');
33
- static boldText = chalk.bold;
34
- static critical: LogMethod = content => {
35
- const message = `${Logger.getPrefix()} ${Logger.errorText(
36
- '[CRITICAL]'
37
- )} ${content}`;
38
- console.log(message);
39
- };
40
- static error: LogErrorMethod = (content, err) => {
41
- const message = `${Logger.getPrefix()} ${Logger.errorText(
42
- `${Logger.isUserTerminal ? '❌' : '[ERROR]'} ${content}${
43
- err ? `\n\n${JSON.stringify(err, null, 2)}` : ''
44
- }`
45
- )}\n`;
46
- if (progress.active) progress.current.interrupt(message);
47
- else console.log(message);
48
- };
49
- static warning: LogMethod = content => {
50
- // if (process.env.DEBUG === 'true') {
51
- const message = `${Logger.getPrefix()} ${Logger.warningText(
52
- `${Logger.isUserTerminal ? '⚠️ ' : '[WARN]'} ${content}`
53
- )}\n`;
54
- if (progress.active) progress.current.interrupt(message);
55
- else console.log(message);
56
- // }
57
- };
58
- static success: LogMethod = content => {
59
- const message = `${Logger.getPrefix()} ${Logger.successText(
60
- `${Logger.isUserTerminal ? '✅' : '[OK]'} ${content}`
61
- )}`;
62
- if (progress.active) progress.current.interrupt(message);
63
- else console.log(message);
64
- };
65
- static info: LogMethod = content => {
66
- const message = `${Logger.getPrefix()} ${
67
- Logger.isUserTerminal ? chalk.bgCyan(' ℹ ') : '[INFO]'
68
- } ${Logger.infoText(content)}`;
69
- if (progress.active) progress.current.interrupt(message);
70
- else console.log(message);
71
- };
72
- static help: LogMethod = content => {
73
- const message = `${Logger.getPrefix()} ${chalk.blue(
74
- `${Logger.isUserTerminal ? '⏩' : '[HELP]'} ${content}`
75
- )}\n`;
76
- if (progress.active) progress.current.interrupt(message);
77
- else console.log(message);
78
- };
79
- static standard: LogMethod = content => {
80
- const message = `${Logger.getPrefix()} ${
81
- Logger.isUserTerminal ? '◻️' : '[STD]'
82
- } \n${Logger.standardText(content)}`;
83
- if (progress.active) progress.current.interrupt(message);
84
- else console.log(message);
85
- progress.current.interrupt(message);
86
- };
87
- static json: LogJsonDepthMethod = (content, depth = 9) =>
88
- console.dir(deepCleaner(content), { colors: true, depth });
89
- static mixed: LogArrayMethod = contentArray =>
90
- console.log(`${Logger.getPrefix()} ${contentArray.join(' ')}`);
91
- static line = () =>
92
- Logger.raw(` ${Logger.infoText(`-------------------------------------`)}`);
93
-
94
- static object: LogJsonMethod = content => {
95
- for (const [key, value] of Object.entries(content)) {
96
- if (value && typeof value === 'object') {
97
- Logger.raw(` ${chalk.bold.grey(key)}:`);
98
- if (key === 'fields' && Array.isArray(value)) {
99
- for (const field of value || []) {
100
- Logger.raw(
101
- ` ${chalk.bold(field.id)}${
102
- field.id === content.entryTitleField
103
- ? '**'
104
- : field.validations.minCount?.value ||
105
- typeof field.validations.required?.message !== 'undefined'
106
- ? '*'
107
- : ''
108
- }: ${chalk.grey(
109
- `${field.dataType}${
110
- field.dataFormat
111
- ? `<${
112
- Array.isArray(
113
- field.validations.allowedFieldTypes?.fields
114
- )
115
- ? `composer[${field.validations.allowedFieldTypes.fields
116
- .map((f: any) => f.id)
117
- .join(' | ')}]`
118
- : field.dataFormat
119
- }${
120
- field.dataFormat === 'entry'
121
- ? `, ${field.validations.allowedContentTypes.contentTypes.join(
122
- ' | '
123
- )}`
124
- : ''
125
- }>`
126
- : ''
127
- }${
128
- field.validations.maxLength?.value
129
- ? `(${field.validations.maxLength.value})`
130
- : ''
131
- }`
132
- )}`
133
- );
134
- }
135
- } else if (key === 'groups' && Array.isArray(value)) {
136
- for (const group of value || []) {
137
- const description =
138
- Object.keys(group.description).length &&
139
- Object.values(group.description)?.[0];
140
- Logger.raw(
141
- ` ${chalk.bold(group.id)}${
142
- description
143
- ? `: ${chalk.grey(Object.values(group.description)?.[0])}`
144
- : ''
145
- }`
146
- );
147
- }
148
- } else {
149
- Logger.objectRecurse(value, 3, ' ');
150
- // for (const [innerkey, innervalue] of Object.entries(value)) {
151
- // if (innervalue && typeof innervalue === 'object') {
152
- // Logger.raw(` ${chalk.bold.grey(innerkey)}:`);
153
- // console.table(innervalue);
154
- // } else if (
155
- // typeof innervalue !== 'undefined' &&
156
- // innervalue !== null
157
- // ) {
158
- // Logger.raw(` ${chalk.bold.grey(innerkey)}: ${innervalue}`);
159
- // }
160
- // }
161
- }
162
- } else if (typeof value !== 'undefined' && value !== null) {
163
- const valueText =
164
- key === 'id' && typeof value === 'string'
165
- ? Logger.highlightText(value)
166
- : value;
167
- Logger.raw(` ${chalk.bold.grey(key)}: ${valueText}`);
168
- }
169
- }
170
- };
171
-
172
- static objectRecurse: LogJsonMethod = (content, depth = 3, indent = '') => {
173
- if (Array.isArray(content)) {
174
- for (const item of content) {
175
- if (item && typeof item === 'object') {
176
- if (Array.isArray(item) && depth > 3)
177
- Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
178
- else Logger.objectRecurse(item, depth + 1, `${indent} `);
179
- } else Logger.raw(`${indent}${item}`);
180
- }
181
- } else
182
- for (const [key, value] of Object.entries(content)) {
183
- if (Array.isArray(value)) {
184
- for (const item of value) {
185
- if (item && typeof item === 'object') {
186
- if (Array.isArray(item) && depth > 3)
187
- Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
188
- else Logger.objectRecurse(item, depth + 1, `${indent}`);
189
- } else {
190
- Logger.raw(`${indent} ${item}`);
191
- }
192
- }
193
- } else if (value && typeof value === 'object') {
194
- Logger.raw(`${indent}${chalk.bold.grey(key)}:`);
195
-
196
- Logger.objectRecurse(value, depth + 1, `${indent} `);
197
- // console.table(value);
198
- } else if (typeof value !== 'undefined' && value !== null) {
199
- Logger.raw(`${indent}${chalk.bold.grey(key)}: ${value}`);
200
- }
201
- }
202
- };
203
- static raw: LogMethod = (content: string) => {
204
- if (progress.active) progress.current.interrupt(content);
205
- else console.log(content);
206
- };
207
- }
208
-
209
- export const logError: LogErrorFunc = (
210
- err = new Error('Undefined error'),
211
- msg,
212
- level = 'error'
213
- ) => {
214
- Logger[level](msg || err.message || err?.data?.message || err.Message);
215
- (Array.isArray(err) ? err : [err]).map((error: AppError) => {
216
- if ('stack' in error) Logger.raw(` ${Logger.infoText(error.stack)}`);
217
- if ('data' in error)
218
- Logger.raw(` ${Logger.infoText(tryStringify(error.data))}`);
219
- });
220
- //Logger.line();
221
- return null;
222
- };
223
-
224
- export const progress = {
225
- active: false,
226
- done: () => new ProgressBar('', 0),
227
- colours: { green: '\u001b[42m \u001b[0m', red: '\u001b[41m \u001b[0m' },
228
- current: new ProgressBar(`:bar`, {
229
- complete: '=',
230
- incomplete: ' ',
231
- width: 20,
232
- total: 100,
233
- }),
234
- };
1
+ /* eslint-disable no-console */
2
+ import chalk from 'chalk';
3
+ import dateFormat from 'dateformat';
4
+ import deepCleaner from 'deep-cleaner';
5
+ import ProgressBar from 'progress';
6
+ import { tryStringify } from '.';
7
+
8
+ type LogMethod = (content: string) => void;
9
+ type LogErrorMethod = (content: string, err?: any) => void;
10
+ type LogJsonMethod = (content: any, depth?: number, indent?: string) => void;
11
+ type LogJsonDepthMethod = (content: any, depth: number) => void;
12
+ type LogArrayMethod = (contentArray: string[]) => void;
13
+ type LogErrorFunc = (
14
+ err: any,
15
+ msg?: string,
16
+ level?: 'error' | 'critical'
17
+ ) => void;
18
+
19
+ export class Logger {
20
+ static isUserTerminal = !!process.stdout.columns;
21
+ static getPrefix = () => {
22
+ return Logger.isUserTerminal
23
+ ? Logger.infoText(`[cli]`)
24
+ : `[${dateFormat(new Date(), 'dd/mm HH:MM:ss')}]`;
25
+ };
26
+ static errorText = chalk.bold.red;
27
+ static warningText = chalk.keyword('orange');
28
+ static successText = chalk.keyword('green');
29
+ static helpText = chalk.blue;
30
+ static highlightText = chalk.yellow;
31
+ static infoText = chalk.keyword('grey');
32
+ static standardText = chalk.keyword('white');
33
+ static boldText = chalk.bold;
34
+ static critical: LogMethod = content => {
35
+ const message = `${Logger.getPrefix()} ${Logger.errorText(
36
+ '[CRITICAL]'
37
+ )} ${content}`;
38
+ console.log(message);
39
+ };
40
+ static error: LogErrorMethod = (content, err) => {
41
+ const message = `${Logger.getPrefix()} ${Logger.errorText(
42
+ `${Logger.isUserTerminal ? '❌' : '[ERROR]'} ${content}${
43
+ err ? `\n\n${JSON.stringify(err, null, 2)}` : ''
44
+ }`
45
+ )}\n`;
46
+ if (progress.active) progress.current.interrupt(message);
47
+ else console.log(message);
48
+ };
49
+ static warning: LogMethod = content => {
50
+ // if (process.env.DEBUG === 'true') {
51
+ const message = `${Logger.getPrefix()} ${Logger.warningText(
52
+ `${Logger.isUserTerminal ? '⚠️ ' : '[WARN]'} ${content}`
53
+ )}\n`;
54
+ if (progress.active) progress.current.interrupt(message);
55
+ else console.log(message);
56
+ // }
57
+ };
58
+ static success: LogMethod = content => {
59
+ const message = `${Logger.getPrefix()} ${Logger.successText(
60
+ `${Logger.isUserTerminal ? '✅' : '[OK]'} ${content}`
61
+ )}`;
62
+ if (progress.active) progress.current.interrupt(message);
63
+ else console.log(message);
64
+ };
65
+ static info: LogMethod = content => {
66
+ const message = `${Logger.getPrefix()} ${
67
+ Logger.isUserTerminal ? chalk.bgCyan(' ℹ ') : '[INFO]'
68
+ } ${Logger.infoText(content)}`;
69
+ if (progress.active) progress.current.interrupt(message);
70
+ else console.log(message);
71
+ };
72
+ static help: LogMethod = content => {
73
+ const message = `${Logger.getPrefix()} ${chalk.blue(
74
+ `${Logger.isUserTerminal ? '⏩' : '[HELP]'} ${content}`
75
+ )}\n`;
76
+ if (progress.active) progress.current.interrupt(message);
77
+ else console.log(message);
78
+ };
79
+ static standard: LogMethod = content => {
80
+ const message = `${Logger.getPrefix()} ${
81
+ Logger.isUserTerminal ? '◻️' : '[STD]'
82
+ } \n${Logger.standardText(content)}`;
83
+ if (progress.active) progress.current.interrupt(message);
84
+ else console.log(message);
85
+ progress.current.interrupt(message);
86
+ };
87
+ static json: LogJsonDepthMethod = (content, depth = 9) =>
88
+ console.dir(deepCleaner(content), { colors: true, depth });
89
+ static mixed: LogArrayMethod = contentArray =>
90
+ console.log(`${Logger.getPrefix()} ${contentArray.join(' ')}`);
91
+ static line = () =>
92
+ Logger.raw(` ${Logger.infoText(`-------------------------------------`)}`);
93
+
94
+ static object: LogJsonMethod = content => {
95
+ for (const [key, value] of Object.entries(content)) {
96
+ if (value && typeof value === 'object') {
97
+ Logger.raw(` ${chalk.bold.grey(key)}:`);
98
+ if (key === 'fields' && Array.isArray(value)) {
99
+ for (const field of value || []) {
100
+ Logger.raw(
101
+ ` ${chalk.bold(field.id)}${
102
+ field.id === content.entryTitleField
103
+ ? '**'
104
+ : field.validations.minCount?.value ||
105
+ typeof field.validations.required?.message !== 'undefined'
106
+ ? '*'
107
+ : ''
108
+ }: ${chalk.grey(
109
+ `${field.dataType}${
110
+ field.dataFormat
111
+ ? `<${
112
+ Array.isArray(
113
+ field.validations.allowedFieldTypes?.fields
114
+ )
115
+ ? `composer[${field.validations.allowedFieldTypes.fields
116
+ .map((f: any) => f.id)
117
+ .join(' | ')}]`
118
+ : field.dataFormat
119
+ }${
120
+ field.dataFormat === 'entry'
121
+ ? `, ${field.validations.allowedContentTypes.contentTypes.join(
122
+ ' | '
123
+ )}`
124
+ : ''
125
+ }>`
126
+ : ''
127
+ }${
128
+ field.validations.maxLength?.value
129
+ ? `(${field.validations.maxLength.value})`
130
+ : ''
131
+ }`
132
+ )}`
133
+ );
134
+ }
135
+ } else if (key === 'groups' && Array.isArray(value)) {
136
+ for (const group of value || []) {
137
+ const description =
138
+ Object.keys(group.description).length &&
139
+ Object.values(group.description)?.[0];
140
+ Logger.raw(
141
+ ` ${chalk.bold(group.id)}${
142
+ description
143
+ ? `: ${chalk.grey(Object.values(group.description)?.[0])}`
144
+ : ''
145
+ }`
146
+ );
147
+ }
148
+ } else {
149
+ Logger.objectRecurse(value, 3, ' ');
150
+ // for (const [innerkey, innervalue] of Object.entries(value)) {
151
+ // if (innervalue && typeof innervalue === 'object') {
152
+ // Logger.raw(` ${chalk.bold.grey(innerkey)}:`);
153
+ // console.table(innervalue);
154
+ // } else if (
155
+ // typeof innervalue !== 'undefined' &&
156
+ // innervalue !== null
157
+ // ) {
158
+ // Logger.raw(` ${chalk.bold.grey(innerkey)}: ${innervalue}`);
159
+ // }
160
+ // }
161
+ }
162
+ } else if (typeof value !== 'undefined' && value !== null) {
163
+ const valueText =
164
+ key === 'id' && typeof value === 'string'
165
+ ? Logger.highlightText(value)
166
+ : value;
167
+ Logger.raw(` ${chalk.bold.grey(key)}: ${valueText}`);
168
+ }
169
+ }
170
+ };
171
+
172
+ static objectRecurse: LogJsonMethod = (content, depth = 3, indent = '') => {
173
+ if (Array.isArray(content)) {
174
+ for (const item of content) {
175
+ if (item && typeof item === 'object') {
176
+ if (Array.isArray(item) && depth > 3)
177
+ Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
178
+ else Logger.objectRecurse(item, depth + 1, `${indent} `);
179
+ } else Logger.raw(`${indent}${item}`);
180
+ }
181
+ } else
182
+ for (const [key, value] of Object.entries(content)) {
183
+ if (Array.isArray(value)) {
184
+ for (const item of value) {
185
+ if (item && typeof item === 'object') {
186
+ if (Array.isArray(item) && depth > 3)
187
+ Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
188
+ else Logger.objectRecurse(item, depth + 1, `${indent}`);
189
+ } else {
190
+ Logger.raw(`${indent} ${item}`);
191
+ }
192
+ }
193
+ } else if (value && typeof value === 'object') {
194
+ Logger.raw(`${indent}${chalk.bold.grey(key)}:`);
195
+
196
+ Logger.objectRecurse(value, depth + 1, `${indent} `);
197
+ // console.table(value);
198
+ } else if (typeof value !== 'undefined' && value !== null) {
199
+ Logger.raw(`${indent}${chalk.bold.grey(key)}: ${value}`);
200
+ }
201
+ }
202
+ };
203
+ static raw: LogMethod = (content: string) => {
204
+ if (progress.active) progress.current.interrupt(content);
205
+ else console.log(content);
206
+ };
207
+ }
208
+
209
+ export const logError: LogErrorFunc = (
210
+ err = new Error('Undefined error'),
211
+ msg,
212
+ level = 'error'
213
+ ) => {
214
+ Logger[level](msg || err.message || err?.data?.message || err.Message);
215
+ (Array.isArray(err) ? err : [err]).map((error: AppError) => {
216
+ if ('stack' in error) Logger.raw(` ${Logger.infoText(error.stack)}`);
217
+ if ('data' in error)
218
+ Logger.raw(` ${Logger.infoText(tryStringify(error.data))}`);
219
+ });
220
+ //Logger.line();
221
+ return null;
222
+ };
223
+
224
+ export const progress = {
225
+ active: false,
226
+ done: () => new ProgressBar('', 0),
227
+ colours: { green: '\u001b[42m \u001b[0m', red: '\u001b[41m \u001b[0m' },
228
+ current: new ProgressBar(`:bar`, {
229
+ complete: '=',
230
+ incomplete: ' ',
231
+ width: 20,
232
+ total: 100,
233
+ }),
234
+ };