contensis-cli 1.2.2-beta.8 → 1.3.0
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/CHANGELOG.md +53 -0
- package/README.md +22 -4
- package/dist/commands/get.js +23 -3
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/globalOptions.js +14 -1
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +7 -1
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/list.js +2 -2
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/push.js +1 -1
- package/dist/commands/push.js.map +1 -1
- package/dist/services/ContensisCliService.js +135 -81
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/shell.js +2 -2
- package/dist/shell.js.map +2 -2
- package/dist/util/console.printer.js +5 -4
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/csv.formatter.js +26 -6
- package/dist/util/csv.formatter.js.map +2 -2
- package/dist/util/json.formatter.js +2 -2
- package/dist/util/json.formatter.js.map +2 -2
- package/dist/util/logger.js +14 -4
- package/dist/util/logger.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +3 -2
- package/src/commands/get.ts +38 -3
- package/src/commands/globalOptions.ts +13 -2
- package/src/commands/import.ts +8 -0
- package/src/commands/list.ts +3 -2
- package/src/commands/push.ts +1 -1
- package/src/services/ContensisCliService.ts +163 -96
- package/src/shell.ts +5 -3
- package/src/util/console.printer.ts +9 -3
- package/src/util/csv.formatter.ts +24 -8
- package/src/util/json.formatter.ts +4 -2
- package/src/util/logger.ts +19 -0
- package/src/version.ts +1 -1
package/src/commands/get.ts
CHANGED
|
@@ -7,9 +7,11 @@ import {
|
|
|
7
7
|
contentTypes,
|
|
8
8
|
delivery,
|
|
9
9
|
entryId,
|
|
10
|
+
exportOption,
|
|
10
11
|
latest,
|
|
11
12
|
mapContensisOpts,
|
|
12
13
|
noCache,
|
|
14
|
+
requiredBy,
|
|
13
15
|
versionStatus,
|
|
14
16
|
zenql,
|
|
15
17
|
} from './globalOptions';
|
|
@@ -67,6 +69,38 @@ Example call:
|
|
|
67
69
|
);
|
|
68
70
|
});
|
|
69
71
|
|
|
72
|
+
program
|
|
73
|
+
.command('proxy')
|
|
74
|
+
.description('get a proxy')
|
|
75
|
+
.argument('<proxyId>', 'id of the proxy to get')
|
|
76
|
+
.addHelpText(
|
|
77
|
+
'after',
|
|
78
|
+
`
|
|
79
|
+
Example call:
|
|
80
|
+
> get proxy b8b6958f-6ae2-41d5-876a-abc86755fd7b
|
|
81
|
+
`
|
|
82
|
+
)
|
|
83
|
+
.action(async (proxyId: string, opts) => {
|
|
84
|
+
await cliCommand(['get', 'proxy', proxyId], opts).PrintProxies(proxyId);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
program
|
|
88
|
+
.command('renderer')
|
|
89
|
+
.description('get a renderer')
|
|
90
|
+
.argument('<rendererId>', 'id of the renderer to get')
|
|
91
|
+
.addHelpText(
|
|
92
|
+
'after',
|
|
93
|
+
`
|
|
94
|
+
Example call:
|
|
95
|
+
> get renderer contensis-website
|
|
96
|
+
`
|
|
97
|
+
)
|
|
98
|
+
.action(async (rendererId: string, opts) => {
|
|
99
|
+
await cliCommand(['get', 'renderer', rendererId], opts).PrintRenderers(
|
|
100
|
+
rendererId
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
70
104
|
program
|
|
71
105
|
.command('role')
|
|
72
106
|
.description('get a role')
|
|
@@ -124,7 +158,8 @@ Example call:
|
|
|
124
158
|
.command('model')
|
|
125
159
|
.description('get a content model')
|
|
126
160
|
.argument('<contentTypeId...>', 'ids of the content models to get')
|
|
127
|
-
.
|
|
161
|
+
.addOption(requiredBy)
|
|
162
|
+
.addOption(exportOption)
|
|
128
163
|
.addOption(noCache)
|
|
129
164
|
.addHelpText(
|
|
130
165
|
'after',
|
|
@@ -138,7 +173,7 @@ Example call:
|
|
|
138
173
|
['get', 'model', modelIds.join(' ')],
|
|
139
174
|
opts,
|
|
140
175
|
mapContensisOpts(opts)
|
|
141
|
-
).PrintContentModels(modelIds, opts
|
|
176
|
+
).PrintContentModels(modelIds, opts);
|
|
142
177
|
});
|
|
143
178
|
|
|
144
179
|
program
|
|
@@ -221,7 +256,7 @@ Example call:
|
|
|
221
256
|
['get', 'assets'],
|
|
222
257
|
opts,
|
|
223
258
|
mapContensisOpts({ dataFormat: 'asset', search, ...opts })
|
|
224
|
-
).GetEntries(
|
|
259
|
+
).GetEntries();
|
|
225
260
|
});
|
|
226
261
|
|
|
227
262
|
sharedGetEntryOptions(
|
|
@@ -46,7 +46,8 @@ export const mapContensisOpts = (opts: any = {}): MigrateRequest => ({
|
|
|
46
46
|
zenQL: opts.zenql,
|
|
47
47
|
transformGuids: !opts.preserveGuids,
|
|
48
48
|
ignoreErrors: opts.ignoreErrors,
|
|
49
|
-
noCache: !opts.cache,
|
|
49
|
+
noCache: !opts.cache, // arg is inverted automatically from `--no-cache` to `cache: false`
|
|
50
|
+
includeDefaults: opts.defaults, // arg is inverted automatically from `--no-defaults` to `defaults: false`
|
|
50
51
|
concurrency: opts.concurrency ? Number(opts.concurrency) : undefined,
|
|
51
52
|
});
|
|
52
53
|
|
|
@@ -90,6 +91,16 @@ const sharedSecret = new Option(
|
|
|
90
91
|
'the shared secret to use when logging in with a client id'
|
|
91
92
|
);
|
|
92
93
|
|
|
94
|
+
/* Model get options */
|
|
95
|
+
export const requiredBy = new Option(
|
|
96
|
+
'--required-by',
|
|
97
|
+
'shows the id(s) that created each dependency'
|
|
98
|
+
);
|
|
99
|
+
export const exportOption = new Option(
|
|
100
|
+
'--export',
|
|
101
|
+
'export the raw resources that make up the content model(s) (used with --output)'
|
|
102
|
+
);
|
|
103
|
+
|
|
93
104
|
/* Entry get options */
|
|
94
105
|
export const delivery = new Option(
|
|
95
106
|
'-delivery --delivery-api',
|
|
@@ -156,7 +167,7 @@ export const outputDetail = new Option(
|
|
|
156
167
|
|
|
157
168
|
export const saveEntries = new Option(
|
|
158
169
|
'-save --save-entries',
|
|
159
|
-
"save the entries we're migrating instead of the migration preview
|
|
170
|
+
"save the entries we're migrating instead of the migration preview (used with --output)"
|
|
160
171
|
);
|
|
161
172
|
|
|
162
173
|
export const concurrency = new Option(
|
package/src/commands/import.ts
CHANGED
|
@@ -30,6 +30,14 @@ export const makeImportCommand = () => {
|
|
|
30
30
|
.argument('[modelIds...]', 'ids of the content models to import (optional)')
|
|
31
31
|
.addOption(noCache)
|
|
32
32
|
.addOption(commit)
|
|
33
|
+
.option(
|
|
34
|
+
'-nod --no-defaults',
|
|
35
|
+
'ignore any default entries or nodes attached to content types or fields'
|
|
36
|
+
)
|
|
37
|
+
.option(
|
|
38
|
+
'-preserve --preserve-guids',
|
|
39
|
+
'import any default entries or nodes using the same id as the source'
|
|
40
|
+
)
|
|
33
41
|
.addHelpText(
|
|
34
42
|
'after',
|
|
35
43
|
`
|
package/src/commands/list.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
|
-
import { mapContensisOpts, noCache } from './globalOptions';
|
|
3
|
+
import { exportOption, mapContensisOpts, noCache } from './globalOptions';
|
|
4
4
|
|
|
5
5
|
export const makeListCommand = () => {
|
|
6
6
|
const list = new Command()
|
|
@@ -41,6 +41,7 @@ Example call:
|
|
|
41
41
|
list
|
|
42
42
|
.command('models')
|
|
43
43
|
.description('print list of content models')
|
|
44
|
+
.addOption(exportOption)
|
|
44
45
|
.addOption(noCache)
|
|
45
46
|
.addHelpText(
|
|
46
47
|
'after',
|
|
@@ -54,7 +55,7 @@ Example call:
|
|
|
54
55
|
['list', 'models'],
|
|
55
56
|
opts,
|
|
56
57
|
mapContensisOpts(opts)
|
|
57
|
-
).PrintContentModels();
|
|
58
|
+
).PrintContentModels([], opts);
|
|
58
59
|
});
|
|
59
60
|
|
|
60
61
|
list
|
package/src/commands/push.ts
CHANGED
|
@@ -51,7 +51,7 @@ export const makePushCommand = () => {
|
|
|
51
51
|
)
|
|
52
52
|
.option(
|
|
53
53
|
'-pr --provider <sourceProvider>',
|
|
54
|
-
'the
|
|
54
|
+
'the source repository provider of the supplied image uri'
|
|
55
55
|
)
|
|
56
56
|
.usage('<block-id> <image uri> [branch] [options]')
|
|
57
57
|
.addHelpText(
|
|
@@ -4,6 +4,7 @@ import fs from 'fs';
|
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
5
|
import fetch from 'node-fetch';
|
|
6
6
|
import path from 'path';
|
|
7
|
+
import clone from 'rfdc';
|
|
7
8
|
|
|
8
9
|
import { Component, ContentType, Project } from 'contensis-core-api';
|
|
9
10
|
import { Role } from 'contensis-management-api/lib/models';
|
|
@@ -1178,7 +1179,7 @@ class ContensisCli {
|
|
|
1178
1179
|
|
|
1179
1180
|
PrintContentModels = async (
|
|
1180
1181
|
modelIds: string[] = [],
|
|
1181
|
-
|
|
1182
|
+
opts: { export?: boolean; requiredBy?: boolean }
|
|
1182
1183
|
) => {
|
|
1183
1184
|
const { currentProject, log, messages } = this;
|
|
1184
1185
|
const contensis = await this.ConnectContensis();
|
|
@@ -1194,93 +1195,112 @@ class ContensisCli {
|
|
|
1194
1195
|
modelIds.some(id => id.toLowerCase() === m.id.toLowerCase())
|
|
1195
1196
|
)
|
|
1196
1197
|
: undefined;
|
|
1198
|
+
const exportResources: (ContentType | Component)[] = [];
|
|
1199
|
+
|
|
1200
|
+
if (opts.export) {
|
|
1201
|
+
// Generate a list of contentTypeIds and componentIds from all models
|
|
1202
|
+
// and dependencies
|
|
1203
|
+
const contentTypeIds = Array.from(
|
|
1204
|
+
new Set([
|
|
1205
|
+
...(returnModels || models || []).map(m => m.id),
|
|
1206
|
+
...(returnModels || models || [])
|
|
1207
|
+
.map(m => m.dependencies?.contentTypes?.map(c => c[0]) || [])
|
|
1208
|
+
.flat(),
|
|
1209
|
+
])
|
|
1210
|
+
);
|
|
1211
|
+
const componentIds = Array.from(
|
|
1212
|
+
new Set(
|
|
1213
|
+
(returnModels || models || [])
|
|
1214
|
+
.map(m => m.dependencies?.components?.map(c => c[0]) || [])
|
|
1215
|
+
.flat()
|
|
1216
|
+
)
|
|
1217
|
+
);
|
|
1197
1218
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
.map(m => m.dependencies?.components?.map(c => c[0]) || [])
|
|
1212
|
-
.flat()
|
|
1213
|
-
)
|
|
1214
|
-
);
|
|
1215
|
-
|
|
1216
|
-
// Create an array of all the content types and component definitions
|
|
1217
|
-
// we will use this when outputting to a file
|
|
1218
|
-
const contentModelBackup = [
|
|
1219
|
-
...contentTypes.filter(c =>
|
|
1220
|
-
contentTypeIds.map(i => i.toLowerCase()).includes(c.id.toLowerCase())
|
|
1221
|
-
),
|
|
1222
|
-
...components.filter(c =>
|
|
1223
|
-
componentIds.map(i => i.toLowerCase()).includes(c.id.toLowerCase())
|
|
1224
|
-
),
|
|
1225
|
-
];
|
|
1219
|
+
// Create an array of all the content types and component definitions
|
|
1220
|
+
// we will use this when outputting to a file
|
|
1221
|
+
exportResources.push(
|
|
1222
|
+
...contentTypes.filter(c =>
|
|
1223
|
+
contentTypeIds
|
|
1224
|
+
.map(i => i.toLowerCase())
|
|
1225
|
+
.includes(c.id.toLowerCase())
|
|
1226
|
+
),
|
|
1227
|
+
...components.filter(c =>
|
|
1228
|
+
componentIds.map(i => i.toLowerCase()).includes(c.id.toLowerCase())
|
|
1229
|
+
)
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1226
1232
|
|
|
1227
1233
|
if (Array.isArray(returnModels)) {
|
|
1228
1234
|
log.success(messages.models.list(currentProject));
|
|
1229
|
-
await this.HandleFormattingAndOutput(
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1235
|
+
await this.HandleFormattingAndOutput(
|
|
1236
|
+
opts.export ? exportResources : returnModels,
|
|
1237
|
+
() => {
|
|
1238
|
+
// print the content models to console
|
|
1239
|
+
for (const model of returnModels) {
|
|
1240
|
+
// create a clone of each model to safely modify
|
|
1241
|
+
const draft = clone()(model);
|
|
1242
|
+
if (!opts.requiredBy) {
|
|
1243
|
+
// truncate parts of the output
|
|
1244
|
+
delete draft.dependencyOf;
|
|
1245
|
+
if (draft.dependencies?.contentTypes)
|
|
1246
|
+
draft.dependencies.contentTypes.forEach(id => id.pop());
|
|
1247
|
+
if (draft.dependencies?.components)
|
|
1248
|
+
draft.dependencies.components.forEach(id => id.pop());
|
|
1249
|
+
}
|
|
1240
1250
|
|
|
1251
|
+
log.raw('');
|
|
1252
|
+
log.object(draft);
|
|
1253
|
+
}
|
|
1241
1254
|
log.raw('');
|
|
1242
|
-
log.object(model);
|
|
1243
1255
|
}
|
|
1244
|
-
|
|
1245
|
-
});
|
|
1256
|
+
);
|
|
1246
1257
|
} else {
|
|
1247
1258
|
log.success(
|
|
1248
1259
|
messages.models.get(currentProject, models?.length.toString() || '0')
|
|
1249
1260
|
);
|
|
1250
1261
|
log.raw('');
|
|
1251
1262
|
if (models?.length) {
|
|
1252
|
-
await this.HandleFormattingAndOutput(
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
const
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1263
|
+
await this.HandleFormattingAndOutput(
|
|
1264
|
+
opts.export ? exportResources : models,
|
|
1265
|
+
() => {
|
|
1266
|
+
// print the content models to console
|
|
1267
|
+
for (const model of models) {
|
|
1268
|
+
const components = model.components?.length || 0;
|
|
1269
|
+
const contentTypes = model.contentTypes?.length || 0;
|
|
1270
|
+
const defaults =
|
|
1271
|
+
(model.defaults?.length || 0) + (model.nodes?.length || 0);
|
|
1272
|
+
const dependencies =
|
|
1273
|
+
(model.dependencies?.components?.length || 0) +
|
|
1274
|
+
(model.dependencies?.contentTypes?.length || 0);
|
|
1275
|
+
const dependencyOf =
|
|
1276
|
+
(model.dependencyOf?.components?.length || 0) +
|
|
1277
|
+
(model.dependencyOf?.contentTypes?.length || 0);
|
|
1278
|
+
|
|
1279
|
+
const hasAny =
|
|
1280
|
+
components + contentTypes + dependencies + dependencyOf;
|
|
1281
|
+
log.raw(
|
|
1282
|
+
` - ${log.highlightText(log.boldText(model.id))} ${
|
|
1283
|
+
hasAny
|
|
1284
|
+
? log.infoText(
|
|
1285
|
+
`{ ${
|
|
1286
|
+
components ? `components: ${components}, ` : ''
|
|
1287
|
+
}${
|
|
1288
|
+
contentTypes
|
|
1289
|
+
? `contentTypes: ${contentTypes}, `
|
|
1290
|
+
: ''
|
|
1291
|
+
}${defaults ? `defaults: ${defaults}, ` : ''}${
|
|
1292
|
+
dependencies ? `references: ${dependencies}, ` : ''
|
|
1293
|
+
}${
|
|
1294
|
+
dependencyOf ? `required by: ${dependencyOf}` : ''
|
|
1295
|
+
} }`
|
|
1296
|
+
)
|
|
1297
|
+
: ''
|
|
1298
|
+
}`
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
log.raw('');
|
|
1281
1302
|
}
|
|
1282
|
-
|
|
1283
|
-
});
|
|
1303
|
+
);
|
|
1284
1304
|
}
|
|
1285
1305
|
}
|
|
1286
1306
|
}
|
|
@@ -1321,7 +1341,7 @@ class ContensisCli {
|
|
|
1321
1341
|
else
|
|
1322
1342
|
await this.HandleFormattingAndOutput(result, () => {
|
|
1323
1343
|
// print the results to console
|
|
1324
|
-
if (!
|
|
1344
|
+
if (!result.committed) {
|
|
1325
1345
|
log.raw(log.boldText(`\nContent types:`));
|
|
1326
1346
|
if (!result.contentTypes) log.info(`- None returned\n`);
|
|
1327
1347
|
else printModelMigrationAnalysis(this, result.contentTypes);
|
|
@@ -1329,19 +1349,60 @@ class ContensisCli {
|
|
|
1329
1349
|
log.raw(log.boldText(`\nComponents:`));
|
|
1330
1350
|
if (!result.components) log.info(`- None returned\n`);
|
|
1331
1351
|
else printModelMigrationAnalysis(this, result.components);
|
|
1352
|
+
|
|
1353
|
+
if (Object.keys(result.defaults).length) {
|
|
1354
|
+
log.raw(log.boldText(`\nDefaults:`));
|
|
1355
|
+
printModelMigrationAnalysis(this, result.defaults);
|
|
1356
|
+
}
|
|
1357
|
+
if (Object.keys(result.nodes).length) {
|
|
1358
|
+
log.raw(log.boldText(`\nNodes:`));
|
|
1359
|
+
printModelMigrationAnalysis(this, result.nodes);
|
|
1360
|
+
}
|
|
1361
|
+
if (result.errors) {
|
|
1362
|
+
log.raw(log.boldText(`\nErrors:`));
|
|
1363
|
+
log.object(result.errors);
|
|
1364
|
+
}
|
|
1332
1365
|
} else {
|
|
1333
|
-
const
|
|
1366
|
+
const { modelsResult = {} } = result;
|
|
1334
1367
|
log.raw(log.boldText(`\nContent types:`));
|
|
1335
1368
|
printModelMigrationResult(
|
|
1336
1369
|
this,
|
|
1337
|
-
|
|
1338
|
-
);
|
|
1339
|
-
|
|
1340
|
-
log.raw(log.boldText(`\nComponents:`));
|
|
1341
|
-
printModelMigrationResult(
|
|
1342
|
-
this,
|
|
1343
|
-
migrateResult[currentProject].components
|
|
1370
|
+
modelsResult[currentProject].contentTypes
|
|
1344
1371
|
);
|
|
1372
|
+
// Only output for components if any status has any results
|
|
1373
|
+
if (
|
|
1374
|
+
Object.values(modelsResult[currentProject].components).some(
|
|
1375
|
+
r => r.length > 0
|
|
1376
|
+
)
|
|
1377
|
+
) {
|
|
1378
|
+
log.raw(log.boldText(`\nComponents:`));
|
|
1379
|
+
printModelMigrationResult(
|
|
1380
|
+
this,
|
|
1381
|
+
modelsResult[currentProject].components
|
|
1382
|
+
);
|
|
1383
|
+
}
|
|
1384
|
+
if (
|
|
1385
|
+
Object.values(modelsResult[currentProject].defaults).some(
|
|
1386
|
+
r => r.length > 0
|
|
1387
|
+
)
|
|
1388
|
+
) {
|
|
1389
|
+
log.raw(log.boldText(`\nDefaults:`));
|
|
1390
|
+
printModelMigrationResult(
|
|
1391
|
+
this,
|
|
1392
|
+
modelsResult[currentProject].defaults
|
|
1393
|
+
);
|
|
1394
|
+
}
|
|
1395
|
+
if (
|
|
1396
|
+
Object.values(modelsResult[currentProject].nodes).some(
|
|
1397
|
+
r => r.length > 0
|
|
1398
|
+
)
|
|
1399
|
+
) {
|
|
1400
|
+
log.raw(log.boldText(`\nNodes:`));
|
|
1401
|
+
printModelMigrationResult(
|
|
1402
|
+
this,
|
|
1403
|
+
modelsResult[currentProject].nodes
|
|
1404
|
+
);
|
|
1405
|
+
}
|
|
1345
1406
|
}
|
|
1346
1407
|
});
|
|
1347
1408
|
} else {
|
|
@@ -1529,14 +1590,15 @@ class ContensisCli {
|
|
|
1529
1590
|
`"${result.query.modelIds?.join(', ')}"`
|
|
1530
1591
|
)}\n`
|
|
1531
1592
|
);
|
|
1593
|
+
if (result.committed === false) {
|
|
1594
|
+
log.raw(log.boldText(`Content types:`));
|
|
1595
|
+
if (!result.contentTypes) log.info(`- None returned\n`);
|
|
1596
|
+
else printModelMigrationAnalysis(this, result.contentTypes);
|
|
1532
1597
|
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
log.raw(log.boldText(`Components:`));
|
|
1538
|
-
if (!result.components) log.info(`- None returned\n`);
|
|
1539
|
-
else printModelMigrationAnalysis(this, result.components);
|
|
1598
|
+
log.raw(log.boldText(`\nComponents:`));
|
|
1599
|
+
if (!result.components) log.info(`- None returned\n`);
|
|
1600
|
+
else printModelMigrationAnalysis(this, result.components);
|
|
1601
|
+
}
|
|
1540
1602
|
});
|
|
1541
1603
|
}
|
|
1542
1604
|
};
|
|
@@ -1727,13 +1789,19 @@ class ContensisCli {
|
|
|
1727
1789
|
withDependents = false,
|
|
1728
1790
|
}: {
|
|
1729
1791
|
withDependents?: boolean;
|
|
1730
|
-
}) => {
|
|
1792
|
+
} = {}) => {
|
|
1731
1793
|
const { currentProject, log, messages } = this;
|
|
1732
1794
|
const contensis = await this.ConnectContensis();
|
|
1733
1795
|
|
|
1734
1796
|
if (contensis) {
|
|
1735
1797
|
log.line();
|
|
1736
1798
|
const entries = await contensis.GetEntries({ withDependents });
|
|
1799
|
+
// TODO: iterate entries and add some extra details to help
|
|
1800
|
+
// with importing later
|
|
1801
|
+
// Add a full sys.uri to asset entries
|
|
1802
|
+
// Add sys.metadata.exportCms
|
|
1803
|
+
// Add sys.metadata.exportProjectId
|
|
1804
|
+
|
|
1737
1805
|
await this.HandleFormattingAndOutput(entries, () =>
|
|
1738
1806
|
// print the entries to console
|
|
1739
1807
|
logEntitiesTable({
|
|
@@ -1779,11 +1847,10 @@ class ContensisCli {
|
|
|
1779
1847
|
|
|
1780
1848
|
if (err) logError(err);
|
|
1781
1849
|
else {
|
|
1782
|
-
const {
|
|
1783
|
-
contensis.content.targets[currentProject];
|
|
1850
|
+
const { entries, nodes } = contensis.content.targets[currentProject];
|
|
1784
1851
|
|
|
1785
1852
|
const output = saveEntries
|
|
1786
|
-
?
|
|
1853
|
+
? entries.migrate?.map(me => me.toJSON())
|
|
1787
1854
|
: result;
|
|
1788
1855
|
await this.HandleFormattingAndOutput(output, () => {
|
|
1789
1856
|
// print the migrateResult to console
|
|
@@ -1875,8 +1942,8 @@ class ContensisCli {
|
|
|
1875
1942
|
if (err) logError(err);
|
|
1876
1943
|
if (result) {
|
|
1877
1944
|
const output = saveEntries
|
|
1878
|
-
? contensis.content.copy.targets[currentProject].
|
|
1879
|
-
me => me.
|
|
1945
|
+
? contensis.content.copy.targets[currentProject].entries.migrate?.map(
|
|
1946
|
+
me => me.toJSON()
|
|
1880
1947
|
)
|
|
1881
1948
|
: result;
|
|
1882
1949
|
await this.HandleFormattingAndOutput(output, () => {
|
package/src/shell.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import figlet from 'figlet';
|
|
2
2
|
import inquirer from 'inquirer';
|
|
3
3
|
import inquirerPrompt from 'inquirer-command-prompt';
|
|
4
|
+
import { split } from 'split-cmd';
|
|
4
5
|
import commands from './commands';
|
|
5
6
|
import { LogMessages } from './localisation/en-GB';
|
|
6
7
|
import CredentialProvider from './providers/CredentialProvider';
|
|
@@ -222,9 +223,10 @@ class ContensisShell {
|
|
|
222
223
|
if (answers.cmd) {
|
|
223
224
|
const program = commands();
|
|
224
225
|
await program.parseAsync(
|
|
225
|
-
answers.cmd
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
split(answers.cmd).map(e => e.replace(/\\"/g, '"')),
|
|
227
|
+
// answers.cmd
|
|
228
|
+
// .match(/"[^"]+"|[^\s]+/g)
|
|
229
|
+
// ?.map(e => e.replace(/"(.+)"/, '$1')),
|
|
228
230
|
{
|
|
229
231
|
from: 'user',
|
|
230
232
|
}
|
|
@@ -393,7 +393,11 @@ export const printModelMigrationAnalysis = (
|
|
|
393
393
|
string,
|
|
394
394
|
any
|
|
395
395
|
][]) {
|
|
396
|
-
let mainOutput = log.standardText(
|
|
396
|
+
let mainOutput = log.standardText(
|
|
397
|
+
` - ${contentTypeId}${
|
|
398
|
+
model.contentTypeId ? ` ${log.helpText(model.contentTypeId)}` : ''
|
|
399
|
+
}`
|
|
400
|
+
);
|
|
397
401
|
let extraOutput = '';
|
|
398
402
|
let errorOutput = '';
|
|
399
403
|
let diffOutput = '';
|
|
@@ -416,12 +420,14 @@ export const printModelMigrationAnalysis = (
|
|
|
416
420
|
mainOutput += log.infoText(
|
|
417
421
|
` [${messages.migrate.status(projectDetails.status)(
|
|
418
422
|
`${projectId}: ${projectDetails.status}`
|
|
419
|
-
)}]
|
|
423
|
+
)}]${
|
|
424
|
+
projectDetails.versionNo ? ` v${projectDetails.versionNo}` : ''
|
|
425
|
+
}`
|
|
420
426
|
);
|
|
421
427
|
if (projectDetails.diff)
|
|
422
428
|
diffOutput += ` ${log.highlightText(`diff:`)} ${log.infoText(
|
|
423
429
|
highlightDiffText(projectDetails.diff)
|
|
424
|
-
)}
|
|
430
|
+
)}`;
|
|
425
431
|
if (projectDetails.error)
|
|
426
432
|
errorOutput += ` ${log.highlightText(
|
|
427
433
|
`error::`
|
|
@@ -13,26 +13,42 @@ export const csvFormatter = async <T>(entries: T | T[]) => {
|
|
|
13
13
|
|
|
14
14
|
// Parse the flattened object to csv
|
|
15
15
|
// const csv = stringify(flatEntries, { header: true });
|
|
16
|
+
// Create an exhaustive list of columns from the entries array
|
|
17
|
+
const columns = new Set<string>(flatEntries.map(e => Object.keys(e)).flat());
|
|
16
18
|
const csv = await new Promise<string>((resolve, reject) => {
|
|
17
|
-
stringify(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
stringify(
|
|
20
|
+
flatEntries,
|
|
21
|
+
{
|
|
22
|
+
header: true,
|
|
23
|
+
cast: { boolean: (value, context) => `${value}` },
|
|
24
|
+
columns: [...columns],
|
|
25
|
+
},
|
|
26
|
+
(err, data) => {
|
|
27
|
+
if (err) reject(err);
|
|
28
|
+
resolve(data);
|
|
29
|
+
}
|
|
30
|
+
);
|
|
21
31
|
});
|
|
22
32
|
return csv;
|
|
23
33
|
};
|
|
24
34
|
|
|
25
35
|
export const csvToJson = async <T = any>(data: string): Promise<T[]> => {
|
|
26
|
-
// return parse(data, {
|
|
27
|
-
// columns: true,
|
|
28
|
-
// skip_empty_lines: true,
|
|
29
|
-
// });
|
|
30
36
|
return new Promise((resolve, reject) => {
|
|
31
37
|
parse(
|
|
32
38
|
data,
|
|
33
39
|
{
|
|
34
40
|
columns: true,
|
|
35
41
|
skip_empty_lines: true,
|
|
42
|
+
cast: (value, context) => {
|
|
43
|
+
if (context.header || context.column === 'sys.version.versionNo')
|
|
44
|
+
return value;
|
|
45
|
+
if (value === '') return undefined;
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(value);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
36
52
|
},
|
|
37
53
|
(err, records) => {
|
|
38
54
|
if (err) reject(err);
|
|
@@ -7,11 +7,13 @@ export const jsonFormatter = <T>(obj: T, fields?: string[]) =>
|
|
|
7
7
|
|
|
8
8
|
// Flatten a JSON object such as an entry so there are no
|
|
9
9
|
// nested object and the keys are presented like "sys.version.versionNo": "1.0"
|
|
10
|
-
export const flattenObject = (obj: any) =>
|
|
10
|
+
export const flattenObject = (obj: any) =>
|
|
11
|
+
flatten(cleaner(obj, ['workflow']), { maxDepth: 99 });
|
|
11
12
|
|
|
12
13
|
// Unflatten a JSON object such as an entry so the arrays and
|
|
13
14
|
// nested objects are reconstructed - the opposite of flattenObject
|
|
14
|
-
export const unflattenObject = (obj: any) =>
|
|
15
|
+
export const unflattenObject = (obj: any) =>
|
|
16
|
+
unflatten(obj, { overwrite: true });
|
|
15
17
|
|
|
16
18
|
// Will limit and sort an object's keys by an array of supplied fields
|
|
17
19
|
export const limitFields = (obj: any, fields?: string[]): any => {
|
package/src/util/logger.ts
CHANGED
|
@@ -140,6 +140,14 @@ export class Logger {
|
|
|
140
140
|
' | '
|
|
141
141
|
)}`
|
|
142
142
|
: ''
|
|
143
|
+
}${
|
|
144
|
+
field.dataFormat === 'contenttype'
|
|
145
|
+
? `[${field.validations?.allowedDataFormats.dataFormats.join(
|
|
146
|
+
' | '
|
|
147
|
+
)}], ${(
|
|
148
|
+
field.validations?.allowedIds?.ids || ['*']
|
|
149
|
+
).join(' | ')}`
|
|
150
|
+
: ''
|
|
143
151
|
}>`
|
|
144
152
|
: ''
|
|
145
153
|
}${
|
|
@@ -195,11 +203,22 @@ export class Logger {
|
|
|
195
203
|
if (item.length)
|
|
196
204
|
Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
|
|
197
205
|
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}`);
|
|
198
216
|
} else Logger.raw(`${indent}${item}`);
|
|
199
217
|
}
|
|
200
218
|
} else {
|
|
201
219
|
let pos = 0;
|
|
202
220
|
for (const [key, value] of Object.entries(content)) {
|
|
221
|
+
if (key === 'stack') continue; // skip stack output for errors
|
|
203
222
|
const thisIndent =
|
|
204
223
|
pos === 0 ? `${indent.substring(0, indent.length - 2)}- ` : indent;
|
|
205
224
|
if (Array.isArray(value)) {
|