contensis-cli 1.0.0-beta.38 → 1.0.0-beta.39
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/create.js +4 -2
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/diff.js +57 -0
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/get.js +40 -11
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/globalOptions.js +4 -3
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +31 -5
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +6 -0
- package/dist/commands/index.js.map +2 -2
- package/dist/commands/list.js +19 -8
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/push.js +2 -1
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/release.js +2 -1
- package/dist/commands/release.js.map +2 -2
- package/dist/commands/remove.js +6 -4
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +6 -3
- package/dist/commands/set.js.map +2 -2
- package/dist/localisation/en-GB.js +43 -24
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/providers/SessionCacheProvider.js +2 -2
- package/dist/providers/SessionCacheProvider.js.map +2 -2
- package/dist/services/ContensisCliService.js +240 -72
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/shell.js +4 -1
- package/dist/shell.js.map +2 -2
- package/dist/util/console.printer.js +87 -4
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/logger.js +45 -13
- package/dist/util/logger.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/create.ts +2 -0
- package/src/commands/diff.ts +39 -0
- package/src/commands/get.ts +48 -4
- package/src/commands/globalOptions.ts +5 -4
- package/src/commands/import.ts +36 -2
- package/src/commands/index.ts +6 -0
- package/src/commands/list.ts +34 -9
- package/src/commands/push.ts +1 -0
- package/src/commands/release.ts +1 -0
- package/src/commands/remove.ts +4 -2
- package/src/commands/set.ts +3 -0
- package/src/localisation/en-GB.ts +58 -33
- package/src/providers/SessionCacheProvider.ts +3 -2
- package/src/services/ContensisCliService.ts +301 -84
- package/src/shell.ts +4 -2
- package/src/util/console.printer.ts +100 -3
- package/src/util/logger.ts +84 -15
- package/src/version.ts +1 -1
|
@@ -16,13 +16,21 @@ import {
|
|
|
16
16
|
PushBlockParams,
|
|
17
17
|
SourceCms,
|
|
18
18
|
logEntriesTable,
|
|
19
|
+
ContentTypesResult,
|
|
20
|
+
Model,
|
|
21
|
+
MigrateModelsResult,
|
|
19
22
|
} from 'migratortron';
|
|
20
23
|
import { Entry } from 'contensis-management-api/lib/models';
|
|
21
24
|
|
|
22
25
|
import { csvFormatter } from '~/util/csv.formatter';
|
|
23
26
|
import { xmlFormatter } from '~/util/xml.formatter';
|
|
24
27
|
import { jsonFormatter } from '~/util/json.formatter';
|
|
25
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
printBlockVersion,
|
|
30
|
+
printMigrateResult,
|
|
31
|
+
printModelMigrationAnalysis,
|
|
32
|
+
printModelMigrationResult,
|
|
33
|
+
} from '~/util/console.printer';
|
|
26
34
|
import { readJsonFile } from '~/providers/file-provider';
|
|
27
35
|
|
|
28
36
|
type OutputFormat = 'json' | 'csv' | 'xml';
|
|
@@ -45,7 +53,7 @@ interface IAuthOptions {
|
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
interface IImportOptions {
|
|
48
|
-
|
|
56
|
+
sourceAlias?: string;
|
|
49
57
|
sourceProjectId?: string;
|
|
50
58
|
}
|
|
51
59
|
|
|
@@ -67,11 +75,9 @@ class ContensisCli {
|
|
|
67
75
|
|
|
68
76
|
contensis?: ContensisMigrationService;
|
|
69
77
|
contensisOpts: Partial<MigrateRequest>;
|
|
70
|
-
contentTypes?: ContentType[];
|
|
71
|
-
components?: Component[];
|
|
72
78
|
currentProject: string;
|
|
73
79
|
|
|
74
|
-
|
|
80
|
+
sourceAlias?: string;
|
|
75
81
|
targetEnv?: string;
|
|
76
82
|
urls:
|
|
77
83
|
| {
|
|
@@ -93,6 +99,7 @@ class ContensisCli {
|
|
|
93
99
|
get cache() {
|
|
94
100
|
return this.session.Get();
|
|
95
101
|
}
|
|
102
|
+
|
|
96
103
|
get currentEnv() {
|
|
97
104
|
return this.cache.currentEnvironment || '';
|
|
98
105
|
}
|
|
@@ -118,6 +125,17 @@ class ContensisCli {
|
|
|
118
125
|
}
|
|
119
126
|
}
|
|
120
127
|
|
|
128
|
+
get contentTypes() {
|
|
129
|
+
return this.contensis?.models.contentTypes();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
get components() {
|
|
133
|
+
return this.contensis?.models.components();
|
|
134
|
+
}
|
|
135
|
+
get models(): Model[] | undefined {
|
|
136
|
+
return this.contensis?.models.contentModels();
|
|
137
|
+
}
|
|
138
|
+
|
|
121
139
|
constructor(
|
|
122
140
|
args: string[],
|
|
123
141
|
outputOpts?: OutputOptions & IConnectOptions & IImportOptions,
|
|
@@ -156,7 +174,7 @@ class ContensisCli {
|
|
|
156
174
|
env.passwordFallback = outputOpts.sharedSecret;
|
|
157
175
|
|
|
158
176
|
this.currentProject = env?.currentProject || 'null';
|
|
159
|
-
this.
|
|
177
|
+
this.sourceAlias = outputOpts?.sourceAlias || currentEnvironment;
|
|
160
178
|
|
|
161
179
|
if (currentEnvironment) {
|
|
162
180
|
this.urls = url(currentEnvironment, env?.currentProject || 'website');
|
|
@@ -273,19 +291,31 @@ class ContensisCli {
|
|
|
273
291
|
};
|
|
274
292
|
|
|
275
293
|
ConnectContensisImport = async ({
|
|
276
|
-
commit,
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
fileDataType,
|
|
294
|
+
commit = false,
|
|
295
|
+
fromFile,
|
|
296
|
+
importDataType,
|
|
280
297
|
}: {
|
|
281
|
-
commit
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
298
|
+
commit?: boolean;
|
|
299
|
+
fromFile?: string;
|
|
300
|
+
importDataType?:
|
|
301
|
+
| 'entries'
|
|
302
|
+
| 'contentTypes'
|
|
303
|
+
| 'components'
|
|
304
|
+
| 'models'
|
|
305
|
+
| 'user-input';
|
|
285
306
|
}) => {
|
|
286
|
-
const
|
|
307
|
+
const source: 'contensis' | 'file' = fromFile ? 'file' : 'contensis';
|
|
308
|
+
|
|
309
|
+
const fileData = fromFile
|
|
310
|
+
? readJsonFile<(Entry | ContentType | Component)[]>(fromFile) || []
|
|
311
|
+
: [];
|
|
312
|
+
|
|
313
|
+
if (typeof fileData === 'string')
|
|
314
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
315
|
+
|
|
316
|
+
const { contensisOpts, currentEnv, env, log, messages, sourceAlias } = this;
|
|
287
317
|
const environments = this.cache.environments || {};
|
|
288
|
-
const sourceEnvironment = environments[
|
|
318
|
+
const sourceEnvironment = environments[sourceAlias || ''] || {};
|
|
289
319
|
const sourceCms =
|
|
290
320
|
('source' in contensisOpts && contensisOpts.source) ||
|
|
291
321
|
({} as Partial<SourceCms>);
|
|
@@ -294,7 +324,7 @@ class ContensisCli {
|
|
|
294
324
|
const sourceProjectId =
|
|
295
325
|
sourceCms.project || sourceEnvironment.currentProject || 'website';
|
|
296
326
|
const isSourceGuidId = sourceUserId && isUuid(sourceUserId);
|
|
297
|
-
const sourceUrls = url(
|
|
327
|
+
const sourceUrls = url(sourceAlias || '', sourceProjectId);
|
|
298
328
|
|
|
299
329
|
const sourcePassword =
|
|
300
330
|
sourceCms.sharedSecret ||
|
|
@@ -308,7 +338,8 @@ class ContensisCli {
|
|
|
308
338
|
const sourceCredentials = await this.GetCredentials(
|
|
309
339
|
sourceUserId,
|
|
310
340
|
sourcePassword,
|
|
311
|
-
|
|
341
|
+
sourceAlias,
|
|
342
|
+
false
|
|
312
343
|
);
|
|
313
344
|
|
|
314
345
|
const cachedSourcePassword = sourceCredentials?.current?.password;
|
|
@@ -321,7 +352,7 @@ class ContensisCli {
|
|
|
321
352
|
const cachedTargetPassword = targetCredentials?.current?.password;
|
|
322
353
|
|
|
323
354
|
if (cachedSourcePassword && cachedTargetPassword) {
|
|
324
|
-
if (source === 'file' ||
|
|
355
|
+
if (source === 'file' || importDataType === 'user-input') {
|
|
325
356
|
this.contensis = new ContensisMigrationService(
|
|
326
357
|
{
|
|
327
358
|
concurrency: 3,
|
|
@@ -336,7 +367,7 @@ class ContensisCli {
|
|
|
336
367
|
targetProjects: [env.currentProject || ''],
|
|
337
368
|
assetHostname: this.urls?.previewWeb,
|
|
338
369
|
},
|
|
339
|
-
...(
|
|
370
|
+
...(importDataType ? { [importDataType]: fileData } : {}),
|
|
340
371
|
},
|
|
341
372
|
!commit
|
|
342
373
|
);
|
|
@@ -374,12 +405,14 @@ class ContensisCli {
|
|
|
374
405
|
if (!currentEnv) log.help(messages.connect.help());
|
|
375
406
|
if (!targetUserId) log.help(messages.connect.tip());
|
|
376
407
|
}
|
|
408
|
+
return this.contensis;
|
|
377
409
|
};
|
|
378
410
|
|
|
379
411
|
GetCredentials = async (
|
|
380
412
|
userId: string,
|
|
381
413
|
password?: string,
|
|
382
|
-
currentEnv = this.currentEnv
|
|
414
|
+
currentEnv = this.currentEnv,
|
|
415
|
+
saveCurrentEnv = true
|
|
383
416
|
): Promise<CredentialProvider | undefined> => {
|
|
384
417
|
const { env, log, messages } = this;
|
|
385
418
|
if (userId) {
|
|
@@ -401,7 +434,7 @@ class ContensisCli {
|
|
|
401
434
|
}
|
|
402
435
|
} else {
|
|
403
436
|
env.passwordFallback = undefined;
|
|
404
|
-
this.session.UpdateEnv(env, currentEnv);
|
|
437
|
+
this.session.UpdateEnv(env, currentEnv, saveCurrentEnv);
|
|
405
438
|
}
|
|
406
439
|
return credentials;
|
|
407
440
|
}
|
|
@@ -738,12 +771,161 @@ class ContensisCli {
|
|
|
738
771
|
let err;
|
|
739
772
|
if (!this.contensis) err = await this.HydrateContensis();
|
|
740
773
|
|
|
741
|
-
if (err) log.error(messages.
|
|
742
|
-
if (this.contensis)
|
|
743
|
-
|
|
744
|
-
|
|
774
|
+
if (err) log.error(messages.models.noList(currentProject));
|
|
775
|
+
if (!this.contensis) log.warning(messages.models.noList(currentProject));
|
|
776
|
+
|
|
777
|
+
return this.contensis;
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
PrintContentModels = async (modelIds: string[] = []) => {
|
|
781
|
+
const { currentProject, log, messages } = this;
|
|
782
|
+
const contensis = await this.GetContentTypes();
|
|
783
|
+
if (contensis) {
|
|
784
|
+
// Retrieve models list for env
|
|
785
|
+
const { models, contentTypes = [], components = [] } = this;
|
|
786
|
+
|
|
787
|
+
// Models to output to console
|
|
788
|
+
const returnModels = modelIds?.length
|
|
789
|
+
? models?.filter((m: Model) =>
|
|
790
|
+
modelIds.some(id => id.toLowerCase() === m.id.toLowerCase())
|
|
791
|
+
)
|
|
792
|
+
: undefined;
|
|
793
|
+
|
|
794
|
+
// Generate a list of contentTypeIds and componentIds from all models
|
|
795
|
+
// and dependencies
|
|
796
|
+
const contentTypeIds = Array.from(
|
|
797
|
+
new Set([
|
|
798
|
+
...(returnModels || models || []).map(m => m.id),
|
|
799
|
+
...(returnModels || models || [])
|
|
800
|
+
.map(m => m.dependencies?.contentTypes?.map(c => c[0]) || [])
|
|
801
|
+
.flat(),
|
|
802
|
+
])
|
|
803
|
+
);
|
|
804
|
+
const componentIds = Array.from(
|
|
805
|
+
new Set(
|
|
806
|
+
(returnModels || models || [])
|
|
807
|
+
.map(m => m.dependencies?.components?.map(c => c[0]) || [])
|
|
808
|
+
.flat()
|
|
809
|
+
)
|
|
810
|
+
);
|
|
811
|
+
|
|
812
|
+
// Create an array of all the content types and component definitions
|
|
813
|
+
// we will use this when outputting to a file
|
|
814
|
+
const contentModelBackup = [
|
|
815
|
+
...contentTypes.filter(c => contentTypeIds.includes(c.id)),
|
|
816
|
+
...components.filter(c => componentIds.includes(c.id)),
|
|
817
|
+
];
|
|
818
|
+
|
|
819
|
+
if (Array.isArray(returnModels)) {
|
|
820
|
+
log.success(messages.models.list(currentProject));
|
|
821
|
+
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
822
|
+
// print the content models to console
|
|
823
|
+
for (const model of returnModels) {
|
|
824
|
+
log.raw('');
|
|
825
|
+
log.object(model);
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
} else {
|
|
829
|
+
log.success(
|
|
830
|
+
messages.models.get(currentProject, models?.length.toString() || '0')
|
|
831
|
+
);
|
|
832
|
+
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
833
|
+
// print the content models s#qto console
|
|
834
|
+
log.raw('');
|
|
835
|
+
for (const model of models || []) {
|
|
836
|
+
const components = model.components?.length || 0;
|
|
837
|
+
const contentTypes = model.contentTypes?.length || 0;
|
|
838
|
+
const dependencies =
|
|
839
|
+
(model.dependencies?.components?.length || 0) +
|
|
840
|
+
(model.dependencies?.contentTypes?.length || 0);
|
|
841
|
+
const dependencyOf =
|
|
842
|
+
(model.dependencyOf?.components?.length || 0) +
|
|
843
|
+
(model.dependencyOf?.contentTypes?.length || 0);
|
|
844
|
+
|
|
845
|
+
const hasAny =
|
|
846
|
+
components + contentTypes + dependencies + dependencyOf;
|
|
847
|
+
log.raw(
|
|
848
|
+
` - ${log.highlightText(log.boldText(model.id))} ${
|
|
849
|
+
hasAny
|
|
850
|
+
? log.infoText(
|
|
851
|
+
`{ ${components ? `components: ${components}, ` : ''}${
|
|
852
|
+
contentTypes ? `contentTypes: ${contentTypes}, ` : ''
|
|
853
|
+
}${dependencies ? `references: ${dependencies}, ` : ''}${
|
|
854
|
+
dependencyOf ? `required by: ${dependencyOf}` : ''
|
|
855
|
+
} }`
|
|
856
|
+
)
|
|
857
|
+
: ''
|
|
858
|
+
}`
|
|
859
|
+
);
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
log.raw('');
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
ImportContentModels = async ({
|
|
869
|
+
commit,
|
|
870
|
+
fromFile,
|
|
871
|
+
}: {
|
|
872
|
+
commit: boolean;
|
|
873
|
+
fromFile: string;
|
|
874
|
+
}) => {
|
|
875
|
+
const { currentProject, log, messages } = this;
|
|
876
|
+
|
|
877
|
+
const fileData = fromFile
|
|
878
|
+
? readJsonFile<(ContentType | Component)[]>(fromFile) || []
|
|
879
|
+
: [];
|
|
880
|
+
if (typeof fileData === 'string')
|
|
881
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
882
|
+
|
|
883
|
+
const contensis = await this.ConnectContensisImport({
|
|
884
|
+
commit,
|
|
885
|
+
fromFile,
|
|
886
|
+
importDataType: 'models',
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
if (contensis) {
|
|
890
|
+
log.line();
|
|
891
|
+
if (contensis.isPreview) {
|
|
892
|
+
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
893
|
+
} else {
|
|
894
|
+
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
const [migrateErr, result] = await contensis.MigrateContentModels();
|
|
898
|
+
|
|
899
|
+
if (migrateErr) logError(migrateErr);
|
|
900
|
+
else
|
|
901
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
902
|
+
// print the results to console
|
|
903
|
+
if (!commit) {
|
|
904
|
+
log.raw(log.boldText(`\nContent types:`));
|
|
905
|
+
if (!result.contentTypes) log.info(`- None returned\n`);
|
|
906
|
+
else printModelMigrationAnalysis(this, result.contentTypes);
|
|
907
|
+
|
|
908
|
+
log.raw(log.boldText(`\nComponents:`));
|
|
909
|
+
if (!result.components) log.info(`- None returned\n`);
|
|
910
|
+
else printModelMigrationAnalysis(this, result.components);
|
|
911
|
+
} else {
|
|
912
|
+
const migrateResult = result as MigrateModelsResult;
|
|
913
|
+
log.raw(log.boldText(`\nContent types:`));
|
|
914
|
+
printModelMigrationResult(
|
|
915
|
+
this,
|
|
916
|
+
migrateResult[currentProject].contentTypes
|
|
917
|
+
);
|
|
918
|
+
|
|
919
|
+
log.raw(log.boldText(`\nComponents:`));
|
|
920
|
+
printModelMigrationResult(
|
|
921
|
+
this,
|
|
922
|
+
migrateResult[currentProject].components
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
});
|
|
745
926
|
} else {
|
|
746
|
-
log.warning(messages.
|
|
927
|
+
log.warning(messages.models.noList(currentProject));
|
|
928
|
+
log.help(messages.connect.tip());
|
|
747
929
|
}
|
|
748
930
|
};
|
|
749
931
|
|
|
@@ -799,15 +981,12 @@ class ContensisCli {
|
|
|
799
981
|
|
|
800
982
|
RemoveContentTypes = async (contentTypeIds: string[], commit = false) => {
|
|
801
983
|
const { currentProject, log, messages } = this;
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
const [err, result] = await this.contensis.DeleteContentTypes(
|
|
809
|
-
contentTypeIds
|
|
810
|
-
);
|
|
984
|
+
const contensis = await this.ConnectContensisImport({
|
|
985
|
+
commit,
|
|
986
|
+
importDataType: 'user-input',
|
|
987
|
+
});
|
|
988
|
+
if (contensis) {
|
|
989
|
+
const [err, result] = await contensis.DeleteContentTypes(contentTypeIds);
|
|
811
990
|
|
|
812
991
|
if (err) {
|
|
813
992
|
log.error(
|
|
@@ -822,7 +1001,7 @@ class ContensisCli {
|
|
|
822
1001
|
messages.contenttypes.removed(
|
|
823
1002
|
currentProject,
|
|
824
1003
|
contentTypeIds.join('", "'),
|
|
825
|
-
!
|
|
1004
|
+
!contensis.isPreview
|
|
826
1005
|
)
|
|
827
1006
|
);
|
|
828
1007
|
// print the results to console
|
|
@@ -851,22 +1030,21 @@ class ContensisCli {
|
|
|
851
1030
|
|
|
852
1031
|
if (!Array.isArray(fileData)) fileData = [fileData];
|
|
853
1032
|
|
|
854
|
-
await this.ConnectContensisImport({
|
|
1033
|
+
const contensis = await this.ConnectContensisImport({
|
|
855
1034
|
commit,
|
|
856
|
-
|
|
1035
|
+
importDataType: fromFile ? 'user-input' : undefined,
|
|
857
1036
|
});
|
|
858
1037
|
|
|
859
|
-
if (
|
|
1038
|
+
if (contensis) {
|
|
860
1039
|
// Pass each content type to the target repo
|
|
861
1040
|
for (const contentType of fileData) {
|
|
862
1041
|
// Fix invalid data
|
|
863
1042
|
contentType.projectId = currentProject;
|
|
864
1043
|
delete contentType.uuid;
|
|
865
1044
|
|
|
866
|
-
const [err, created, createStatus] =
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
].repo.UpsertContentType(false, contentType);
|
|
1045
|
+
const [err, created, createStatus] = await contensis.models.targetRepos[
|
|
1046
|
+
currentProject
|
|
1047
|
+
].repo.UpsertContentType(false, contentType);
|
|
870
1048
|
|
|
871
1049
|
if (err) log.error(err.message, err);
|
|
872
1050
|
if (createStatus) {
|
|
@@ -884,6 +1062,53 @@ class ContensisCli {
|
|
|
884
1062
|
}
|
|
885
1063
|
};
|
|
886
1064
|
|
|
1065
|
+
DiffModels = async (
|
|
1066
|
+
{
|
|
1067
|
+
fromFile,
|
|
1068
|
+
}: {
|
|
1069
|
+
fromFile: string;
|
|
1070
|
+
},
|
|
1071
|
+
modelIds: string[] = []
|
|
1072
|
+
) => {
|
|
1073
|
+
const { log } = this;
|
|
1074
|
+
|
|
1075
|
+
let fileData = fromFile ? readJsonFile<ContentType[]>(fromFile) || [] : [];
|
|
1076
|
+
if (typeof fileData === 'string')
|
|
1077
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
1078
|
+
|
|
1079
|
+
if (!Array.isArray(fileData)) fileData = [fileData];
|
|
1080
|
+
|
|
1081
|
+
const contensis = await this.ConnectContensisImport({
|
|
1082
|
+
fromFile,
|
|
1083
|
+
importDataType: 'models',
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
if (contensis) {
|
|
1087
|
+
const [err, result] = (await to(
|
|
1088
|
+
contensis.models.Diff(fileData.length ? fileData : modelIds)
|
|
1089
|
+
)) as [Error | null, ContentTypesResult | undefined];
|
|
1090
|
+
|
|
1091
|
+
if (err) log.error(err.message, err);
|
|
1092
|
+
if (result)
|
|
1093
|
+
// print the content type to console
|
|
1094
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
1095
|
+
log.success(
|
|
1096
|
+
`Queried models ${log.infoText(
|
|
1097
|
+
`"${result.query.modelIds?.join(', ')}"`
|
|
1098
|
+
)}\n`
|
|
1099
|
+
);
|
|
1100
|
+
|
|
1101
|
+
log.raw(log.boldText(`Content types:`));
|
|
1102
|
+
if (!result.contentTypes) log.info(`- None returned\n`);
|
|
1103
|
+
else printModelMigrationAnalysis(this, result.contentTypes);
|
|
1104
|
+
|
|
1105
|
+
log.raw(log.boldText(`Components:`));
|
|
1106
|
+
if (!result.components) log.info(`- None returned\n`);
|
|
1107
|
+
else printModelMigrationAnalysis(this, result.components);
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
|
|
887
1112
|
PrintComponents = async () => {
|
|
888
1113
|
const { currentProject, log, messages } = this;
|
|
889
1114
|
await this.GetContentTypes();
|
|
@@ -933,13 +1158,12 @@ class ContensisCli {
|
|
|
933
1158
|
|
|
934
1159
|
RemoveComponents = async (componentIds: string[], commit = false) => {
|
|
935
1160
|
const { currentProject, log, messages } = this;
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
const [err, result] = await this.contensis.DeleteContentTypes(
|
|
1161
|
+
const contensis = await this.ConnectContensisImport({
|
|
1162
|
+
commit,
|
|
1163
|
+
importDataType: 'user-input',
|
|
1164
|
+
});
|
|
1165
|
+
if (contensis) {
|
|
1166
|
+
const [err, result] = await contensis.DeleteContentTypes(
|
|
943
1167
|
undefined,
|
|
944
1168
|
componentIds
|
|
945
1169
|
);
|
|
@@ -957,7 +1181,7 @@ class ContensisCli {
|
|
|
957
1181
|
messages.components.removed(
|
|
958
1182
|
currentProject,
|
|
959
1183
|
componentIds.join('", "'),
|
|
960
|
-
!
|
|
1184
|
+
!contensis.isPreview
|
|
961
1185
|
)
|
|
962
1186
|
);
|
|
963
1187
|
// print the results to console
|
|
@@ -986,22 +1210,21 @@ class ContensisCli {
|
|
|
986
1210
|
|
|
987
1211
|
if (!Array.isArray(fileData)) fileData = [fileData];
|
|
988
1212
|
|
|
989
|
-
await this.ConnectContensisImport({
|
|
1213
|
+
const contensis = await this.ConnectContensisImport({
|
|
990
1214
|
commit,
|
|
991
|
-
|
|
1215
|
+
importDataType: fromFile ? 'user-input' : undefined,
|
|
992
1216
|
});
|
|
993
1217
|
|
|
994
|
-
if (
|
|
1218
|
+
if (contensis) {
|
|
995
1219
|
// Pass each component to the target repo
|
|
996
1220
|
for (const component of fileData) {
|
|
997
1221
|
// Fix invalid data
|
|
998
1222
|
component.projectId = currentProject;
|
|
999
1223
|
delete component.uuid;
|
|
1000
1224
|
|
|
1001
|
-
const [err, created, createStatus] =
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
].repo.UpsertComponent(false, component);
|
|
1225
|
+
const [err, created, createStatus] = await contensis.models.targetRepos[
|
|
1226
|
+
currentProject
|
|
1227
|
+
].repo.UpsertComponent(false, component);
|
|
1005
1228
|
|
|
1006
1229
|
if (err) log.error(err.message, err);
|
|
1007
1230
|
if (createStatus) {
|
|
@@ -1021,19 +1244,18 @@ class ContensisCli {
|
|
|
1021
1244
|
|
|
1022
1245
|
RemoveEntry = async (id: string, commit = false) => {
|
|
1023
1246
|
const { currentEnv, log, messages } = this;
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
});
|
|
1247
|
+
const contensis = await this.ConnectContensisImport({
|
|
1248
|
+
commit,
|
|
1249
|
+
importDataType: 'user-input',
|
|
1250
|
+
});
|
|
1029
1251
|
|
|
1030
|
-
if (
|
|
1031
|
-
if (
|
|
1252
|
+
if (contensis) {
|
|
1253
|
+
if (contensis.isPreview) {
|
|
1032
1254
|
console.log(log.successText(` -- PREVIEW -- `));
|
|
1033
1255
|
} else {
|
|
1034
1256
|
console.log(log.warningText(` *** COMMITTING DELETE *** `));
|
|
1035
1257
|
}
|
|
1036
|
-
const [err, result] = await
|
|
1258
|
+
const [err, result] = await contensis.DeleteEntries();
|
|
1037
1259
|
if (result)
|
|
1038
1260
|
this.HandleFormattingAndOutput(result, () => {
|
|
1039
1261
|
// print the migrateResult to console
|
|
@@ -1061,21 +1283,21 @@ class ContensisCli {
|
|
|
1061
1283
|
withDependents?: boolean;
|
|
1062
1284
|
}) => {
|
|
1063
1285
|
const { currentProject, log, messages } = this;
|
|
1064
|
-
await this.ConnectContensis();
|
|
1286
|
+
const contensis = await this.ConnectContensis();
|
|
1065
1287
|
|
|
1066
|
-
if (
|
|
1288
|
+
if (contensis) {
|
|
1067
1289
|
log.line();
|
|
1068
|
-
const entries = await
|
|
1290
|
+
const entries = await contensis.GetEntries({ withDependents });
|
|
1069
1291
|
this.HandleFormattingAndOutput(entries, () =>
|
|
1070
1292
|
// print the entries to console
|
|
1071
1293
|
logEntriesTable(
|
|
1072
1294
|
entries,
|
|
1073
1295
|
currentProject,
|
|
1074
|
-
|
|
1296
|
+
contensis.payload.query?.fields
|
|
1075
1297
|
)
|
|
1076
1298
|
);
|
|
1077
1299
|
} else {
|
|
1078
|
-
log.warning(messages.
|
|
1300
|
+
log.warning(messages.models.noList(currentProject));
|
|
1079
1301
|
log.help(messages.connect.tip());
|
|
1080
1302
|
}
|
|
1081
1303
|
};
|
|
@@ -1089,26 +1311,21 @@ class ContensisCli {
|
|
|
1089
1311
|
}) => {
|
|
1090
1312
|
const { currentProject, log, messages } = this;
|
|
1091
1313
|
|
|
1092
|
-
const
|
|
1093
|
-
if (typeof fileData === 'string')
|
|
1094
|
-
throw new Error(`Import file format must be of type JSON`);
|
|
1095
|
-
|
|
1096
|
-
await this.ConnectContensisImport({
|
|
1314
|
+
const contensis = await this.ConnectContensisImport({
|
|
1097
1315
|
commit,
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
fileDataType: 'entries',
|
|
1316
|
+
fromFile,
|
|
1317
|
+
importDataType: 'entries',
|
|
1101
1318
|
});
|
|
1102
1319
|
|
|
1103
|
-
if (
|
|
1320
|
+
if (contensis) {
|
|
1104
1321
|
log.line();
|
|
1105
|
-
if (
|
|
1322
|
+
if (contensis.isPreview) {
|
|
1106
1323
|
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
1107
1324
|
} else {
|
|
1108
1325
|
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
1109
1326
|
}
|
|
1110
1327
|
|
|
1111
|
-
const [migrateErr, migrateResult] = await
|
|
1328
|
+
const [migrateErr, migrateResult] = await contensis.MigrateEntries();
|
|
1112
1329
|
|
|
1113
1330
|
if (migrateErr) logError(migrateErr);
|
|
1114
1331
|
else
|
|
@@ -1117,7 +1334,7 @@ class ContensisCli {
|
|
|
1117
1334
|
printMigrateResult(this, migrateResult);
|
|
1118
1335
|
});
|
|
1119
1336
|
} else {
|
|
1120
|
-
log.warning(messages.
|
|
1337
|
+
log.warning(messages.models.noList(currentProject));
|
|
1121
1338
|
log.help(messages.connect.tip());
|
|
1122
1339
|
}
|
|
1123
1340
|
};
|
package/src/shell.ts
CHANGED
|
@@ -40,12 +40,11 @@ class ContensisShell {
|
|
|
40
40
|
inquirerPrompt.setConfig({
|
|
41
41
|
history: {
|
|
42
42
|
save: true,
|
|
43
|
-
folder: path.join(process.cwd()
|
|
43
|
+
folder: path.join(process.cwd()),
|
|
44
44
|
limit: 100,
|
|
45
45
|
blacklist: ['quit'],
|
|
46
46
|
},
|
|
47
47
|
});
|
|
48
|
-
// inquirer.registerPrompt('command', inquirerPrompt);
|
|
49
48
|
|
|
50
49
|
const { log, messages } = this;
|
|
51
50
|
|
|
@@ -136,15 +135,18 @@ class ContensisShell {
|
|
|
136
135
|
availableCommands.push('login', 'list projects', 'set project');
|
|
137
136
|
if (userId)
|
|
138
137
|
availableCommands.push(
|
|
138
|
+
'diff models',
|
|
139
139
|
'get block',
|
|
140
140
|
'get block logs',
|
|
141
141
|
'get contenttype',
|
|
142
142
|
'get component',
|
|
143
143
|
'get entries',
|
|
144
|
+
'get model',
|
|
144
145
|
'get version',
|
|
145
146
|
'import contenttypes',
|
|
146
147
|
'import components',
|
|
147
148
|
'import entries',
|
|
149
|
+
'import models',
|
|
148
150
|
'list blocks',
|
|
149
151
|
'list contenttypes',
|
|
150
152
|
'list components',
|