Skip to content

Commit

Permalink
Updates migration toolkit code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Jul 8, 2024
1 parent f57e55f commit 76e4d1b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {
MigrationAsset,
} from "@kontent-ai-consulting/migration-toolkit";
import { MigrationAsset } from "@kontent-ai-consulting/migration-toolkit";
import { readFileSync } from "fs"; // Only if loading local data

const migrationAssets: MigrationAsset[] = [];

const asset: MigrationAsset = {
// You can load the data from anywhere, not just from the filesystem
binaryData: readFileSync("./path/to/file.jpg"),
Expand All @@ -15,16 +11,18 @@ const asset: MigrationAsset = {
// Name the asset
title: "My asset",
// Asign the asset to a collection
collection: "default",
collection: {
codename: "default",
},
// Specify localized asset descriptions
descriptions: [
{
language: {
codename: "default"
codename: "default",
},
description: "Alt text"
}
]
description: "Alt text",
},
],
};

migrationAssets.push(asset);
const migrationAssets: MigrationAsset[] = [asset];
129 changes: 70 additions & 59 deletions ts/migrate-from-other-systems/migration_toolkit_map_migrationitem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,90 @@ import {
} from "@kontent-ai-consulting/migration-toolkit";

// Define the structure of your Kontent.ai content type
interface MovieModel extends MigrationElements {
interface MovieType extends MigrationElements {
title: MigrationElementModels.TextElement;
plot: MigrationElementModels.RichTextElement;
length: MigrationElementModels.NumberElement;
category: MigrationElementModels.MultipleChoiceElement;
poster: MigrationElementModels.AssetElement;
}

const migrationItems: MigrationItem[] = [];

const movie: MigrationItem<MovieModel> = {
const movie: MigrationItem<MovieType> = {
system: {
name: "Warrior",
// Ensure a unique codename. Check https://kontent.ai/learn/rules-for-codenames
codename: "warrior",
collection: { codename: "default", },
collection: { codename: "default" },
// Map your source language to the language codename in Kontent.ai
language: { codename: "default", },
type: { codename: "movie", },
workflow: { codename: "default", },
// Tip: You can have the item published during the import
workflow_step: { codename: "published", },
language: { codename: "default" },
type: { codename: "movie" },
workflow: { codename: "default" },
},
elements: {
title: elementsBuilder.textElement({ value: "Warrior" }),
length: elementsBuilder.numberElement({ value: 140 }),
category: elementsBuilder.multipleChoiceElement({
value: [ // Reference multiple choice options by their codenames
{
codename: "drama"
},
{
codename: "action"
},
]
}),
poster: elementsBuilder.assetElement({
value: [ // Reference assets by their codenames
{
codename: "warrior_teaser",
},
],
}),
plot: elementsBuilder.richTextElement({
value: { // Check supported HTML elements at https://kontent.ai/learn/rich-text-in-mapi
value: `<h1>Warrior</h1><p>...</p>`,
components: [],
// Tip: You can migrate up to 2 versions - 1 published and one in draft state. This is optional and typically
// you only need to migrate a single version of your content
versions: [
{
workflow_step: {
// Tip: You can have the item published during the import or use any other workflow step
codename: "published",
},
}),
releasecategory: elementsBuilder.taxonomyElement({
value: [ // Reference taxonomy terms by their codenames
{
codename: "global_release",
},
],
}),
released: elementsBuilder.dateTimeElement({
value: "2011-09-09T00:00:00Z",
}),
seoname: elementsBuilder.urlSlugElement({
value: {
mode: "autogenerated",
value: "", // Empty string because 'value' is autogenerated based on the dependent text element
elements: {
title: elementsBuilder.textElement({ value: "Warrior" }),
length: elementsBuilder.numberElement({ value: 140 }),
category: elementsBuilder.multipleChoiceElement({
value: [
// Reference multiple choice options by their codenames
{
codename: "drama",
},
{
codename: "action",
},
],
}),
poster: elementsBuilder.assetElement({
value: [
// Reference assets by their codenames
{
codename: "warrior_teaser",
},
],
}),
plot: elementsBuilder.richTextElement({
value: {
// Check supported HTML elements at https://kontent.ai/learn/rich-text-in-mapi
value: `<h1>Warrior</h1><p>...</p>`,
components: [],
},
}),
releasecategory: elementsBuilder.taxonomyElement({
value: [
// Reference taxonomy terms by their codenames
{
codename: "global_release",
},
],
}),
released: elementsBuilder.dateTimeElement({
value: "2011-09-09T00:00:00Z",
}),
seoname: elementsBuilder.urlSlugElement({
value: {
mode: "autogenerated",
value: "", // Empty string because 'value' is autogenerated based on the dependent text element
},
}),
stars: elementsBuilder.linkedItemsElement({
value: [
// Reference content items by their codenames
{
codename: "tom_hardy",
},
],
}),
},
}),
stars: elementsBuilder.linkedItemsElement({
value: [ // Reference content items by their codenames
{
codename: "tom_hardy",
},
],
}),
},
},
],
};

migrationItems.push(movie);
const migrationItems: MigrationItem[] = [movie];
19 changes: 12 additions & 7 deletions ts/migrate-from-other-systems/migration_toolkit_migrationitem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ const migrationItem: MigrationItem = {
type: { codename: "article" },
// Assign the variant to a workflow
workflow: { codename: "default" },
// Put the variant in a specific workflow step
workflow_step: { codename: "draft" },
},
elements: { // Variant's content
// For each element specified by the item's content type, add properties named using element codenames.
// Example: element_codename: elementsBuilder.textElement({ value: 'plaintext' }),
}
};
versions: [
{
// Put the variant in a specific workflow step
workflow_step: { codename: "draft" },
elements: {
// Variant's content
// For each element specified by the item's content type, add properties named using element codenames.
// Example: element_codename: elementsBuilder.textElement({ value: 'plaintext' }),
},
},
],
};

0 comments on commit 76e4d1b

Please sign in to comment.