contensis-cli 1.3.1-beta.5 → 1.3.1-beta.7

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.
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var html_formatter_exports = {};
20
+ __export(html_formatter_exports, {
21
+ htmlFormatter: () => htmlFormatter
22
+ });
23
+ module.exports = __toCommonJS(html_formatter_exports);
24
+ var import_json = require("./json.formatter");
25
+ const htmlFormatter = (entries, isDoc = true) => {
26
+ const flatEntries = [];
27
+ if (Array.isArray(entries))
28
+ for (const entry of entries) {
29
+ flatEntries.push((0, import_json.flattenObject)(entry));
30
+ }
31
+ else flatEntries.push((0, import_json.flattenObject)(entries));
32
+ const columns = new Set(flatEntries.map((e) => Object.keys(e)).flat());
33
+ let table = `<table id="contensis-cli-table"><thead><tr>`;
34
+ for (const column of columns) {
35
+ table += `<td>${column}</td>`;
36
+ }
37
+ table += `</tr></thead><tbody>`;
38
+ for (const row of flatEntries) {
39
+ table += `<tr>`;
40
+ for (const column of columns) {
41
+ const val = row[column];
42
+ table += `<td>${typeof val === "undefined" ? "" : val}</td>`;
43
+ }
44
+ table += `</tr>`;
45
+ }
46
+ table += `</tbody></table>`;
47
+ if (isDoc)
48
+ table = `<html><head>${headTag()}</head><body>${table}${scriptTag()}</body></html>`;
49
+ return table;
50
+ };
51
+ const headTag = () => {
52
+ return `<link rel="stylesheet" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.css" />
53
+ <script
54
+ src="https://code.jquery.com/jquery-3.7.1.slim.min.js"
55
+ integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8="
56
+ crossorigin="anonymous"></script>
57
+ <script src="https://cdn.datatables.net/2.1.8/js/dataTables.js"></script>`;
58
+ };
59
+ const scriptTag = () => {
60
+ return `<script>
61
+ let table = new DataTable('#contensis-cli-table', {
62
+ pageLength: 50
63
+ });
64
+ </script>`;
65
+ };
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ htmlFormatter
69
+ });
70
+ //# sourceMappingURL=html.formatter.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/util/html.formatter.ts"],
4
+ "sourcesContent": ["import { flattenObject } from './json.formatter';\n\nexport const htmlFormatter = <T>(entries: T | T[], isDoc = true) => {\n // Flatten the passed in object\n const flatEntries = [] as any[];\n if (Array.isArray(entries))\n for (const entry of entries) {\n flatEntries.push(flattenObject(entry));\n }\n else flatEntries.push(flattenObject(entries));\n\n // Parse the flattened object to csv\n // const csv = stringify(flatEntries, { header: true });\n // Create an exhaustive list of columns from the entries array\n const columns = new Set<string>(flatEntries.map(e => Object.keys(e)).flat());\n\n let table = `<table id=\"contensis-cli-table\"><thead><tr>`;\n for (const column of columns) {\n table += `<td>${column}</td>`;\n }\n table += `</tr></thead><tbody>`;\n for (const row of flatEntries) {\n table += `<tr>`;\n for (const column of columns) {\n const val = row[column];\n table += `<td>${typeof val === 'undefined' ? '' : val}</td>`;\n }\n table += `</tr>`;\n }\n table += `</tbody></table>`;\n\n if (isDoc)\n table = `<html><head>${headTag()}</head><body>${table}${scriptTag()}</body></html>`;\n return table;\n};\n\nconst headTag = () => {\n return `<link rel=\"stylesheet\" href=\"https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.css\" />\n<script\n src=\"https://code.jquery.com/jquery-3.7.1.slim.min.js\"\n integrity=\"sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=\"\n crossorigin=\"anonymous\"></script>\n<script src=\"https://cdn.datatables.net/2.1.8/js/dataTables.js\"></script>`;\n};\n\nconst scriptTag = () => {\n return `<script>\nlet table = new DataTable('#contensis-cli-table', {\n pageLength: 50\n});\n</script>`;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA8B;AAEvB,MAAM,gBAAgB,CAAI,SAAkB,QAAQ,SAAS;AAElE,QAAM,cAAc,CAAC;AACrB,MAAI,MAAM,QAAQ,OAAO;AACvB,eAAW,SAAS,SAAS;AAC3B,kBAAY,SAAK,2BAAc,KAAK,CAAC;AAAA,IACvC;AAAA,MACG,aAAY,SAAK,2BAAc,OAAO,CAAC;AAK5C,QAAM,UAAU,IAAI,IAAY,YAAY,IAAI,OAAK,OAAO,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;AAE3E,MAAI,QAAQ;AACZ,aAAW,UAAU,SAAS;AAC5B,aAAS,OAAO,MAAM;AAAA,EACxB;AACA,WAAS;AACT,aAAW,OAAO,aAAa;AAC7B,aAAS;AACT,eAAW,UAAU,SAAS;AAC5B,YAAM,MAAM,IAAI,MAAM;AACtB,eAAS,OAAO,OAAO,QAAQ,cAAc,KAAK,GAAG;AAAA,IACvD;AACA,aAAS;AAAA,EACX;AACA,WAAS;AAET,MAAI;AACF,YAAQ,eAAe,QAAQ,CAAC,gBAAgB,KAAK,GAAG,UAAU,CAAC;AACrE,SAAO;AACT;AAEA,MAAM,UAAU,MAAM;AACpB,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAMT;AAEA,MAAM,YAAY,MAAM;AACtB,SAAO;AAAA;AAAA;AAAA;AAAA;AAKT;",
6
+ "names": []
7
+ }
package/dist/version.js CHANGED
@@ -21,7 +21,7 @@ __export(version_exports, {
21
21
  LIB_VERSION: () => LIB_VERSION
22
22
  });
