contensis-cli 1.0.0-beta.6 → 1.0.0-beta.61

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 (71) hide show
  1. package/README.md +760 -75
  2. package/dist/commands/connect.js +3 -3
  3. package/dist/commands/connect.js.map +2 -2
  4. package/dist/commands/create.js +30 -10
  5. package/dist/commands/create.js.map +2 -2
  6. package/dist/commands/diff.js +57 -0
  7. package/dist/commands/diff.js.map +7 -0
  8. package/dist/commands/get.js +61 -12
  9. package/dist/commands/get.js.map +2 -2
  10. package/dist/commands/globalOptions.js +22 -17
  11. package/dist/commands/globalOptions.js.map +2 -2
  12. package/dist/commands/import.js +46 -11
  13. package/dist/commands/import.js.map +2 -2
  14. package/dist/commands/index.js +9 -1
  15. package/dist/commands/index.js.map +2 -2
  16. package/dist/commands/list.js +19 -8
  17. package/dist/commands/list.js.map +2 -2
  18. package/dist/commands/login.js +3 -3
  19. package/dist/commands/login.js.map +2 -2
  20. package/dist/commands/push.js +8 -4
  21. package/dist/commands/push.js.map +2 -2
  22. package/dist/commands/release.js +47 -0
  23. package/dist/commands/release.js.map +7 -0
  24. package/dist/commands/remove.js +40 -8
  25. package/dist/commands/remove.js.map +2 -2
  26. package/dist/commands/set.js +53 -12
  27. package/dist/commands/set.js.map +2 -2
  28. package/dist/localisation/en-GB.js +100 -48
  29. package/dist/localisation/en-GB.js.map +2 -2
  30. package/dist/providers/CredentialProvider.js +36 -7
  31. package/dist/providers/CredentialProvider.js.map +3 -3
  32. package/dist/providers/SessionCacheProvider.js +21 -1
  33. package/dist/providers/SessionCacheProvider.js.map +2 -2
  34. package/dist/providers/file-provider.js +8 -4
  35. package/dist/providers/file-provider.js.map +3 -3
  36. package/dist/services/ContensisCliService.js +640 -375
  37. package/dist/services/ContensisCliService.js.map +3 -3
  38. package/dist/shell.js +27 -10
  39. package/dist/shell.js.map +3 -3
  40. package/dist/util/console.printer.js +171 -55
  41. package/dist/util/console.printer.js.map +2 -2
  42. package/dist/util/index.js +5 -2
  43. package/dist/util/index.js.map +3 -3
  44. package/dist/util/logger.js +47 -16
  45. package/dist/util/logger.js.map +2 -2
  46. package/dist/version.js +1 -1
  47. package/dist/version.js.map +1 -1
  48. package/package.json +2 -2
  49. package/src/commands/connect.ts +3 -2
  50. package/src/commands/create.ts +37 -8
  51. package/src/commands/diff.ts +41 -0
  52. package/src/commands/get.ts +80 -5
  53. package/src/commands/globalOptions.ts +18 -17
  54. package/src/commands/import.ts +57 -7
  55. package/src/commands/index.ts +9 -1
  56. package/src/commands/list.ts +35 -9
  57. package/src/commands/login.ts +3 -2
  58. package/src/commands/push.ts +9 -2
  59. package/src/commands/release.ts +32 -0
  60. package/src/commands/remove.ts +50 -4
  61. package/src/commands/set.ts +65 -9
  62. package/src/localisation/en-GB.ts +146 -65
  63. package/src/providers/CredentialProvider.ts +39 -6
  64. package/src/providers/SessionCacheProvider.ts +29 -2
  65. package/src/providers/file-provider.ts +12 -4
  66. package/src/services/ContensisCliService.ts +789 -426
  67. package/src/shell.ts +31 -11
  68. package/src/util/console.printer.ts +240 -78
  69. package/src/util/index.ts +12 -6
  70. package/src/util/logger.ts +87 -18
  71. package/src/version.ts +1 -1
package/src/shell.ts CHANGED
@@ -1,13 +1,14 @@
1
- import path from 'path';
2
1
  import figlet from 'figlet';
3
2
  import inquirer from 'inquirer';
4
3
  import inquirerPrompt from 'inquirer-command-prompt';
5
4
  import commands from './commands';
6
5
  import { LogMessages } from './localisation/en-GB';
7
- import { logError, Logger } from './util/logger';
8
6
  import CredentialProvider from './providers/CredentialProvider';
