# @blinkmobile/forms-template-helper

> Helper utilities for template functions in Blink Forms plugins

Latest version **1.0.0** (published 2018-05-17) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @blinkmobile/forms-template-helper
pnpm add @blinkmobile/forms-template-helper
yarn add @blinkmobile/forms-template-helper
bun add @blinkmobile/forms-template-helper
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-05-17 |
| First published | 2017-05-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 8 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Blink Mobile Technologies |
| Maintainers | blinkmobile-admin, k7n4n5t3w4rt, simon_marklar |
| Keywords | Blink, Mobile, BlinkMobile, template, Forms, plugin |

## Links

- npm: https://www.npmjs.com/package/@blinkmobile/forms-template-helper
- Repository: https://github.com/blinkmobile/forms-cli/tree/master/packages/forms-template-helper
- npm.io page: https://npm.io/package/@blinkmobile/forms-template-helper

## Dependencies (8)

- [co](https://npm.io/package/co.md) 4.6.0
- [glob](https://npm.io/package/glob.md) 7.1.1
- [mkdirp](https://npm.io/package/mkdirp.md) 0.5.1
- [rimraf](https://npm.io/package/rimraf.md) 2.6.1
- [mustache](https://npm.io/package/mustache.md) 2.3.0
- [recursive-copy](https://npm.io/package/recursive-copy.md) 2.0.6
- [transducers-js](https://npm.io/package/transducers-js.md) 0.4.174
- [@blinkmobile/maybe-run](https://npm.io/package/@blinkmobile/maybe-run.md) ^1.0.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-05-17
- 1.0.0-alpha.8 — 2018-05-17
- 1.0.0-alpha.7 — 2018-05-17
- 1.0.0-alpha.6 — 2018-05-17
- 1.0.0-alpha.4 — 2017-10-16
- 1.0.0-alpha.3 — 2017-08-04
- 1.0.0-alpha.2 — 2017-06-28
- 1.0.0-alpha.1 — 2017-05-12

## README

# Forms CLI Template Helper

A collection of functions to help making a Framework plugin for the Blink Mobile Technologies Forms CLI easier.

See The [AngularJS](../bm-plugin-forms-angularjs) package for a detailed implementation.

## Installation

Install this module as part of your plugin code:

```
npm i --save @blinkmobile/forms-template-helper
```

Then require the module where needed and use the exposed API functions

## API

The template helper exposes the following functions via an object. The majority of function are wrapped by the functions provided by "service", but are exposed for convenience

### makeTemplateStore <a id="maketemplatestore"></a>

makeTemplateStore(templatePath: string) => Promise<TemplateStore>

Reads the folder/file structure from `templatePath` and creates the Templates. Templates in the root `templatePath` are the default templates. Folders represent forms, with the templates contained in the folders overriding the default templates of the same name.

### service <a id="service"></a>
Deprecated. Will be removed before next release
Object containing two functions that wrap most the below functions.

- load (templatePath) => Promise(&lt;Array&lt;MustacheRenderers>)
    - Loads all templates in a given path. Sub folders are treated as 'types', eg a folder structure of
```
|-templates
| |-html
| | |-text.mustache
| |-js
| | |-controller.js.mustache
```

results in two types of templates, "html" and "js"

- getByType (type) => Array&lt;object>
    - returns an object where the key is the name of the file (minus the .mustache part) and the value is a Mustache Renderer, "primed" with the template

### fileListHelper <a id="fileListHelper"></a>

Object containing helper functions for getting lists of files.

- getFileList(path &lt;string>) => Promise(Array&lt;string>)
    - Gets a list of files from the specified path
- getFolderList(path &lt;string>) => Promise(Array&lt;string>)
    - Gets a list of folders from the specified path

### readFileContents <a id="readFileContents"></a>

readFileContents(path-to-file &lt;string>) => Promise(contents &lt;string>)

Asynchronously reads the contents of a file and resolves with the contents of the file.

### mustacheRenderer <a id="mustacheRenderer"></a>

Object containing helper functions to prime a mustache template with the contents of a mustache file

- renderer (template&lt;string>) => (data&lt;object>) => &lt;string>
    - Returns a function that accepts an object of data, lazily runs mustache on the initial template with the data
- createRenderer (filePath&lt;string>) => (data&lt;object>) => &lt;string>
    - Takes a path to a mustache file and reads the file, passing the template to the above `renderer` function, returning the result



### writeFile <a id="writeFile"></a>

writeFile(filePath&lt;string>, contents&lt;string>) => Promise(filePath&lt;string>)

Writes `contents` to `path`. Will recursively create the path if it doesn't exist

### lazyWriteFile <a id="lazyWriteFile"></a>

lazyWriteFile (filePath&lt;string>, contents&lt;string>) => (basePath = '') => writeFile

Same as writeFile but returns a function that will write the file to `basePath` when run

### writeTemplates <a id="writeTemplates"></a>

writeTemplates (srcFolder&lt;string>, destFolder&lt;string>)

Used by the forms transformer during initialisation to copy the templates into the forms project folder.
`srcFolder` is where in your plugin project the template files are, `destFolder` is where they will be copied to. Note that all contents of `destFolder` are removed.

See the [docs/](docs/) folder for specific implementation details

---
_Source: https://npm.io/package/@blinkmobile/forms-template-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
