@ministryofjustice/fb-transformers
Component transformation functions with a CLI for Form Builder
Last updated a month ago by form-builder-developers .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @ministryofjustice/fb-transformers 
SYNC missed versions from official npm registry.

fb-transformers

Functions in this module transform Form Builder fileupload components into upload components and create any page.uploadCheck or page.uploadSummary steps, too.

Each of these functions return a Promise. The promise can be resolved as part of a chain or using await. (The examples below use await syntax.)

All of these functions is exposed to the command line with Commander.

Primary functions

hasFileUploadComponentInForm

Accepts a path to a Form directory as an argument. It walks all the steps and standalone pages looking for fileupload component and returns a boolean:

const directoryPath = '~/Documents/formbuilder/forms/ComponentFileUpload'

await hasFileUploadComponentInForm(directoryPath) // resolves to a boolean

transformFileUploadComponentsInForm

Accepts a path to a Form directory as an argument. It walks all the steps and standalone pages looking for fileupload components and returns an array:

const directoryPath = '~/Documents/formbuilder/forms/ComponentFileUpload'

await transformFileUploadComponentsInForm(directoryPath) // resolves to an array of strings

The resolved array contains a list of all the files that were examined, not all the files that have been changed.

Secondary functions

These functions are exported from the module and are used internally by the module.

hasFileUploadComponent

Accepts a path to a Form JSON file as an argument. It does not walk -- it is only interested in the properties of that Form step.

const filePath = '~/Documents/formbuilder/forms/ComponentFileUpload/metadata/page/page.fileupload.json'

await hasFileUploadComponent(filePath) // resolves to a boolean

hasUploadComponent

Accepts a path to a Form JSON file as an argument. As above, it does not walk.

const filePath = '~/Documents/formbuilder/forms/ComponentUpload/metadata/page/page.upload.json'

await hasUploadComponent(filePath) // resolves to a boolean

hasUploadCheckStep

Accepts a path to a Form JSON file as an argument. As above, it does not walk.

const filePath = '~/Documents/formbuilder/forms/ComponentUpload/metadata/page/page.upload.json'

await hasUploadCheckStep(filePath) // resolves to a boolean

hasUploadSummaryStep

Accepts a path to a Form JSON file as an argument. As above, it does not walk.

const filePath = '~/Documents/formbuilder/forms/ComponentUpload/metadata/page/page.upload.json'

await hasUploadCheckStep(filePath) // resolves to a boolean

Commander and the CLI

These functions are exposed to the command line so that a developer can update a Form cloned to their environment, or run them from the shell in any other environment.

All of these flags should be prefaced with npm start --. The double hyphen indicates that subsequent flags should be passed to the command. For example, assuming you have cloned a Form repository named ComponentFileUpload to your environment:

npm start -- --has-file-upload-in-form ~/Documents/formbuilder/forms/ComponentFileUpload

This will set the DEBUG variable to enable logging in the terminal, and then execute the command:

node app --has-file-upload-in-form ~/Documents/formbuilder/forms/ComponentFileUpload

Simply executing this on its own will invoke the functions silently, which is probably not what you want.

Flags

Each of these flags should be followed either by the path to a Form, or the path to a step JSON file.

Paths starting with the "~" character will be resolved to the user's home directory. (Paths containing whitespace should be provided in quotes.)

An error will be thrown if a path is not provided.

hasFileUploadComponentInForm

  • -h, --has-file-upload-in-form String, path to Form

Determines whether Form has fileupload component(s), invokes hasFileUploadComponentInForm:

npm start -- --has-file-upload-in-form ~/Documents/formbuilder/forms/ComponentFileUpload

--has-file-upload-in-form

transformFileUploadComponentsInForm

  • -t, --transform-file-upload-in-form String, path to Form

Transforms fileupload component(s) in Form, invokes transformFileUploadComponentsInForm:

npm start -- --transform-file-upload-in-form ~/Documents/formbuilder/forms/ComponentFileUpload

--transform-file-upload-in-form

hasFileUploadComponent

  • --has-file-upload String, path to step

Determines whether step has fileupload components(s), invokes hasFileUploadComponent:

npm start -- --has-file-upload ~/Documents/formbuilder/forms/ComponentFileUpload/metadata/page/page.fileupload.json

--has-file-upload

transformFileUploadComponents

  • --transform-file-upload String, path to step

Transforms fileupload components(s) in step_, invokes transformFileUploadComponents:

npm start -- --transform-file-upload ~/Documents/formbuilder/forms/ComponentFileUpload/metadata/page/page.fileupload.json

--transform-file-upload

hasUploadComponent

  • --has-upload String, path to step

Determines whether step has upload components(s), invokes hasUploadComponent:

npm start -- --has-upload ~/Documents/formbuilder/forms/ComponentUpload/metadata/page/page.upload.json

--has-upload

hasUploadCheckStep

  • --has-upload-check String, path to step

Determines whether step has page.uploadCheck step, invokes hasUploadCheckStep:

npm start -- --has-upload-check ~/Documents/formbuilder/forms/ComponentUpload/metadata/page/page.upload.json

--has-upload-check

hasUploadSummaryStep

  • --has-upload-summary String, path to step

Determines whether step has page.uploadSummary step, invokes hasUploadSummaryStep:

npm start -- --has-upload-summary ~/Documents/formbuilder/forms/ComponentUpload/metadata/page/page.upload.json

--has-upload-summary

Current Tags

  • 1.0.4                                ...           latest (a month ago)

5 Versions

  • 1.0.4                                ...           a month ago
  • 1.0.3                                ...           2 months ago
  • 1.0.2                                ...           2 months ago
  • 1.0.1                                ...           2 months ago
  • 1.0.0                                ...           2 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 14
Dependencies (5)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |