The source code is also heavily commented and run through Docker, so you can read the resulting annotated source code for more details about the implementation.
Check the CHANGELOG for information about new features and breaking changes.
To get that result, we use the following commands and we give the answer John to the question and also an output folder to store the generated content.
gt; cd <projectTemplatePath>
gt; project-scaffolder
prompt: Enter your username: John
prompt: finally the output directory (will be created if not existing): <outputFolder>
Project configuration:
username: John
To get that result, we use the following commands and we give the answer John to the question and also an output folder to store the generated content.
gt; cd <projectTemplatePath>
gt; project-scaffolder
prompt: Enter your username: John
prompt: Enter the sub path: one/two/three
prompt: finally the output directory (will be created if not existing): <outputFolder>
Project configuration:
username: John
subPath: one/two/three
Based on the previous examples, you see that your project template need to contains several elements that are used to generate your project from your template.
package.json Define your npm module to allow using project-scaffolder in a specific version for your project template;
scaff.yml where you will store the configuration to be prompt to your template user (and later on, additional project template properties that can be used in the template generation proecss);
template the folder where your template files are stored. The content of this folder will be processed and filtered to generate your project.
The files stored in the template folder can be:
text files that will be handled by templating engine to apply the filtering;
binary file that will be simply copy from the project template to the project generated.
During the generation process, each text files will be given to Nunjucks which is the template engine used in project-scaffolder. This template engine is based on Jinja template engine. Then the syntax is quite similar and the possiblity to use filters is there. It means that you can be able to write something like that in your template files:
{{ someVariable | upper }}
which will result to (if someVariable value is "John"):
JOHN
The same possibility is available to filter the paths but there, we need a different syntax.
The syntax for variable replacement and filtering is the following:
__variableName__
and
__variableName-filterName__
The limitation of that syntax is that you cannot use - in the variable name or the filter name.
How to override the template config file and the template folder
By default, the scaff.yml and template folder are mandatory in a template project but you have the possibility to use a custom folder path and a custom configuration file.
For that, you have to use environment variables when you invoke project-scaffolder.
You can use only one of these options if you want.
How to write a configuration file
First, you need to create the file scaff.yml at the root of your template project.
Now, you are able to write something like that:
prompt:
properties:
propertyName:
message: Some message there
required: true
default: some default value
extras:
- extra-module
The prompt.properties configuration
This configuration section defines the questions that will be asked when the command project-scaffolder is run in the template project.
As the project-scaffolder use the module prompt to present the command line user interface, you can define the options as described in prompt documentation.
There is only one exception which do not allow to use before.
Then you can define a command line question like that: