A simple code scaffolding tool to speed up repetitive coding tasks.
npm install -g scaffr
npx scaffr /path/to/template/folder /path/to/destination
# Using templates from local machine
scaffr /path/to/template/folder /path/to/destination
# Or using zip files over HTTP
scaffr https://example.com/my-template.zip /path/to/destination
# Example:
# scaffr ~/templates/project-template ./HelloWorld
A template can have any number/kind of files. Scaffr will then interpret contents and file names when it encounters template syntax.
For example:
scaffr ~/templates/project-template ./HelloWorld
will result in:
Source file | Destination file |
---|---|
~/templates/project-template/{{name}}.js | ./HelloWorld/HelloWorld.js |
Scaffr uses Lodash's _.template
function to process templates. Variables use {{
and }}
for interpolation.
Example:
// {{name}}.js
const hello = () => 'Hello, from {{name}}!';
export default hello;
will be compiled into:
// HelloWorld.js
const hello = () => 'Hello, from HelloWorld!';
export default hello;
For more informations on templating please refer to Lodash documentation.
The following list of variables is available for every file:
Variable | Description |
---|---|
name | Folder name. Example: if destination path is /path/to/MyProject , name would be MyProject |
destPath | Destination full path |
templatePath | Template full path |
_ | Lodash library passed in for convenience |
A sample template can be found in the /examples
folder.