Installation and setup

This section describes how to install and setup the Uniform CLI so you can use it to backup and restore assets from your Uniform project.

The Uniform CLI is provided in an npm package. This package can be installed in a couple of different ways, depending on your needs and where you are in your process.

  • If you are creating a project you have to invoke the CLI globally because there are no project dependencies yet.
  • If you're working with an established project, you'll need to include project dependencies, like the version.

Installing the CLI in a project allows you to run the uniform command from scripts in package.json. Uniform recommends this method for active development work because it lets projects reference independent CLI versions.

  1. Open a terminal in the root of your project.

  2. Enter the following command:

    npm i -D @uniformdev/cli@latest
  3. To test that the command is available, enter the following command:

    npx uniform --version
  4. The following is an example of a script that uses a uniform command:

    package.json

    { "name": "my-package", "version": "0.1.0", "private": true, "scripts": { "uniform:version": "uniform --version" }, "devDependencies": { "@uniformdev/cli": "latest" } }

Installing the CLI globally allows you to run the uniform command from any terminal prompt.

  1. Open a terminal.
  2. Enter the following command:
    npm i @uniformdev/cli@latest -g
  3. To test that the command is available, enter the following command:
    uniform --version

The Uniform CLI uses an API key to communicate with Uniform. The API key must be specified for all commands you send using the CLI. This allows you to configure specific permissions for the API key so you can lock down what the CLI is allowed to do. For example, if you are using the CLI in a CI/CD scenario, it's probably sufficient to set read-only permissions on the API key.

When you send a command using the Uniform CLI, the command is intended for a specific Uniform project. As a result, you must also specify the Uniform project ID for all commands you send using the CLI.

These values can be set in a couple of different ways.

When these values are set as environment variables, you don't need to explicitly pass them to each command you run.

ValueEnvironment variable nameExample
Uniform API keyUNIFORM_CLI_API_KEYUNIFORM_CLI_API_KEY=<API key>
Uniform project IDUNIFORM_PROJECT_IDUNIFORM_PROJECT_ID=<project ID>

note

You should use UNIFORM_CLI_API_KEY for access through the CLI only, to safely give that API key write permissions (if needed). For read-only access in your application, define a separate API key UNIFORM_API_KEY instead.

The following demonstrates how these variables can be set in an .env file:

.env

UNIFORM_API_KEY=<YOUR API KEY> UNIFORM_PROJECT_ID=<YOUR PROJECT ID>

Passing these values to the command you run gives you the ability to be very explicit about what you want to happen.

ValueSwitch
Uniform API key--apiKey
Uniform project ID-p, --project

The following demonstrates a command where the API key and project ID are specified using switches:

uniform canvas composition list --apiKey AAA... --project BBB...