Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 2.16 KB

creatingTemplates.md

File metadata and controls

43 lines (33 loc) · 2.16 KB

Creating Your Own Templates

One of the main goals of Cyto is to make it as easy as possible to write your own templates. Fortunately, the templates themselves are mostly just boilerplate, which we can generate using Cyto! This is exactly what the cyto create <templateId> command does.

Creating a template

I'd recommend making a new directory where you can store all of the templates that you create. You'll need to follow the installation instructions for Cyto in this directory. Under the hood, cyto create is just generating the (somewhat redundantly) named cyto-template-cyto-template template. This template is installed along with cyto-cli. cyto create will write new template boilerplate to $PWD/<group>/<name>. This provides a directory structure that looks like this:

|-- templateLibrary
    |-- cyto
    |   |-- helloworld
    |       |-- cyto.config.js
    |       |-- package.json
    |       |-- {{id}}.txt
    |-- react
        |-- component
            |-- cyto.config.js
            |-- package.json
            |-- {{id}}.js

After performing all required setup, creating a new template is a breeze:

> cyto create tutorials-cyto
Generating cyto-template with id tutorials-cyto
? files:  dep1.txt, dep2.txt
? args:
? createDirectory:  No
? description:  My first cyto template
? scope:
> ls tutorials/cyto
cyto.config.js dep1.txt       dep2.txt       package.json

Testing new templates

You can use the cyto verify command to ensure that your template is valid. You can also install your template in your template directory by running npm install ./<group>/<name> from the root of your template library directory. Your new template will be ready to be generated by others after you npm publish it.

Scoped templates

Cyto supports creating templates under npm scopes. To publish a template under an npm scope, make sure that you include the scope in the templateId. For example, if I wanted to publish a template called react-component under the @taylorc93 scope, I'd give the template a templateId of @taylorc93/react-component and publish it to npm as @taylorc93/cyto-template-react-component.