contensis-cli 1.3.1-beta.0 → 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 (112) hide show
  1. package/README.md +78 -6
  2. package/dist/commands/copy.js +2 -2
  3. package/dist/commands/copy.js.map +2 -2
  4. package/dist/commands/create.js +1 -2
  5. package/dist/commands/create.js.map +1 -1
  6. package/dist/commands/globalOptions.js +16 -4
  7. package/dist/commands/globalOptions.js.map +2 -2
  8. package/dist/commands/import.js +1 -1
  9. package/dist/commands/import.js.map +2 -2
  10. package/dist/commands/index.js +4 -2
  11. package/dist/commands/index.js.map +2 -2
  12. package/dist/commands/list.js.map +1 -1
  13. package/dist/commands/login.js +1 -2
  14. package/dist/commands/login.js.map +1 -1
  15. package/dist/commands/push.js +102 -10
  16. package/dist/commands/push.js.map +3 -3
  17. package/dist/commands/remove.js +15 -4
  18. package/dist/commands/remove.js.map +2 -2
  19. package/dist/commands/set.js +2 -4
  20. package/dist/commands/set.js.map +1 -1
  21. package/dist/commands/update.js +70 -0
  22. package/dist/commands/update.js.map +7 -0
  23. package/dist/factories/RequestHandlerFactory.js +12 -5
  24. package/dist/factories/RequestHandlerFactory.js.map +2 -2
  25. package/dist/index.js +4 -0
  26. package/dist/index.js.map +1 -1
  27. package/dist/localisation/en-GB.js +19 -2
  28. package/dist/localisation/en-GB.js.map +2 -2
  29. package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js.map +1 -1
  30. package/dist/mappers/DevInit-to-CIWorkflow.js +11 -6
  31. package/dist/mappers/DevInit-to-CIWorkflow.js.map +1 -1
  32. package/dist/mappers/DevRequests-to-RequestHanderCliArgs.js +4 -2
  33. package/dist/mappers/DevRequests-to-RequestHanderCliArgs.js.map +1 -1
  34. package/dist/models/CliService.d.js.map +1 -1
  35. package/dist/providers/CredentialProvider.js +11 -4
  36. package/dist/providers/CredentialProvider.js.map +2 -2
  37. package/dist/providers/GitHubCliModuleProvider.js +8 -10
  38. package/dist/providers/GitHubCliModuleProvider.js.map +1 -1
  39. package/dist/providers/HttpProvider.js +5 -4
  40. package/dist/providers/HttpProvider.js.map +1 -1
  41. package/dist/providers/ManifestProvider.js +1 -4
  42. package/dist/providers/ManifestProvider.js.map +1 -1
  43. package/dist/providers/SessionCacheProvider.js +26 -8
  44. package/dist/providers/SessionCacheProvider.js.map +2 -2
  45. package/dist/providers/file-provider.js +13 -11
  46. package/dist/providers/file-provider.js.map +1 -1
  47. package/dist/services/ContensisAuthService.js +1 -2
  48. package/dist/services/ContensisAuthService.js.map +1 -1
  49. package/dist/services/ContensisCliService.js +194 -127
  50. package/dist/services/ContensisCliService.js.map +3 -3
  51. package/dist/services/ContensisDevService.js +15 -18
  52. package/dist/services/ContensisDevService.js.map +2 -2
  53. package/dist/services/ContensisRoleService.js +8 -10
  54. package/dist/services/ContensisRoleService.js.map +1 -1
  55. package/dist/shell.js +31 -15
  56. package/dist/shell.js.map +2 -2
  57. package/dist/util/api-ids.js.map +1 -1
  58. package/dist/util/console.printer.js +15 -17
  59. package/dist/util/console.printer.js.map +2 -2
  60. package/dist/util/csv.formatter.js +8 -15
  61. package/dist/util/csv.formatter.js.map +2 -2
  62. package/dist/util/diff.js +6 -4
  63. package/dist/util/diff.js.map +1 -1
  64. package/dist/util/dotenv.js +1 -2
  65. package/dist/util/dotenv.js.map +1 -1
  66. package/dist/util/error.js.map +1 -1
  67. package/dist/util/fetch.js +4 -0
  68. package/dist/util/fetch.js.map +1 -1
  69. package/dist/util/git.js +8 -8
  70. package/dist/util/git.js.map +1 -1
  71. package/dist/util/gitignore.js +4 -0
  72. package/dist/util/gitignore.js.map +1 -1
  73. package/dist/util/html.formatter.js +70 -0
  74. package/dist/util/html.formatter.js.map +7 -0
  75. package/dist/util/index.js +5 -1
  76. package/dist/util/index.js.map +2 -2
  77. package/dist/util/json.formatter.js +6 -4
  78. package/dist/util/json.formatter.js.map +1 -1
  79. package/dist/util/logger.js +47 -53
  80. package/dist/util/logger.js.map +2 -2
  81. package/dist/util/os.js +4 -0
  82. package/dist/util/os.js.map +1 -1
  83. package/dist/util/xml.formatter.js +4 -0
  84. package/dist/util/xml.formatter.js.map +1 -1
  85. package/dist/util/yaml.js +1 -2
  86. package/dist/util/yaml.js.map +1 -1
  87. package/dist/version.js +1 -1
  88. package/dist/version.js.map +1 -1
  89. package/esbuild.config.js +12 -16
  90. package/package.json +31 -32
  91. package/src/commands/copy.ts +3 -1
  92. package/src/commands/globalOptions.ts +10 -3
  93. package/src/commands/import.ts +2 -0
  94. package/src/commands/index.ts +4 -0
  95. package/src/commands/push.ts +125 -1
  96. package/src/commands/remove.ts +20 -0
  97. package/src/commands/update.ts +84 -0
  98. package/src/factories/RequestHandlerFactory.ts +1 -1
  99. package/src/localisation/en-GB.ts +16 -1
  100. package/src/models/CliService.d.ts +1 -1
  101. package/src/providers/CredentialProvider.ts +2 -2
  102. package/src/providers/SessionCacheProvider.ts +26 -2
  103. package/src/services/ContensisCliService.ts +187 -49
  104. package/src/services/ContensisDevService.ts +2 -2
  105. package/src/shell.ts +20 -9
  106. package/src/util/console.printer.ts +23 -19
  107. package/src/util/csv.formatter.ts +1 -1
  108. package/src/util/html.formatter.ts +52 -0
  109. package/src/util/index.ts +1 -1
  110. package/src/util/logger.ts +17 -16
  111. package/src/version.ts +1 -1
  112. package/tsconfig.json +1 -1
