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.
Configure the Uniform CLI#
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.
Execute within a project#
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.
Open a terminal in the root of your project.
Enter the following command:
npm i -D @uniformdev/cli@latestTo test that the command is available, enter the following command:
npx uniform --versionThe 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" } }
Invoke globally#
Installing the CLI globally allows you to run the uniform
command from any terminal prompt.
- Open a terminal.
- Enter the following command:npm i @uniformdev/cli@latest -g
- To test that the command is available, enter the following command:uniform --version
Authenticate#
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.
Environment variables#
When these values are set as environment variables, you don't need to explicitly pass them to each command you run.
Value | Environment variable name | Example |
---|---|---|
Uniform API key | UNIFORM_CLI_API_KEY | UNIFORM_CLI_API_KEY=<API key> |
Uniform project ID | UNIFORM_PROJECT_ID | UNIFORM_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
CLI command switches#
Passing these values to the command you run gives you the ability to be very explicit about what you want to happen.
Value | Switch |
---|---|
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: