Static Data Types
If your sample you are templating has a type of file that you want to allow your users to specify statically, do the following.
Copy samples for each file that a static data type will have to the
$TEMPLATE/static directory. But instead of the name use a descriptive file type name, and append the
For instance, if
$SAMPLE/src/commands/push.ts) could be called a
commandFile, then you could create a
$TEMPLATE/static/commandFile.hbs file from it.
Place the type in Config and Ns Files
Come up with a name for a static data type for which you want to create the files. For instance, say you have commands and want to create two files for each, a command file and a test file. You can call the type
command. Add the name under
staticto the config file. Here's one for the type
static: command: commandFile: name: __slug__ suffix: '.ts' directory: src/commands commandTest: name: __slug__ suffix: '.test.ts' directory: test/commands
- For each file type you need a
name, which is just a string with the substring slug inserted somewhere. Then, when a code base is created with an ns file, the ns file should include a slug for each static type, which will be inserted properly in its location. In this case, both file types are simply named as the slug.
- Each file type also has a
suffix, which gets appended to the filename.
- Also, you need to specify a
directorywhere the file will be inserted into the code base.
- For each file type you need a
Add the static type with it's instances to
static. For instance:
static: command: push: slug: push pull: slug: pull
Make sure that you are generating the proper files. Of course, they will not contain the proper contents yet.
geeneelets you add a value for
specsto every static instance. The value of
specscan be any object, array of objects, etc. It will then be passed into the contextForDynamic of
geeneeto be used in your partials and helpers.
To decide what you need in
spec, look at a sample instance for the file or files that you want to generate. Figure out what sorts of data fields you need to generate one. Then add a
specto each static type instance in
$TEMPLATE/sample.ns.yml. For instance, this may be the final version:
static: command: push: slug: push specs: description: >- push all the current projects listed in a projects file. ... Interactively confirms each project to pull and pulls to the proper directory. params: - name: projectsFile - flag: p - description: path to a yaml file with list of projects. Each must have dir and branch. pull: slug: pull specs: description: >- pull all the current projects listed in a projects file. Interactively confirms each project to pull and pulls to the proper directory. params: - name: projectsFile - flag: p - description: path to a yaml file with list of projects. Each must have dir and branch.
Note: you can also include sections for custom code. So you shouldn't require your template users to enter huge fields into their ns file.
Check out Handlebars in geenee for an understanding of how to modify the file by adding any partials or helpers that you'd like.
At any point you can test your template output. Just keep updating it until you are producing a working version of $SAMPLE that was generated from your template!