Showing posts with label Sitecore CLI. Show all posts
Showing posts with label Sitecore CLI. Show all posts

Monday, 22 September 2025

Sitecore XM Cloud Content SDK vs. JSS SDK: Key Differences and New Features

September 22, 2025 0

 


In my previous blog post on the Sitecore XM Cloud Content SDK, I discussed how you can install and start working with the Content SDK. In this blog, I'll focus on the differences between the JSS SDK and the Content SDK, along with some of the new concepts introduced in the Content SDK.

Comparison with JSS SDK

1. Reduced Folder Size and Complexity
The Content SDK removes functionality not strictly required for XM Cloud, leading to smaller, less complex starter applications that are inherently easier to understand and maintain.

2. Experience Editor Removal
This is one of the most impactful changes. Unlike JSS, the Content SDK does not support the Experience Editor. Instead, all visual editing is handled through the XM Cloud Pages Builder in metadata integration mode. This eliminates the need for chromes integration mode—previously central to the Experience Editor—and enables further code optimizations.

3. Mapping Components
In the Content SDK, all components must be manually registered in the app’s .sitecore/component-map.ts file. Unlike traditional JSS apps, Content SDK apps don’t automatically update mappings for newly scaffolded components through a file watcher. This approach gives developers greater control, allowing them to decide when and how components are exposed to XM Cloud. At the same time, the Content SDK provides flexibility by offering an automated option to generate component maps using the sitecore-tools project component generate-map CLI command, which includes a file watcher mode.

4. Centralized Configuration Files

  • .env.container.example — Used when working with a Sitecore container instance. Copy this file, rename it to .env.local, and update the required environment variables.

  • .env.remote.example — Used when working with a Sitecore remote instance. Copy this file and rename it to .env.local.

  • sitecore.config.ts — Serves as the central configuration file for the app. To access values from sitecore.cli.config, use:

    import scConfig from 'sitecore.config';
  • sitecore.cli.config.ts — Provides CLI commands and supports scripts for common tasks during Content SDK project development.

5. Data Fetching
The new Sitecore Client Data Fetching API, powered by the SitecoreClient class, centralizes all data-fetching logic. This replaces the older JSS data-fetching plugins, offering a more unified and streamlined way to retrieve content.

6. Middleware Handling
Middleware is now managed within the middleware.ts file in Next.js. A new utility function, defineMiddleware, simplifies middleware composition and improves visibility into execution order. This removes the need for separate middleware plugin files used in JSS, making middleware logic easier to maintain.

7. CLI Tooling
The Content SDK introduces its own set of dedicated CLI commands, replacing legacy JSS CLI tools. For instance, the familiar jss scaffold component command is now replaced by:

sitecore-tools project component scaffold

8. XM Cloud Starter Kit
Alongside the Content SDK, a new XM Cloud Starter Kit is available. The xmcloud-foundation-head repository continues to serve as the JSS-based starter kit. Both provide a Next.js skatepark demo site, but the Content SDK version uses Tailwind CSS instead of Bootstrap.

In addition, the new starter kit includes:

  • An empty Next.js head app example

  • An empty Angular head app example

  • Three new Next.js demo head app examples

Some New Concepts

SitecoreClient API
The SitecoreClient class is a generic, framework-agnostic client that you can use to interact with XM Cloud's headless APIs and services. It provides a unified interface for retrieving and managing content, layout, dictionary data, error pages, preview data, sitemaps, robots.txt, and other site-related information from an XM Cloud backend, typically via GraphQL endpoints.

CLI Commands

  • The build command
    The sitecore-tools project build command prepares app-specific build artifacts, such as those required for the app to connect to XM Cloud. It does this by sequentially executing the functions listed in the build: section of your CLI config file.

  • The scaffold command
    The sitecore-tools project component scaffold command generates a new component in the src/components/ folder of your app, based on the default template for the framework.

  • Generate-map Command
    (sitecore-tools project component generate-map)
    This command generates the component map file at /.sitecore/component-map.ts. It supports defining component source paths, importing components from NPM packages, applying exclude patterns, and specifying a custom destination.

Content SDK Pros and Cons

Pros

  • Reduced Size & Complexity: Content SDK apps are smaller and less complex than JSS apps, making them easier to understand, maintain, and run faster with smaller bundle sizes.

  • Seamless XM Cloud Pages Integration: Out-of-the-box visual editing and component testing directly in XM Cloud Pages, empowering marketing teams.

  • Unified Data Fetching: The SitecoreClient class provides a single, streamlined interface for all XM Cloud headless API interactions.

  • Modern Development Workflow: Enables contemporary workflows and architectures for headless development.

  • Rapid Development: Includes an empty Next.js head app and multiple demo apps to accelerate project setup and customization.

  • Rich Out-of-the-Box Features: Supports personalization, A/B/n testing, multisite setups, GraphQL utilities, SSR/SSG, and locale-based routing.

  • Developer Autonomy: Offers more control over component mapping, allowing developers to decide which components to register.

Cons

  • No Experience Editor Support: With the shift to XM Cloud Pages (and the deprecation of the Experience Editor), teams relying heavily on EE must adapt their workflows.

  • Migration Effort for Existing JSS Apps: Migrating to Content SDK requires dependency updates, configuration changes, and code refactoring, which can be complex depending on the app. Sitecore provides an upgrade guide.

  • Learning Curve for New Concepts: Developers need to get familiar with new elements such as the SitecoreClient class, centralized config files (sitecore.config.ts, sitecore.cli.config.ts), and the defineMiddleware utility.

