contensis-cli 1.3.1-beta.1 → 1.3.1-beta.10

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 (52) hide show
  1. package/README.md +77 -5
  2. package/dist/commands/copy.js +2 -2
  3. package/dist/commands/copy.js.map +2 -2
  4. package/dist/commands/globalOptions.js +13 -4
  5. package/dist/commands/globalOptions.js.map +2 -2
  6. package/dist/commands/import.js +1 -1
  7. package/dist/commands/import.js.map +2 -2
  8. package/dist/commands/index.js +4 -0
  9. package/dist/commands/index.js.map +2 -2
  10. package/dist/commands/push.js +89 -0
  11. package/dist/commands/push.js.map +3 -3
  12. package/dist/commands/remove.js +13 -0
  13. package/dist/commands/remove.js.map +2 -2
  14. package/dist/commands/update.js +70 -0
  15. package/dist/commands/update.js.map +7 -0
  16. package/dist/localisation/en-GB.js +11 -1
  17. package/dist/localisation/en-GB.js.map +2 -2
  18. package/dist/models/CliService.d.js.map +1 -1
  19. package/dist/providers/CredentialProvider.js.map +2 -2
  20. package/dist/providers/SessionCacheProvider.js +18 -0
  21. package/dist/providers/SessionCacheProvider.js.map +2 -2
  22. package/dist/services/ContensisCliService.js +139 -45
  23. package/dist/services/ContensisCliService.js.map +3 -3
  24. package/dist/shell.js +21 -9
  25. package/dist/shell.js.map +2 -2
  26. package/dist/util/console.printer.js +3 -1
  27. package/dist/util/console.printer.js.map +2 -2
  28. package/dist/util/html.formatter.js +70 -0
  29. package/dist/util/html.formatter.js.map +7 -0
  30. package/dist/util/logger.js +2 -3
  31. package/dist/util/logger.js.map +2 -2
  32. package/dist/version.js +1 -1
  33. package/dist/version.js.map +1 -1
  34. package/esbuild.config.js +3 -3
  35. package/package.json +28 -29
  36. package/src/commands/copy.ts +3 -1
  37. package/src/commands/globalOptions.ts +10 -3
  38. package/src/commands/import.ts +2 -0
  39. package/src/commands/index.ts +4 -0
  40. package/src/commands/push.ts +125 -1
  41. package/src/commands/remove.ts +20 -0
  42. package/src/commands/update.ts +84 -0
  43. package/src/localisation/en-GB.ts +16 -1
  44. package/src/models/CliService.d.ts +1 -1
  45. package/src/providers/CredentialProvider.ts +2 -2
  46. package/src/providers/SessionCacheProvider.ts +26 -2
  47. package/src/services/ContensisCliService.ts +255 -104
  48. package/src/shell.ts +20 -9
  49. package/src/util/console.printer.ts +23 -19
  50. package/src/util/html.formatter.ts +52 -0
  51. package/src/util/logger.ts +2 -2
  52. package/src/version.ts +1 -1
