Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Info

We recommend familiarising yourself with how the Forms CLI works before writing your own plugin.

What is a Forms CLI Plug-in?

The Forms CLI uses a plug-in to turn a JSON definition of a Blink form into source code for a specific framework. It deals only with forms and their functionality, however you could write a plug-in pack that could build an entire project. 

Plugin API

A plug-in consists of an entry point that exposes four functions that are called at various points by the Forms CLI. The Forms CLI must expose an object of the following structure:

...

Currently we only support plug-ins installed in a node_modules folder in your projects folder. To develop a plugin we recommend making a new project folder for the plug in (that is not in the project that will be using forms components built with the Forms CLI), and then use npm link to link your plugin to a project using the forms transformer.

ProcessForm Function

processForm(definition) => Array<() => Promise>

The Forms CLI does the job of getting a forms definition from your definition source (answerSpace or JSON files currently supported), normalizing it, then passing each form to your plug-in, collecting the results.

processForm is called by the Forms CLI and passed a single form definition in normalized JSON. Its job is to do whatever is needed to prepare the definition, and then return a function (or array of functions) that return a Promise. As such there is no rules to what you do with the definition, as frameworks vary, the job of processForm varies from framework to framework. 

processForm(definition) => Array<() => Promise>


It is recommended to use the template-helper module, which provides functions to load templates from a folder, create "primed" mustache templates and a lazyWriter function that is used by the AngularJS plug-in as the return value of processForm.

For a full implementation example, see the AngularJS or JSON plug-ins.

...