@kontent-ai/migration-toolkit 2.9.1 → 3.0.0-1
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/README.md +19 -17
- package/dist/core/config.js +3 -3
- package/dist/core/config.js.map +1 -1
- package/dist/core/helpers/workflow-helper.d.ts +1 -1
- package/dist/core/helpers/workflow-helper.js +28 -26
- package/dist/core/helpers/workflow-helper.js.map +1 -1
- package/dist/core/logs/loggers.d.ts +1 -1
- package/dist/core/logs/loggers.js +15 -15
- package/dist/core/logs/loggers.js.map +1 -1
- package/dist/core/models/core.models.d.ts +29 -22
- package/dist/core/models/error.models.d.ts +26 -0
- package/dist/core/models/error.models.js +104 -0
- package/dist/core/models/error.models.js.map +1 -0
- package/dist/core/models/log.models.d.ts +2 -2
- package/dist/core/models/migration.models.d.ts +17 -19
- package/dist/core/models/migration.schema.d.ts +9 -9
- package/dist/core/models/migration.schema.js +28 -28
- package/dist/core/models/migration.schema.js.map +1 -1
- package/dist/core/utils/array.utils.d.ts +1 -1
- package/dist/core/utils/array.utils.js +4 -3
- package/dist/core/utils/array.utils.js.map +1 -1
- package/dist/core/utils/binary-data.utils.d.ts +1 -1
- package/dist/core/utils/binary-data.utils.js +6 -6
- package/dist/core/utils/binary-data.utils.js.map +1 -1
- package/dist/core/utils/confirm.utils.d.ts +3 -1
- package/dist/core/utils/confirm.utils.js +92 -24
- package/dist/core/utils/confirm.utils.js.map +1 -1
- package/dist/core/utils/error.utils.d.ts +1 -1
- package/dist/core/utils/error.utils.js +16 -14
- package/dist/core/utils/error.utils.js.map +1 -1
- package/dist/core/utils/external-id.utils.js +1 -1
- package/dist/core/utils/external-id.utils.js.map +1 -1
- package/dist/core/utils/global.utils.d.ts +3 -3
- package/dist/core/utils/global.utils.js +20 -18
- package/dist/core/utils/global.utils.js.map +1 -1
- package/dist/core/utils/http.utils.d.ts +2 -2
- package/dist/core/utils/http.utils.js +4 -4
- package/dist/core/utils/http.utils.js.map +1 -1
- package/dist/core/utils/management-client-utils.d.ts +4 -4
- package/dist/core/utils/management-client-utils.js +37 -34
- package/dist/core/utils/management-client-utils.js.map +1 -1
- package/dist/core/utils/processing-utils.d.ts +4 -4
- package/dist/core/utils/processing-utils.js +13 -13
- package/dist/core/utils/processing-utils.js.map +1 -1
- package/dist/core/utils/run.utils.d.ts +2 -2
- package/dist/core/utils/run.utils.js +7 -7
- package/dist/core/utils/run.utils.js.map +1 -1
- package/dist/core/utils/try.utils.d.ts +14 -0
- package/dist/core/utils/try.utils.js +18 -0
- package/dist/core/utils/try.utils.js.map +1 -0
- package/dist/export/context/export-context-fetcher.d.ts +1 -1
- package/dist/export/context/export-context-fetcher.js +92 -62
- package/dist/export/context/export-context-fetcher.js.map +1 -1
- package/dist/export/export-manager.d.ts +2 -2
- package/dist/export/export-manager.js +73 -59
- package/dist/export/export-manager.js.map +1 -1
- package/dist/export/export.models.d.ts +21 -2
- package/dist/export/utils/export.utils.d.ts +1 -1
- package/dist/export/utils/export.utils.js +3 -2
- package/dist/export/utils/export.utils.js.map +1 -1
- package/dist/file/file-manager.d.ts +2 -2
- package/dist/file/file-manager.js +7 -7
- package/dist/file/file-manager.js.map +1 -1
- package/dist/import/comparers/asset-comparer.d.ts +2 -2
- package/dist/import/comparers/asset-comparer.js +12 -11
- package/dist/import/comparers/asset-comparer.js.map +1 -1
- package/dist/import/context/import-context-fetcher.d.ts +1 -1
- package/dist/import/context/import-context-fetcher.js +77 -73
- package/dist/import/context/import-context-fetcher.js.map +1 -1
- package/dist/import/import-manager.d.ts +1 -1
- package/dist/import/import-manager.js +59 -56
- package/dist/import/import-manager.js.map +1 -1
- package/dist/import/import.models.d.ts +6 -2
- package/dist/import/importers/assets-importer.d.ts +3 -3
- package/dist/import/importers/assets-importer.js +46 -43
- package/dist/import/importers/assets-importer.js.map +1 -1
- package/dist/import/importers/content-items-importer.d.ts +3 -3
- package/dist/import/importers/content-items-importer.js +28 -25
- package/dist/import/importers/content-items-importer.js.map +1 -1
- package/dist/import/importers/language-variant-importer.d.ts +3 -3
- package/dist/import/importers/language-variant-importer.js +45 -45
- package/dist/import/importers/language-variant-importer.js.map +1 -1
- package/dist/import/importers/workflow-importer.d.ts +3 -2
- package/dist/import/importers/workflow-importer.js +58 -54
- package/dist/import/importers/workflow-importer.js.map +1 -1
- package/dist/import/utils/import.utils.d.ts +1 -1
- package/dist/import/utils/import.utils.js +3 -2
- package/dist/import/utils/import.utils.js.map +1 -1
- package/dist/index.d.ts +11 -7
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/dist/metadata.js +3 -3
- package/dist/metadata.js.map +1 -1
- package/dist/node/cli/actions/export-action.d.ts +1 -1
- package/dist/node/cli/actions/export-action.js +29 -23
- package/dist/node/cli/actions/export-action.js.map +1 -1
- package/dist/node/cli/actions/import-action.d.ts +1 -1
- package/dist/node/cli/actions/import-action.js +15 -12
- package/dist/node/cli/actions/import-action.js.map +1 -1
- package/dist/node/cli/actions/migrate-action.d.ts +1 -1
- package/dist/node/cli/actions/migrate-action.js +26 -22
- package/dist/node/cli/actions/migrate-action.js.map +1 -1
- package/dist/node/cli/app.js +13 -12
- package/dist/node/cli/app.js.map +1 -1
- package/dist/node/cli/args/args-fetcher.d.ts +1 -1
- package/dist/node/cli/args/args-fetcher.js +14 -13
- package/dist/node/cli/args/args-fetcher.js.map +1 -1
- package/dist/node/cli/args/args-setter.d.ts +1 -1
- package/dist/node/cli/args/args-setter.js +8 -6
- package/dist/node/cli/args/args-setter.js.map +1 -1
- package/dist/node/cli/cli.models.d.ts +2 -2
- package/dist/node/cli/commands.js +68 -56
- package/dist/node/cli/commands.js.map +1 -1
- package/dist/toolkit/elements-builder.d.ts +1 -1
- package/dist/toolkit/elements-builder.js +12 -12
- package/dist/toolkit/elements-builder.js.map +1 -1
- package/dist/toolkit/export.d.ts +2 -2
- package/dist/toolkit/export.js +8 -8
- package/dist/toolkit/export.js.map +1 -1
- package/dist/toolkit/file.d.ts +2 -1
- package/dist/toolkit/file.js +18 -16
- package/dist/toolkit/file.js.map +1 -1
- package/dist/toolkit/import.d.ts +1 -1
- package/dist/toolkit/import.js +12 -12
- package/dist/toolkit/import.js.map +1 -1
- package/dist/toolkit/migrate.d.ts +13 -4
- package/dist/toolkit/migrate.js +15 -13
- package/dist/toolkit/migrate.js.map +1 -1
- package/dist/translation/extraction/items-extraction.processor.d.ts +5 -4
- package/dist/translation/extraction/items-extraction.processor.js +73 -35
- package/dist/translation/extraction/items-extraction.processor.js.map +1 -1
- package/dist/translation/helpers/export-placeholder.utils.d.ts +11 -0
- package/dist/translation/helpers/export-placeholder.utils.js +11 -0
- package/dist/translation/helpers/export-placeholder.utils.js.map +1 -0
- package/dist/translation/helpers/rich-text.processor.d.ts +6 -6
- package/dist/translation/helpers/rich-text.processor.js +38 -38
- package/dist/translation/helpers/rich-text.processor.js.map +1 -1
- package/dist/translation/transforms/export-transforms.d.ts +2 -2
- package/dist/translation/transforms/export-transforms.js +93 -67
- package/dist/translation/transforms/export-transforms.js.map +1 -1
- package/dist/translation/transforms/import-transforms.d.ts +2 -2
- package/dist/translation/transforms/import-transforms.js +38 -40
- package/dist/translation/transforms/import-transforms.js.map +1 -1
- package/dist/zip/zip-manager.d.ts +4 -3
- package/dist/zip/zip-manager.js +9 -9
- package/dist/zip/zip-manager.js.map +1 -1
- package/dist/zip/zip-packager.d.ts +2 -2
- package/dist/zip/zip-packager.js +19 -17
- package/dist/zip/zip-packager.js.map +1 -1
- package/dist/zip/zip-transformer.d.ts +3 -2
- package/dist/zip/zip-transformer.js +16 -15
- package/dist/zip/zip-transformer.js.map +1 -1
- package/dist/zip/zip.models.d.ts +2 -2
- package/lib/core/config.ts +6 -6
- package/lib/core/helpers/workflow-helper.ts +190 -185
- package/lib/core/logs/loggers.ts +52 -52
- package/lib/core/models/core.models.ts +130 -119
- package/lib/core/models/error.models.ts +148 -0
- package/lib/core/models/log.models.ts +20 -20
- package/lib/core/models/migration.models.ts +54 -57
- package/lib/core/models/migration.schema.ts +108 -108
- package/lib/core/utils/array.utils.ts +43 -42
- package/lib/core/utils/binary-data.utils.ts +16 -16
- package/lib/core/utils/confirm.utils.ts +184 -106
- package/lib/core/utils/error.utils.ts +69 -72
- package/lib/core/utils/external-id.utils.ts +4 -4
- package/lib/core/utils/global.utils.ts +81 -75
- package/lib/core/utils/http.utils.ts +23 -23
- package/lib/core/utils/management-client-utils.ts +189 -186
- package/lib/core/utils/processing-utils.ts +82 -82
- package/lib/core/utils/run.utils.ts +50 -50
- package/lib/core/utils/try.utils.ts +30 -0
- package/lib/export/context/export-context-fetcher.ts +472 -447
- package/lib/export/export-manager.ts +250 -232
- package/lib/export/export.models.ts +71 -56
- package/lib/export/utils/export.utils.ts +9 -7
- package/lib/file/file-manager.ts +28 -28
- package/lib/import/comparers/asset-comparer.ts +107 -106
- package/lib/import/context/import-context-fetcher.ts +462 -462
- package/lib/import/import-manager.ts +243 -240
- package/lib/import/import.models.ts +69 -67
- package/lib/import/importers/assets-importer.ts +240 -236
- package/lib/import/importers/content-items-importer.ts +126 -122
- package/lib/import/importers/language-variant-importer.ts +324 -328
- package/lib/import/importers/workflow-importer.ts +372 -367
- package/lib/import/utils/import.utils.ts +9 -7
- package/lib/index.ts +12 -8
- package/lib/metadata.ts +3 -4
- package/lib/node/cli/actions/export-action.ts +44 -38
- package/lib/node/cli/actions/import-action.ts +32 -29
- package/lib/node/cli/actions/migrate-action.ts +50 -46
- package/lib/node/cli/app.ts +21 -21
- package/lib/node/cli/args/args-fetcher.ts +55 -54
- package/lib/node/cli/args/args-setter.ts +34 -32
- package/lib/node/cli/cli.models.ts +17 -17
- package/lib/node/cli/commands.ts +165 -153
- package/lib/toolkit/elements-builder.ts +69 -69
- package/lib/toolkit/export.ts +21 -21
- package/lib/toolkit/file.ts +59 -53
- package/lib/toolkit/import.ts +32 -32
- package/lib/toolkit/migrate.ts +60 -49
- package/lib/translation/extraction/items-extraction.processor.ts +203 -173
- package/lib/translation/helpers/export-placeholder.utils.ts +10 -0
- package/lib/translation/helpers/rich-text.processor.ts +311 -311
- package/lib/translation/transforms/export-transforms.ts +313 -279
- package/lib/translation/transforms/import-transforms.ts +188 -191
- package/lib/zip/zip-manager.ts +28 -27
- package/lib/zip/zip-packager.ts +75 -73
- package/lib/zip/zip-transformer.ts +112 -107
- package/lib/zip/zip.models.ts +7 -7
- package/package.json +91 -84
- package/dist/core/index.d.ts +0 -16
- package/dist/core/index.js +0 -17
- package/dist/core/index.js.map +0 -1
- package/dist/export/index.d.ts +0 -2
- package/dist/export/index.js +0 -3
- package/dist/export/index.js.map +0 -1
- package/dist/file/index.d.ts +0 -1
- package/dist/file/index.js +0 -2
- package/dist/file/index.js.map +0 -1
- package/dist/import/index.d.ts +0 -2
- package/dist/import/index.js +0 -3
- package/dist/import/index.js.map +0 -1
- package/dist/toolkit/index.d.ts +0 -5
- package/dist/toolkit/index.js +0 -6
- package/dist/toolkit/index.js.map +0 -1
- package/dist/translation/index.d.ts +0 -4
- package/dist/translation/index.js +0 -5
- package/dist/translation/index.js.map +0 -1
- package/dist/zip/index.d.ts +0 -4
- package/dist/zip/index.js +0 -5
- package/dist/zip/index.js.map +0 -1
- package/lib/core/index.ts +0 -18
- package/lib/export/index.ts +0 -2
- package/lib/file/index.ts +0 -1
- package/lib/import/index.ts +0 -2
- package/lib/toolkit/index.ts +0 -5
- package/lib/translation/index.ts +0 -4
- package/lib/zip/index.ts +0 -4
|
@@ -1,264 +1,267 @@
|
|
|
1
|
-
import type { ManagementClient } from
|
|
2
|
-
import chalk from
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import type { ManagementClient } from "@kontent-ai/management-sdk";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { getDefaultLogger } from "../core/logs/loggers.js";
|
|
4
|
+
import type { Logger } from "../core/models/log.models.js";
|
|
5
|
+
import { extractErrorData } from "../core/utils/error.utils.js";
|
|
6
|
+
import { defaultExternalIdGenerator } from "../core/utils/external-id.utils.js";
|
|
7
|
+
import { getMigrationManagementClient } from "../core/utils/management-client-utils.js";
|
|
8
|
+
import { importContextFetcherAsync } from "./context/import-context-fetcher.js";
|
|
9
|
+
import type { ImportConfig, ImportContext, ImportedItem, ImportedLanguageVariant, ImportResult } from "./import.models.js";
|
|
10
|
+
import { assetsImporter } from "./importers/assets-importer.js";
|
|
11
|
+
import { contentItemsImporter } from "./importers/content-items-importer.js";
|
|
12
|
+
import { languageVariantImporter } from "./importers/language-variant-importer.js";
|
|
10
13
|
|
|
11
14
|
const reportFilename: string = `import-report.json`;
|
|
12
15
|
|
|
13
16
|
type ReportResult = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
17
|
+
readonly errorsCount: number;
|
|
18
|
+
readonly assets: {
|
|
19
|
+
readonly count: number;
|
|
20
|
+
readonly successful: Array<{ readonly codename: string }>;
|
|
21
|
+
readonly failed: Array<{ readonly codename: string; readonly error: string }>;
|
|
22
|
+
};
|
|
23
|
+
readonly languageVariants: {
|
|
24
|
+
readonly count: number;
|
|
25
|
+
readonly successful: Array<{
|
|
26
|
+
readonly codename: string;
|
|
27
|
+
readonly language: { readonly codename: string };
|
|
28
|
+
readonly type: { readonly codename: string };
|
|
29
|
+
}>;
|
|
30
|
+
readonly failed: Array<{
|
|
31
|
+
readonly codename: string;
|
|
32
|
+
readonly language: { readonly codename: string };
|
|
33
|
+
readonly type: { readonly codename: string };
|
|
34
|
+
readonly error: string;
|
|
35
|
+
}>;
|
|
36
|
+
};
|
|
37
|
+
readonly contentItems: {
|
|
38
|
+
readonly count: number;
|
|
39
|
+
readonly successful: Array<{ readonly codename: string }>;
|
|
40
|
+
readonly failed: Array<{ readonly codename: string; readonly type: { readonly codename: string }; readonly error: string }>;
|
|
41
|
+
};
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
export function importManager(config: ImportConfig) {
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
const logger: Logger = config.logger ?? getDefaultLogger();
|
|
46
|
+
const targetEnvironmentClient: Readonly<ManagementClient> = getMigrationManagementClient(config);
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
const importAssetsAsync = async (importContext: ImportContext): Promise<Pick<ImportResult, "editedAssets" | "uploadedAssets">> => {
|
|
49
|
+
if (!importContext.categorizedImportData.assets.length) {
|
|
50
|
+
logger.log({
|
|
51
|
+
type: "info",
|
|
52
|
+
message: `There are no assets to import`,
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
editedAssets: [],
|
|
56
|
+
uploadedAssets: [],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
return await assetsImporter({
|
|
61
|
+
client: targetEnvironmentClient,
|
|
62
|
+
importContext: importContext,
|
|
63
|
+
logger: logger,
|
|
64
|
+
}).importAsync();
|
|
65
|
+
};
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const importContentItemsAsync = async (importContext: ImportContext): Promise<readonly ImportedItem[]> => {
|
|
68
|
+
if (!importContext.categorizedImportData.contentItems.length) {
|
|
69
|
+
logger.log({
|
|
70
|
+
type: "info",
|
|
71
|
+
message: `There are no content items to import`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
return await contentItemsImporter({
|
|
76
|
+
client: targetEnvironmentClient,
|
|
77
|
+
importContext: importContext,
|
|
78
|
+
logger: logger,
|
|
79
|
+
}).importAsync();
|
|
80
|
+
};
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
const importLanguageVariantsAsync = async (
|
|
83
|
+
importContext: ImportContext,
|
|
84
|
+
contentItems: readonly ImportedItem[],
|
|
85
|
+
): Promise<readonly ImportedLanguageVariant[]> => {
|
|
86
|
+
if (!importContext.categorizedImportData.contentItems.length) {
|
|
87
|
+
logger.log({
|
|
88
|
+
type: "info",
|
|
89
|
+
message: `There are no language variants to import`,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
return await languageVariantImporter({
|
|
94
|
+
client: targetEnvironmentClient,
|
|
95
|
+
importContext: importContext,
|
|
96
|
+
logger: logger,
|
|
97
|
+
preparedContentItems: contentItems,
|
|
98
|
+
}).importAsync();
|
|
99
|
+
};
|
|
97
100
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
101
|
+
const getReportResult = (importResult: ImportResult): ReportResult => {
|
|
102
|
+
return {
|
|
103
|
+
errorsCount:
|
|
104
|
+
importResult.editedAssets.filter((m) => m.state === "error").length +
|
|
105
|
+
importResult.uploadedAssets.filter((m) => m.state === "error").length +
|
|
106
|
+
importResult.contentItems.filter((m) => m.state === "error").length +
|
|
107
|
+
importResult.languageVariants.filter((m) => m.state === "error").length,
|
|
108
|
+
assets: {
|
|
109
|
+
count: importResult.uploadedAssets.length + importResult.editedAssets.length,
|
|
110
|
+
successful: [
|
|
111
|
+
...importResult.uploadedAssets.filter((m) => m.state === "valid").map((m) => m.inputItem.codename),
|
|
112
|
+
...importResult.editedAssets.filter((m) => m.state === "valid").map((m) => m.inputItem.migrationAsset.codename),
|
|
113
|
+
].map((m) => {
|
|
114
|
+
return {
|
|
115
|
+
codename: m,
|
|
116
|
+
};
|
|
117
|
+
}),
|
|
118
|
+
failed: [
|
|
119
|
+
...importResult.uploadedAssets
|
|
120
|
+
.filter((m) => m.state === "error")
|
|
121
|
+
.map((m) => {
|
|
122
|
+
return {
|
|
123
|
+
codename: m.inputItem.codename,
|
|
124
|
+
error: extractErrorData(m.error).message,
|
|
125
|
+
};
|
|
126
|
+
}),
|
|
127
|
+
...importResult.editedAssets
|
|
128
|
+
.filter((m) => m.state === "error")
|
|
129
|
+
.map((m) => {
|
|
130
|
+
return {
|
|
131
|
+
codename: m.inputItem.migrationAsset.codename,
|
|
132
|
+
error: extractErrorData(m.error).message,
|
|
133
|
+
};
|
|
134
|
+
}),
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
contentItems: {
|
|
138
|
+
count: importResult.contentItems.length,
|
|
139
|
+
successful: importResult.contentItems
|
|
140
|
+
.filter((m) => m.state === "valid")
|
|
141
|
+
.map((m) => {
|
|
142
|
+
return {
|
|
143
|
+
codename: m.inputItem.system.codename,
|
|
144
|
+
};
|
|
145
|
+
}),
|
|
146
|
+
failed: importResult.contentItems
|
|
147
|
+
.filter((m) => m.state === "error")
|
|
148
|
+
.map((m) => {
|
|
149
|
+
return {
|
|
150
|
+
codename: m.inputItem.system.codename,
|
|
151
|
+
type: m.inputItem.system.type,
|
|
152
|
+
error: extractErrorData(m.error).message,
|
|
153
|
+
};
|
|
154
|
+
}),
|
|
155
|
+
},
|
|
156
|
+
languageVariants: {
|
|
157
|
+
count: importResult.languageVariants.length,
|
|
158
|
+
successful: importResult.languageVariants
|
|
159
|
+
.filter((m) => m.state === "valid")
|
|
160
|
+
.map((m) => {
|
|
161
|
+
return {
|
|
162
|
+
codename: m.inputItem.system.codename,
|
|
163
|
+
language: m.inputItem.system.language,
|
|
164
|
+
type: m.inputItem.system.type,
|
|
165
|
+
};
|
|
166
|
+
}),
|
|
167
|
+
failed: importResult.languageVariants
|
|
168
|
+
.filter((m) => m.state === "error")
|
|
169
|
+
.map((m) => {
|
|
170
|
+
return {
|
|
171
|
+
codename: m.inputItem.system.codename,
|
|
172
|
+
language: m.inputItem.system.language,
|
|
173
|
+
type: m.inputItem.system.type,
|
|
174
|
+
error: extractErrorData(m.error).message,
|
|
175
|
+
};
|
|
176
|
+
}),
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
};
|
|
177
180
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
181
|
+
const printReportToConsole = (reportResult: ReportResult, logger: Logger): void => {
|
|
182
|
+
const errors: readonly string[][] = [
|
|
183
|
+
...reportResult.assets.failed.map((m) => [
|
|
184
|
+
`Object type: ${chalk.yellow("Asset")}`,
|
|
185
|
+
`Codename: ${chalk.yellow(m.codename)}`,
|
|
186
|
+
`${chalk.red(m.error)}`,
|
|
187
|
+
]),
|
|
188
|
+
...reportResult.contentItems.failed.map((m) => [
|
|
189
|
+
`Object type: ${chalk.yellow("Content item")}`,
|
|
190
|
+
`Codename:${chalk.yellow(m.codename)}`,
|
|
191
|
+
`Content Type: ${chalk.yellow(m.type.codename)}`,
|
|
192
|
+
`${chalk.red(m.error)}`,
|
|
193
|
+
]),
|
|
194
|
+
...reportResult.languageVariants.failed.map((m) => [
|
|
195
|
+
`Object type: ${chalk.yellow("Language variant")}`,
|
|
196
|
+
`Codename: ${chalk.yellow(m.codename)}`,
|
|
197
|
+
`Language: ${chalk.yellow(m.language.codename)}`,
|
|
198
|
+
`Content Type: ${chalk.yellow(m.type.codename)}`,
|
|
199
|
+
`${chalk.red(m.error)}`,
|
|
200
|
+
]),
|
|
201
|
+
];
|
|
199
202
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
errors.forEach((error, index) => {
|
|
204
|
+
logger.log({ message: `${chalk.red(`\nError #${index + 1}`)}` });
|
|
205
|
+
error.forEach((m) => {
|
|
206
|
+
logger.log({ message: m });
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
207
210
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
211
|
+
return {
|
|
212
|
+
async importAsync(): Promise<ImportResult> {
|
|
213
|
+
const importContext = await (
|
|
214
|
+
await importContextFetcherAsync({
|
|
215
|
+
migrationData: config.data,
|
|
216
|
+
externalIdGenerator: config.externalIdGenerator ?? defaultExternalIdGenerator,
|
|
217
|
+
logger: logger,
|
|
218
|
+
managementClient: targetEnvironmentClient,
|
|
219
|
+
})
|
|
220
|
+
).getImportContextAsync();
|
|
218
221
|
|
|
219
|
-
|
|
220
|
-
|
|
222
|
+
// #1 Assets
|
|
223
|
+
const { editedAssets, uploadedAssets } = await importAssetsAsync(importContext);
|
|
221
224
|
|
|
222
|
-
|
|
223
|
-
|
|
225
|
+
// #2 Content items
|
|
226
|
+
const contentItems = await importContentItemsAsync(importContext);
|
|
224
227
|
|
|
225
|
-
|
|
226
|
-
|
|
228
|
+
// #3 Language variants
|
|
229
|
+
const languageVariants = await importLanguageVariantsAsync(importContext, contentItems);
|
|
227
230
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
231
|
+
const reportResult = getReportResult({
|
|
232
|
+
contentItems,
|
|
233
|
+
editedAssets,
|
|
234
|
+
languageVariants,
|
|
235
|
+
uploadedAssets,
|
|
236
|
+
});
|
|
234
237
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
238
|
+
if (reportResult.errorsCount) {
|
|
239
|
+
printReportToConsole(reportResult, logger);
|
|
240
|
+
logger.log({
|
|
241
|
+
type: "completed",
|
|
242
|
+
message: `Finished import with '${chalk.red(reportResult.errorsCount)}' ${
|
|
243
|
+
reportResult.errorsCount === 1 ? "error" : "errors"
|
|
244
|
+
}`,
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
logger.log({
|
|
248
|
+
type: "completed",
|
|
249
|
+
message: `Finished import`,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
249
252
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
253
|
+
return {
|
|
254
|
+
editedAssets,
|
|
255
|
+
uploadedAssets,
|
|
256
|
+
contentItems,
|
|
257
|
+
languageVariants,
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
getReportFile(importResult: ImportResult): { readonly filename: string; readonly content: string } {
|
|
261
|
+
return {
|
|
262
|
+
filename: reportFilename,
|
|
263
|
+
content: JSON.stringify(getReportResult(importResult)),
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
};
|
|
264
267
|
}
|