Skip to content

Templates

The CLI has in-built support for using custom cookiecutter templates to create new projects in your workspace.

Template path

Given a templates/ directory contains some templates:

WORKSPACE_ROOT/
    templates/
        library-template/
        application-template/
    workspace.json

Make these templates available by adding the directory to the template path:

workspace template path add templates/ Added templates to available template directories.

Tip

Any templates added to the directory above will automatically be available to the workspace.

Inspect the available templates with:

workspace template list library-template templates/library-template application-template templates/application-template

Info

Multiple directories can be added to the template path. To inspect the current template path, use workspace info.

Using templates

Available templates can be used to create a new projects:

workspaces new --template library-template libs/my-new-library Created new project my-new-library at libs/my-new-library.

Tip

Ensure cookiecutter is installed with pip install workspace-cli[cookiecutter].

Default variables

Some additional variables can be automatically made available to project templates:

  • {{ workspace_project_path }} is the relative path of the project from the workspace root.
  • {{ workspace_project_name }} is the name of the project in the workspace.

To make these available, include them in the template's cookiecutter.json file, e.g.

{
    "workspace_project_path": null,
    "workspace_project_name": null
}

Warning

Encoding these in a project creates coupling between the project and the workspace.