-
Notifications
You must be signed in to change notification settings - Fork 1
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 .hbs
extension.
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.
-
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 understatic
to the config file. Here's one for the typecommand
: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
directory
where 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
$TEMPLATE/sample.ns.yml
understatic
. 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.
-
ns-flip
lets you add a value forspecs
to every static instance. The value ofspecs
can be any object, array of objects, etc. It will then be passed into the contextForDynamic ofns-flip
to 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 aspec
to 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 ns-flip 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!