Filesystem.template()

Read file at source path as a template, render with provided data, then write to destination path.

Uses Lodash template syntax (e.g. `<%= %>`, `<%- %>`, `<% %>`) Also provides access to the Node.js core utility module (as `util`), as well as Lodash itself (as `_`).

Usage

Hover over inputs/exits for more info.

var Filesystem = require('machinepack-fs');


// Read file at source path as a template, render with provided data, then write to destination path.

Filesystem.template({

source: '/Users/mikermcneil/.tmp/foo.tpl',

destination: '/Users/mikermcneil/.tmp/bar.md',

data: '===',

force: false,

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// Source template file not found.

noTemplate: function () {

 

},

// One or more variables used in the template were not provided in the template data.

missingData: function (info) {

 

},

// Could not render the template due to invalid or unparseable syntax.

couldNotRender: function () {

 

},

// Something already exists at the specified path (overwrite by enabling the `force` input)

alreadyExists: function () {

 

},

// OK.

success: function () {

 

},

});

Inputs

source required

The path on disk to the template file.

'/Users/mikermcneil/.tmp/foo.tpl'
destination required

The path on disk where the resulting file should be written

'/Users/mikermcneil/.tmp/bar.md'
data

The data which will be accessible from the template

'==='
force

Whether or not to overwrite existing file(s).

false

Exits

error

An unexpected error occurred.

noTemplate

Source template file not found.

missingData

One or more variables used in the template were not provided in the template data.

{ message: 'Some variables (`me`,`friends`) were used in template "/code/machine/docs/.type-table.tpl", but not provided in the template data dictionary.',
  missingVariables: [ 'me', 'friends' ] }
couldNotRender

Could not render the template due to invalid or unparseable syntax.

alreadyExists

Something already exists at the specified path (overwrite by enabling the `force` input)

success

OK.