@kontent-ai/migration-toolkit 2.9.1 → 3.0.0-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/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 +27 -22
- package/dist/core/models/error.models.d.ts +14 -0
- package/dist/core/models/error.models.js +25 -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 +14 -14
- 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 +1 -1
- package/dist/core/utils/confirm.utils.js +21 -20
- 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 +34 -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/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 +46 -37
- 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 +28 -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 +25 -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 +128 -119
- package/lib/core/models/error.models.ts +41 -0
- package/lib/core/models/log.models.ts +20 -20
- package/lib/core/models/migration.models.ts +54 -54
- 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 +106 -105
- 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 +186 -186
- package/lib/core/utils/processing-utils.ts +82 -82
- package/lib/core/utils/run.utils.ts +50 -50
- package/lib/export/context/export-context-fetcher.ts +472 -447
- package/lib/export/export-manager.ts +233 -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 +43 -38
- package/lib/node/cli/actions/import-action.ts +32 -29
- package/lib/node/cli/actions/migrate-action.ts +49 -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,9 +1,10 @@
|
|
|
1
|
-
import type { LanguageVariantElements, SharedContracts } from
|
|
2
|
-
import { LanguageVariantElementsBuilder } from
|
|
3
|
-
import type { MigrationElementTransformData, MigrationElementType, MigrationItem } from
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
1
|
+
import type { LanguageVariantElements, SharedContracts } from "@kontent-ai/management-sdk";
|
|
2
|
+
import { LanguageVariantElementsBuilder } from "@kontent-ai/management-sdk";
|
|
3
|
+
import type { MigrationElementTransformData, MigrationElementType, MigrationItem } from "../../core/models/migration.models.js";
|
|
4
|
+
import { parseAsMigrationReferencesArray } from "../../core/utils/array.utils.js";
|
|
5
|
+
import { isString } from "../../core/utils/global.utils.js";
|
|
6
|
+
import type { ImportContext, ImportTransformFunc } from "../../import/import.models.js";
|
|
7
|
+
import { richTextProcessor } from "../helpers/rich-text.processor.js";
|
|
7
8
|
|
|
8
9
|
const elementsBuilder = new LanguageVariantElementsBuilder();
|
|
9
10
|
|
|
@@ -12,202 +13,198 @@ const elementsBuilder = new LanguageVariantElementsBuilder();
|
|
|
12
13
|
* Kontent.ai Management API understands
|
|
13
14
|
*/
|
|
14
15
|
export const importTransforms: Readonly<Record<MigrationElementType, ImportTransformFunc>> = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
16
|
+
subpages: (data) => {
|
|
17
|
+
return elementsBuilder.linkedItemsElement({
|
|
18
|
+
element: {
|
|
19
|
+
codename: data.elementCodename,
|
|
20
|
+
},
|
|
21
|
+
value: parseAsMigrationReferencesArray(data.elementData.value).map((m) => {
|
|
22
|
+
return {
|
|
23
|
+
codename: m.codename,
|
|
24
|
+
};
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
asset: (data) => {
|
|
29
|
+
const assetReferences = parseAsMigrationReferencesArray(data.elementData.value)
|
|
30
|
+
.map((reference) => reference.codename)
|
|
31
|
+
.map<Readonly<SharedContracts.IReferenceObjectContract>>((codename) => {
|
|
32
|
+
const assetState = data.importContext.getAssetStateInTargetEnvironment(codename);
|
|
33
|
+
|
|
34
|
+
// only reference with external_id if item does not exist in target env
|
|
35
|
+
// API currently only supports referencing assets by ids only, not by codenames
|
|
36
|
+
return {
|
|
37
|
+
id: assetState.asset ? assetState.asset.id : undefined,
|
|
38
|
+
external_id: assetState.asset ? undefined : assetState.externalIdToUse,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return elementsBuilder.assetElement({
|
|
43
|
+
element: {
|
|
44
|
+
codename: data.elementCodename,
|
|
45
|
+
},
|
|
46
|
+
value: assetReferences,
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
custom: (data) => {
|
|
50
|
+
return elementsBuilder.customElement({
|
|
51
|
+
element: {
|
|
52
|
+
codename: data.elementCodename,
|
|
53
|
+
},
|
|
54
|
+
value: data.elementData.value && isString(data.elementData.value) ? data.elementData.value : null,
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
date_time: (data) => {
|
|
58
|
+
return elementsBuilder.dateTimeElement({
|
|
59
|
+
element: {
|
|
60
|
+
codename: data.elementCodename,
|
|
61
|
+
},
|
|
62
|
+
value: data.elementData.value && isString(data.elementData.value) ? data.elementData.value : null,
|
|
63
|
+
display_timezone: data.elementData.display_timezone ?? null,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
modular_content: (data) => {
|
|
67
|
+
const linkedItemReferences = parseAsMigrationReferencesArray(data.elementData.value)
|
|
68
|
+
.map((reference) => reference.codename)
|
|
69
|
+
.map<Readonly<SharedContracts.IReferenceObjectContract>>((codename) => {
|
|
70
|
+
const itemState = data.importContext.getItemStateInTargetEnvironment(codename);
|
|
71
|
+
|
|
72
|
+
// only reference with external_id if item does not exist in target env
|
|
73
|
+
return {
|
|
74
|
+
codename: itemState.item ? itemState.item.codename : undefined,
|
|
75
|
+
external_id: itemState.item ? undefined : itemState.externalIdToUse,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return elementsBuilder.linkedItemsElement({
|
|
80
|
+
element: {
|
|
81
|
+
codename: data.elementCodename,
|
|
82
|
+
},
|
|
83
|
+
value: linkedItemReferences,
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
multiple_choice: (data) => {
|
|
87
|
+
return elementsBuilder.multipleChoiceElement({
|
|
88
|
+
element: {
|
|
89
|
+
codename: data.elementCodename,
|
|
90
|
+
},
|
|
91
|
+
value: parseAsMigrationReferencesArray(data.elementData.value).map((m) => {
|
|
92
|
+
return {
|
|
93
|
+
codename: m.codename,
|
|
94
|
+
};
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
number: (data) => {
|
|
99
|
+
return elementsBuilder.numberElement({
|
|
100
|
+
element: {
|
|
101
|
+
codename: data.elementCodename,
|
|
102
|
+
},
|
|
103
|
+
value: data.elementData.value ? +data.elementData.value : null,
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
rich_text: (data) => {
|
|
107
|
+
return elementsBuilder.richTextElement({
|
|
108
|
+
element: {
|
|
109
|
+
codename: data.elementCodename,
|
|
110
|
+
},
|
|
111
|
+
components: mapComponents({
|
|
112
|
+
importContext: data.importContext,
|
|
113
|
+
migrationItems: data.migrationItems,
|
|
114
|
+
elementData: data.elementData,
|
|
115
|
+
}),
|
|
116
|
+
value:
|
|
117
|
+
processImportRichTextHtmlValue({
|
|
118
|
+
elementData: data.elementData,
|
|
119
|
+
importContext: data.importContext,
|
|
120
|
+
migrationItems: data.migrationItems,
|
|
121
|
+
}) ?? null,
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
taxonomy: (data) => {
|
|
125
|
+
return elementsBuilder.taxonomyElement({
|
|
126
|
+
element: {
|
|
127
|
+
codename: data.elementCodename,
|
|
128
|
+
},
|
|
129
|
+
value: parseAsMigrationReferencesArray(data.elementData.value).map((m) => {
|
|
130
|
+
return {
|
|
131
|
+
codename: m.codename,
|
|
132
|
+
};
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
text: (data) => {
|
|
137
|
+
return elementsBuilder.textElement({
|
|
138
|
+
element: {
|
|
139
|
+
codename: data.elementCodename,
|
|
140
|
+
},
|
|
141
|
+
value: data.elementData.value && isString(data.elementData.value) ? data.elementData.value : null,
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
url_slug: (data) => {
|
|
145
|
+
return elementsBuilder.urlSlugElement({
|
|
146
|
+
element: {
|
|
147
|
+
codename: data.elementCodename,
|
|
148
|
+
},
|
|
149
|
+
value: data.elementData.value && isString(data.elementData.value) ? data.elementData.value : null,
|
|
150
|
+
mode: data.elementData.mode ?? "autogenerated",
|
|
151
|
+
});
|
|
152
|
+
},
|
|
152
153
|
};
|
|
153
154
|
|
|
154
155
|
function mapComponents(data: {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
readonly elementData: MigrationElementTransformData;
|
|
157
|
+
readonly importContext: ImportContext;
|
|
158
|
+
readonly migrationItems: readonly MigrationItem[];
|
|
158
159
|
}): LanguageVariantElements.IRichTextComponent[] {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
160
|
+
return (data.elementData.components ?? []).map((component) => {
|
|
161
|
+
const mappedComponent: Readonly<LanguageVariantElements.IRichTextComponent> = {
|
|
162
|
+
id: component.system.id,
|
|
163
|
+
type: {
|
|
164
|
+
codename: component.system.type.codename,
|
|
165
|
+
},
|
|
166
|
+
elements: Object.entries(component.elements).map(([key, element]) => {
|
|
167
|
+
const transformedElementValue = importTransforms[element.type]({
|
|
168
|
+
elementCodename: key,
|
|
169
|
+
importContext: data.importContext,
|
|
170
|
+
migrationItems: data.migrationItems,
|
|
171
|
+
elementData: element,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return transformedElementValue;
|
|
175
|
+
}),
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return mappedComponent;
|
|
179
|
+
});
|
|
179
180
|
}
|
|
180
181
|
|
|
181
182
|
function processImportRichTextHtmlValue(data: {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
readonly elementData: MigrationElementTransformData;
|
|
184
|
+
readonly importContext: ImportContext;
|
|
185
|
+
readonly migrationItems: readonly MigrationItem[];
|
|
185
186
|
}): string | undefined {
|
|
186
|
-
|
|
187
|
-
return undefined;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
let richTextHtml: string = data.elementData.value && isString(data.elementData.value) ? data.elementData.value : '';
|
|
187
|
+
let richTextHtml: string = data.elementData.value && isString(data.elementData.value) ? data.elementData.value : "";
|
|
191
188
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
189
|
+
// replace item codenames with existing codename or external_id
|
|
190
|
+
richTextHtml = richTextProcessor().processItemCodenames(richTextHtml, (codename) => {
|
|
191
|
+
return data.importContext.getItemStateInTargetEnvironment(codename);
|
|
192
|
+
}).html;
|
|
196
193
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
194
|
+
// replace link item codenames with existing codename or external_id
|
|
195
|
+
richTextHtml = richTextProcessor().processLinkItemCodenames(richTextHtml, (codename) => {
|
|
196
|
+
return data.importContext.getItemStateInTargetEnvironment(codename);
|
|
197
|
+
}).html;
|
|
201
198
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
199
|
+
// replace asset codenames with existing codename or external_id
|
|
200
|
+
richTextHtml = richTextProcessor().processAssetCodenames(richTextHtml, (codename) => {
|
|
201
|
+
return data.importContext.getAssetStateInTargetEnvironment(codename);
|
|
202
|
+
}).html;
|
|
206
203
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
// replace link asset codenames with existing codename or external_id
|
|
205
|
+
richTextHtml = richTextProcessor().processLinkAssetCodenames(richTextHtml, (codename) => {
|
|
206
|
+
return data.importContext.getAssetStateInTargetEnvironment(codename);
|
|
207
|
+
}).html;
|
|
211
208
|
|
|
212
|
-
|
|
209
|
+
return richTextHtml;
|
|
213
210
|
}
|
package/lib/zip/zip-manager.ts
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import type { Buffer as BufferProxy } from
|
|
2
|
-
import JSZip from
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
1
|
+
import type { Buffer as BufferProxy } from "buffer";
|
|
2
|
+
import JSZip from "jszip";
|
|
3
|
+
import { getDefaultLogger } from "../core/logs/loggers.js";
|
|
4
|
+
import type { Logger } from "../core/models/log.models.js";
|
|
5
|
+
import type { MigrationData } from "../core/models/migration.models.js";
|
|
6
|
+
import type { FileBinaryData } from "./zip.models.js";
|
|
7
|
+
import { zipPackager } from "./zip-packager.js";
|
|
8
|
+
import { zipTransformer } from "./zip-transformer.js";
|
|
8
9
|
|
|
9
10
|
export function zipManager(logger?: Logger) {
|
|
10
|
-
|
|
11
|
+
const loggerToUse = logger ?? getDefaultLogger();
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const createZipAsync = async (migrationData: MigrationData): Promise<FileBinaryData> => {
|
|
14
|
+
loggerToUse.log({
|
|
15
|
+
type: "info",
|
|
16
|
+
message: `Creating zip package`,
|
|
17
|
+
});
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
return await zipTransformer(zipPackager(new JSZip()), loggerToUse).transformAsync(migrationData);
|
|
20
|
+
};
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const parseZipAsync = async (zipFile: BufferProxy): Promise<MigrationData> => {
|
|
23
|
+
loggerToUse.log({
|
|
24
|
+
type: "info",
|
|
25
|
+
message: `Parsing zip file`,
|
|
26
|
+
});
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const zipPackage = zipPackager(await JSZip.loadAsync(zipFile, {}));
|
|
29
|
+
return await zipTransformer(zipPackage, loggerToUse).parseAsync();
|
|
30
|
+
};
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
return {
|
|
33
|
+
createZipAsync,
|
|
34
|
+
parseZipAsync,
|
|
35
|
+
};
|
|
35
36
|
}
|
package/lib/zip/zip-packager.ts
CHANGED
|
@@ -1,85 +1,87 @@
|
|
|
1
|
-
import { Buffer as BufferProxy } from
|
|
2
|
-
import chalk from
|
|
3
|
-
import type JSZip from
|
|
4
|
-
import { match } from
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
1
|
+
import { Buffer as BufferProxy } from "buffer";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import type JSZip from "jszip";
|
|
4
|
+
import { match } from "ts-pattern";
|
|
5
|
+
import { getDefaultLogger } from "../core/logs/loggers.js";
|
|
6
|
+
import { MigrationToolkitError } from "../core/models/error.models.js";
|
|
7
|
+
import type { Logger } from "../core/models/log.models.js";
|
|
8
|
+
import { exitProgram, formatBytes, getCurrentEnvironment } from "../core/utils/global.utils.js";
|
|
9
|
+
import type { FileBinaryData, ZipCompressionLevel, ZipPackager } from "./zip.models.js";
|
|
8
10
|
|
|
9
|
-
type ZipOutputType =
|
|
11
|
+
type ZipOutputType = "nodebuffer" | "blob";
|
|
10
12
|
|
|
11
13
|
export function zipPackager(jsZip: JSZip): ZipPackager {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const getZipOutputType = (): "nodebuffer" | "blob" => {
|
|
15
|
+
return match(getCurrentEnvironment())
|
|
16
|
+
.returnType<ZipOutputType>()
|
|
17
|
+
.with("browser", () => "blob")
|
|
18
|
+
.with("node", () => "nodebuffer")
|
|
19
|
+
.exhaustive();
|
|
20
|
+
};
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
const getZipSizeInBytes = (zipData: FileBinaryData): number => {
|
|
23
|
+
return match(zipData)
|
|
24
|
+
.when(
|
|
25
|
+
(data) => data instanceof Blob,
|
|
26
|
+
(data) => data.size,
|
|
27
|
+
)
|
|
28
|
+
.when(
|
|
29
|
+
(data) => data instanceof BufferProxy,
|
|
30
|
+
(data) => data.byteLength,
|
|
31
|
+
)
|
|
32
|
+
.otherwise(() => {
|
|
33
|
+
exitProgram({
|
|
34
|
+
message: `Unrecognized zip data type '${typeof zipData}'`,
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
return {
|
|
40
|
+
addFile(filePath: string, data: string | FileBinaryData): JSZip {
|
|
41
|
+
return jsZip.file(filePath, data);
|
|
42
|
+
},
|
|
43
|
+
addFolder(name: string): ZipPackager {
|
|
44
|
+
const folder = jsZip.folder(name);
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
if (!folder) {
|
|
47
|
+
throw new MigrationToolkitError("invalidFolder", `Failed to add folder '${name}'`);
|
|
48
|
+
}
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
return zipPackager(folder);
|
|
51
|
+
},
|
|
52
|
+
async generateZipAsync(config: { logger?: Logger; compressionLevel?: ZipCompressionLevel }): Promise<FileBinaryData> {
|
|
53
|
+
const logger = config.logger ?? getDefaultLogger();
|
|
54
|
+
const zipOutputType = getZipOutputType();
|
|
55
|
+
const compressionLevel: ZipCompressionLevel = config.compressionLevel ?? 9;
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
logger.log({
|
|
58
|
+
type: "info",
|
|
59
|
+
message: `Creating zip file using '${chalk.yellow(zipOutputType)}' with compression level '${chalk.yellow(
|
|
60
|
+
compressionLevel.toString(),
|
|
61
|
+
)}'`,
|
|
62
|
+
});
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
const result = await jsZip.generateAsync({
|
|
65
|
+
type: zipOutputType,
|
|
66
|
+
compression: "DEFLATE",
|
|
67
|
+
compressionOptions: {
|
|
68
|
+
level: compressionLevel,
|
|
69
|
+
},
|
|
70
|
+
streamFiles: true,
|
|
71
|
+
});
|
|
70
72
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
logger.log({
|
|
74
|
+
type: "info",
|
|
75
|
+
message: `Zip successfully generated (${chalk.yellow(formatBytes(getZipSizeInBytes(result)))})`,
|
|
76
|
+
});
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
return result;
|
|
79
|
+
},
|
|
80
|
+
async getBinaryDataAsync(filePath: string): Promise<FileBinaryData | undefined> {
|
|
81
|
+
return await jsZip.file(filePath)?.async(getZipOutputType());
|
|
82
|
+
},
|
|
83
|
+
async getFileContentAsync(filePath: string): Promise<string | undefined> {
|
|
84
|
+
return await jsZip.file(filePath)?.async("string");
|
|
85
|
+
},
|
|
86
|
+
};
|
|
85
87
|
}
|