reusable-serverless-template
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "reusable-serverless-template", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
# Reusable serverless template | ||
A node.js template processor for creating reusable [serverless](https://serverless.com/) templates. | ||
A node.js template processor for creating reusable [serverless](https://serverless.com/) resources | ||
or configuration fragments. | ||
It loads a specified yaml file with supported template placeholders recursively and resolves them with passed params. | ||
It resolves serverless variables including ${custom:var-name}, ${opt:var-name} if the var-name is matched with params. | ||
The engine loads a specified top-level yaml file recursively and resolves template placeholders. | ||
_tfile_ loads nested template files. Parameters passed to tfile are matched against serverless | ||
variables-style placeholders _${custom:var-name}_ and _${opt:var-name}_ in the nested file. | ||
A top level file as well as nested files do not need to be valid yaml objects, | ||
only the final structure, after the processing is done, has to be. | ||
only the final structure, after the processing is done, has to be. This allows a flexibility to define partial | ||
yaml arrays or objects which can be merged into a parent file. | ||
The final yaml object is loaded using [js-yaml](https://www.npmjs.com/package/js-yaml) | ||
@@ -19,8 +23,9 @@ | ||
``` | ||
A scope of the parameters passed to template#load is the top level file, | ||
nested files have to be loaded with own parameters using ``tfile`` placeholder. | ||
## Supported placeholders | ||
A scope of the parameters passed to template#load function, as well as _tfile_ parameters, is the parent file only. | ||
There are not propagated to nested templates to avoid bugs related to missing nested template parameters, which are | ||
wrongly resolved by parent parameters. | ||
## Placeholders | ||
## tfile | ||
@@ -31,8 +36,9 @@ | ||
Avoid using the following reserved characters for file names``}`` ``:`` | ||
Avoid using the following reserved characters for parameter names and values ``,`` ``=`` | ||
Avoid using the following reserved characters for: | ||
* file names ``}`` ``:`` | ||
* parameters names and values ``,`` ``=`` | ||
**Syntax:** ``` tfile:[file path]:[parameters]```, where | ||
* _file_ a relative path to nested template file (relative to the directory of the top level file) | ||
* _paramters_ comma separated name-value pairs of parameters to replace opt and custom placeholders in the nested | ||
* _file_ a relative path to nested template file (relative to the directory of the loaded top level file) | ||
* _parameters_ comma separated name-value pairs of parameters to replace opt and custom placeholders in the nested | ||
template file | ||
@@ -42,3 +48,3 @@ | ||
* without parameters ``${tfile:iamRoleStatements/dynamoDbFull.yml}`` | ||
* nested file without parameters ``${tfile:iamRoleStatements/dynamoDbFull.yml}`` | ||
* with parameters ``${tfile:iamRoleStatements/dynamoDbFull.yml:tableName=webhook}`` | ||
@@ -48,7 +54,7 @@ | ||
Variables names specified using these placeholders are replaced with parameters passed from template#load function or | ||
tfile | ||
Variables names specified using these placeholders are replaced with parameters passed from template#load function in top level file | ||
or tfile in nested templates | ||
**Syntax:** ```opt:[variable name]``` or ```custom:[variable name]```, where | ||
* _variable name_ is matched with parameter names | ||
* _variable name_ is matched against parameter names | ||
@@ -130,5 +136,5 @@ **Usage:** | ||
## Changelog | ||
1.0.1 added support to match and resolve nested variables for example | ||
``` | ||
${self:custom.tableName${opt:env}} | ||
``` | ||
* 1.0.5 support comments - # at the beginning of a line (with optional lead white spaces) will skip the line | ||
from processing | ||
* 1.0.1 added support to match and resolve nested variables like | ||
``${self:custom.tableName${opt:env}}`` |
20867
135