Schematics

Use composable storefront schematics to install composable storefront libraries in your Angular project.

Composable storefront schematics allow you to install composable storefront libraries in your project. The following sections describe what the composable storefront schematics do, and also provide information about the various options and commands you can use with the schematics. If you are a developer and are looking for more technical information, see the READMEInformation published on non-SAP site in the composable storefront schematics project.

Prerequisites

Before using composable storefront schematics, ensure that you have all of the necessary prerequisites.

Your Angular development environment should include the following:

  • Angular CLIInformation published on non-SAP site Version 15.2.4 is the minimum required. The most recent 15.x version is strongly recommended. Version 16 and higher is not supported.

  • Node.jsInformation published on non-SAP site Version 16.13.0 or a newer 16.x version, or else version 18.10.0 or a newer 18.x version. Node.js 14.20 and newer 14.x versions are supported by Angular 15, but are no longer supported by SAP Commerce Cloud hosting services.

  • npmInformation published on non-SAP site Version 8.0 or newer.

Adding Composable Storefront Core Libraries and Features to Your Angular Project

You can add composable storefront core libraries and features to your Angular project by running the following command from your project root:

ng add @spartacus/schematics@latest

The following is a description of the various options you can use with the ng add @spartacus/schematics@latest command:

  • baseUrl sets the base URL of your CX OCC back end.

  • baseSite is a comma-separated list of base site(s) to use with composable storefront.

  • currency is a comma-separated list of currencies to use in composable storefront.

  • language is a comma-separated list of languages to use in composable storefront.

  • urlParameters is a comma-separated list that represents the order of site-context parameters, such as ['baseSite', 'language', 'currency'], for example.

  • occPrefix sets the OCC API prefix, such as /occ/v2/, for example.

  • useMetaTags determines whether or not to configure the baseUrl and mediaUrl in the meta tags from index.html.

  • featureLevel sets the application feature level. The default value is the same as the version of the composable storefront packages you are working with. For example, the featureLevel for @spartacus/schematics@3.2.0 is 3.2.

  • overwriteAppComponent overwrites the content of app.component.html. The default value is true.

  • pwa includes progressive web application (PWA) features when building the application.

  • ssr includes the server-side rendering (SSR) configuration.

  • lazy installs features with lazy loading configured for each of the feature modules. The default value is true.

  • project allows you to specify the project that you want to configure your composable storefront application in. The default is the workspace default project.

  • interactive allows you to bypass the schematics prompts and install composable storefront with a predefined set of features.

  • theme allows you to import the CSS for a built-in theme, such as santorini. If you do not set a value for this parameter, the default Sparta theme is used.

The following is an example that generates an application that is ready to be used with the electronics storefront, that sets the baseUrl and the baseSite, and that also enables server-side rendering:

ng add @spartacus/schematics@latest --base-url https://composable-storefront-demo.eastus.cloudapp.azure.com:543/ --base-site=electronics-spa --ssr

This next example bypasses the schematics prompts and installs composable storefront with a predefined set of features:

ng add @spartacus/schematics@latest --base-url https://composable-storefront-demo.eastus.cloudapp.azure.com:543/ --base-site=electronics-spa --no-interactive

To see which features are included when you use the --no-interactive flag, see schema.jsonInformation published on non-SAP site.

Additional Commands for Core Libraries and Features

By default, the ng add @spartacus/schematics command adds only a basic configuration of composable storefront. The following is a description of the commands you can use to extend your application:

  • ng g @spartacus/schematics:add-pwa adds a composable storefront-specific PWA module.

  • ng g @spartacus/schematics:add-ssr adds the SSR configuration.

  • ng g @spartacus/schematics:add-cms-component generates a CMS component, and adds the CMS component mapping to the specified module, or to a newly-generated module, if no module is specified. For more information, see CMS Component Schematic, below.

How Composable Storefront Schematics Work

When you run ng add @spartacus/schematics, the command does the following:

Procedure

  1. Adds the required dependencies.
  2. Sets up composable storefront modules in the project and provides the default configuration. For more information, see Reference App Structure.
  3. Imports composable storefront styles to main.scss.
  4. Adds the cx-storefront component to your app.component.
  5. Optionally updates index.html with the composable storefront URL endpoints in meta tags.
  6. If the --ssr flag is included, the command does the following:
    • Adds server-side rendering dependencies.

    • Provides additional files that are required for SSR.

CMS Component Schematic

The following is a description of the available options for the CMS component schematic:

  • --declare-cms-module specifies which module the newly-generated CMS component is added to. If no module is specified, a new module is generated.

  • --cms-component-data, alias --cms, injects the CmsComponentData into the new component. By default, this option is set to true.

  • --cms-component-data-model, alias --cms-model, specifies the model class for the CmsComponentData, such as MyModel, for example. This argument is required if --cms-component-data is set to true.

  • --cms-component-data-model-path, alias --cms-model-path, specifies the import path for the CmsComponentData. The default is @spartacus/core.

Aside from these custom options, the add-cms-component supports almost all options that are available for the Angular component and module schematics. The full list can be seen in this schema.jsonInformation published on non-SAP site file.

The following Angular options are not supported:

  • Deprecated options.

  • The --module option for components. If you want to specify an existing module for a component, use --declare-cms-module. The module option is only applied to the Angular module schematic.

  • The --skip-import option.

Using the 'add-cms-component' Schematic

The following are some examples of how the add-cms-component schematic can be used:

  • ng g @spartacus/schematics:add-cms-component myAwesomeCms --cms-model=MyModel generates the my-awesome-cms.component.ts component and the my-awesome-cms.module.ts module.

  • ng g @spartacus/schematics:add-cms-component myAwesomeCms --cms-model=MyModel --declare-cms-module=my-cms-path/my-cms generates the my-awesome-cms.component.ts component and adds it to the specified CMS mapping for my-cms-path/my-cms.module.ts.

  • ng g @spartacus/schematics:add-cms-component myAwesomeCms --cms-model=MyModel --module=app generates the my-awesome-cms.component.ts component and the my-awesome-cms.module.ts module, and imports them to the specified app.module.ts.

  • ng g @spartacus/schematics:add-cms-component myAwesomeCms --cms-model=MyModel --module=app --declare-cms-module=my-cms-path/my-cms generates the my-awesome-cms.component.ts component and adds it to the specified my-cms-path/my-cms.module.ts module. It also imports my-cms.module.ts to the specified app.module.ts.

Installing Additional Composable Storefront Libraries

You need to first install the composable storefront core libraries before you can install additional composable storefront libraries. For more information, see Adding Composable Storefront Core Libraries and Features to Your Angular Project, above.

Integration Libraries and Feature Libraries

During the initial set up of your storefront using schematics, you have the option to install a number of composable storefront features, which is done by installing the relevant integration or feature libraries. The following is a list of the integration libraries and feature libraries that you can install, along with information about what is included in each package.

If you do not install a particular integration library or feature library during the initial set up of your storefront, you can always install any of these libraries later on using schematics. The command to install a library is the following:

ng add <package-name>

For example, you can install the @spartacus/asm library with the following command:

ng add @spartacus/asm

You can also include options when you use the ng add command, as follows:

  • lazy installs features with lazy loading configured for each of the feature modules within the library. The default is true.

  • project allows you to specify the project that you want to configure the composable storefront feature library in. The default is the workspace default project.

The following is an example of the ng add command that installs the tracking library without the configuration for lazy loading:

ng add @spartacus/tracking --no-lazy