Developing a Template
Static Templates
The simplest form of template supported by the Enact CLI is a flat static directory of fileas to be copied. Static templates should include a root-level package.json
, which will get npm install
executed upon creation via enact create
.
A simple example would be the default moonstone template embedded with the Enact CLI itself.
Dynamic Template Generators
An enhanced form of template generators are also supported. In this form, the static template files are within a ./template
subdirectory and a root-level index.js
is available. The index.js
can export hooks which enact create
can tie into.
Available optonal properties that can be exported:
overwrite
[boolean] Whether or not to overwrite existing files when copying the files from./template
.install
[boolean] Whether or not to runnpm install
duringenact create
.validate
[function|Promise] Code run when validating theenact create
target directory/name. Should throw/reject when an invalid name is used.prepare
[function|Promise] Code run just before copying the static files within./template
to the target directory.setup
[function|Promise] Code run just after copying the static files, but before runningnpm install
.complete
[function|Promise] Code run just after everything is finished. Useful to output instructions or a message to the user.
When omitted/undefined
, the function/promise properties will fallback to the default application template handler property values. If explicitly set as false
, those events will be disabled during enact create
.
Note: template generators can even have their own root package.json
with dependencies that will be installed locally when the template is installed.
Distributing
For static templates, git repositories are a simple and straightforward method of sharing. Dynamic template generators have the added advantage of distribution on NPM if desired.
Created a template of your own? We’d love to hear about it!