Skip to content

Static Data Types

YizYah edited this page Mar 2, 2021 · 3 revisions

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

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.

Place the type in Config and Ns Files

  1. 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 static to the config file. Here's one for the type command:

    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.
  2. Add the static type with it's instances to $TEMPLATE/sample.ns.yml under static. For instance:

    static:
      command:
        push:
          slug: push
        pull:
          slug: pull
    

Generate

Make sure that you are generating the proper files. Of course, they will not contain the proper contents yet.

Add Specs

  1. geenee lets you add a value for specs to every static instance. The value of specs can be any object, array of objects, etc. It will then be passed into the contextForDynamic of geenee 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 a spec 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.

  2. 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!