The various kinds of templates in SAO

EGOIST
⚔️ SAO
Published in
2 min readAug 5, 2017

SAO was designed to support as many kinds of template as possible, currently it supports:

  • local directory
  • npm package
  • git repo

local directory

Most likely you will only use local directory for testing purpose:

sao ./path/to/template
sao /absolute/path/to/template

It works on windows too:

sao c://path...

npm package

The most common way to share a template is publishing it on npm, prefixing the package name with template-.

sao nm
sao template-nm
# these two are equivalent
# it will use `template-nm` on npm

We prefix it to prevent from package naming conflict, but you can still use desired package name without prefix if you like:

sao npm:my-awesome-template

Use the special keyword npm: so we won’t prefix my-awesome-template with template- , instead we use the package my-awesome-template directly from npm.

Package name also supports versioning:

sao nm@0.2.1

This will make SAO install template-nm@0.2.1 if it’s not yet cached on your machine. To skip the cached template run sao nm@0.2.1 --install instead.

git repo

The easiest way to share your template is via git repo:

sao egoist/template-nm 

This will download (if not yet cached) the repo to ~/.sao/repos/egoist::template-nm directory, and then generate project from it.

Of course it supports git branch and tags too:

sao egoist/template-nm#dev
sao egoist/template-nm@v0.2.1

By default, we assume that the git repo host is GitHub, but you may use GitLab or BitBucket too:

sao gitlab:user/repo
sao bitbucket:user/repo

For private repos, we can’t download it directly, instead we usegit clone :

sao gitlab:user/private-repo --clone

What if the package/repo is not an SAO template?

When the source does not have an sao.js and a template folder in its root directory, it’s not a valid SAO template. In this case we simply copy the source to target path.

--

--