23
23
  module.exports = __toCommonJS(version_exports);
24
- const LIB_VERSION = "1.3.1-beta.5";
24
+ const LIB_VERSION = "1.3.1-beta.7";
25
25
  // Annotate the CommonJS export names for ESM import in node:
26
26
  0 && (module.exports = {
27
27
  LIB_VERSION
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["export const LIB_VERSION = \"1.3.1-beta.5\";\n"],
4
+ "sourcesContent": ["export const LIB_VERSION = \"1.3.1-beta.7\";\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "contensis-cli",
3
- "version": "1.3.1-beta.5",
3
+ "version": "1.3.1-beta.7",
4
4
  "description": "A fully featured Contensis command line interface with a shell UI provides simple and intuitive ways to manage or profile your content in any NodeJS terminal.",
5
5
  "repository": "https://github.com/contensis/cli",
6
6
  "homepage": "https://github.com/contensis/cli/tree/main/packages/contensis-cli#readme",
@@ -40,7 +40,7 @@
40
40
  "jsonpath-mapper": "^1.1.0",
41
41
  "keytar": "^7.9.0",
42
42
  "lodash": "^4.17.21",
43
- "migratortron": "^1.0.0-beta.64",
43
+ "migratortron": "^1.0.0-beta.69",
44
44
  "nanospinner": "^1.1.0",
45
45
  "node-fetch": "^2.6.7",
46
46
  "parse-git-config": "^3.0.0",
@@ -60,8 +60,8 @@ const output = new Option(
60
60
 
61
61
  const format = new Option(
62
62
  '-f --format <format>',
63
- 'format output as csv, json, xml or table (default)'
64
- ).choices(['csv', 'json', 'xml', 'table']);
63
+ 'format output as csv, json, html, xml or default'
64
+ ).choices(['csv', 'json', 'html', 'xml', 'table']);
65
65
 
66
66
  /* Connect options */
67
67
  const alias = new Option(
@@ -183,7 +183,7 @@ export const noCache = new Option(
183
183
 
184
184
  export const noPublish = new Option(
185
185
  '--no-publish',
186
- 'don\'t publish created or updated entries'
186
+ "don't publish created or updated entries"
187
187
  );
188
188
 
189
189
  export const addConnectOptions = (program: Command) =>
@@ -1,7 +1,18 @@
1
1
  import { Command } from 'commander';
2
2
  import mapJson from 'jsonpath-mapper';
3
- import { PushBlockParams } from 'migratortron';
3
+ import { generateGuid, PushBlockParams } from 'migratortron';
4
+ import path from 'path';
5
+ import { Asset } from 'contensis-delivery-api';
4
6
  import { cliCommand } from '~/services/ContensisCliService';
7
+ import {
8
+ commit,
9
+ mapContensisOpts,
10
+ noPublish,
11
+ outputDetail,
12
+ saveEntries,
13
+ } from './globalOptions';
14
+ import { jsonFormatter } from '~/util/json.formatter';
15
+ import { cwdPath } from '~/providers/file-provider';
5
16
 
6
17
  export const makePushCommand = () => {
7
18
  const push = new Command()
@@ -11,6 +22,119 @@ export const makePushCommand = () => {
11
22
  .showHelpAfterError(true)
12
23
  .exitOverride();
13
24
 
25
+ push
26
+ .command('asset')
27
+ .description('push an asset')
28
+ .argument('<content-type-id>', 'the content type id of the asset to push')
29
+ .argument(
30
+ '<title>',
31
+ 'the title of the asset as it appears in the cms (use quotes)'
32
+ )
33
+ .argument(
34
+ '[description]',
35
+ 'the description or altText of the asset (use quotes)'
36
+ )
37
+ .option(
38
+ '-from --from-file <fromFile>',
39
+ 'the local file path of the source asset'
40
+ )
41
+ .option('-url --from-url <fromUrl>', 'the full url of the source asset')
42
+ .option(
43
+ '-to --target-file-path <targetFilePath>',
44
+ 'the file path in the cms project to push the asset to e.g. "/asset-library/"'
45
+ )
46
+ .option(
47
+ '-name --target-file-name <targetFileName>',
48
+ 'set the file name in the cms project'
49
+ )
50
+ .option('-i --id <id>', 'push the asset with a specific guid')
51
+ .addOption(commit)
52
+ .addOption(noPublish)
53
+ .addOption(outputDetail)
54
+ .addOption(saveEntries)
55
+ .usage('<content-type-id> <title> [description] [options]')
56
+ .addHelpText(
57
+ 'after',
58
+ `
59
+ Example call:
60
+ > push asset pdf "Example file" "An example of a PDF asset" --from-file example.pdf --target-file-path /asset-library/pdf/\n`
61
+ )
62
+ .action(
63
+ async (
64
+ contentTypeId: string,
65
+ title: string,
66
+ description: string,
67
+ opts
68
+ ) => {
69
+ const cli = cliCommand(
70
+ ['push', 'asset', contentTypeId, title, description],
71
+ opts,
72
+ mapContensisOpts({ preserveGuids: true, ...opts, id: undefined })
73
+ );
74
+ const mapSourceVars = {
75
+ contentTypeId,
76
+ title,
77
+ description,
78
+ ...opts,
79
+ };
80
+
81
+ const assetEntry: Asset = mapJson(mapSourceVars, {
82
+ entryTitle: 'title',
83
+ title: 'title',
84
+ entryDescription: 'description',
85
+ description: 'description',
86
+ altText: ({ contentTypeId, description }) =>
87
+ contentTypeId === 'image' ? description : undefined,
88
+ sys: {
89
+ dataFormat: () => 'asset',
90
+ contentTypeId: 'contentTypeId',
91
+ id: 'id',
92
+ isPublished: () => true, // can be overridden by !opts.publish
93
+ properties: {
94
+ filename: {
95
+ $path: ['targetFileName', 'fromFile', 'fromUrl'],
96
+ $formatting: (nameOrPath: string) => {
97
+ return path.basename(nameOrPath);
98
+ },
99
+ },
100
+ filePath: {
101
+ $path: 'targetFilePath',
102
+ $default: (_, { fromFile, fromUrl }) => {
103
+ const toPosixPath = (windowsPath: string) =>
104
+ windowsPath.replace(/^(\w):|\\+/g, '/$1');
105
+
106
+ return path.dirname(
107
+ toPosixPath(fromFile || fromUrl.split(':/')[1])
108
+ );
109
+ },
110
+ },
111
+ },
112
+ uri: {
113
+ $path: ['fromFile', 'fromUrl'],
114
+ $formatting: (from: string) =>
115
+ from?.startsWith('http') ? from : cwdPath(from),
116
+ },
117
+ },
118
+ });
119
+
120
+ if (!assetEntry.sys.id)
121
+ assetEntry.sys.id = generateGuid(
122
+ cli.currentEnv,
123
+ cli.currentProject,
124
+ `${assetEntry.sys.contentTypeId}-${assetEntry.sys.properties.filePath.replaceAll('/', '').toLowerCase()}-${assetEntry.sys.properties.filename.toLowerCase()}`
125
+ );
126
+
127
+ console.log(jsonFormatter(assetEntry));
128
+
129
+ await cli.ImportEntries({
130
+ commit: opts.commit,
131
+ logOutput: opts.outputDetail,
132
+ saveEntries: opts.saveEntries,
133
+ data: [assetEntry],
134
+ });
135
+ }
136
+ );
137
+
14
138
  push
15
139
  .command('block')
16
140
  .description('push a block')
@@ -9,7 +9,7 @@ export type CliUrls =
9
9
  }
10
10
  | undefined;
11
11
 
12
- export type OutputFormat = 'json' | 'csv' | 'xml';
12
+ export type OutputFormat = 'json' | 'csv' | 'html' | 'xml';
13
13
 
14
14
  export type OutputOptions = {
15
15
  format?: OutputFormat;
@@ -50,6 +50,7 @@ import {
50
50
  printNodesMigrateResult,
51
51
  } from '~/util/console.printer';
52
52
  import { csvFormatter } from '~/util/csv.formatter';
53
+ import { htmlFormatter } from '~/util/html.formatter';
53
54
  import { jsonFormatter, limitFields } from '~/util/json.formatter';
54
55
  import { xmlFormatter } from '~/util/xml.formatter';
55
56
  import { isDebug } from '~/util/debug';
@@ -126,6 +127,7 @@ class ContensisCli {
126
127
  ) {
127
128
  // console.log('args: ', JSON.stringify(args, null, 2));
128
129
 
130
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
129
131
  const [exe, script, verb = '', noun = '', ...restArgs] = args;
130
132
  this.verb = verb?.toLowerCase();
131
133
  this.noun = noun?.toLowerCase();
@@ -323,6 +325,7 @@ class ContensisCli {
323
325
  commit = false,
324
326
  fromFile,
325
327
  importDataType,
328
+ importData,
326
329
  }: {
327
330
  commit?: boolean;
328
331
  fromFile?: string;
@@ -333,10 +336,13 @@ class ContensisCli {
333
336
  | 'models'
334
337
  | 'nodes'
335
338
  | 'user-input';
339
+ importData?: any[];
336
340
  }) => {
337
- const source: 'contensis' | 'file' = fromFile ? 'file' : 'contensis';
341
+ const source: 'contensis' | 'file' =
342
+ fromFile || importData ? 'file' : 'contensis';
338
343
 
339
- const fileData = fromFile ? (await readFileAsJSON(fromFile)) || [] : [];
344
+ const fileData =
345
+ importData || (fromFile ? (await readFileAsJSON(fromFile)) || [] : []);
340
346
 
341
347
  if (typeof fileData === 'string')
342
348
  throw new Error(`Import file format must be of type JSON`);
@@ -1860,11 +1866,13 @@ class ContensisCli {
1860
1866
  fromFile,
1861
1867
  logOutput,
1862
1868
  saveEntries,
1869
+ data,
1863
1870
  }: {
1864
1871
  commit: boolean;
1865
- fromFile: string;
1872
+ fromFile?: string;
1866
1873
  logOutput: string;
1867
1874
  saveEntries: boolean;
1875
+ data?: any[];
1868
1876
  }) => {
1869
1877
  const { currentEnv, currentProject, log, messages } = this;
1870
1878
 
@@ -1872,6 +1880,7 @@ class ContensisCli {
1872
1880
  commit,
1873
1881
  fromFile,
1874
1882
  importDataType: 'entries',
1883
+ importData: data,
1875
1884
  });
1876
1885
 
1877
1886
  if (contensis) {
@@ -1902,7 +1911,10 @@ class ContensisCli {
1902
1911
  showDiff: logOutput === 'all' || logOutput === 'changes',
1903
1912
  showChanged: logOutput === 'changes',
1904
1913
  });
1905
- if (['all', 'changes'].includes(logOutput))
1914
+ if (
1915
+ ['all', 'changes'].includes(logOutput) &&
1916
+ nodes.migrateNodes.length
1917
+ )
1906
1918
  printNodeTreeOutput(
1907
1919
  this,
1908
1920
  {
@@ -2764,6 +2776,9 @@ class ContensisCli {
2764
2776
  } else if (format === 'csv') {
2765
2777
  log.raw('');
2766
2778
  log.raw(log.infoText(await csvFormatter(limitFields(obj, fields))));
2779
+ } else if (format === 'html') {
2780
+ log.raw('');
2781
+ log.raw(log.infoText(htmlFormatter(limitFields(obj, fields))));
2767
2782
  } else if (format === 'xml') {
2768
2783
  log.raw('');
2769
2784
  log.raw(log.infoText(xmlFormatter(limitFields(obj, fields))));
@@ -2778,6 +2793,8 @@ class ContensisCli {
2778
2793
  const isText = !tryParse(obj) && typeof obj === 'string';
2779
2794
  if (format === 'csv') {
2780
2795
  writeString = await csvFormatter(limitFields(obj, fields));
2796
+ } else if (format === 'html') {
2797
+ writeString = htmlFormatter(limitFields(obj, fields));
2781
2798
  } else if (format === 'xml') {
2782
2799
  writeString = xmlFormatter(limitFields(obj, fields));
2783
2800
  } else
@@ -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/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.3.1-beta.5";
1
+ export const LIB_VERSION = "1.3.1-beta.7";