package/src/shell.ts CHANGED
@@ -14,6 +14,7 @@ import { LIB_VERSION } from './version';
14
14
  class ContensisShell {
15
15
  private currentEnvironment!: string;
16
16
  private emptyInputCounter: number = 0;
17
+ private cache!: SessionCache;
17
18
  private env!: EnvironmentCache;
18
19
  private firstStart = true;
19
20
  private userId: string = '';
@@ -22,12 +23,12 @@ class ContensisShell {
22
23
 
23
24
  private refreshEnvironment = () => {
24
25
  // Reload any persisted changes from the disk cache
25
- const {
26
- cache: { currentEnvironment = '', environments = {} },
27
- } = new ContensisCli([]);
26
+ const { cache } = new ContensisCli([]);
27
+ this.cache = cache; // read the cache to pre-load suggestions
28
28
  // console.log(`refreshing env w/${currentEnvironment}`);
29
- this.currentEnvironment = currentEnvironment;
30
- this.env = environments[currentEnvironment];
29
+ this.currentEnvironment = cache.currentEnvironment || '';
30
+ const environments = cache.environments || {};
31
+ this.env = environments[this.currentEnvironment];
31
32
 
32
33
  // Reload logging here to support changing language
33
34
  Logging('en-GB').then(({ messages, Log }) => {
@@ -128,12 +129,21 @@ class ContensisShell {
128
129
  },
129
130
  },
130
131
  'connect',
132
+ ...Object.keys(this.cache.environments || {}).map(
133
+ alias => `connect ${alias}`
134
+ ),
131
135
  'list envs',
136
+ 'remove env',
132
137
  'quit',
133
138
  ];
134
139
 
135
140
  if (currentEnvironment)
136
- availableCommands.push('login', 'list projects', 'set project');
141
+ availableCommands.push(
142
+ 'login',
143
+ 'list projects',
144
+ 'set project',
145
+ ...(this.env?.projects || []).map(project => `set project ${project}`)
146
+ );
137
147
  if (userId)
138
148
  availableCommands.push(
139
149
  'copy field',
@@ -176,6 +186,7 @@ class ContensisShell {
176
186
  'list roles',
177
187
  'list webhooks',
178
188
  'list workflows',
189
+ 'push asset',
179
190
  'push block',
180
191
  'remove components',
181
192
  'remove contenttypes',
@@ -189,7 +200,8 @@ class ContensisShell {
189
200
  'set role description',
190
201
  'set role assignments',
191
202
  'set role enabled',
192
- 'set role permissions'
203
+ 'set role permissions',
204
+ 'update field'
193
205
  );
194
206
 
195
207
  const prompt = inquirer.createPromptModule();
@@ -243,9 +255,8 @@ class ContensisShell {
243
255
  : JSON.stringify(ex, null, 2)
244
256
  }`
245
257
  );
246
- } finally {
247
- return this.contensisPrompt();
248
258
  }
259
+ return this.contensisPrompt();
249
260
  }
250
261
  })
251
262
  .catch((err: Error) => {
@@ -125,7 +125,7 @@ export const printEntriesMigrateResult = (
125
125
  showAll = false,
126
126
  showChanged = false,
127
127
  }: {
128
- action?: 'import' | 'delete';
128
+ action?: 'import' | 'update' | 'delete';
129
129
  showDiff?: boolean;
130
130
  showAll?: boolean;
131
131
  showChanged?: boolean;
@@ -138,7 +138,7 @@ export const printEntriesMigrateResult = (
138
138
  ) as [string, any]) {
139
139
  for (const [originalId, entryStatus] of Object.entries(entryRes) as [
140
140
  string,
141
- any
141
+ any,
142
142
  ][]) {
143
143
  if (
144
144
  showAll ||
@@ -191,17 +191,21 @@ export const printEntriesMigrateResult = (
191
191
  migrateResult.entries || {}
192
192
  ) as [string, any][]) {
193
193
  log.help(
194
- `${action} from project ${
195
- action === 'delete'
196
- ? log.warningText(currentProject)
197
- : `${log.highlightText(projectId)} to ${log.boldText(
198
- log.warningText(currentProject)
199
- )}`
200
- }`
194
+ action === 'update'
195
+ ? `update entries in project ${log.boldText(
196
+ log.warningText(currentProject)
197
+ )}`
198
+ : `${action}${
199
+ action === 'delete'
200
+ ? ` from project ${log.warningText(currentProject)}`
201
+ : `${projectId ? ` from project ${log.highlightText(projectId)}` : ''} to ${log.boldText(
202
+ log.warningText(currentProject)
203
+ )}`
204
+ }`
201
205
  );
202
206
  for (const [contentTypeId, count] of Object.entries(contentTypeCounts) as [
203
207
  string,
204
- number
208
+ number,
205
209
  ][]) {
206
210
  const isTotalCountRow = contentTypeId === 'totalCount';
207
211
  const migrateStatusAndCount =
@@ -227,8 +231,8 @@ export const printEntriesMigrateResult = (
227
231
  const changedColor = isTotalCountRow
228
232
  ? log.helpText
229
233
  : changedPercentage === '100'
230
- ? log.successText
231
- : log.warningText;
234
+ ? log.successText
235
+ : log.warningText;
232
236
 
233
237
  if (isTotalCountRow && 'nodes' in migrateResult) {
234
238
  printNodesMigrateResult(service, migrateResult, {
@@ -257,8 +261,8 @@ export const printEntriesMigrateResult = (
257
261
  isTotalCountRow
258
262
  ? `[to ${action}: ${noChangeOrTotalEntriesCount}]`
259
263
  : changedPercentage === '100'
260
- ? 'up to date'
261
- : `[needs update: ${100 - Number(changedPercentage)}%]`
264
+ ? 'up to date'
265
+ : `[needs update: ${100 - Number(changedPercentage)}%]`
262
266
  }`
263
267
  )
264
268
  }`
@@ -391,7 +395,7 @@ export const printModelMigrationAnalysis = (
391
395
  ) => {
392
396
  for (const [contentTypeId, model] of Object.entries(result) as [
393
397
  string,
394
- any
398
+ any,
395
399
  ][]) {
396
400
  let mainOutput = log.standardText(
397
401
  ` - ${contentTypeId}${
@@ -415,7 +419,7 @@ export const printModelMigrationAnalysis = (
415
419
  if (key === 'projects') {
416
420
  for (const [projectId, projectDetails] of Object.entries(details) as [
417
421
  string,
418
- any
422
+ any,
419
423
  ][]) {
420
424
  mainOutput += log.infoText(
421
425
  ` [${messages.migrate.status(projectDetails.status)(
@@ -460,7 +464,7 @@ export const printModelMigrationResult = (
460
464
  ) => {
461
465
  for (const [status, ids] of Object.entries(result) as [
462
466
  MigrateResultStatus,
463
- string[]
467
+ string[],
464
468
  ][]) {
465
469
  if (ids?.length) {
466
470
  if (status === 'errors') {
@@ -555,8 +559,8 @@ export const printNodeTreeOutput = (
555
559
  fullOutput || isRoot || !node.slug ? node.path : `/${node.slug}`
556
560
  )
557
561
  : fullOutput || isRoot || !node.slug
558
- ? node.path
559
- : `/${node.slug}`
562
+ ? node.path
563
+ : `/${node.slug}`
560
564
  )}${node.entry ? ` ${log.helpText(node.entry.sys.contentTypeId)}` : ''}${
561
565
  node.childCount ? ` +${node.childCount}` : ``
562
566
  } ${'displayName' in node ? log.infoText(node.displayName) : ''}${
@@ -0,0 +1,52 @@
1
+ import { flattenObject } from './json.formatter';
2
+
3
+ export const htmlFormatter = <T>(entries: T | T[], isDoc = true) => {
4
+ // Flatten the passed in object
5
+ const flatEntries = [] as any[];
6
+ if (Array.isArray(entries))
7
+ for (const entry of entries) {
8
+ flatEntries.push(flattenObject(entry));
9
+ }
10
+ else flatEntries.push(flattenObject(entries));
11
+
12
+ // Parse the flattened object to csv
13
+ // const csv = stringify(flatEntries, { header: true });
14
+ // Create an exhaustive list of columns from the entries array
15
+ const columns = new Set<string>(flatEntries.map(e => Object.keys(e)).flat());
16
+
17
+ let table = `<table id="contensis-cli-table"><thead><tr>`;
18
+ for (const column of columns) {
19
+ table += `<td>${column}</td>`;
20
+ }
21
+ table += `</tr></thead><tbody>`;
22
+ for (const row of flatEntries) {
23
+ table += `<tr>`;
24
+ for (const column of columns) {
25
+ const val = row[column];
26
+ table += `<td>${typeof val === 'undefined' ? '' : val}</td>`;
27
+ }
28
+ table += `</tr>`;
29
+ }
30
+ table += `</tbody></table>`;
31
+
32
+ if (isDoc)
33
+ table = `<html><head>${headTag()}</head><body>${table}${scriptTag()}</body></html>`;
34
+ return table;
35
+ };
36
+
37
+ const headTag = () => {
38
+ return `<link rel="stylesheet" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.css" />
39
+ <script
40
+ src="https://code.jquery.com/jquery-3.7.1.slim.min.js"
41
+ integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8="
42
+ crossorigin="anonymous"></script>
43
+ <script src="https://cdn.datatables.net/2.1.8/js/dataTables.js"></script>`;
44
+ };
45
+
46
+ const scriptTag = () => {
47
+ return `<script>
48
+ let table = new DataTable('#contensis-cli-table', {
49
+ pageLength: 50
50
+ });
51
+ </script>`;
52
+ };
@@ -55,10 +55,10 @@ export class Logger {
55
55
  if (progress.active) progress.current.interrupt(message);
56
56
  else console.log(message);
57
57
  };
58
- static warning: LogMethod = content => {
58
+ static warning: LogMethod = (content, newline = '\n') => {
59
59
  const message = `${Logger.getPrefix()} ${Logger.warningText(
60
60
  `${Logger.isUserTerminal ? '⚠️ ' : '[WARN]'} ${content}`
61
- )}\n`;
61
+ )}${newline}`;
62
62
  if (progress.active) progress.current.interrupt(message);
63
63
  else console.log(message);
64
64
  // }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.3.1-beta.1";
1
+ export const LIB_VERSION = "1.3.1-beta.10";