jondot / hygen

The simple, fast, and scalable code generator that lives in your project.

Home Page:http://www.hygen.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hygen parsing templates not in the specified folder path

dylanaubrey opened this issue · comments

I have a couple of template paths that I am using with hygen, an example of the structure is below:

_templates/
  new/
    pkg/
    repo/
      library/

Within new/pkg/ and within new/repo/library I have a bunch of .ejs.t files.

When I execute hygen with the path to new/repo/library, I am getting a ReferenceError originating from one of the ejs.t files located in the new/pkg/ directory because one of the variables referenced there is not defined.

The hygen command I am executing is:

HYGEN_TMPLS=/absolutePathTo/_templates  /absolutePathTo/.bin/hygen new repo library --name "lib-name" --desc "Lib desc" --author "Me" --homepage "https://github.com/org/lib-name" --mainFilename "main" --language "typescript" --packageManager "pnpm" --packageManagerTemporaryCmd "pnpm dlx"

Note, the template path and hygen binary are absolute paths because this code is part of a cli library that a user installs via npm.

When I execute the above command I am getting the following error:

ReferenceError: ejs:1
 >> 1| <%= packageManagerTemporaryCmd %> create-next-app@latest <%= dirPath %> --use-<%= packageManager %> --<%= language %>

dirPath is not defined

The frontmatter above is part of a ejs.t file in the pkg/ directory. I assumed it would not parse these files because they are not what I have specified to use.

Is that assumption wrong? Do I need to pass in variables to all templates? Can you see anything wrong with that I am doing based on the details I have provided?

closing as my understanding of the positional arguments passed to hygen and how this relates to the folder structure of the templates was not accurate. I had thought the positional arguments would determine the point in the template folder structure at which hygen would start looking for templates, but after debugging this does not seem to be the case, it just uses the first (generator) and second (action). I think can get around this limitation by passing in a template path that is further down the directory tree.