0.2.3 • Published 6 years ago
template-resolver v0.2.3
template-resolver
Resolves env variables & inline shell commands in static files. Features:
- Resolves env variables in files in the form of
${ENV_VAR}
- Runs inline shell commands in files in the form of
$(command)
- Runs inline shell commands in files in the form of
`command`
- Resolves & inlines imports in the form of
import './child'
Usage
Command Line
Use the command template-resolver
or tmpl
.
cat myfile.tmpl | template-resolver > result.txt
echo 'current env is ${NODE_ENV}' | tmpl
current env is development
echo 'our system arch is `uname -p`' | tmpl
current env is i386
echo 'our system name is $(uname -s)' | tmpl
current env is Darwin
Node API
var resolver = require('template-resolver');
var content = 'our system is "$(uname -s) `uname -p`" under ${NODE_ENV} env';
resolver(content).then((result)=> {
result //= our system is "Darwin i386" under development env
});
Imports
Any import statements encountered in a file will be recursivly inlined inside the importing file. By default import paths will be resolved relative to the CWD
but can be specified via the -c dir
cli argument or as the second argument passed to the node API.
Example
└─ dir/main
├─ dir/children/one
└─ dir/children/two
./dir/main
this is main file and these are my children:
import './children/one'
import './children/two'
Command Line
cat ./dir/main | template-resolver -c ./dir
Node API
require('template-resolver')(content, './dir')
License
MIT © Daniel Kalen