7
+ import { appRootDir } from './providers/file-provider';
9
8
  import ContensisCli, { cliCommand } from './services/ContensisCliService';
10
9
  import { Logging } from './util';
10
+ import { logError, Logger } from './util/logger';
11
+ import { LIB_VERSION } from './version';
11
12
 
12
13
  class ContensisShell {
13
14
  private currentEnvironment!: string;
@@ -39,12 +40,11 @@ class ContensisShell {
39
40
  inquirerPrompt.setConfig({
40
41
  history: {
41
42
  save: true,
42
- folder: path.join(__dirname, '../'),
43
+ folder: appRootDir,
43
44
  limit: 100,
44
45
  blacklist: ['quit'],
45
46
  },
46
47
  });
47
- // inquirer.registerPrompt('command', inquirerPrompt);
48
48
 
49
49
  const { log, messages } = this;
50
50
 
@@ -64,7 +64,7 @@ class ContensisShell {
64
64
  return;
65
65
  }
66
66
  console.log(log.successText(data));
67
- console.log(log.infoText(messages.app.startup()));
67
+ console.log(log.infoText(messages.app.startup(LIB_VERSION)));
68
68
  console.log(log.helpText(messages.app.help()));
69
69
 
70
70
  this.start().catch(ex => log.error(ex));
@@ -72,8 +72,13 @@ class ContensisShell {
72
72
  );
73
73
  }
74
74
 
75
+ restart = async () => {
76
+ this.firstStart = false;
77
+ this.log.line(); // add a line so we can see where the shell has been restarted
78
+ await this.start();
79
+ };
80
+
75
81
  start = async () => {
76
- this.log.line();
77
82
  this.refreshEnvironment();
78
83
  this.userId = '';
79
84
  const { currentEnvironment, env, log, messages } = this;
@@ -98,7 +103,10 @@ class ContensisShell {
98
103
  silent: true,
99
104
  }
100
105
  );
101
- if (token) this.userId = env.lastUserId;
106
+ if (token) {
107
+ this.userId = env.lastUserId;
108
+ if (!env.currentProject) log.warning(messages.projects.tip());
109
+ }
102
110
  this.firstStart = false;
103
111
  this.refreshEnvironment();
104
112
  } else {
@@ -127,14 +135,20 @@ class ContensisShell {
127
135
  availableCommands.push('login', 'list projects', 'set project');
128
136
  if (userId)
129
137
  availableCommands.push(
138
+ 'create project',
139
+ 'diff models',
130
140
  'get block',
131
141
  'get block logs',
132
142
  'get contenttype',
133
143
  'get component',
134
144
  'get entries',
145
+ 'get model',
146
+ 'get project',
147
+ 'get version',
135
148
  'import contenttypes',
136
149
  'import components',
137
150
  'import entries',
151
+ 'import models',
138
152
  'list blocks',
139
153
  'list contenttypes',
140
154
  'list components',
@@ -143,10 +157,13 @@ class ContensisShell {
143
157
  'list webhooks',
144
158
  'create key',
145
159
  'push block',
160
+ 'release block',
146
161
  'remove key',
147
- 'remove entry',
162
+ 'remove entries',
148
163
  'remove contenttypes',
149
- 'remove components'
164
+ 'remove components',
165
+ 'set project name',
166
+ 'set project description'
150
167
  );
151
168
 
152
169
  const prompt = inquirer.createPromptModule();
@@ -168,7 +185,7 @@ class ContensisShell {
168
185
  return true;
169
186
  }
170
187
  },
171
- prefix: `${env?.currentProject || 'contensis'}`,
188
+ prefix: `${env?.currentProject || log.infoText('contensis')}`,
172
189
  short: true,
173
190
  },
174
191
  ])
