@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,90 +1,105 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from
|
|
2
|
+
AssetFolderModels,
|
|
3
|
+
CollectionModels,
|
|
4
|
+
ContentItemModels,
|
|
5
|
+
LanguageModels,
|
|
6
|
+
LanguageVariantModels,
|
|
7
|
+
ManagementClient,
|
|
8
|
+
SharedModels,
|
|
9
|
+
TaxonomyModels,
|
|
10
|
+
WorkflowModels,
|
|
11
|
+
} from "@kontent-ai/management-sdk";
|
|
12
12
|
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ReferencedDataInLanguageVariants
|
|
23
|
-
} from '../core/index.js';
|
|
13
|
+
AssetStateInSourceEnvironmentById,
|
|
14
|
+
FlattenedContentType,
|
|
15
|
+
FlattenedContentTypeElement,
|
|
16
|
+
ItemStateInSourceEnvironmentById,
|
|
17
|
+
ReferencedDataInLanguageVariants,
|
|
18
|
+
} from "../core/models/core.models.js";
|
|
19
|
+
import type { Logger } from "../core/models/log.models.js";
|
|
20
|
+
import type { MigrationComponent, MigrationElementTransformData, MigrationUrlSlugMode } from "../core/models/migration.models.js";
|
|
21
|
+
import type { ManagementClientConfig } from "../core/utils/management-client-utils.js";
|
|
24
22
|
|
|
25
23
|
export interface ExportContextEnvironmentData {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
readonly languages: readonly Readonly<LanguageModels.LanguageModel>[];
|
|
25
|
+
readonly contentTypes: readonly Readonly<FlattenedContentType>[];
|
|
26
|
+
readonly collections: readonly Readonly<CollectionModels.Collection>[];
|
|
27
|
+
readonly assetFolders: readonly Readonly<AssetFolderModels.AssetFolder>[];
|
|
28
|
+
readonly workflows: readonly Readonly<WorkflowModels.Workflow>[];
|
|
29
|
+
readonly taxonomies: readonly Readonly<TaxonomyModels.Taxonomy>[];
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
export type ExportElementValue = string | number | SharedModels.ReferenceObject[] | undefined;
|
|
35
33
|
|
|
36
34
|
export interface ExportElement {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
readonly value: ExportElementValue;
|
|
36
|
+
readonly components: readonly MigrationComponent[];
|
|
37
|
+
readonly urlSlugMode: MigrationUrlSlugMode | undefined;
|
|
38
|
+
readonly displayTimezone: string | undefined;
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
export type ExportTransformFunc = (data: {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
readonly typeElement: FlattenedContentTypeElement;
|
|
43
|
+
readonly exportElement: ExportElement;
|
|
44
|
+
readonly context: ExportContext;
|
|
47
45
|
}) => MigrationElementTransformData;
|
|
48
46
|
|
|
49
47
|
export interface ExportContext {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
readonly environmentData: ExportContextEnvironmentData;
|
|
49
|
+
readonly referencedData: ReferencedDataInLanguageVariants;
|
|
50
|
+
readonly getItemStateInSourceEnvironment: (id: string) => ItemStateInSourceEnvironmentById;
|
|
51
|
+
readonly getAssetStateInSourceEnvironment: (id: string) => AssetStateInSourceEnvironmentById;
|
|
52
|
+
readonly exportItems: readonly ExportItem[];
|
|
53
|
+
readonly getElement: GetFlattenedElementByIds;
|
|
54
|
+
readonly exportContextOptions: ExportContextOptions;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
export interface SourceExportItem {
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
readonly itemCodename: string;
|
|
59
|
+
readonly languageCodename: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ExportContextOptions {
|
|
63
|
+
/**
|
|
64
|
+
* When enabled, the export process will skip missing items and assets instead of throwing errors.
|
|
65
|
+
* Missing references will be filtered out from the exported data.
|
|
66
|
+
* Default: false
|
|
67
|
+
*/
|
|
68
|
+
readonly skipMissingReferences?: boolean;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
export interface ExportConfig extends ManagementClientConfig {
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
readonly exportItems: readonly SourceExportItem[];
|
|
73
|
+
readonly logger?: Logger;
|
|
74
|
+
/**
|
|
75
|
+
* When enabled, the export process will skip missing items and assets instead of throwing errors.
|
|
76
|
+
* Missing references will be filtered out from the exported data.
|
|
77
|
+
* Default: false
|
|
78
|
+
*/
|
|
79
|
+
readonly skipMissingReferences?: boolean;
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
export interface DefaultExportContextConfig {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
readonly logger: Logger;
|
|
84
|
+
readonly exportItems: readonly SourceExportItem[];
|
|
85
|
+
readonly managementClient: Readonly<ManagementClient>;
|
|
86
|
+
readonly skipMissingReferences: boolean;
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
export type GetFlattenedElementByIds = (contentTypeId: string, elementId: string) => FlattenedContentTypeElement;
|
|
75
90
|
|
|
76
91
|
export interface ExportItemVersion {
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
readonly workflowStepCodename: string;
|
|
93
|
+
readonly languageVariant: Readonly<LanguageVariantModels.ContentItemLanguageVariant>;
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
export interface ExportItem {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
97
|
+
readonly requestItem: SourceExportItem;
|
|
98
|
+
readonly versions: readonly ExportItemVersion[];
|
|
99
|
+
readonly contentItem: Readonly<ContentItemModels.ContentItem>;
|
|
85
100
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
readonly collection: Readonly<CollectionModels.Collection>;
|
|
102
|
+
readonly language: Readonly<LanguageModels.LanguageModel>;
|
|
103
|
+
readonly workflow: Readonly<WorkflowModels.Workflow>;
|
|
104
|
+
readonly contentType: Readonly<FlattenedContentType>;
|
|
90
105
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import chalk from
|
|
2
|
-
import
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { MigrationToolkitError } from "../../core/models/error.models.js";
|
|
3
|
+
import type { SourceExportItem } from "../export.models.js";
|
|
3
4
|
|
|
4
5
|
export function throwErrorForItemRequest(itemRequest: SourceExportItem, message: string): never {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
throw new MigrationToolkitError(
|
|
7
|
+
"exportFailedForItem",
|
|
8
|
+
`Export failed for item '${chalk.yellow(itemRequest.itemCodename)}' in language '${chalk.cyan(
|
|
9
|
+
itemRequest.languageCodename,
|
|
10
|
+
)}'. Reason: ${message}`,
|
|
11
|
+
);
|
|
10
12
|
}
|
package/lib/file/file-manager.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import type { Logger } from
|
|
1
|
+
import { promises } from "node:fs";
|
|
2
|
+
import type { Buffer as BufferProxy } from "buffer";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import type { Logger } from "../core/models/log.models.js";
|
|
5
5
|
|
|
6
6
|
export function fileManager(logger: Logger) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const getFilePath = (filename: string): string => {
|
|
8
|
+
return `./${filename}`;
|
|
9
|
+
};
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const loadFileAsync = async (filename: string): Promise<BufferProxy> => {
|
|
12
|
+
const filePath = getFilePath(filename);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
logger.log({
|
|
15
|
+
type: "readFs",
|
|
16
|
+
message: `Reading file '${chalk.yellow(filePath)}'`,
|
|
17
|
+
});
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const file = await promises.readFile(filePath);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
return file;
|
|
22
|
+
};
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const writeFileAsync = async (fileNameWithoutExtension: string, content: string | BufferProxy): Promise<void> => {
|
|
25
|
+
const filePath = getFilePath(fileNameWithoutExtension);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
logger.log({
|
|
28
|
+
type: "writeFs",
|
|
29
|
+
message: `Storing file '${chalk.yellow(filePath)}'`,
|
|
30
|
+
});
|
|
31
|
+
await promises.writeFile(filePath, content);
|
|
32
|
+
};
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
return {
|
|
35
|
+
loadFileAsync,
|
|
36
|
+
writeFileAsync,
|
|
37
|
+
};
|
|
38
38
|
}
|
|
@@ -1,106 +1,107 @@
|
|
|
1
|
-
import type { AssetFolderModels, AssetModels, CollectionModels, LanguageModels } from
|
|
2
|
-
import deepEqual from
|
|
3
|
-
import type { MigrationAsset, MigrationAssetDescription } from
|
|
4
|
-
import { findRequired
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
1
|
+
import type { AssetFolderModels, AssetModels, CollectionModels, LanguageModels } from "@kontent-ai/management-sdk";
|
|
2
|
+
import deepEqual from "deep-equal";
|
|
3
|
+
import type { MigrationAsset, MigrationAssetDescription } from "../../core/models/migration.models.js";
|
|
4
|
+
import { findRequired } from "../../core/utils/array.utils.js";
|
|
5
|
+
import { geSizeInBytes } from "../../core/utils/binary-data.utils.js";
|
|
6
|
+
|
|
7
|
+
export function shouldUpdateAsset(data: {
|
|
8
|
+
readonly migrationAsset: MigrationAsset;
|
|
9
|
+
readonly targetAsset: Readonly<AssetModels.Asset>;
|
|
10
|
+
readonly collections: readonly Readonly<CollectionModels.Collection>[];
|
|
11
|
+
readonly languages: readonly Readonly<LanguageModels.LanguageModel>[];
|
|
12
|
+
readonly assetFolders: readonly Readonly<AssetFolderModels.AssetFolder>[];
|
|
13
|
+
}): boolean {
|
|
14
|
+
return !(
|
|
15
|
+
isInSameCollection(data) &&
|
|
16
|
+
areDescriptionsIdentical(data) &&
|
|
17
|
+
isTitleIdentical(data) &&
|
|
18
|
+
isFolderIdentical(data) &&
|
|
19
|
+
isBinaryFileIdentical(data)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function shouldReplaceBinaryFile(data: {
|
|
24
|
+
readonly migrationAsset: MigrationAsset;
|
|
25
|
+
readonly targetAsset: Readonly<AssetModels.Asset>;
|
|
26
|
+
}): boolean {
|
|
27
|
+
return !isBinaryFileIdentical(data);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isBinaryFileIdentical(data: {
|
|
31
|
+
readonly migrationAsset: MigrationAsset;
|
|
32
|
+
readonly targetAsset: Readonly<AssetModels.Asset>;
|
|
33
|
+
}): boolean {
|
|
34
|
+
const sourceFileSize = geSizeInBytes(data.migrationAsset.binary_data);
|
|
35
|
+
const targetFileSize = data.targetAsset.size;
|
|
36
|
+
|
|
37
|
+
const sourceFilename = data.migrationAsset.filename;
|
|
38
|
+
const targetFilename = data.targetAsset.fileName;
|
|
39
|
+
|
|
40
|
+
return sourceFileSize === targetFileSize && sourceFilename === targetFilename;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isFolderIdentical(data: {
|
|
44
|
+
readonly migrationAsset: MigrationAsset;
|
|
45
|
+
readonly targetAsset: Readonly<AssetModels.Asset>;
|
|
46
|
+
readonly assetFolders: readonly Readonly<AssetFolderModels.AssetFolder>[];
|
|
47
|
+
}): boolean {
|
|
48
|
+
return data.assetFolders.find((m) => m.id === data.targetAsset.folder?.id)?.codename === data.migrationAsset.folder?.codename;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isTitleIdentical(data: { readonly migrationAsset: MigrationAsset; readonly targetAsset: Readonly<AssetModels.Asset> }): boolean {
|
|
52
|
+
const sourceTitle = data.migrationAsset.title?.length ? data.migrationAsset.title : undefined;
|
|
53
|
+
const targetTitle = data.targetAsset.title?.length ? data.targetAsset.title : undefined;
|
|
54
|
+
|
|
55
|
+
return sourceTitle === targetTitle;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isInSameCollection(data: {
|
|
59
|
+
readonly migrationAsset: MigrationAsset;
|
|
60
|
+
readonly targetAsset: Readonly<AssetModels.Asset>;
|
|
61
|
+
readonly collections: readonly Readonly<CollectionModels.Collection>[];
|
|
62
|
+
}): boolean {
|
|
63
|
+
return (
|
|
64
|
+
data.collections.find((m) => m.id === data.targetAsset.collection?.reference?.id)?.codename ===
|
|
65
|
+
data.migrationAsset.collection?.codename
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function areDescriptionsIdentical(data: {
|
|
70
|
+
readonly migrationAsset: MigrationAsset;
|
|
71
|
+
readonly targetAsset: Readonly<AssetModels.Asset>;
|
|
72
|
+
readonly languages: readonly Readonly<LanguageModels.LanguageModel>[];
|
|
73
|
+
}): boolean {
|
|
74
|
+
const sourceMigrationDescriptions = (data.migrationAsset.descriptions ?? [])
|
|
75
|
+
.map<MigrationAssetDescription>((description) => {
|
|
76
|
+
return {
|
|
77
|
+
description: description.description?.length ? description.description : undefined,
|
|
78
|
+
language: {
|
|
79
|
+
codename: description.language.codename,
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
})
|
|
83
|
+
.toSorted();
|
|
84
|
+
const targetMigrationDescriptions = mapToMigrationDescriptions(data).toSorted();
|
|
85
|
+
|
|
86
|
+
return deepEqual(sourceMigrationDescriptions, targetMigrationDescriptions);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function mapToMigrationDescriptions(data: {
|
|
90
|
+
readonly targetAsset: Readonly<AssetModels.Asset>;
|
|
91
|
+
readonly languages: readonly Readonly<LanguageModels.LanguageModel>[];
|
|
92
|
+
}): MigrationAssetDescription[] {
|
|
93
|
+
return data.targetAsset.descriptions.map((description) => {
|
|
94
|
+
const languageId = description.language.id;
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
description: description.description?.length ? description.description : undefined,
|
|
98
|
+
language: {
|
|
99
|
+
codename: findRequired(
|
|
100
|
+
data.languages,
|
|
101
|
+
(language) => language.id === languageId,
|
|
102
|
+
`Could not find language with id '${languageId}'`,
|
|
103
|
+
).codename,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|