@kontent-ai/migration-toolkit 1.5.1 → 2.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/dist/es2022/core/models/migration.models.d.ts +4 -5
- package/dist/es2022/core/models/migration.schema.d.ts +46 -233
- package/dist/es2022/core/models/migration.schema.js +7 -22
- package/dist/es2022/core/models/migration.schema.js.map +1 -1
- package/dist/es2022/core/utils/binary-data.utils.d.ts +1 -0
- package/dist/es2022/core/utils/binary-data.utils.js.map +1 -1
- package/dist/es2022/export/export-manager.d.ts +1 -1
- package/dist/es2022/export/export-manager.js +6 -5
- package/dist/es2022/export/export-manager.js.map +1 -1
- package/dist/es2022/export/export.models.d.ts +4 -3
- package/dist/es2022/import/comparers/asset-comparer.js +2 -2
- package/dist/es2022/import/comparers/asset-comparer.js.map +1 -1
- package/dist/es2022/import/import.models.d.ts +2 -2
- package/dist/es2022/import/importers/assets-importer.js +2 -2
- package/dist/es2022/import/importers/assets-importer.js.map +1 -1
- package/dist/es2022/import/importers/language-variant-importer.js +4 -4
- package/dist/es2022/import/importers/language-variant-importer.js.map +1 -1
- package/dist/es2022/metadata.js +2 -2
- package/dist/es2022/toolkit/file.js +3 -2
- package/dist/es2022/toolkit/file.js.map +1 -1
- package/dist/es2022/translation/extraction/items-extraction.processor.d.ts +2 -2
- package/dist/es2022/translation/extraction/items-extraction.processor.js +10 -4
- package/dist/es2022/translation/extraction/items-extraction.processor.js.map +1 -1
- package/dist/es2022/translation/helpers/rich-text.processor.d.ts +2 -0
- package/dist/es2022/translation/helpers/rich-text.processor.js +56 -1
- package/dist/es2022/translation/helpers/rich-text.processor.js.map +1 -1
- package/dist/es2022/translation/transforms/export-transforms.js +131 -83
- package/dist/es2022/translation/transforms/export-transforms.js.map +1 -1
- package/dist/es2022/translation/transforms/import-transforms.js +22 -19
- package/dist/es2022/translation/transforms/import-transforms.js.map +1 -1
- package/dist/es2022/zip/zip-manager.d.ts +1 -0
- package/dist/es2022/zip/zip-manager.js +1 -1
- package/dist/es2022/zip/zip-manager.js.map +1 -1
- package/dist/es2022/zip/zip-packager.js +2 -1
- package/dist/es2022/zip/zip-packager.js.map +1 -1
- package/dist/es2022/zip/zip-transformer.d.ts +1 -1
- package/dist/es2022/zip/zip-transformer.js +3 -3
- package/dist/es2022/zip/zip-transformer.js.map +1 -1
- package/dist/es2022/zip/zip.models.d.ts +1 -0
- package/lib/core/models/migration.models.ts +12 -15
- package/lib/core/models/migration.schema.ts +11 -36
- package/lib/core/utils/binary-data.utils.ts +1 -0
- package/lib/export/export-manager.ts +22 -21
- package/lib/export/export.models.ts +18 -17
- package/lib/import/comparers/asset-comparer.ts +2 -2
- package/lib/import/import.models.ts +17 -17
- package/lib/import/importers/assets-importer.ts +2 -2
- package/lib/import/importers/language-variant-importer.ts +13 -13
- package/lib/metadata.ts +2 -2
- package/lib/toolkit/file.ts +3 -2
- package/lib/translation/extraction/items-extraction.processor.ts +16 -9
- package/lib/translation/helpers/rich-text.processor.ts +81 -1
- package/lib/translation/transforms/export-transforms.ts +143 -103
- package/lib/translation/transforms/import-transforms.ts +27 -31
- package/lib/zip/zip-manager.ts +2 -1
- package/lib/zip/zip-packager.ts +4 -3
- package/lib/zip/zip-transformer.ts +4 -4
- package/lib/zip/zip.models.ts +1 -0
- package/package.json +14 -13
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MigrationElementType,
|
|
3
|
-
MigrationReference,
|
|
4
|
-
MigrationRichTextElementValue,
|
|
5
|
-
MigrationUrlSlugElementValue,
|
|
6
|
-
findRequired,
|
|
7
|
-
isNotUndefined
|
|
8
|
-
} from '../../core/index.js';
|
|
9
1
|
import { ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk';
|
|
10
|
-
import { ExportTransformFunc, ExportContext, ExportElement } from '../../export/index.js';
|
|
11
|
-
import { richTextProcessor } from '../helpers/rich-text.processor.js';
|
|
12
2
|
import chalk from 'chalk';
|
|
3
|
+
import { MigrationElementTransformData, MigrationElementType, MigrationReference, findRequired, isNotUndefined } from '../../core/index.js';
|
|
4
|
+
import { ExportContext, ExportElement, ExportTransformFunc } from '../../export/index.js';
|
|
5
|
+
import { richTextProcessor } from '../helpers/rich-text.processor.js';
|
|
13
6
|
|
|
14
7
|
export const exportTransforms: Readonly<Record<MigrationElementType, ExportTransformFunc>> = {
|
|
15
|
-
text: (data) =>
|
|
8
|
+
text: (data) => {
|
|
9
|
+
return {
|
|
10
|
+
value: data.exportElement.value?.toString()
|
|
11
|
+
};
|
|
12
|
+
},
|
|
16
13
|
number: (data) => {
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
14
|
+
if (data.exportElement.value === undefined || data.exportElement.value === null) {
|
|
15
|
+
return {
|
|
16
|
+
value: undefined
|
|
17
|
+
};
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
if (Array.isArray(data.exportElement.value)) {
|
|
@@ -23,40 +22,55 @@ export const exportTransforms: Readonly<Record<MigrationElementType, ExportTrans
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
if (data.exportElement.value === 0) {
|
|
26
|
-
return
|
|
25
|
+
return {
|
|
26
|
+
value: 0
|
|
27
|
+
};
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
return
|
|
30
|
+
return {
|
|
31
|
+
value: +data.exportElement.value
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
date_time: (data) => {
|
|
35
|
+
return {
|
|
36
|
+
value: data.exportElement.value?.toString(),
|
|
37
|
+
display_timezone: data.exportElement.displayTimezone ?? undefined
|
|
38
|
+
};
|
|
30
39
|
},
|
|
31
|
-
date_time: (data) => data.exportElement.value?.toString(),
|
|
32
40
|
rich_text: (data) => transformRichTextValue(data.exportElement, data.context),
|
|
33
41
|
asset: (data) => {
|
|
34
42
|
if (!data.exportElement.value) {
|
|
35
|
-
return
|
|
43
|
+
return {
|
|
44
|
+
value: []
|
|
45
|
+
};
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
if (!Array.isArray(data.exportElement.value)) {
|
|
39
49
|
throw Error(`Expected value to be an array`);
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
return {
|
|
53
|
+
// translate asset id to codename
|
|
54
|
+
value: data.exportElement.value
|
|
55
|
+
.map((m) => m.id)
|
|
56
|
+
.filter(isNotUndefined)
|
|
57
|
+
.map<MigrationReference>((id) => {
|
|
58
|
+
const assetState = data.context.getAssetStateInSourceEnvironment(id);
|
|
59
|
+
|
|
60
|
+
if (assetState.asset) {
|
|
61
|
+
// reference asset by codename
|
|
62
|
+
return { codename: assetState.asset.codename };
|
|
63
|
+
} else {
|
|
64
|
+
throw Error(`Missing asset with id '${chalk.red(id)}'`);
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
};
|
|
56
68
|
},
|
|
57
69
|
taxonomy: (data) => {
|
|
58
70
|
if (!data.exportElement.value) {
|
|
59
|
-
return
|
|
71
|
+
return {
|
|
72
|
+
value: []
|
|
73
|
+
};
|
|
60
74
|
}
|
|
61
75
|
|
|
62
76
|
if (!Array.isArray(data.exportElement.value)) {
|
|
@@ -73,57 +87,67 @@ export const exportTransforms: Readonly<Record<MigrationElementType, ExportTrans
|
|
|
73
87
|
`Could not find taxonomy group with id '${chalk.red(taxonomyGroupId)}'`
|
|
74
88
|
);
|
|
75
89
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
return {
|
|
91
|
+
// translate taxonomy term to codename
|
|
92
|
+
value: data.exportElement.value
|
|
93
|
+
.map((m) => m.id)
|
|
94
|
+
.filter(isNotUndefined)
|
|
95
|
+
.map<MigrationReference>((id) => {
|
|
96
|
+
const taxonomyTerm = findTaxonomy(id, taxonomy);
|
|
97
|
+
|
|
98
|
+
if (taxonomyTerm) {
|
|
99
|
+
// reference taxonomy term by codename
|
|
100
|
+
return { codename: taxonomyTerm.codename };
|
|
101
|
+
} else {
|
|
102
|
+
throw Error(`Missing taxonomy term with id '${chalk.red(id)}'`);
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
};
|
|
90
106
|
},
|
|
91
107
|
modular_content: (data) => {
|
|
92
108
|
if (!data.exportElement.value) {
|
|
93
|
-
return
|
|
109
|
+
return {
|
|
110
|
+
value: []
|
|
111
|
+
};
|
|
94
112
|
}
|
|
95
113
|
|
|
96
114
|
if (!Array.isArray(data.exportElement.value)) {
|
|
97
115
|
throw Error(`Expected value to be an array`);
|
|
98
116
|
}
|
|
99
117
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
return {
|
|
119
|
+
// translate item id to codename
|
|
120
|
+
value: data.exportElement.value
|
|
121
|
+
.map((m) => m.id)
|
|
122
|
+
.filter(isNotUndefined)
|
|
123
|
+
.map<MigrationReference>((id) => {
|
|
124
|
+
const itemState = data.context.getItemStateInSourceEnvironment(id);
|
|
125
|
+
|
|
126
|
+
if (itemState.item) {
|
|
127
|
+
// reference item by codename
|
|
128
|
+
return { codename: itemState.item.codename };
|
|
129
|
+
} else {
|
|
130
|
+
throw Error(`Missing item with id '${chalk.red(id)}'`);
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
custom: (data) => {
|
|
136
|
+
return {
|
|
137
|
+
value: data.exportElement.value?.toString()
|
|
138
|
+
};
|
|
114
139
|
},
|
|
115
|
-
custom: (data) => data.exportElement.value?.toString(),
|
|
116
140
|
url_slug: (data) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
141
|
+
return {
|
|
142
|
+
value: data.exportElement.value?.toString() ?? undefined,
|
|
143
|
+
mode: data.exportElement.urlSlugMode ?? 'autogenerated'
|
|
120
144
|
};
|
|
121
|
-
|
|
122
|
-
return urlSlugElementValue;
|
|
123
145
|
},
|
|
124
146
|
multiple_choice: (data) => {
|
|
125
147
|
if (!data.exportElement.value) {
|
|
126
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
value: []
|
|
150
|
+
};
|
|
127
151
|
}
|
|
128
152
|
|
|
129
153
|
if (!Array.isArray(data.exportElement.value)) {
|
|
@@ -133,45 +157,51 @@ export const exportTransforms: Readonly<Record<MigrationElementType, ExportTrans
|
|
|
133
157
|
// translate multiple choice option id to codename
|
|
134
158
|
const multipleChoiceElement = data.typeElement.element as Readonly<ContentTypeElements.IMultipleChoiceElement>;
|
|
135
159
|
|
|
136
|
-
return
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
160
|
+
return {
|
|
161
|
+
value: data.exportElement.value
|
|
162
|
+
.map((m) => m.id)
|
|
163
|
+
.filter(isNotUndefined)
|
|
164
|
+
.map<MigrationReference>((id) => {
|
|
165
|
+
const option = findRequired(
|
|
166
|
+
multipleChoiceElement.options,
|
|
167
|
+
(option) => option.id === id,
|
|
168
|
+
`Could not find multiple choice element with option id '${chalk.red(id)}'`
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
if (!option.codename) {
|
|
172
|
+
throw Error(`Invalid codename for multiple choice option '${chalk.red(option.name)}'`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return { codename: option.codename };
|
|
176
|
+
})
|
|
177
|
+
};
|
|
152
178
|
},
|
|
153
179
|
subpages: (data) => {
|
|
154
180
|
if (!data.exportElement.value) {
|
|
155
|
-
return
|
|
181
|
+
return {
|
|
182
|
+
value: []
|
|
183
|
+
};
|
|
156
184
|
}
|
|
157
185
|
if (!Array.isArray(data.exportElement.value)) {
|
|
158
186
|
throw Error(`Expected value to be an array`);
|
|
159
187
|
}
|
|
160
188
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
189
|
+
return {
|
|
190
|
+
// translate item id to codename
|
|
191
|
+
value: data.exportElement.value
|
|
192
|
+
.map((m) => m.id)
|
|
193
|
+
.filter(isNotUndefined)
|
|
194
|
+
.map<MigrationReference>((id) => {
|
|
195
|
+
const itemState = data.context.getItemStateInSourceEnvironment(id);
|
|
196
|
+
|
|
197
|
+
if (itemState.item) {
|
|
198
|
+
// reference item by codename
|
|
199
|
+
return { codename: itemState.item.codename };
|
|
200
|
+
} else {
|
|
201
|
+
throw Error(`Missing item with id '${chalk.red(id)}'`);
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
};
|
|
175
205
|
}
|
|
176
206
|
};
|
|
177
207
|
|
|
@@ -191,10 +221,7 @@ function findTaxonomy(termId: string, taxonomy: Readonly<TaxonomyModels.Taxonomy
|
|
|
191
221
|
return undefined;
|
|
192
222
|
}
|
|
193
223
|
|
|
194
|
-
function transformRichTextValue(
|
|
195
|
-
exportElement: ExportElement | undefined,
|
|
196
|
-
context: ExportContext
|
|
197
|
-
): MigrationRichTextElementValue | undefined {
|
|
224
|
+
function transformRichTextValue(exportElement: ExportElement | undefined, context: ExportContext): MigrationElementTransformData {
|
|
198
225
|
if (!exportElement || !exportElement.value) {
|
|
199
226
|
return {
|
|
200
227
|
components: [],
|
|
@@ -243,6 +270,19 @@ function transformRichTextValue(
|
|
|
243
270
|
};
|
|
244
271
|
}).html;
|
|
245
272
|
|
|
273
|
+
// replace link asset ids with codenames
|
|
274
|
+
richTextHtml = richTextProcessor().processLinkAssetIds(richTextHtml, (id) => {
|
|
275
|
+
const assetInEnv = context.getAssetStateInSourceEnvironment(id).asset;
|
|
276
|
+
|
|
277
|
+
if (!assetInEnv) {
|
|
278
|
+
throw Error(`Failed to get asset with id '${chalk.red(id)}'`);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return {
|
|
282
|
+
codename: assetInEnv.codename
|
|
283
|
+
};
|
|
284
|
+
}).html;
|
|
285
|
+
|
|
246
286
|
return {
|
|
247
287
|
components: exportElement.components,
|
|
248
288
|
value: richTextHtml
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
parseAsMigrationReferencesArray,
|
|
4
|
-
MigrationElementType,
|
|
5
|
-
MigrationRichTextElementValue,
|
|
6
|
-
MigrationItem,
|
|
7
|
-
MigrationUrlSlugElementValue
|
|
8
|
-
} from '../../core/index.js';
|
|
1
|
+
import { LanguageVariantElements, LanguageVariantElementsBuilder, SharedContracts } from '@kontent-ai/management-sdk';
|
|
2
|
+
import { MigrationElementTransformData, MigrationElementType, MigrationItem, parseAsMigrationReferencesArray } from '../../core/index.js';
|
|
9
3
|
import { ImportContext, ImportTransformFunc } from '../../import/index.js';
|
|
10
4
|
import { richTextProcessor } from '../helpers/rich-text.processor.js';
|
|
11
5
|
|
|
@@ -21,7 +15,7 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
21
15
|
element: {
|
|
22
16
|
codename: data.elementCodename
|
|
23
17
|
},
|
|
24
|
-
value: parseAsMigrationReferencesArray(data.value).map((m) => {
|
|
18
|
+
value: parseAsMigrationReferencesArray(data.elementData.value).map((m) => {
|
|
25
19
|
return {
|
|
26
20
|
codename: m.codename
|
|
27
21
|
};
|
|
@@ -29,7 +23,7 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
29
23
|
});
|
|
30
24
|
},
|
|
31
25
|
asset: (data) => {
|
|
32
|
-
const assetReferences = parseAsMigrationReferencesArray(data.value)
|
|
26
|
+
const assetReferences = parseAsMigrationReferencesArray(data.elementData.value)
|
|
33
27
|
.map((reference) => reference.codename)
|
|
34
28
|
.map<Readonly<SharedContracts.IReferenceObjectContract>>((codename) => {
|
|
35
29
|
const assetState = data.importContext.getAssetStateInTargetEnvironment(codename);
|
|
@@ -54,7 +48,7 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
54
48
|
element: {
|
|
55
49
|
codename: data.elementCodename
|
|
56
50
|
},
|
|
57
|
-
value: data.value?.toString() ?? ''
|
|
51
|
+
value: data.elementData.value?.toString() ?? ''
|
|
58
52
|
});
|
|
59
53
|
},
|
|
60
54
|
date_time: (data) => {
|
|
@@ -62,11 +56,12 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
62
56
|
element: {
|
|
63
57
|
codename: data.elementCodename
|
|
64
58
|
},
|
|
65
|
-
value: data.value?.toString() ?? null
|
|
59
|
+
value: data.elementData.value?.toString() ?? null,
|
|
60
|
+
display_timezone: data.elementData.display_timezone ?? null
|
|
66
61
|
});
|
|
67
62
|
},
|
|
68
63
|
modular_content: (data) => {
|
|
69
|
-
const linkedItemReferences = parseAsMigrationReferencesArray(data.value)
|
|
64
|
+
const linkedItemReferences = parseAsMigrationReferencesArray(data.elementData.value)
|
|
70
65
|
.map((reference) => reference.codename)
|
|
71
66
|
.map<Readonly<SharedContracts.IReferenceObjectContract>>((codename) => {
|
|
72
67
|
const itemState = data.importContext.getItemStateInTargetEnvironment(codename);
|
|
@@ -90,7 +85,7 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
90
85
|
element: {
|
|
91
86
|
codename: data.elementCodename
|
|
92
87
|
},
|
|
93
|
-
value: parseAsMigrationReferencesArray(data.value).map((m) => {
|
|
88
|
+
value: parseAsMigrationReferencesArray(data.elementData.value).map((m) => {
|
|
94
89
|
return {
|
|
95
90
|
codename: m.codename
|
|
96
91
|
};
|
|
@@ -102,12 +97,10 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
102
97
|
element: {
|
|
103
98
|
codename: data.elementCodename
|
|
104
99
|
},
|
|
105
|
-
value: data.
|
|
100
|
+
value: data.elementData ? +data.elementData : null
|
|
106
101
|
});
|
|
107
102
|
},
|
|
108
103
|
rich_text: (data) => {
|
|
109
|
-
const rteElementValue = data.value as MigrationRichTextElementValue;
|
|
110
|
-
|
|
111
104
|
return elementsBuilder.richTextElement({
|
|
112
105
|
element: {
|
|
113
106
|
codename: data.elementCodename
|
|
@@ -115,11 +108,11 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
115
108
|
components: mapComponents({
|
|
116
109
|
importContext: data.importContext,
|
|
117
110
|
migrationItems: data.migrationItems,
|
|
118
|
-
|
|
111
|
+
elementData: data.elementData
|
|
119
112
|
}),
|
|
120
113
|
value:
|
|
121
114
|
processImportRichTextHtmlValue({
|
|
122
|
-
|
|
115
|
+
elementData: data.elementData,
|
|
123
116
|
importContext: data.importContext,
|
|
124
117
|
migrationItems: data.migrationItems
|
|
125
118
|
}) ?? null
|
|
@@ -130,7 +123,7 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
130
123
|
element: {
|
|
131
124
|
codename: data.elementCodename
|
|
132
125
|
},
|
|
133
|
-
value: parseAsMigrationReferencesArray(data.value).map((m) => {
|
|
126
|
+
value: parseAsMigrationReferencesArray(data.elementData.value).map((m) => {
|
|
134
127
|
return {
|
|
135
128
|
codename: m.codename
|
|
136
129
|
};
|
|
@@ -142,28 +135,26 @@ export const importTransforms: Readonly<Record<MigrationElementType, ImportTrans
|
|
|
142
135
|
element: {
|
|
143
136
|
codename: data.elementCodename
|
|
144
137
|
},
|
|
145
|
-
value: data.value?.toString() ?? null
|
|
138
|
+
value: data.elementData.value?.toString() ?? null
|
|
146
139
|
});
|
|
147
140
|
},
|
|
148
141
|
url_slug: (data) => {
|
|
149
|
-
const urlSlugElementValue = data.value as Readonly<MigrationUrlSlugElementValue>;
|
|
150
|
-
|
|
151
142
|
return elementsBuilder.urlSlugElement({
|
|
152
143
|
element: {
|
|
153
144
|
codename: data.elementCodename
|
|
154
145
|
},
|
|
155
|
-
value:
|
|
156
|
-
mode:
|
|
146
|
+
value: data.elementData.value?.toString() ?? '',
|
|
147
|
+
mode: data.elementData.mode ?? 'autogenerated'
|
|
157
148
|
});
|
|
158
149
|
}
|
|
159
150
|
};
|
|
160
151
|
|
|
161
152
|
function mapComponents(data: {
|
|
162
|
-
readonly
|
|
153
|
+
readonly elementData: MigrationElementTransformData;
|
|
163
154
|
readonly importContext: ImportContext;
|
|
164
155
|
readonly migrationItems: readonly MigrationItem[];
|
|
165
156
|
}): LanguageVariantElements.IRichTextComponent[] {
|
|
166
|
-
return data.
|
|
157
|
+
return (data.elementData.components ?? []).map((component) => {
|
|
167
158
|
const mappedComponent: Readonly<LanguageVariantElements.IRichTextComponent> = {
|
|
168
159
|
id: component.system.id,
|
|
169
160
|
type: {
|
|
@@ -174,7 +165,7 @@ function mapComponents(data: {
|
|
|
174
165
|
elementCodename: key,
|
|
175
166
|
importContext: data.importContext,
|
|
176
167
|
migrationItems: data.migrationItems,
|
|
177
|
-
|
|
168
|
+
elementData: element
|
|
178
169
|
});
|
|
179
170
|
|
|
180
171
|
return transformedElementValue;
|
|
@@ -186,15 +177,15 @@ function mapComponents(data: {
|
|
|
186
177
|
}
|
|
187
178
|
|
|
188
179
|
function processImportRichTextHtmlValue(data: {
|
|
189
|
-
readonly
|
|
180
|
+
readonly elementData: MigrationElementTransformData;
|
|
190
181
|
readonly importContext: ImportContext;
|
|
191
182
|
readonly migrationItems: readonly MigrationItem[];
|
|
192
183
|
}): string | undefined {
|
|
193
|
-
if (!data.
|
|
184
|
+
if (!data.elementData) {
|
|
194
185
|
return undefined;
|
|
195
186
|
}
|
|
196
187
|
|
|
197
|
-
let richTextHtml: string = data.
|
|
188
|
+
let richTextHtml: string = data.elementData.value?.toString() ?? '';
|
|
198
189
|
|
|
199
190
|
// replace item codenames with existing codename or external_id
|
|
200
191
|
richTextHtml = richTextProcessor().processItemCodenames(richTextHtml, (codename) => {
|
|
@@ -211,5 +202,10 @@ function processImportRichTextHtmlValue(data: {
|
|
|
211
202
|
return data.importContext.getAssetStateInTargetEnvironment(codename);
|
|
212
203
|
}).html;
|
|
213
204
|
|
|
205
|
+
// replace link asset codenames with existing codename or external_id
|
|
206
|
+
richTextHtml = richTextProcessor().processLinkAssetCodenames(richTextHtml, (codename) => {
|
|
207
|
+
return data.importContext.getAssetStateInTargetEnvironment(codename);
|
|
208
|
+
}).html;
|
|
209
|
+
|
|
214
210
|
return richTextHtml;
|
|
215
211
|
}
|
package/lib/zip/zip-manager.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
1
2
|
import JSZip from 'jszip';
|
|
2
3
|
import { Logger, MigrationData, getDefaultLogger } from '../core/index.js';
|
|
3
|
-
import { zipTransformer } from './zip-transformer.js';
|
|
4
4
|
import { zipPackager } from './zip-packager.js';
|
|
5
|
+
import { zipTransformer } from './zip-transformer.js';
|
|
5
6
|
import { FileBinaryData } from './zip.models.js';
|
|
6
7
|
|
|
7
8
|
export function zipManager(logger?: Logger) {
|
package/lib/zip/zip-packager.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
4
|
-
import { FileBinaryData, ZipCompressionLevel, ZipPackager } from './zip.models.js';
|
|
3
|
+
import JSZip from 'jszip';
|
|
5
4
|
import { match } from 'ts-pattern';
|
|
5
|
+
import { Logger, exitProgram, formatBytes, getCurrentEnvironment, getDefaultLogger } from '../core/index.js';
|
|
6
|
+
import { FileBinaryData, ZipCompressionLevel, ZipPackager } from './zip.models.js';
|
|
6
7
|
|
|
7
8
|
type ZipOutputType = 'nodebuffer' | 'blob';
|
|
8
9
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { FileBinaryData, ZipPackager } from './zip.models.js';
|
|
4
3
|
import {
|
|
5
4
|
Logger,
|
|
6
5
|
MigrationAsset,
|
|
@@ -12,6 +11,7 @@ import {
|
|
|
12
11
|
getDefaultLogger,
|
|
13
12
|
mapAsync
|
|
14
13
|
} from '../core/index.js';
|
|
14
|
+
import { FileBinaryData, ZipPackager } from './zip.models.js';
|
|
15
15
|
|
|
16
16
|
type ZipAssetRecord = z.infer<typeof ZipMigrationAssetSchema>;
|
|
17
17
|
|
|
@@ -52,8 +52,8 @@ export function zipTransformer(zip: ZipPackager, logger?: Logger) {
|
|
|
52
52
|
folder: asset.folder
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
if (asset.
|
|
56
|
-
codenameFolder.addFile(asset.filename, asset.
|
|
55
|
+
if (asset.binary_data) {
|
|
56
|
+
codenameFolder.addFile(asset.filename, asset.binary_data);
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
|
|
@@ -93,7 +93,7 @@ export function zipTransformer(zip: ZipPackager, logger?: Logger) {
|
|
|
93
93
|
title: assetRecord.title,
|
|
94
94
|
descriptions: assetRecord.descriptions,
|
|
95
95
|
folder: assetRecord.folder,
|
|
96
|
-
|
|
96
|
+
binary_data: binaryFile
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
return migrationAsset;
|
package/lib/zip/zip.models.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kontent-ai/migration-toolkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "This program can be used to import content related data into Kontent.ai from various formats. Additionally, it can also be used to export Kontent.ai data using Delivery API.",
|
|
5
5
|
"preferGlobal": true,
|
|
6
6
|
"private": false,
|
|
@@ -53,37 +53,38 @@
|
|
|
53
53
|
"license": "MIT",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@kontent-ai-consulting/tools-analytics": "0.0.7",
|
|
56
|
-
"@kontent-ai/management-sdk": "7.
|
|
56
|
+
"@kontent-ai/management-sdk": "7.4.0",
|
|
57
57
|
"browser-or-node": "3.0.0",
|
|
58
58
|
"bytes": "3.1.2",
|
|
59
59
|
"chalk": "5.3.0",
|
|
60
60
|
"dotenv": "16.4.5",
|
|
61
61
|
"jszip": "3.10.1",
|
|
62
62
|
"mime": "4.0.4",
|
|
63
|
-
"ora": "8.0
|
|
63
|
+
"ora": "8.1.0",
|
|
64
64
|
"prompts": "2.4.2",
|
|
65
65
|
"yargs": "17.7.2",
|
|
66
66
|
"p-limit": "6.1.0",
|
|
67
67
|
"deep-equal": "2.2.3",
|
|
68
68
|
"zod": "3.23.8",
|
|
69
|
-
"ts-pattern": "5.
|
|
69
|
+
"ts-pattern": "5.4.0",
|
|
70
|
+
"buffer": "6.0.3"
|
|
70
71
|
},
|
|
71
72
|
"devDependencies": {
|
|
72
|
-
"@eslint/js": "9.
|
|
73
|
+
"@eslint/js": "9.11.1",
|
|
73
74
|
"@types/deep-equal": "1.0.4",
|
|
74
75
|
"@types/browser-or-node": "1.3.2",
|
|
75
76
|
"@types/bytes": "3.1.4",
|
|
76
77
|
"@types/eslint__js": "8.42.3",
|
|
77
|
-
"@types/node": "22.
|
|
78
|
+
"@types/node": "22.7.4",
|
|
78
79
|
"@types/prompts": "2.4.9",
|
|
79
80
|
"@types/yargs": "17.0.33",
|
|
80
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
81
|
-
"@typescript-eslint/parser": "8.
|
|
82
|
-
"eslint": "9.
|
|
81
|
+
"@typescript-eslint/eslint-plugin": "8.8.0",
|
|
82
|
+
"@typescript-eslint/parser": "8.8.0",
|
|
83
|
+
"eslint": "9.11.1",
|
|
83
84
|
"standard-version": "9.5.0",
|
|
84
|
-
"tslib": "2.
|
|
85
|
-
"tsx": "4.
|
|
86
|
-
"typescript": "5.
|
|
87
|
-
"typescript-eslint": "8.
|
|
85
|
+
"tslib": "2.7.0",
|
|
86
|
+
"tsx": "4.19.1",
|
|
87
|
+
"typescript": "5.6.2",
|
|
88
|
+
"typescript-eslint": "8.8.0"
|
|
88
89
|
}
|
|
89
90
|
}
|