@@ -221,7 +238,10 @@ class ContensisShell {
221
238
  let globalShell: ContensisShell;
222
239
 
223
240
  export const shell = () => {
224
- if (typeof process.argv?.[2] !== 'undefined') return { start() {} } as any;
241
+ // Return a benign function for shell().restart() when used in cli context
242
+ // as some commands need to restart the shell to show an updated prompt
243
+ // after successful connect / login / set project
244
+ if (typeof process.argv?.[2] !== 'undefined') return { restart() {} } as any;
225
245
  if (!globalShell) globalShell = new ContensisShell();
226
246
  return globalShell;
227
247
  };
@@ -1,6 +1,7 @@
1
1
  import dayjs from 'dayjs';
2
- import { BlockVersion, MigrateStatus } from 'migratortron';
2
+ import { BlockVersion, MigrateModelsResult, MigrateStatus } from 'migratortron';
3
3
  import ContensisCli from '~/services/ContensisCliService';
4
+ import { Logger } from './logger';
4
5
 
5
6
  const formatDate = (date: Date | string, format = 'DD/MM/YYYY HH:mm') =>
6
7
  dayjs(date).format(format);
@@ -104,57 +105,22 @@ export const printBlockVersion = (
104
105
  };
105
106
 
106
107
  export const printMigrateResult = (
107
- { log, messages, contensis, currentProject }: ContensisCli,
108
+ { log, messages, currentProject }: ContensisCli,
108
109
  migrateResult: any,
109
- { action = 'import' }: { action?: 'import' | 'delete' } = {}
110
+ {
111
+ action = 'import',
112
+ showDiff = false,
113
+ showAllEntries = false,
114
+ showChangedEntries = false,
115
+ }: {
116
+ action?: 'import' | 'delete';
117
+ showDiff?: boolean;
118
+ showAllEntries?: boolean;
119
+ showChangedEntries?: boolean;
120
+ } = {}
110
121
  ) => {
111
122
  console.log(``);
112
123
 
113
- if (action === 'import') {
114
- for (const [projectId, contentTypeCounts] of Object.entries(
115
- migrateResult.entries || {}
116
- ) as [string, any][]) {
117
- console.log(
118
- `import from project ${log.highlightText(projectId)} to ${log.boldText(
119
- log.successText(currentProject)
120
- )}`
121
- );
122
- for (const [contentTypeId, count] of Object.entries(
123
- contentTypeCounts
124
- ) as [string, number][]) {
125
- const entriesToMigrate =
126
- migrateResult.entriesToMigrate?.[projectId]?.[contentTypeId];
127
-
128
- console.log(
129
- ` - ${
130
- contentTypeId === 'totalCount'
131
- ? log.warningText(`${contentTypeId}: ${count}`)
132
- : log.helpText(`${contentTypeId}: ${count}`)
133
- } ${log.infoText`[existing: ${(
134
- ((migrateResult.existing?.[projectId]?.[contentTypeId] || 0) /
135
- count) *
136
- 100
137
- ).toFixed(0)}%]`} [${
138
- typeof entriesToMigrate !== 'number' ? `unchanged` : `to update`
139
- }: ${(
140
- ((typeof entriesToMigrate !== 'number'
141
- ? entriesToMigrate?.['no change'] || 0
142
- : entriesToMigrate) /
143
- count) *
144
- 100
145
- ).toFixed(0)}%]`
146
- );
147
- }
148
- console.log(``);
149
- }
150
- }
151
- if (
152
- contensis?.isPreview &&
153
- migrateResult.entriesToMigrate?.[currentProject]?.totalCount > 0 &&
154
- !migrateResult.errors
155
- ) {
156
- log.help(messages.entries.commitTip());
157
- }
158
124
  for (const [contentTypeId, entryRes] of Object.entries(
159
125
  migrateResult.entriesToMigrate.entryIds
160
126
  ) as [string, any]) {
@@ -162,42 +128,238 @@ export const printMigrateResult = (
162
128
  string,
163
129
  any
164
130
  ][]) {
131
+ if (
132
+ showAllEntries ||
133
+ (showChangedEntries &&
134
+ (
135
+ Object.entries(
136
+ Object.entries(entryStatus[currentProject])[0]
137
+ )[1][1] as any
138
+ ).status !== 'no change')
139
+ ) {
140
+ console.log(
141
+ log.infoText(
142
+ `${originalId} ${Object.entries(entryStatus || {})
143
+ .filter(x => x[0] !== 'entryTitle')
144
+ .map(([projectId, projectStatus]) => {
145
+ const [targetGuid, { status }] = (Object.entries(
146
+ projectStatus || {}
147
+ )?.[0] as [string, { status: MigrateStatus }]) || [
148
+ '',
149
+ { x: { status: undefined } },
150
+ ];
151
+ return `${messages.migrate.status(status)(`${status}`)}${
152
+ targetGuid !== originalId ? `-> ${targetGuid}` : ''
153
+ }`;
154
+ })}`
155
+ ) + ` ${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`
156
+ );
157
+
158
+ for (const [projectId, projectStatus] of Object.entries(
159
+ entryStatus
160
+ ).filter(([key]) => key !== 'entryTitle') as [string, any][]) {
161
+ const [targetGuid, { error, diff, status }] = Object.entries(
162
+ projectStatus
163
+ )[0] as [string, any];
164
+ if (error) log.error(error);
165
+ if (diff && showDiff) {
166
+ console.log(
167
+ ` ${log.highlightText(`diff:`)} ${log.infoText(
168
+ highlightDiffText(diff)
169
+ )}\n`
170
+ );
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+ if (showAllEntries || showChangedEntries) console.log(``);
177
+
178
+ for (const [projectId, contentTypeCounts] of Object.entries(
179
+ migrateResult.entries || {}
180
+ ) as [string, any][]) {
181
+ log.help(
182
+ `${action} from project ${
183
+ action === 'delete'
184
+ ? log.warningText(currentProject)
185
+ : `${log.highlightText(projectId)} to ${log.boldText(
186
+ log.warningText(currentProject)
187
+ )}`
188
+ }`
189
+ );
190
+ for (const [contentTypeId, count] of Object.entries(contentTypeCounts) as [
191
+ string,
192
+ number
193
+ ][]) {
194
+ const isTotalCountRow = contentTypeId === 'totalCount';
195
+ const migrateStatusAndCount =
196
+ migrateResult.entriesToMigrate[currentProject][contentTypeId];
197
+ const existingCount =
198
+ migrateResult.existing?.[currentProject]?.[contentTypeId] || 0;
199
+ const existingPercent = ((existingCount / count) * 100).toFixed(0);
200
+ const noChangeOrTotalEntriesCount =
201
+ typeof migrateStatusAndCount !== 'number'
202
+ ? migrateStatusAndCount?.['no change'] || 0
203
+ : migrateStatusAndCount;
204
+
205
+ const changedPercentage = (
206
+ (noChangeOrTotalEntriesCount / count) *
207
+ 100
208
+ ).toFixed(0);
209
+
210
+ const existingColor =
211
+ existingPercent === '0' || action === 'delete'
212
+ ? log.warningText
213
+ : log.infoText;
214
+
215
+ const changedColor = isTotalCountRow
216
+ ? log.helpText
217
+ : changedPercentage === '100'
218
+ ? log.successText
219
+ : log.warningText;
220
+
165
221
  console.log(
166
- log.infoText(
167
- `${originalId} [${Object.entries(entryStatus || {})
168
- .filter(x => x[0] !== 'entryTitle')
169
- .map(([projectId, projectStatus]) => {
170
- const [targetGuid, { status }] = (Object.entries(
171
- projectStatus || {}
172
- )?.[0] as [string, { status: MigrateStatus }]) || [
173
- '',
174
- { x: { status: undefined } },
175
- ];
176
- return `${messages.entries.migrateStatus(status)(
177
- `${projectId}: ${status}`
178
- )}${targetGuid !== originalId ? `-> ${targetGuid}` : ''}`;
179
- })}]`
180
- )
222
+ ` - ${
223
+ isTotalCountRow
224
+ ? log.highlightText(
225
+ `${contentTypeId}: ${noChangeOrTotalEntriesCount}`
226
+ )
227
+ : `${contentTypeId}: ${log.helpText(count)}`
228
+ }${
229
+ changedPercentage === '100' || isTotalCountRow
230
+ ? ''
231
+ : existingColor(` [existing: ${`${existingPercent}%`}]`)
232
+ }${
233
+ existingPercent === '0' || (action === 'import' && isTotalCountRow)
234
+ ? ''
235
+ : changedColor(
236
+ ` ${
237
+ isTotalCountRow
238
+ ? `[to ${action}: ${noChangeOrTotalEntriesCount}]`
239
+ : changedPercentage === '100'
240
+ ? 'up to date'
241
+ : `[needs update: ${100 - Number(changedPercentage)}%]`
242
+ }`
243
+ )
244
+ }`
245
+ );
246
+ }
247
+ }
248
+ if (migrateResult.errors?.length) {
249
+ console.log(
250
+ ` - ${log.errorText(`errors: ${migrateResult.errors.length}`)}\n`
251
+ );
252
+ for (const error of migrateResult.errors)
253
+ log.error(error.message || error, null, '');
254
+ }
255
+ };
256
+
257
+ const highlightDiffText = (str: string) => {
258
+ const addedRegex = new RegExp(/<<\+>>(.*?)<<\/\+>>/, 'g');
259
+ const removedRegex = new RegExp(/<<->>(.*?)<<\/->>/, 'g');
260
+ return str
261
+ .replace(addedRegex, match => {
262
+ return Logger.successText(
263
+ match.replace(/<<\+>>/g, '<+>').replace(/<<\/\+>>/g, '</+>')
264
+ );
265
+ })
266
+ .replace(removedRegex, match => {
267
+ return Logger.errorText(
268
+ match.replace(/<<->>/g, '<->').replace(/<<\/->>/g, '</->')
181
269
  );
182
- console.log(` ${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`);
270
+ });
271
+ };
183
272
 
184
- for (const [projectId, projectStatus] of Object.entries(
185
- entryStatus
186
- ).filter(([key]) => key !== 'entryTitle') as [string, any][]) {
187
- const [targetGuid, { error, diff, status }] = Object.entries(
188
- projectStatus
189
- )[0] as [string, any];
190
- if (error) log.error(error);
191
- if (diff) {
192
- console.log(
193
- ` ${messages.entries.migrateStatus(status)(status)} ${log.infoText(
194
- targetGuid
195
- )} ${log.infoText(contentTypeId)} ${log.infoText(projectId)}`
273
+ export const printModelMigrationAnalysis = (
274
+ { log, messages }: ContensisCli,
275
+ result: any = {}
276
+ ) => {
277
+ for (const [contentTypeId, model] of Object.entries(result) as [
278
+ string,
279
+ any
280
+ ][]) {
281
+ let mainOutput = log.standardText(` - ${contentTypeId}`);
282
+ let extraOutput = '';
283
+ let errorOutput = '';
284
+ let diffOutput = '';
285
+ for (const [key, details] of Object.entries(model) as [string, any][]) {
286
+ if (key === 'dependencies') {
287
+ extraOutput += log.infoText(
288
+ ` references: [${details?.join(', ')}]\n`
289
+ );
290
+ }
291
+ if (key === 'dependencyOf') {
292
+ extraOutput += log.infoText(
293
+ ` required by: [${details?.join(', ')}]\n`
294
+ );
295
+ }
296
+ if (key === 'projects') {
297
+ for (const [projectId, projectDetails] of Object.entries(details) as [
298
+ string,
299
+ any
300
+ ][]) {
301
+ mainOutput += log.infoText(
302
+ ` [${messages.migrate.status(projectDetails.status)(
303
+ `${projectId}: ${projectDetails.status}`
304
+ )}] v${projectDetails.versionNo}`
196
305
  );
197
- console.log(``);
198
- console.log(log.highlightText(diff));
306
+ if (projectDetails.diff)
307
+ diffOutput += ` ${log.highlightText(`diff:`)} ${log.infoText(
308
+ highlightDiffText(projectDetails.diff)
309
+ )}\n`;
310
+ if (projectDetails.error)
311
+ errorOutput += ` ${log.highlightText(
312
+ `error::`
313
+ )} ${log.errorText(projectDetails.error)}`;
199
314
  }
200
315
  }
201
316
  }
317
+ console.log(mainOutput);
318
+ if (extraOutput) {
319
+ const search = '\n';
320
+ const replace = '';
321
+ console.log(
322
+ extraOutput.replace(
323
+ new RegExp(search + '([^' + search + ']*)$'),
324
+ replace + '$1'
325
+ )
326
+ );
327
+ }
328
+ if (diffOutput) console.log(diffOutput);
329
+ if (errorOutput) console.log(errorOutput);
330
+ }
331
+ };
332
+
333
+ type MigrateResultSummary = MigrateModelsResult['']['contentTypes'];
334
+ type MigrateResultStatus = keyof MigrateResultSummary;
335
+
336
+ export const printModelMigrationResult = (
337
+ { log, messages }: ContensisCli,
338
+ result: MigrateResultSummary
339
+ ) => {
340
+ for (const [status, ids] of Object.entries(result) as [
341
+ MigrateResultStatus,
342
+ string[]
343
+ ][]) {
344
+ if (ids?.length) {
345
+ if (status === 'errors') {
346
+ const errors: [string, MappedError][] = ids as any;
347
+ log.raw(
348
+ ` - ${status}: [ ${messages.migrate.models.result(status)(
349
+ ids.map(id => id[0]).join(', ')
350
+ )} ]\n`
351
+ );
352
+ for (const [contentTypeId, error] of errors)
353
+ log.error(
354
+ `${log.highlightText(contentTypeId)}: ${error.message}`,
355
+ error
356
+ );
357
+ } else
358
+ log.raw(
359
+ ` - ${status}: [ ${messages.migrate.models.result(status)(
360
+ ids.join(', ')
361
+ )} ]`
362
+ );
363
+ }
202
364
  }
203
365
  };
package/src/util/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import mergeWith from 'lodash/mergeWith';
2
2
  import { Logger } from './logger';
3
+ import { LogMessages as enGB } from '../localisation/en-GB.js';
3
4
 
4
5
  export const isSharedSecret = (str = '') =>
5
6
  str.length > 80 && str.split('-').length === 3 ? str : undefined;
@@ -50,12 +51,17 @@ export const url = (alias: string, project: string) => {
50
51
  };
51
52
 
52
53
  export const Logging = async (language = 'en-GB') => {
53
- const { LogMessages: defaultMessages } = await import(
54
- `../localisation/en-GB.js`
55
- );
56
- const { LogMessages: localisedMessages } = await import(
57
- `../localisation/${language}.js`
58
- );
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
+ }
59
65
  return {
60
66
  messages: mergeWith(
61
67
  localisedMessages,
@@ -6,8 +6,9 @@ import ProgressBar from 'progress';
6
6
  import { tryStringify } from '.';
7
7
 
8
8
  type LogMethod = (content: string) => void;
9
- type LogErrorMethod = (content: string, err?: any) => void;
10
- type LogJsonMethod = (content: any) => void;
9
+ type LogErrorMethod = (content: string, err?: any, newline?: string) => void;
10
+ type LogJsonMethod = (content: any, depth?: number, indent?: string) => void;
11
+ type LogJsonDepthMethod = (content: any, depth: number) => void;
11
12
  type LogArrayMethod = (contentArray: string[]) => void;
12
13
  type LogErrorFunc = (
13
14
  err: any,
@@ -36,12 +37,12 @@ export class Logger {
36
37
  )} ${content}`;
37
38
  console.log(message);
38
39
  };
39
- static error: LogErrorMethod = (content, err) => {
40
+ static error: LogErrorMethod = (content, err, newline = '\n') => {
40
41
  const message = `${Logger.getPrefix()} ${Logger.errorText(
41
42
  `${Logger.isUserTerminal ? '❌' : '[ERROR]'} ${content}${
42
43
  err ? `\n\n${JSON.stringify(err, null, 2)}` : ''
43
44
  }`
44
- )}\n`;
45
+ )}${newline}`;
45
46
  if (progress.active) progress.current.interrupt(message);
46
47
  else console.log(message);
47
48
  };
@@ -83,7 +84,7 @@ export class Logger {
83
84
  else console.log(message);
84
85
  progress.current.interrupt(message);
85
86
  };
86
- static json: LogJsonMethod = (content, depth = 9) =>
87
+ static json: LogJsonDepthMethod = (content, depth = 9) =>
87
88
  console.dir(deepCleaner(content), { colors: true, depth });
88
89
  static mixed: LogArrayMethod = contentArray =>
89
90
  console.log(`${Logger.getPrefix()} ${contentArray.join(' ')}`);
@@ -97,7 +98,38 @@ export class Logger {
97
98
  if (key === 'fields' && Array.isArray(value)) {
98
99
  for (const field of value || []) {
99
100
  Logger.raw(
100
- ` ${chalk.bold(field.id)}: ${chalk.grey(field.dataType)}`
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
+ )}`
101
133
  );
102
134
  }
103
135
  } else if (key === 'groups' && Array.isArray(value)) {
@@ -114,22 +146,59 @@ export class Logger {
114
146
  );
115
147
  }
116
148
  } else {
117
- for (const [innerkey, innervalue] of Object.entries(value)) {
118
- if (innervalue && typeof innervalue === 'object') {
119
- Logger.raw(` ${chalk.bold.grey(innerkey)}:`);
120
- console.table(innervalue);
121
- } else if (
122
- typeof innervalue !== 'undefined' ||
123
- innervalue !== null
124
- ) {
125
- Logger.raw(` ${chalk.bold.grey(innerkey)}: ${innervalue}`);
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}`);
126
191
  }
127
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}`);
128
200
  }
129
- } else if (typeof value !== 'undefined' || value !== null) {
130
- Logger.raw(` ${chalk.bold.grey(key)}: ${value}`);
131
201
  }
132
- }
133
202
  };
134
203
  static raw: LogMethod = (content: string) => {
135
204
  if (progress.active) progress.current.interrupt(content);
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.0.0-beta.6";
1
+ export const LIB_VERSION = "1.0.0-beta.61";