@@ -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) : ''}${
@@ -89,7 +89,7 @@ const determineMost = (chunk: string, items: string[]) => {
89
89
  items.forEach(item => {
90
90
  itemCount[item] = 0;
91
91
  });
92
- for (var i = 0; i < chunk.length; i++) {
92
+ for (let i = 0; i < chunk.length; i++) {
93
93
  if (chunk[i] === '"') ignoreString = !ignoreString;
94
94
  else if (!ignoreString && chunk[i] in itemCount) {
95
95
  currValue = ++itemCount[chunk[i]];
@@ -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
+ };
package/src/util/index.ts CHANGED
@@ -58,7 +58,7 @@ export const Logging = async (language = 'en-GB') => {
58
58
  // const { LogMessages: defaultMessages } = await import(
59
59
  // `../localisation/en-GB.js`
60
60
  // );
61
- let localisedMessages = defaultMessages;
61
+ const localisedMessages = defaultMessages;
62
62
 
63
63
  if (language === 'en-GB') {
64
64
  // Using a variable import e.g. `import(`../localisation/${language}.js`);`
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-console */
2
1
  import chalk from 'chalk';
3
2
  import dateFormat from 'dateformat';
4
3
  import deepCleaner from 'deep-cleaner';
@@ -56,10 +55,10 @@ export class Logger {
56
55
  if (progress.active) progress.current.interrupt(message);
57
56
  else console.log(message);
58
57
  };
59
- static warning: LogMethod = content => {
58
+ static warning: LogMethod = (content, newline = '\n') => {
60
59
  const message = `${Logger.getPrefix()} ${Logger.warningText(
61
60
  `${Logger.isUserTerminal ? '⚠️ ' : '[WARN]'} ${content}`
62
- )}\n`;
61
+ )}${newline}`;
63
62
  if (progress.active) progress.current.interrupt(message);
64
63
  else console.log(message);
65
64
  // }
@@ -120,9 +119,9 @@ export class Logger {
120
119
  field.id === content.entryTitleField
121
120
  ? '**'
122
121
  : field.validations.minCount?.value ||
123
- typeof field.validations.required?.message !== 'undefined'
124
- ? '*'
125
- : ''
122
+ typeof field.validations.required?.message !== 'undefined'
123
+ ? '*'
124
+ : ''
126
125
  }: ${chalk.grey(
127
126
  `${field.dataType}${
128
127
  field.dataFormat
@@ -203,16 +202,17 @@ export class Logger {
203
202
  if (item.length)
204
203
  Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
205
204
  else Logger.objectRecurse(item, depth + 1, `${indent} `);
206
- else
207
- Array.isArray(item)
208
- ? Logger.raw(
209
- `${indent}${chalk.grey(`[`)}${item.join(', ')}${chalk.grey(
210
- `]`
211
- )}`
212
- )
213
- : typeof item === 'object' && item
214
- ? Logger.objectRecurse(item, depth + 1, `${indent} `)
215
- : Logger.raw(`${indent}${item}`);
205
+ else {
206
+ if (Array.isArray(item))
207
+ Logger.raw(
208
+ `${indent}${chalk.grey(`[`)}${item.join(', ')}${chalk.grey(
209
+ `]`
210
+ )}`
211
+ );
212
+ else if (typeof item === 'object' && item)
213
+ Logger.objectRecurse(item, depth + 1, `${indent} `);
214
+ else Logger.raw(`${indent}${item}`);
215
+ }
216
216
  } else Logger.raw(`${indent}${item}`);
217
217
  }
218
218
  } else {
@@ -253,6 +253,7 @@ export class Logger {
253
253
  content: string,
254
254
  displayLength = 30,
255
255
  consoleWidth = process.stdout.columns,
256
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
256
257
  logMethod: Function = console.info
257
258
  ) => {
258
259
  if (consoleWidth) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.3.1-beta.0";
1
+ export const LIB_VERSION = "1.3.1-beta.10";
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "allowJs": true,
3
+ "allowJs": false,
4
4
  "module": "CommonJS",
5
5
  "esModuleInterop": true,
6
6
  "target": "esnext",