contensis-cli 1.1.1-beta.2 → 1.1.1-beta.3
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.
- package/dist/commands/list.js +2 -2
- package/dist/commands/list.js.map +2 -2
- package/dist/providers/file-provider.js +1 -1
- package/dist/providers/file-provider.js.map +2 -2
- package/dist/services/ContensisCliService.js +44 -44
- package/dist/services/ContensisCliService.js.map +2 -2
- package/dist/util/csv.formatter.js +23 -7
- package/dist/util/csv.formatter.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/list.ts +2 -2
- package/src/providers/file-provider.ts +1 -1
- package/src/services/ContensisCliService.ts +45 -44
- package/src/util/csv.formatter.ts +27 -9
- package/src/version.ts +1 -1
|
@@ -23,9 +23,9 @@ __export(csv_formatter_exports, {
|
|
|
23
23
|
detectCsv: () => detectCsv
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(csv_formatter_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_csv = require("csv");
|
|
27
27
|
var import_json = require("./json.formatter");
|
|
28
|
-
const csvFormatter = (entries) => {
|
|
28
|
+
const csvFormatter = async (entries) => {
|
|
29
29
|
const flatEntries = [];
|
|
30
30
|
if (Array.isArray(entries))
|
|
31
31
|
for (const entry of entries) {
|
|
@@ -33,13 +33,29 @@ const csvFormatter = (entries) => {
|
|
|
33
33
|
}
|
|
34
34
|
else
|
|
35
35
|
flatEntries.push((0, import_json.flattenObject)(entries));
|
|
36
|
-
const csv = (
|
|
36
|
+
const csv = await new Promise((resolve, reject) => {
|
|
37
|
+
(0, import_csv.stringify)(flatEntries, { header: true }, (err, data) => {
|
|
38
|
+
if (err)
|
|
39
|
+
reject(err);
|
|
40
|
+
resolve(data);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
37
43
|
return csv;
|
|
38
44
|
};
|
|
39
|
-
const csvToJson = (data) => {
|
|
40
|
-
return (
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
const csvToJson = async (data) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
(0, import_csv.parse)(
|
|
48
|
+
data,
|
|
49
|
+
{
|
|
50
|
+
columns: true,
|
|
51
|
+
skip_empty_lines: true
|
|
52
|
+
},
|
|
53
|
+
(err, records) => {
|
|
54
|
+
if (err)
|
|
55
|
+
reject(err);
|
|
56
|
+
resolve(records);
|
|
57
|
+
}
|
|
58
|
+
);
|
|
43
59
|
});
|
|
44
60
|
};
|
|
45
61
|
const detectCsv = (chunk, opts) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/csv.formatter.ts"],
|
|
4
|
-
"sourcesContent": ["import { parse, stringify } from 'csv
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { parse, stringify } from 'csv';\n// import { parse, stringify } from 'csv/sync';\nimport { flattenObject } from './json.formatter';\n\nexport const csvFormatter = async <T>(entries: T | T[]) => {\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 const csv = await new Promise<string>((resolve, reject) => {\n stringify(flatEntries, { header: true }, (err, data) => {\n if (err) reject(err);\n resolve(data);\n });\n });\n return csv;\n};\n\nexport const csvToJson = async <T = any>(data: string): Promise<T[]> => {\n // return parse(data, {\n // columns: true,\n // skip_empty_lines: true,\n // });\n return new Promise((resolve, reject) => {\n parse(\n data,\n {\n columns: true,\n skip_empty_lines: true,\n },\n (err, records) => {\n if (err) reject(err);\n resolve(records);\n }\n );\n });\n};\n\nexport const detectCsv = (\n chunk: string,\n opts?: { delimiters?: string[]; newlines?: string[] }\n) => {\n opts = opts || {};\n if (Buffer.isBuffer(chunk)) chunk = chunk + '';\n const delimiters = opts.delimiters || [',', ';', '\\t', '|'];\n const newlines = opts.newlines || ['\\n', '\\r'];\n\n const lines = chunk.split(/[\\n\\r]+/g);\n\n const delimiter = determineMost(lines[0], delimiters);\n const newline = determineMost(chunk, newlines);\n\n if (!delimiter) return null;\n\n return {\n delimiter: delimiter,\n newline: newline,\n };\n};\n\nconst determineMost = (chunk: string, items: string[]) => {\n const itemCount = {} as any;\n let ignoreString = false;\n let maxValue = 0;\n let maxChar;\n let currValue;\n items.forEach(item => {\n itemCount[item] = 0;\n });\n for (var i = 0; i < chunk.length; i++) {\n if (chunk[i] === '\"') ignoreString = !ignoreString;\n else if (!ignoreString && chunk[i] in itemCount) {\n currValue = ++itemCount[chunk[i]];\n if (currValue > maxValue) {\n maxValue = currValue;\n maxChar = chunk[i];\n }\n }\n }\n return maxChar;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAiC;AAEjC,kBAA8B;AAEvB,MAAM,eAAe,OAAU,YAAqB;AAEzD,QAAM,cAAc,CAAC;AACrB,MAAI,MAAM,QAAQ,OAAO;AACvB,eAAW,SAAS,SAAS;AAC3B,kBAAY,SAAK,2BAAc,KAAK,CAAC;AAAA,IACvC;AAAA;AACG,gBAAY,SAAK,2BAAc,OAAO,CAAC;AAI5C,QAAM,MAAM,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AACzD,8BAAU,aAAa,EAAE,QAAQ,KAAK,GAAG,CAAC,KAAK,SAAS;AACtD,UAAI;AAAK,eAAO,GAAG;AACnB,cAAQ,IAAI;AAAA,IACd,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAEO,MAAM,YAAY,OAAgB,SAA+B;AAKtE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC;AAAA,MACE;AAAA,MACA;AAAA,QACE,SAAS;AAAA,QACT,kBAAkB;AAAA,MACpB;AAAA,MACA,CAAC,KAAK,YAAY;AAChB,YAAI;AAAK,iBAAO,GAAG;AACnB,gBAAQ,OAAO;AAAA,MACjB;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,MAAM,YAAY,CACvB,OACA,SACG;AACH,SAAO,QAAQ,CAAC;AAChB,MAAI,OAAO,SAAS,KAAK;AAAG,YAAQ,QAAQ;AAC5C,QAAM,aAAa,KAAK,cAAc,CAAC,KAAK,KAAK,KAAM,GAAG;AAC1D,QAAM,WAAW,KAAK,YAAY,CAAC,MAAM,IAAI;AAE7C,QAAM,QAAQ,MAAM,MAAM,UAAU;AAEpC,QAAM,YAAY,cAAc,MAAM,IAAI,UAAU;AACpD,QAAM,UAAU,cAAc,OAAO,QAAQ;AAE7C,MAAI,CAAC;AAAW,WAAO;AAEvB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,gBAAgB,CAAC,OAAe,UAAoB;AACxD,QAAM,YAAY,CAAC;AACnB,MAAI,eAAe;AACnB,MAAI,WAAW;AACf,MAAI;AACJ,MAAI;AACJ,QAAM,QAAQ,UAAQ;AACpB,cAAU,QAAQ;AAAA,EACpB,CAAC;AACD,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,QAAI,MAAM,OAAO;AAAK,qBAAe,CAAC;AAAA,aAC7B,CAAC,gBAAgB,MAAM,MAAM,WAAW;AAC/C,kBAAY,EAAE,UAAU,MAAM;AAC9B,UAAI,YAAY,UAAU;AACxB,mBAAW;AACX,kBAAU,MAAM;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
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.1.1-beta.
|
|
24
|
+
const LIB_VERSION = "1.1.1-beta.3";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
LIB_VERSION
|
package/dist/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["export const LIB_VERSION = \"1.1.1-beta.
|
|
4
|
+
"sourcesContent": ["export const LIB_VERSION = \"1.1.1-beta.3\";\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.1.1-beta.
|
|
3
|
+
"version": "1.1.1-beta.3",
|
|
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",
|
package/src/commands/list.ts
CHANGED
|
@@ -118,7 +118,7 @@ export const readFileAsJSON = async <T = any>(
|
|
|
118
118
|
try {
|
|
119
119
|
switch (detectedFile.type) {
|
|
120
120
|
case 'csv': {
|
|
121
|
-
const flatJson = csvToJson(detectedFile.contents);
|
|
121
|
+
const flatJson = await csvToJson(detectedFile.contents);
|
|
122
122
|
const unflattenedJson = flatJson.map(record => unflattenObject(record));
|
|
123
123
|
return unflattenedJson as T;
|
|
124
124
|
}
|
|
@@ -189,12 +189,12 @@ class ContensisCli {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
PrintEnvironments = () => {
|
|
192
|
+
PrintEnvironments = async () => {
|
|
193
193
|
const { log, messages } = this;
|
|
194
194
|
const { currentEnvironment, environments = {} } = this.cache;
|
|
195
195
|
const envKeys = Object.keys(environments);
|
|
196
196
|
log.success(messages.envs.found(envKeys.length));
|
|
197
|
-
this.HandleFormattingAndOutput(envKeys, () => {
|
|
197
|
+
await this.HandleFormattingAndOutput(envKeys, () => {
|
|
198
198
|
// print the envKeys to console
|
|
199
199
|
for (const env of envKeys) {
|
|
200
200
|
console.log(` - ${currentEnvironment === env ? '* ' : ''}${env}`);
|
|
@@ -563,7 +563,7 @@ class ContensisCli {
|
|
|
563
563
|
|
|
564
564
|
if (Array.isArray(projects)) {
|
|
565
565
|
// Print contensis version to console
|
|
566
|
-
this.HandleFormattingAndOutput(contensis.contensisVersion, () =>
|
|
566
|
+
await this.HandleFormattingAndOutput(contensis.contensisVersion, () =>
|
|
567
567
|
log.raw(log.highlightText(contensis.contensisVersion))
|
|
568
568
|
);
|
|
569
569
|
}
|
|
@@ -586,7 +586,7 @@ class ContensisCli {
|
|
|
586
586
|
);
|
|
587
587
|
if (token) {
|
|
588
588
|
// Print bearer token to console
|
|
589
|
-
this.HandleFormattingAndOutput(token, () =>
|
|
589
|
+
await this.HandleFormattingAndOutput(token, () =>
|
|
590
590
|
log.raw(log.highlightText(token))
|
|
591
591
|
);
|
|
592
592
|
}
|
|
@@ -625,7 +625,7 @@ class ContensisCli {
|
|
|
625
625
|
log.success(messages.projects.list());
|
|
626
626
|
log.raw('');
|
|
627
627
|
|
|
628
|
-
this.HandleFormattingAndOutput(projects, () => {
|
|
628
|
+
await this.HandleFormattingAndOutput(projects, () => {
|
|
629
629
|
// print the projects to console
|
|
630
630
|
for (const project of projects.sort((a, b) =>
|
|
631
631
|
a.id.localeCompare(b.id)
|
|
@@ -679,7 +679,7 @@ class ContensisCli {
|
|
|
679
679
|
|
|
680
680
|
if (foundProject) {
|
|
681
681
|
log.raw('');
|
|
682
|
-
this.HandleFormattingAndOutput(foundProject, log.object);
|
|
682
|
+
await this.HandleFormattingAndOutput(foundProject, log.object);
|
|
683
683
|
}
|
|
684
684
|
|
|
685
685
|
if (projectsErr) {
|
|
@@ -744,7 +744,7 @@ class ContensisCli {
|
|
|
744
744
|
|
|
745
745
|
if (Array.isArray(apiKeys)) {
|
|
746
746
|
log.success(messages.keys.list(currentEnv));
|
|
747
|
-
this.HandleFormattingAndOutput(apiKeys, () => {
|
|
747
|
+
await this.HandleFormattingAndOutput(apiKeys, () => {
|
|
748
748
|
// print the keys to console
|
|
749
749
|
for (const {
|
|
750
750
|
id,
|
|
@@ -833,7 +833,7 @@ class ContensisCli {
|
|
|
833
833
|
|
|
834
834
|
if (!roles.length) log.help(messages.roles.noneExist());
|
|
835
835
|
|
|
836
|
-
this.HandleFormattingAndOutput(roles, () => {
|
|
836
|
+
await this.HandleFormattingAndOutput(roles, () => {
|
|
837
837
|
// print the roles to console
|
|
838
838
|
for (const {
|
|
839
839
|
id,
|
|
@@ -916,7 +916,7 @@ class ContensisCli {
|
|
|
916
916
|
|
|
917
917
|
const role = findByIdOrName(roles, roleNameOrId);
|
|
918
918
|
|
|
919
|
-
if (role) this.HandleFormattingAndOutput(role, log.object);
|
|
919
|
+
if (role) await this.HandleFormattingAndOutput(role, log.object);
|
|
920
920
|
else log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
921
921
|
}
|
|
922
922
|
|
|
@@ -939,7 +939,7 @@ class ContensisCli {
|
|
|
939
939
|
messages.roles.created(currentEnv, role.id || role.name || '')
|
|
940
940
|
);
|
|
941
941
|
|
|
942
|
-
this.HandleFormattingAndOutput(created, log.object);
|
|
942
|
+
await this.HandleFormattingAndOutput(created, log.object);
|
|
943
943
|
|
|
944
944
|
log.help(messages.roles.tip());
|
|
945
945
|
return role.id;
|
|
@@ -979,7 +979,7 @@ class ContensisCli {
|
|
|
979
979
|
else {
|
|
980
980
|
log.success(messages.roles.set());
|
|
981
981
|
|
|
982
|
-
this.HandleFormattingAndOutput(updated, log.object);
|
|
982
|
+
await this.HandleFormattingAndOutput(updated, log.object);
|
|
983
983
|
}
|
|
984
984
|
} else {
|
|
985
985
|
// Role does not exist
|
|
@@ -1043,7 +1043,7 @@ class ContensisCli {
|
|
|
1043
1043
|
const stringFromLanguageObject = (o: { [lang: string]: string }) =>
|
|
1044
1044
|
Object.values(o || {})?.[0];
|
|
1045
1045
|
|
|
1046
|
-
this.HandleFormattingAndOutput(workflows, () => {
|
|
1046
|
+
await this.HandleFormattingAndOutput(workflows, () => {
|
|
1047
1047
|
// print the workflows to console
|
|
1048
1048
|
// log.object(workflows);
|
|
1049
1049
|
for (const {
|
|
@@ -1106,7 +1106,8 @@ class ContensisCli {
|
|
|
1106
1106
|
|
|
1107
1107
|
const workflow = findByIdOrName(workflows, workflowNameOrId);
|
|
1108
1108
|
|
|
1109
|
-
if (workflow)
|
|
1109
|
+
if (workflow)
|
|
1110
|
+
await this.HandleFormattingAndOutput(workflow, log.object);
|
|
1110
1111
|
else
|
|
1111
1112
|
log.error(messages.workflows.failedGet(currentEnv, workflowNameOrId));
|
|
1112
1113
|
}
|
|
@@ -1128,7 +1129,7 @@ class ContensisCli {
|
|
|
1128
1129
|
if (created) {
|
|
1129
1130
|
log.success(messages.projects.created(currentEnv, project.id));
|
|
1130
1131
|
|
|
1131
|
-
this.HandleFormattingAndOutput(created, () => {
|
|
1132
|
+
await this.HandleFormattingAndOutput(created, () => {
|
|
1132
1133
|
// set the CLI project to the newly created project
|
|
1133
1134
|
this.SetProject(project.id);
|
|
1134
1135
|
// print all the projects to console
|
|
@@ -1156,7 +1157,7 @@ class ContensisCli {
|
|
|
1156
1157
|
if (updated) {
|
|
1157
1158
|
log.success(messages.projects.updated(currentEnv, currentProject));
|
|
1158
1159
|
|
|
1159
|
-
this.HandleFormattingAndOutput(updated, log.object);
|
|
1160
|
+
await this.HandleFormattingAndOutput(updated, log.object);
|
|
1160
1161
|
return updated.id;
|
|
1161
1162
|
}
|
|
1162
1163
|
|
|
@@ -1216,7 +1217,7 @@ class ContensisCli {
|
|
|
1216
1217
|
|
|
1217
1218
|
if (Array.isArray(returnModels)) {
|
|
1218
1219
|
log.success(messages.models.list(currentProject));
|
|
1219
|
-
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
1220
|
+
await this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
1220
1221
|
// print the content models to console
|
|
1221
1222
|
for (const model of returnModels) {
|
|
1222
1223
|
log.raw('');
|
|
@@ -1230,7 +1231,7 @@ class ContensisCli {
|
|
|
1230
1231
|
);
|
|
1231
1232
|
log.raw('');
|
|
1232
1233
|
if (models?.length) {
|
|
1233
|
-
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
1234
|
+
await this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
1234
1235
|
// print the content models to console
|
|
1235
1236
|
for (const model of models) {
|
|
1236
1237
|
const components = model.components?.length || 0;
|
|
@@ -1300,7 +1301,7 @@ class ContensisCli {
|
|
|
1300
1301
|
|
|
1301
1302
|
if (migrateErr) logError(migrateErr);
|
|
1302
1303
|
else
|
|
1303
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
1304
|
+
await this.HandleFormattingAndOutput(result, () => {
|
|
1304
1305
|
// print the results to console
|
|
1305
1306
|
if (!commit) {
|
|
1306
1307
|
log.raw(log.boldText(`\nContent types:`));
|
|
@@ -1340,7 +1341,7 @@ class ContensisCli {
|
|
|
1340
1341
|
|
|
1341
1342
|
if (Array.isArray(contentTypes)) {
|
|
1342
1343
|
log.success(messages.contenttypes.list(currentProject));
|
|
1343
|
-
this.HandleFormattingAndOutput(contentTypes, () => {
|
|
1344
|
+
await this.HandleFormattingAndOutput(contentTypes, () => {
|
|
1344
1345
|
// print the content types to console
|
|
1345
1346
|
for (const contentType of contentTypes) {
|
|
1346
1347
|
const fieldsLength = contentType.fields?.length || 0;
|
|
@@ -1371,7 +1372,7 @@ class ContensisCli {
|
|
|
1371
1372
|
messages.contenttypes.get(currentProject, contentType.id)
|
|
1372
1373
|
);
|
|
1373
1374
|
// print the content type to console
|
|
1374
|
-
this.HandleFormattingAndOutput(contentType, log.object);
|
|
1375
|
+
await this.HandleFormattingAndOutput(contentType, log.object);
|
|
1375
1376
|
} else {
|
|
1376
1377
|
log.error(
|
|
1377
1378
|
messages.contenttypes.failedGet(currentProject, contentTypeId)
|
|
@@ -1407,7 +1408,7 @@ class ContensisCli {
|
|
|
1407
1408
|
)
|
|
1408
1409
|
);
|
|
1409
1410
|
// print the results to console
|
|
1410
|
-
this.HandleFormattingAndOutput(result, () =>
|
|
1411
|
+
await this.HandleFormattingAndOutput(result, () =>
|
|
1411
1412
|
log.object(jsonFormatter(result))
|
|
1412
1413
|
);
|
|
1413
1414
|
}
|
|
@@ -1460,7 +1461,7 @@ class ContensisCli {
|
|
|
1460
1461
|
)
|
|
1461
1462
|
);
|
|
1462
1463
|
// print the content type to console
|
|
1463
|
-
this.HandleFormattingAndOutput(contentType, () => {});
|
|
1464
|
+
await this.HandleFormattingAndOutput(contentType, () => {});
|
|
1464
1465
|
}
|
|
1465
1466
|
}
|
|
1466
1467
|
}
|
|
@@ -1497,7 +1498,7 @@ class ContensisCli {
|
|
|
1497
1498
|
if (err) log.error(err.message, err);
|
|
1498
1499
|
if (result)
|
|
1499
1500
|
// print the content type to console
|
|
1500
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
1501
|
+
await this.HandleFormattingAndOutput(result, () => {
|
|
1501
1502
|
log.success(
|
|
1502
1503
|
`Queried models ${log.infoText(
|
|
1503
1504
|
`"${result.query.modelIds?.join(', ')}"`
|
|
@@ -1525,7 +1526,7 @@ class ContensisCli {
|
|
|
1525
1526
|
if (Array.isArray(components)) {
|
|
1526
1527
|
log.success(messages.components.list(currentProject));
|
|
1527
1528
|
|
|
1528
|
-
this.HandleFormattingAndOutput(components, () => {
|
|
1529
|
+
await this.HandleFormattingAndOutput(components, () => {
|
|
1529
1530
|
// print the components to console
|
|
1530
1531
|
for (const component of components) {
|
|
1531
1532
|
const fieldsLength = component.fields?.length || 0;
|
|
@@ -1554,7 +1555,7 @@ class ContensisCli {
|
|
|
1554
1555
|
if (component) {
|
|
1555
1556
|
log.success(messages.components.get(currentProject, component.id));
|
|
1556
1557
|
// print the component to console
|
|
1557
|
-
this.HandleFormattingAndOutput(component, log.object);
|
|
1558
|
+
await this.HandleFormattingAndOutput(component, log.object);
|
|
1558
1559
|
} else {
|
|
1559
1560
|
log.error(messages.components.failedGet(currentProject, componentId));
|
|
1560
1561
|
}
|
|
@@ -1591,7 +1592,7 @@ class ContensisCli {
|
|
|
1591
1592
|
)
|
|
1592
1593
|
);
|
|
1593
1594
|
// print the results to console
|
|
1594
|
-
this.HandleFormattingAndOutput(result, () =>
|
|
1595
|
+
await this.HandleFormattingAndOutput(result, () =>
|
|
1595
1596
|
log.info(jsonFormatter(result))
|
|
1596
1597
|
);
|
|
1597
1598
|
}
|
|
@@ -1644,7 +1645,7 @@ class ContensisCli {
|
|
|
1644
1645
|
)
|
|
1645
1646
|
);
|
|
1646
1647
|
// print the component to console
|
|
1647
|
-
this.HandleFormattingAndOutput(component, () => {});
|
|
1648
|
+
await this.HandleFormattingAndOutput(component, () => {});
|
|
1648
1649
|
}
|
|
1649
1650
|
}
|
|
1650
1651
|
}
|
|
@@ -1665,7 +1666,7 @@ class ContensisCli {
|
|
|
1665
1666
|
}
|
|
1666
1667
|
const [err, result] = await contensis.DeleteEntries();
|
|
1667
1668
|
if (result)
|
|
1668
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
1669
|
+
await this.HandleFormattingAndOutput(result, () => {
|
|
1669
1670
|
// print the migrateResult to console
|
|
1670
1671
|
printEntriesMigrateResult(this, result, {
|
|
1671
1672
|
action: 'delete',
|
|
@@ -1701,7 +1702,7 @@ class ContensisCli {
|
|
|
1701
1702
|
if (contensis) {
|
|
1702
1703
|
log.line();
|
|
1703
1704
|
const entries = await contensis.GetEntries({ withDependents });
|
|
1704
|
-
this.HandleFormattingAndOutput(entries, () =>
|
|
1705
|
+
await this.HandleFormattingAndOutput(entries, () =>
|
|
1705
1706
|
// print the entries to console
|
|
1706
1707
|
logEntitiesTable({
|
|
1707
1708
|
entries,
|
|
@@ -1744,7 +1745,7 @@ class ContensisCli {
|
|
|
1744
1745
|
|
|
1745
1746
|
if (err) logError(err);
|
|
1746
1747
|
else
|
|
1747
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
1748
|
+
await this.HandleFormattingAndOutput(result, () => {
|
|
1748
1749
|
// print the migrateResult to console
|
|
1749
1750
|
printEntriesMigrateResult(this, result, {
|
|
1750
1751
|
showAll: logOutput === 'all',
|
|
@@ -1799,7 +1800,7 @@ class ContensisCli {
|
|
|
1799
1800
|
|
|
1800
1801
|
log.success(messages.nodes.get(currentProject, rootPath, depth));
|
|
1801
1802
|
|
|
1802
|
-
this.HandleFormattingAndOutput(nodes, () => {
|
|
1803
|
+
await this.HandleFormattingAndOutput(nodes, () => {
|
|
1803
1804
|
// print the nodes to console
|
|
1804
1805
|
log.object({ ...root, children: undefined, language: undefined });
|
|
1805
1806
|
printNodeTreeOutput(this, root);
|
|
@@ -1843,7 +1844,7 @@ class ContensisCli {
|
|
|
1843
1844
|
|
|
1844
1845
|
if (err) log.raw(``);
|
|
1845
1846
|
else
|
|
1846
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
1847
|
+
await this.HandleFormattingAndOutput(result, () => {
|
|
1847
1848
|
// print the migrateResult to console
|
|
1848
1849
|
printNodeTreeOutput(this, migrateTree, logOutput, logLimit);
|
|
1849
1850
|
printNodesMigrateResult(this, result, {
|
|
@@ -1912,7 +1913,7 @@ class ContensisCli {
|
|
|
1912
1913
|
}
|
|
1913
1914
|
const [err, result] = await contensis.DeleteNodes();
|
|
1914
1915
|
if (result) {
|
|
1915
|
-
this.HandleFormattingAndOutput(result, () => {
|
|
1916
|
+
await this.HandleFormattingAndOutput(result, () => {
|
|
1916
1917
|
// print the migrateResult to console
|
|
1917
1918
|
printNodeTreeOutput(
|
|
1918
1919
|
this,
|
|
@@ -1969,7 +1970,7 @@ class ContensisCli {
|
|
|
1969
1970
|
log.success(messages.webhooks.list(currentEnv));
|
|
1970
1971
|
if (!webhooks?.length) log.warning(messages.webhooks.noneExist());
|
|
1971
1972
|
else {
|
|
1972
|
-
this.HandleFormattingAndOutput(filteredResults, () => {
|
|
1973
|
+
await this.HandleFormattingAndOutput(filteredResults, () => {
|
|
1973
1974
|
// print the keys to console
|
|
1974
1975
|
for (const {
|
|
1975
1976
|
id,
|
|
@@ -2047,7 +2048,7 @@ class ContensisCli {
|
|
|
2047
2048
|
const [err, blocks] = await contensis.blocks.GetBlocks();
|
|
2048
2049
|
|
|
2049
2050
|
if (Array.isArray(blocks)) {
|
|
2050
|
-
this.HandleFormattingAndOutput(blocks, () => {
|
|
2051
|
+
await this.HandleFormattingAndOutput(blocks, () => {
|
|
2051
2052
|
// print the blocks to console
|
|
2052
2053
|
log.success(messages.blocks.list(currentEnv, env.currentProject));
|
|
2053
2054
|
for (const {
|
|
@@ -2102,7 +2103,7 @@ class ContensisCli {
|
|
|
2102
2103
|
);
|
|
2103
2104
|
|
|
2104
2105
|
if (blocks) {
|
|
2105
|
-
this.HandleFormattingAndOutput(blocks, () => {
|
|
2106
|
+
await this.HandleFormattingAndOutput(blocks, () => {
|
|
2106
2107
|
// print the version detail to console
|
|
2107
2108
|
log.success(
|
|
2108
2109
|
messages.blocks.get(blockId, currentEnv, env.currentProject)
|
|
@@ -2163,7 +2164,7 @@ class ContensisCli {
|
|
|
2163
2164
|
);
|
|
2164
2165
|
}
|
|
2165
2166
|
if (blockVersion) {
|
|
2166
|
-
this.HandleFormattingAndOutput(blockVersion, () => {
|
|
2167
|
+
await this.HandleFormattingAndOutput(blockVersion, () => {
|
|
2167
2168
|
// print the version detail to console
|
|
2168
2169
|
printBlockVersion(this, blockVersion);
|
|
2169
2170
|
});
|
|
@@ -2254,7 +2255,7 @@ class ContensisCli {
|
|
|
2254
2255
|
);
|
|
2255
2256
|
|
|
2256
2257
|
if (blockVersion) {
|
|
2257
|
-
this.HandleFormattingAndOutput(blockVersion, () => {
|
|
2258
|
+
await this.HandleFormattingAndOutput(blockVersion, () => {
|
|
2258
2259
|
// print the version detail to console
|
|
2259
2260
|
log.success(
|
|
2260
2261
|
messages.blocks.actionComplete(
|
|
@@ -2314,7 +2315,7 @@ class ContensisCli {
|
|
|
2314
2315
|
logs.endsWith('\n') ? logs.slice(0, logs.length - 1) : logs;
|
|
2315
2316
|
const renderLogs = removeTrailingNewline(blockLogs);
|
|
2316
2317
|
|
|
2317
|
-
this.HandleFormattingAndOutput(renderLogs, () => {
|
|
2318
|
+
await this.HandleFormattingAndOutput(renderLogs, () => {
|
|
2318
2319
|
// print the logs to console
|
|
2319
2320
|
console.log(
|
|
2320
2321
|
` - ${blockId} ${branch} ${
|
|
@@ -2418,7 +2419,7 @@ class ContensisCli {
|
|
|
2418
2419
|
); // TODO: resolve any cast;
|
|
2419
2420
|
|
|
2420
2421
|
if (Array.isArray(proxies)) {
|
|
2421
|
-
this.HandleFormattingAndOutput(proxies, () => {
|
|
2422
|
+
await this.HandleFormattingAndOutput(proxies, () => {
|
|
2422
2423
|
// print the proxies to console
|
|
2423
2424
|
log.success(messages.proxies.list(currentEnv, env.currentProject));
|
|
2424
2425
|
for (const { id, name, description, endpoints, version } of proxies) {
|
|
@@ -2457,7 +2458,7 @@ class ContensisCli {
|
|
|
2457
2458
|
); // TODO: resolve any cast
|
|
2458
2459
|
|
|
2459
2460
|
if (Array.isArray(renderers)) {
|
|
2460
|
-
this.HandleFormattingAndOutput(renderers, () => {
|
|
2461
|
+
await this.HandleFormattingAndOutput(renderers, () => {
|
|
2461
2462
|
// print the renderers to console
|
|
2462
2463
|
log.success(messages.renderers.list(currentEnv, env.currentProject));
|
|
2463
2464
|
for (const {
|
|
@@ -2493,7 +2494,7 @@ class ContensisCli {
|
|
|
2493
2494
|
}
|
|
2494
2495
|
}
|
|
2495
2496
|
};
|
|
2496
|
-
HandleFormattingAndOutput = <T>(obj: T, logFn: (obj: T) => void) => {
|
|
2497
|
+
HandleFormattingAndOutput = async <T>(obj: T, logFn: (obj: T) => void) => {
|
|
2497
2498
|
const { format, log, messages, output } = this;
|
|
2498
2499
|
const fields = this.contensis?.payload.query?.fields;
|
|
2499
2500
|
|
|
@@ -2502,7 +2503,7 @@ class ContensisCli {
|
|
|
2502
2503
|
logFn(obj);
|
|
2503
2504
|
} else if (format === 'csv') {
|
|
2504
2505
|
log.raw('');
|
|
2505
|
-
log.raw(log.infoText(csvFormatter(limitFields(obj, fields))));
|
|
2506
|
+
log.raw(log.infoText(await csvFormatter(limitFields(obj, fields))));
|
|
2506
2507
|
} else if (format === 'xml') {
|
|
2507
2508
|
log.raw('');
|
|
2508
2509
|
log.raw(log.infoText(xmlFormatter(limitFields(obj, fields))));
|
|
@@ -2516,7 +2517,7 @@ class ContensisCli {
|
|
|
2516
2517
|
let writeString = '';
|
|
2517
2518
|
const isText = !tryParse(obj) && typeof obj === 'string';
|
|
2518
2519
|
if (format === 'csv') {
|
|
2519
|
-
writeString = csvFormatter(limitFields(obj, fields));
|
|
2520
|
+
writeString = await csvFormatter(limitFields(obj, fields));
|
|
2520
2521
|
} else if (format === 'xml') {
|
|
2521
2522
|
writeString = xmlFormatter(limitFields(obj, fields));
|
|
2522
2523
|
} else
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { parse, stringify } from 'csv
|
|
1
|
+
import { parse, stringify } from 'csv';
|
|
2
2
|
// import { parse, stringify } from 'csv/sync';
|
|
3
3
|
import { flattenObject } from './json.formatter';
|
|
4
4
|
|
|
5
|
-
export const csvFormatter = <T>(entries: T | T[]) => {
|
|
5
|
+
export const csvFormatter = async <T>(entries: T | T[]) => {
|
|
6
6
|
// Flatten the passed in object
|
|
7
|
-
const flatEntries = [];
|
|
7
|
+
const flatEntries = [] as any[];
|
|
8
8
|
if (Array.isArray(entries))
|
|
9
9
|
for (const entry of entries) {
|
|
10
10
|
flatEntries.push(flattenObject(entry));
|
|
@@ -12,15 +12,33 @@ export const csvFormatter = <T>(entries: T | T[]) => {
|
|
|
12
12
|
else flatEntries.push(flattenObject(entries));
|
|
13
13
|
|
|
14
14
|
// Parse the flattened object to csv
|
|
15
|
-
const csv = stringify(flatEntries, { header: true });
|
|
16
|
-
|
|
15
|
+
// const csv = stringify(flatEntries, { header: true });
|
|
16
|
+
const csv = await new Promise<string>((resolve, reject) => {
|
|
17
|
+
stringify(flatEntries, { header: true }, (err, data) => {
|
|
18
|
+
if (err) reject(err);
|
|
19
|
+
resolve(data);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
17
22
|
return csv;
|
|
18
23
|
};
|
|
19
24
|
|
|
20
|
-
export const csvToJson = <T>(data: string): T[] => {
|
|
21
|
-
return parse(data, {
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
export const csvToJson = async <T = any>(data: string): Promise<T[]> => {
|
|
26
|
+
// return parse(data, {
|
|
27
|
+
// columns: true,
|
|
28
|
+
// skip_empty_lines: true,
|
|
29
|
+
// });
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
parse(
|
|
32
|
+
data,
|
|
33
|
+
{
|
|
34
|
+
columns: true,
|
|
35
|
+
skip_empty_lines: true,
|
|
36
|
+
},
|
|
37
|
+
(err, records) => {
|
|
38
|
+
if (err) reject(err);
|
|
39
|
+
resolve(records);
|
|
40
|
+
}
|
|
41
|
+
);
|
|
24
42
|
});
|
|
25
43
|
};
|
|
26
44
|
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.1.1-beta.
|
|
1
|
+
export const LIB_VERSION = "1.1.1-beta.3";
|