1. Developer guides

CLI commands and configuration

The Content SDK CLI provides commands and supports scripts for common tasks during the development of projects using the Content SDK. To use the CLI, you must first install it globally on your local machine.

The CLI is configured using the sitecore.cli.config.ts file by default. When this file is created as part of an app using a starter template, it contains the following configuration settings:

import {
  defineCliConfig,
  generateMetadata,
  generateSites,
  writeImportMap,
  extractFiles,
} from '@sitecore-content-sdk/angular/config-cli';
import scConfig from './sitecore.config';

export default defineCliConfig({
  config: scConfig,
  build: {
    commands: [
      generateMetadata(),
      generateSites(),
    ],
  },
  componentMap: {
    paths: ['src/app/components'],
    exclude: ['**/*.spec.ts', 'src/app/components/content-sdk'],
  },
});
Note

The build command supports the --config flag that you can use to provide the location of a config file.

The build command

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

sitecore-tools project build

Your app's package.json file includes a build script that calls this CLI command, so it runs every time your app is built.

By default, the CLI will try to use a file named sitecore.cli.config.ts in the folder where you run the command. If that file does not exist the CLI will try to use sitecore.cli.config.js instead.

If you're running the command in a folder that doesn't contain either of these files, you need to specify the name and (relative) location of the file by using the --config argument, as shown in the following example where a custom file is used in the current folder:

sitecore-tools project build --config=custom.sitecore.cli.config.ts

Within the config file's build.commands: section, you can add custom functionality as shown with myBuildCommand() in the following example:

import { defineCliConfig, generateSites, generateMetadata } from '@sitecore-content-sdk/angular/config-cli';
import type { AngularSitecoreConfig } from '@sitecore-content-sdk/angular/config';
import scConfig from './sitecore.config';

const myBuildCommand = (
  param: string
): (({ scConfig }: { scConfig: AngularSitecoreConfig }) => Promise<void>) => {
  return async ({ scConfig }) => {
    console.log(param, scConfig.defaultSite);
    return Promise.resolve();
  };
};

export default defineCliConfig({
  config,
  build: {
    commands: [generateMetadata(), generateSites(), myBuildCommand('this is my build command!')],
  },
});

You can configure the default generateMetadata method using a GenerateMetadataConfig object. It accepts two optional parameters:

Parameter

Type

Description

destinationPath

string

Specify the path to store the generated metadata. If no value is provided, the default path is used.

Default: .sitecore/metadata.json

allowWorkspaces

boolean

Specify whether to allow metadata generation for npm monorepos.

Default: false

For additional examples of customization, look at the implementations of generateMetadata and generateSites in the core package.

The experimental list command

The sitecore-tools project experimental list command lists the experimental features available in your Content SDK app and whether each feature is enabled. It reads the features from the app's installed @sitecore-content-sdk packages, including @sitecore-content-sdk/angular.

Run the command from the root folder of your app:

sitecore-tools project experimental list

For each feature, the output includes:

DetailDescription
NameThe feature's display name and ID.
Statusenabled or disabled.
Environment variableThe variable used to enable the feature.
DescriptionA short description of the feature.

The command also prints instructions for enabling features. For example, the following output shows a sample feature:

Experimental features available in @sitecore-content-sdk/angular:

  Dummy Feature (dummy-feature)
    Status:               disabled
    Environment variable: CSDK_EXPERIMENTAL_DUMMY_FEATURE
    Sample experimental feature used to verify the visibility API.

Set an environment variable to "true" to enable a single feature, or CSDK_GLOBAL_EXPERIMENTAL_FEATURES_ENABLED="true" to enable all of them.

Sample dummy features are available to verify the command. Actual experimental features appear in the same format as they become available.

To enable experimental features:

  • To enable one feature, set its environment variable to true.
  • To enable all features, set CSDK_GLOBAL_EXPERIMENTAL_FEATURES_ENABLED=true.

Use the lowercase value true. Values such as TRUE and 1 do not enable features. Run the command again after changing the environment variables to see the updated status.

If the installed packages have no experimental features, the command reports that none are available in the current version. If you run it outside a Content SDK app, it prints the following error:

Content SDK app not found. Run this command from the root folder of a Content SDK app.
If you have suggestions for improving this article, let us know!