Sync CLI commands

The commands in this section allow you to manage all project assets. See the full list.

The uniform sync command requires a configuration file to specify how it should work. By default, it looks for the uniform.config.ts file in the project's root directory.

It's a TypeScript, JavaScript, or JSON file that exports the configuration object. The object should have a serialization key with a configuration object to specify how uniform sync command should work.

Here is an example of configuration file to enable backup/restore of canvas entities with default settings (YAML format, mirror mode, ./uniform-data directory).

import type { CLIConfiguration } from '@uniformdev/cli'; const config: CLIConfiguration = { serialization: { entitiesConfig: { composition: {}, component: {}, projectMapDefinition: {}, projectMapNode: {}, } } }; module.exports = config;

The configuration allows you to control 4 things:

  • Serialization format: yaml or json
  • Serialization mode: mirror or createOrUpdate or create
  • Serialization directory or file path to store serialized data
  • Serialization entities configuration: to specify which entities and how to serialize

Use will depend on your application. An example case could be where you want to push a new component from your local environment. Review the output details of the push component command.

There are also 3 levels of granular configuration:

  • Global configuration
  • Per entity type configuration
  • Per pull or push command configuration

Here is an example with explanation:

import type { CLIConfiguration } from '@uniformdev/cli'; const config: CLIConfiguration = { // Sync command related configuration should be under "serialization" key serialization: { // Serialization format should be yaml for all enabled entities, unless other format is specified per entity type format: "yaml", // Same regarding mode mode: "mirror", // Same regarding directory. Note that every content type will be saved in its own subdirectory: `./uniform-data/<content-type>` directory: "./uniform-data", entitiesConfig: { // To enable serialization for specific entity type, you should add it to "entitiesConfig" object. empty object is enough category: {}, component: { // Override serialization format for component entity type format: "json", mode: "createOrUpdate", directory: "./custom-directory-for-components" }, composition: { format: "json", pull: { // Override serialization mode for composition entity type for push command mode: "create" }, push: { // Disable only pushing compositions (if 'push' is not specified, it is enabled using top level settings by default) disabled: true }, // Only pull published compositions state: 'published' } } } } module.exports = config;

The default configuration before merging with user provided configuration is:

import type { CLIConfiguration } from '@uniformdev/cli'; const config: CLIConfiguration = { serialization: { format: "yaml", mode: "mirror", directory: "./uniform-data", // no entity types are enabled by default entitiesConfig: {} } } module.exports = config;

Most of the time you will need to override only entitiesConfig object:

import type { CLIConfiguration } from '@uniformdev/cli'; const config: CLIConfiguration = { serialization: { format: "yaml", mode: "mirror", directory: "./uniform-data", entitiesConfig: { composition: { push: { // May be useful to only create new compositions and not update existing ones to avoid accidental overrides mode: 'create' } }, pattern: {}, category: {}, component: {}, dataType: {}, signal: {}, test: {}, aggregate: {}, enrichment: {}, quirk: {}, projectMapDefinition: {}, projectMapNode: {}, redirect: {}, } } } module.exports = config;

To configure this command you should provide the configuration file in one of two ways:

Use the cosmiconfig package to locate the configuration file in the project root. You can see different ways of naming the configuration .

You can also use TypeScript files as configuration files. In this case, you should provide a ts extension in the file name.

You can specify the file explicitly:

uniform sync pull --config ./production-uniform.config.ts

The pull command will fetch all configured project entities from the Uniform Project and save them to the local file system.

uniform sync pull

The push command will read all configured project entities from the local file system and push them to the target Uniform Project.

uniform sync push
import type { CLIConfiguration } from '@uniformdev/cli'; const config: CLIConfiguration = { serialization: { directory: './uniform-data/data.json', entitiesConfig: { composition: {}, component: {}, projectMapDefinition: {}, projectMapNode: {}, } } }; module.exports = config;
import type { CLIConfiguration } from '@uniformdev/cli'; require('dotenv').config(); const prodConfig: CLIConfiguration = { serialization: { entitiesConfig: { composition: {}, redirect: {}, component: {}, category: {}, quirk: {}, test: {}, }, directory: 'uniform-prodaction-data.json', }, }; const devConfig: CLIConfiguration = { serialization: { entitiesConfig: { composition: { push: { disabled: true, } }, dataType: { push: { disabled: true, } }, redirect: {}, component: {}, category: {}, quirk: {}, test: {}, }, }, }; module.exports = process.env.NODE_ENV === 'production' ? prodConfig : devConfig;