The Sitecore XM Cloud Content SDK represents a major step forward in headless development on XM Cloud. Content SDK is providing a streamlined, efficient, and developer-friendly experience. 

References

Wednesday, 3 September 2025

Migrating Content and Users with the XM to XM Cloud Migration Tool CLI

September 03, 2025 0

In my previous blog, I discussed how we can migrate content, media, and users using the XM to XM Cloud Migration Tool – GUI option.

In today’s blog, I’ll walk you through the CLI (Command Line Interface) option, which provides the same functionality but is also ideal for scripting and automation.

Step 1: Configuration Setup

It is very important to use the same configuration settings as in the GUI version, stored in the appsettings.json file.
If needed, you can adjust some values manually. You can also refer to a sample appsettings.json file here.

Key Configurations

RAIFs Configuration

The XM to XM Cloud Migration Tool transfers content and media via RAIFs (batches).

  • The default values in appsettings.json are balanced for most customers.

  • ItemsPerRaif defines the number of items per transfer.

    • Too low → creates too many RAIF files.

    • Too high → may impact transfer speed.

  • MediaSizeLimit defines the maximum media size per RAIF.

    • Must be a long value.


Content Migration Configuration

Ensure proper settings for source and target configuration before executing migration.


Step 2: Explore CLI Options

Navigate to the folder containing the console app and run:

.\XMMigration.exe --help

This will display a list of all available commands.


Step 3: Migrate Content

Run the following command to migrate content:

.\XMMigration.exe content



Step 4: Migrate Users

You have multiple options for migrating users:

  • Retrieve domains from the source instance

    .\XMMigration.exe users --retrieve-domains

  • Migrate users by passing domains (comma separated)

    .\XMMigration.exe users --migrate-userdomains sitecore


This may ask to login to XM Cloud-


Key Points to Remember

  1. This tool can only be used for “as-is” migration.

    • Content cannot be transformed.

    • Content templates cannot be updated.

  2. Templates must be migrated first, followed by content.

  3. Only media items stored in the database can be migrated.

  4. Best suited for migrating a large volume of legacy content to XM Cloud.

Conclusion

The XM to XM Cloud Migration Tool’s CLI option is powerful for automation and large-scale migrations. With proper configuration and sequence, it ensures a smooth transfer of content, media, and users to XM Cloud.

Monday, 28 August 2023

Step by step guide to install and configure Sitecore CLI

August 28, 2023 0

Sitecore Serialization refers to a process within the Sitecore web content management system (CMS)that allows developers to save and retrieve Sitecore items and their associated data in a structured format. This process is commonly used for version control, content deployment, and collaboration in Sitecore development projects.

Sitecore Serialization essentially involves converting Sitecore items, which are the building blocks of content within the CMS, into files that can be stored in a version control system, such as Git. These files typically include configuration data, templates, layouts, renderings, and other relevant information about the Sitecore items. 

There are many tools available that provide Sitecore Serialization for content management in different types of machines and environments.

  • TDS
  • UNICORN
  • SITECORE CLI

The objective of this post is to provide a step-by-step guide to setting up Sitecore CLI in your solution.

Prerequisites:

Please ensure that you are working with Sitecore version 10.0 or later, as Sitecore CLI is not available for earlier versions. Additionally, you will need to have .NET Core 3.1 or a later version installed on your server. 

Step 1: Install Sitecore Management Services package 

·        Download Sitecore Management Services package from the URL: https://dev.sitecore.net/Downloads/Sitecore_CLI.aspx 

·        Now, Install the package on Sitecore instance using Sitecore Control Panel > Install a package.


Step 2: Install the Sitecore CLI

The Sitecore CLI requires .NET Core. Open a command prompt and run "dotnet --list-sdks". If you see the version as 3.1 (For me, the version is 6) or above, you are ready to proceed.

Now, open PowerShell as an administrator and navigate to the Visual Studio solution folder. Install the CLI by executing the following script:

dotnet new tool-manifest
dotnet nuget add source -n Sitecore https://sitecore.myget.org/F/sc-packages/api/v3/index.json
dotnet tool install Sitecore.CLI --add-source https://sitecore.myget.org/F/sc-packages/api/v3/index.json


Step 3:Initialize Sitecore CLI

Next, initialize your new serialization project by entering the following in the terminal:

dotnet sitecore init


This action will generate the Sitecore.json file.


Step 4: Connecting to Sitecore

To connect to a Sitecore instance type in the following command:

dotnet sitecore login --authority https://<Sitecore identity server> --cm https://<Sitecore instance> --allow-write true
Upon executing the above command, a login screen will open up in your browser.





After successfully logging in, you are ready to perform serialization (push, pull), and database publishing using the commands below.


You can use either the "ser" or "serialization" command to pull or push the data.
dotnet sitecore ser pull
dotnet sitecore ser push


During the setup process, I encountered the following error related to the installation of the CLI plugin version. Please find the error details and the solution below:

Solution: Check the plugin versions using the "Sitecore plugins list" command. Then update plugins with the latest version using the following command:

Sitecore plugins init --overwrite


Conclusion

To serialize Sitecore items, you can install and configure Sitecore CLI by following the steps provided above.