@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,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 { MigrationItem } from "../../core/models/migration.models.js";
|
|
3
4
|
|
|
4
5
|
export function throwErrorForMigrationItem(migrationItem: MigrationItem, message: string): never {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
throw new MigrationToolkitError(
|
|
7
|
+
"importFailedForItem",
|
|
8
|
+
`Import failed for item '${chalk.yellow(migrationItem.system.codename)}' in language '${chalk.cyan(
|
|
9
|
+
migrationItem.system.language,
|
|
10
|
+
)}'. Reason: ${message}`,
|
|
11
|
+
);
|
|
10
12
|
}
|
package/lib/index.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
//
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export * from
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: We need to export the public API
|
|
2
|
+
export { getDefaultLogger } from "./core/logs/loggers.js";
|
|
3
|
+
export { MigrationToolkitError, MissingAssetError, MissingItemError } from "./core/models/error.models.js";
|
|
4
|
+
export type { Logger, LogMessage, LogSpinnerData, LogSpinnerMessage } from "./core/models/log.models.js";
|
|
5
|
+
export * from "./core/models/migration.models.js";
|
|
6
|
+
export { defaultExternalIdGenerator, type ExternalIdGenerator } from "./core/utils/external-id.utils.js";
|
|
7
|
+
export type { SourceExportItem } from "./export/export.models.js";
|
|
8
|
+
export { elementsBuilder } from "./toolkit/elements-builder.js";
|
|
9
|
+
export { exportAsync } from "./toolkit/export.js";
|
|
10
|
+
export { extractAsync, storeAsync } from "./toolkit/file.js";
|
|
11
|
+
export { importAsync } from "./toolkit/import.js";
|
|
12
|
+
export { migrateAsync } from "./toolkit/migrate.js";
|
package/lib/metadata.ts
CHANGED
|
@@ -1,45 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { getDefaultLogger } from "../../../core/logs/loggers.js";
|
|
2
|
+
import { confirmExportAsync } from "../../../core/utils/confirm.utils.js";
|
|
3
|
+
import { defaultZipFilename } from "../../../core/utils/global.utils.js";
|
|
4
|
+
import { exportAsync } from "../../../toolkit/export.js";
|
|
5
|
+
import { storeAsync } from "../../../toolkit/file.js";
|
|
6
|
+
import type { CliArgumentsFetcher } from "../cli.models.js";
|
|
4
7
|
|
|
5
8
|
export async function exportActionAsync(cliFetcher: CliArgumentsFetcher): Promise<void> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const logger = getDefaultLogger();
|
|
10
|
+
const language = cliFetcher.getRequiredArgumentValue("language");
|
|
11
|
+
const environmentId = cliFetcher.getRequiredArgumentValue("sourceEnvironmentId");
|
|
12
|
+
const apiKey = cliFetcher.getRequiredArgumentValue("sourceApiKey");
|
|
13
|
+
const items = cliFetcher.getRequiredArgumentValue("items").split(",");
|
|
14
|
+
const baseUrl = cliFetcher.getOptionalArgumentValue("baseUrl");
|
|
15
|
+
const force = cliFetcher.getBooleanArgumentValue("force", false);
|
|
16
|
+
const skipMissingReferences = cliFetcher.getBooleanArgumentValue("skipMissingReferences", false);
|
|
17
|
+
const filename = cliFetcher.getOptionalArgumentValue("filename") ?? defaultZipFilename;
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
await confirmExportAsync({
|
|
20
|
+
force,
|
|
21
|
+
apiKey,
|
|
22
|
+
environmentId,
|
|
23
|
+
logger,
|
|
24
|
+
dataToExport: {
|
|
25
|
+
itemsCount: items.length,
|
|
26
|
+
},
|
|
27
|
+
skipMissingReferences,
|
|
28
|
+
});
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const exportedData = await exportAsync({
|
|
31
|
+
logger,
|
|
32
|
+
environmentId,
|
|
33
|
+
apiKey,
|
|
34
|
+
baseUrl,
|
|
35
|
+
exportItems: items.map((m) => {
|
|
36
|
+
return {
|
|
37
|
+
itemCodename: m,
|
|
38
|
+
languageCodename: language,
|
|
39
|
+
};
|
|
40
|
+
}),
|
|
41
|
+
skipMissingReferences,
|
|
42
|
+
});
|
|
37
43
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
await storeAsync({
|
|
45
|
+
data: exportedData,
|
|
46
|
+
filename: filename,
|
|
47
|
+
logger: logger,
|
|
48
|
+
});
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
logger.log({ type: "completed", message: `Export has been successful` });
|
|
45
51
|
}
|
|
@@ -1,36 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { getDefaultLogger } from "../../../core/logs/loggers.js";
|
|
2
|
+
import { confirmImportAsync } from "../../../core/utils/confirm.utils.js";
|
|
3
|
+
import { defaultZipFilename } from "../../../core/utils/global.utils.js";
|
|
4
|
+
import { extractAsync } from "../../../toolkit/file.js";
|
|
5
|
+
import { importAsync } from "../../../toolkit/import.js";
|
|
6
|
+
import type { CliArgumentsFetcher } from "../cli.models.js";
|
|
4
7
|
|
|
5
8
|
export async function importActionAsync(argsFetcher: CliArgumentsFetcher): Promise<void> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const log = getDefaultLogger();
|
|
10
|
+
const environmentId = argsFetcher.getRequiredArgumentValue("targetEnvironmentId");
|
|
11
|
+
const apiKey = argsFetcher.getRequiredArgumentValue("targetApiKey");
|
|
12
|
+
const baseUrl = argsFetcher.getOptionalArgumentValue("baseUrl");
|
|
13
|
+
const createReportFile = argsFetcher.getBooleanArgumentValue("createReportFile", false);
|
|
14
|
+
const force = argsFetcher.getBooleanArgumentValue("force", false);
|
|
15
|
+
const filename = argsFetcher.getOptionalArgumentValue("filename") ?? defaultZipFilename;
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
await confirmImportAsync({
|
|
18
|
+
force: force,
|
|
19
|
+
apiKey: apiKey,
|
|
20
|
+
environmentId: environmentId,
|
|
21
|
+
logger: log,
|
|
22
|
+
});
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const importData = await extractAsync({
|
|
25
|
+
logger: log,
|
|
26
|
+
filename: filename,
|
|
27
|
+
});
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
await importAsync({
|
|
30
|
+
logger: log,
|
|
31
|
+
data: importData,
|
|
32
|
+
baseUrl: baseUrl,
|
|
33
|
+
environmentId: environmentId,
|
|
34
|
+
apiKey: apiKey,
|
|
35
|
+
createReportFile: createReportFile,
|
|
36
|
+
});
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
log.log({ type: "completed", message: `Import has been successful` });
|
|
36
39
|
}
|
|
@@ -1,52 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { getDefaultLogger } from "../../../core/logs/loggers.js";
|
|
2
|
+
import { confirmMigrateAsync } from "../../../core/utils/confirm.utils.js";
|
|
3
|
+
import type { SourceExportItem } from "../../../export/export.models.js";
|
|
4
|
+
import { migrateAsync } from "../../../toolkit/migrate.js";
|
|
5
|
+
import type { CliArgumentsFetcher } from "../cli.models.js";
|
|
5
6
|
|
|
6
7
|
export async function migrateActionAsync(argsFetcher: CliArgumentsFetcher): Promise<void> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
const logger = getDefaultLogger();
|
|
9
|
+
const sourceEnvironmentId = argsFetcher.getRequiredArgumentValue("sourceEnvironmentId");
|
|
10
|
+
const sourceApiKey = argsFetcher.getRequiredArgumentValue("sourceApiKey");
|
|
11
|
+
const targetEnvironmentId = argsFetcher.getRequiredArgumentValue("targetEnvironmentId");
|
|
12
|
+
const targetApiKey = argsFetcher.getRequiredArgumentValue("targetApiKey");
|
|
13
|
+
const force = argsFetcher.getBooleanArgumentValue("force", false);
|
|
14
|
+
const skipMissingReferences = argsFetcher.getBooleanArgumentValue("skipMissingReferences", false);
|
|
15
|
+
const items = argsFetcher.getRequiredArgumentValue("items").split(",");
|
|
16
|
+
const language = argsFetcher.getRequiredArgumentValue("language");
|
|
17
|
+
const migrateItems: readonly SourceExportItem[] = items.map((m) => {
|
|
18
|
+
return {
|
|
19
|
+
itemCodename: m,
|
|
20
|
+
languageCodename: language,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
await confirmMigrateAsync({
|
|
25
|
+
skipMissingReferences,
|
|
26
|
+
force,
|
|
27
|
+
sourceEnvironment: {
|
|
28
|
+
apiKey: sourceApiKey,
|
|
29
|
+
environmentId: sourceEnvironmentId,
|
|
30
|
+
},
|
|
31
|
+
targetEnvironment: {
|
|
32
|
+
apiKey: targetApiKey,
|
|
33
|
+
environmentId: targetEnvironmentId,
|
|
34
|
+
},
|
|
35
|
+
logger,
|
|
36
|
+
dataToMigrate: {
|
|
37
|
+
itemsCount: migrateItems.length,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
await migrateAsync({
|
|
42
|
+
logger,
|
|
43
|
+
sourceEnvironment: {
|
|
44
|
+
environmentId: sourceEnvironmentId,
|
|
45
|
+
apiKey: sourceApiKey,
|
|
46
|
+
items: migrateItems,
|
|
47
|
+
skipMissingReferences,
|
|
48
|
+
},
|
|
49
|
+
targetEnvironment: {
|
|
50
|
+
environmentId: targetEnvironmentId,
|
|
51
|
+
apiKey: targetApiKey,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
logger.log({ type: "completed", message: `Migration has been successful` });
|
|
52
56
|
}
|
package/lib/node/cli/app.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import chalk from
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import { exitProgram
|
|
6
|
-
import { exportActionAsync } from
|
|
7
|
-
import { importActionAsync } from
|
|
8
|
-
import { migrateActionAsync } from
|
|
9
|
-
import { argumentsFetcherAsync } from
|
|
10
|
-
import { cliArgs } from
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { match } from "ts-pattern";
|
|
4
|
+
import { handleError } from "../../core/utils/error.utils.js";
|
|
5
|
+
import { exitProgram } from "../../core/utils/global.utils.js";
|
|
6
|
+
import { exportActionAsync } from "./actions/export-action.js";
|
|
7
|
+
import { importActionAsync } from "./actions/import-action.js";
|
|
8
|
+
import { migrateActionAsync } from "./actions/migrate-action.js";
|
|
9
|
+
import { argumentsFetcherAsync } from "./args/args-fetcher.js";
|
|
10
|
+
import { cliArgs } from "./commands.js";
|
|
11
11
|
|
|
12
12
|
// Need to register --help commands
|
|
13
13
|
cliArgs.registerCommands();
|
|
14
14
|
|
|
15
15
|
const run = async () => {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const argsFetcher = await argumentsFetcherAsync();
|
|
17
|
+
const action = argsFetcher.getCliAction();
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
return await match(action)
|
|
20
|
+
.with("export", async () => await exportActionAsync(argsFetcher))
|
|
21
|
+
.with("import", async () => await importActionAsync(argsFetcher))
|
|
22
|
+
.with("migrate", async () => await migrateActionAsync(argsFetcher))
|
|
23
|
+
.otherwise(() =>
|
|
24
|
+
exitProgram({
|
|
25
|
+
message: `Invalid action '${chalk.red(action)}'`,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
run().catch((err) => {
|
|
31
|
-
|
|
31
|
+
handleError(err);
|
|
32
32
|
});
|
|
@@ -1,60 +1,61 @@
|
|
|
1
|
-
import chalk from
|
|
2
|
-
import { match } from
|
|
3
|
-
import yargs from
|
|
4
|
-
import { hideBin } from
|
|
5
|
-
import type { CliAction, LiteralUnion } from
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { match } from "ts-pattern";
|
|
3
|
+
import yargs from "yargs";
|
|
4
|
+
import { hideBin } from "yargs/helpers";
|
|
5
|
+
import type { CliAction, LiteralUnion } from "../../../core/models/core.models.js";
|
|
6
|
+
import { MigrationToolkitError } from "../../../core/models/error.models.js";
|
|
7
|
+
import { exitProgram } from "../../../core/utils/global.utils.js";
|
|
8
|
+
import type { CliArgumentsFetcher } from "../cli.models.js";
|
|
8
9
|
|
|
9
10
|
type ArgvResult = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
[x: string]: unknown;
|
|
12
|
+
_: (string | number)[];
|
|
13
|
+
$0: string;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
16
|
export async function argumentsFetcherAsync(): Promise<CliArgumentsFetcher> {
|
|
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
|
-
|
|
17
|
+
const argv = yargs(hideBin(process.argv));
|
|
18
|
+
const resolvedArgv: ArgvResult = await argv.argv;
|
|
19
|
+
|
|
20
|
+
const getOptionalArgumentValue = (argName: string) => {
|
|
21
|
+
return resolvedArgv[argName]?.toString();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
getCliAction(): CliAction {
|
|
26
|
+
const command = resolvedArgv._[0]?.toString()?.toLowerCase() as LiteralUnion<CliAction>;
|
|
27
|
+
|
|
28
|
+
return match(command)
|
|
29
|
+
.returnType<CliAction>()
|
|
30
|
+
.with("export", () => "export")
|
|
31
|
+
.with("import", () => "import")
|
|
32
|
+
.with("migrate", () => "migrate")
|
|
33
|
+
.otherwise(() => {
|
|
34
|
+
throw new MigrationToolkitError("unsupportedCommand", `Unsupported command '${chalk.yellow(command)}'`);
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
getOptionalArgumentValue(argName: string): string | undefined {
|
|
38
|
+
return resolvedArgv[argName]?.toString();
|
|
39
|
+
},
|
|
40
|
+
getRequiredArgumentValue(argName: string): string {
|
|
41
|
+
const value = getOptionalArgumentValue(argName);
|
|
42
|
+
|
|
43
|
+
if (!value) {
|
|
44
|
+
exitProgram({
|
|
45
|
+
message: `Missing '${chalk.yellow(argName)}' argument value`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value;
|
|
50
|
+
},
|
|
51
|
+
getBooleanArgumentValue(argName: string, defaultValue: boolean): boolean {
|
|
52
|
+
const value = getOptionalArgumentValue(argName);
|
|
53
|
+
|
|
54
|
+
if (!value) {
|
|
55
|
+
return defaultValue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return value.toLowerCase() === "true".toLowerCase();
|
|
59
|
+
},
|
|
60
|
+
};
|
|
60
61
|
}
|
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
import yargs from
|
|
2
|
-
import { hideBin } from
|
|
3
|
-
import type { CliArgumentsSetter, Command, CommandOption } from
|
|
1
|
+
import yargs from "yargs";
|
|
2
|
+
import { hideBin } from "yargs/helpers";
|
|
3
|
+
import type { CliArgumentsSetter, Command, CommandOption } from "../cli.models.js";
|
|
4
4
|
|
|
5
5
|
export function argumentsSetter(): CliArgumentsSetter {
|
|
6
|
-
|
|
6
|
+
const argv = yargs(hideBin(process.argv));
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
return {
|
|
9
|
+
withCommand(command: Command): CliArgumentsSetter {
|
|
10
|
+
argv.command(command.name, command.description, (yargs) => {
|
|
11
|
+
command.examples.forEach((example) => {
|
|
12
|
+
yargs.example(command.name, example);
|
|
13
|
+
});
|
|
14
|
+
command.options.forEach((option) => {
|
|
15
|
+
yargs.positional(option.name, {
|
|
16
|
+
alias: option.alias,
|
|
17
|
+
describe: option.description,
|
|
18
|
+
type: option.type,
|
|
19
|
+
demandOption: option.isRequired,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
return this;
|
|
25
|
+
},
|
|
26
|
+
withOption(option: CommandOption): CliArgumentsSetter {
|
|
27
|
+
argv.option(option.name, {
|
|
28
|
+
alias: option.alias,
|
|
29
|
+
description: option.description,
|
|
30
|
+
type: option.type,
|
|
31
|
+
demandOption: option.isRequired,
|
|
32
|
+
});
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
return this;
|
|
35
|
+
},
|
|
36
|
+
registerCommands(): void {
|
|
37
|
+
argv.parseSync();
|
|
38
|
+
},
|
|
39
|
+
};
|
|
38
40
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import type { CliAction } from
|
|
1
|
+
import type { CliAction } from "../../core/models/core.models.js";
|
|
2
2
|
|
|
3
3
|
export interface Command {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly options: readonly CommandOption[];
|
|
7
|
+
readonly examples: string[];
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface CommandOption {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
readonly name: string;
|
|
12
|
+
readonly isRequired: boolean;
|
|
13
|
+
readonly alias?: string;
|
|
14
|
+
readonly description?: string;
|
|
15
|
+
readonly type?: "boolean" | "number" | "string";
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export type CliArgumentsSetter = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
withCommand(command: Command): CliArgumentsSetter;
|
|
20
|
+
withOption(option: CommandOption): CliArgumentsSetter;
|
|
21
|
+
registerCommands(): void;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export type CliArgumentsFetcher = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
getCliAction(): CliAction;
|
|
26
|
+
getOptionalArgumentValue(argName: string): string | undefined;
|
|
27
|
+
getRequiredArgumentValue(argName: string): string;
|
|
28
|
+
getBooleanArgumentValue(argName: string, defaultValue: boolean): boolean;
|
|
29
29
|
};
|