Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 164 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"chalk": "^5.3.0",
"node-stream-zip": "^1.15.0",
"open": "^10.1.0",
"ora": "^8.1.0",
"ts-pattern": "^5.3.1",
"yargs": "^17.7.2",
"zod": "^3.23.8",
Expand All @@ -70,4 +71,4 @@
"uuid": "^9.0.1",
"vitest": "^2.1.1"
}
}
}
1 change: 1 addition & 0 deletions src/modules/sync/constants/emojiCodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const noSyncTaskEmoji = "\u{2728}";
37 changes: 20 additions & 17 deletions src/modules/sync/sync/assetFolders.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { AssetFolderModels, ManagementClient } from "@kontent-ai/management-sdk";
import { oraPromise } from "ora";
import { match } from "ts-pattern";

import { logError, logInfo, LogOptions } from "../../../log.js";
import { handleKontentErrors, throwError } from "../../../utils/error.js";
import { apply, not } from "../../../utils/function.js";
import { omit } from "../../../utils/object.js";
import { serially } from "../../../utils/requests.js";
import { noSyncTaskEmoji } from "../constants/emojiCodes.js";
import { DiffModel } from "../types/diffModel.js";
import { getTargetCodename, PatchOperation } from "../types/patchOperation.js";
import { isOp } from "./utils.js";
Expand All @@ -16,29 +18,30 @@ export const syncAssetFolders = async (
logOptions: LogOptions,
) => {
if (!operations.length) {
logInfo(logOptions, "standard", "No asset folders updates");
logInfo(logOptions, "standard", `${noSyncTaskEmoji}No asset folders updates.`);
return;
}

logInfo(logOptions, "standard", "Updating asset folders");

const removeOps = operations.filter(isOp("remove"));

await serially(removeOps.map(operation => () =>
client
.modifyAssetFolders()
.withData([convertOperation(operation)])
.toPromise()
.catch(handleKontentErrors(err => {
logError(
logOptions,
"error",
`Failed to remove asset folder "${operation.path}" error: ${JSON.stringify(err)}. Skipping it.`,
);
await oraPromise(
serially(removeOps.map(operation => () =>
client
.modifyAssetFolders()
.withData([convertOperation(operation)])
.toPromise()
.catch(handleKontentErrors(err => {
logError(
logOptions,
"error",
`Failed to remove asset folder "${operation.path}" error: ${JSON.stringify(err)}. Skipping it.`,
);

return undefined;
}, [5])) // this is a generic code for invalid body, but the error with folder containing assets unfortunately doesn't have a specific code
));
return undefined;
}, [5])) // this is a generic code for invalid body, but the error with folder containing assets unfortunately doesn't have a specific code
)),
{ text: "Updating asset folders" },
);

const restOps = operations.filter(not(isOp("remove")));

Expand Down
34 changes: 20 additions & 14 deletions src/modules/sync/sync/collections.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { CollectionModels, ManagementClient } from "@kontent-ai/management-sdk";
import { oraPromise } from "ora";

import { logInfo, LogOptions } from "../../../log.js";
import { omit } from "../../../utils/object.js";
import { noSyncTaskEmoji } from "../constants/emojiCodes.js";
import { DiffModel } from "../types/diffModel.js";
import { getTargetCodename, PatchOperation } from "../types/patchOperation.js";

Expand All @@ -11,16 +13,17 @@ export const syncAddAndReplaceCollections = (
logOptions: LogOptions,
) => {
if (!collections.length) {
logInfo(logOptions, "standard", "No collections to add or update");
logInfo(logOptions, "standard", `${noSyncTaskEmoji} No collections to add or update`);
return Promise.resolve();
}

logInfo(logOptions, "standard", "Adding and updating collections");

return client
.setCollections()
.withData(collections.filter(op => op.op !== "remove").map(transformCollectionsReferences))
.toPromise();
return oraPromise(
client
.setCollections()
.withData(collections.filter(op => op.op !== "remove").map(transformCollectionsReferences))
.toPromise(),
{ text: "Adding and updating collections" },
);
};

export const syncRemoveCollections = (
Expand All @@ -31,16 +34,19 @@ export const syncRemoveCollections = (
const collectionsRemoveOps = collections.filter(op => op.op === "remove");

if (!collectionsRemoveOps.length) {
logInfo(logOptions, "standard", "No collections to delete");
logInfo(logOptions, "standard", `${noSyncTaskEmoji} No collections to delete`);
return Promise.resolve();
}

logInfo(logOptions, "standard", "Deleting collections");

return client
.setCollections()
.withData(collectionsRemoveOps.map(transformCollectionsReferences))
.toPromise();
return oraPromise(
client
.setCollections()
.withData(collectionsRemoveOps.map(transformCollectionsReferences))
.toPromise(),
{
text: "Deleting collections",
},
);
};

const transformCollectionsReferences = (operation: PatchOperation): CollectionModels.ISetCollectionData => {
Expand Down
Loading