Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to change the default _templates directory on hygen init #381

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions hygen.io/docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ This creates a project-local `_templates` folder for you at your source root wit
* `hygen generator new generatorName` - builds a new generator for you
* `hygen generator with-prompt new generatorName` - the same as before, only this one will be prompt driven.


:::note

It is also possible to change the default templates directory `_templates` to a different location. To do so, you must use the parameter `--tmpls-dir` followed by the directory path relative to your directory.

Let's say that you to use the folder `.templates`instead of the default one, for your templates dir. To do this, you have to execute the following command:

```sh
hygen init self --tmpls-dir .templates
```

This command well setup your templates in the `.templates`directory first; and then it will generate a default `.hygen.js` file with the default templates directory set as `.templates`.

```js
/** @autogenerated-by init:self */

module.exports = {
templates: `${__dirname}/.templates`
}%
```

:::

<br />


[[info]]
|###### Template Locality
|On multi-team projects, each team can have their own templates right there in the shared repo.
Expand Down
1 change: 1 addition & 0 deletions src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const printHelp = (templates: string, logger: Logger) => {
Here's how to start using Hygen:

$ hygen init self
$ hygen init self --tmpls-dir <templates-dir> # To override the default templates dir
$ hygen with-prompt new --name my-generator

(edit your generator in _templates/my-generator)
Expand Down
8 changes: 8 additions & 0 deletions src/templates/init/self/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
params: ({ args }) => {
return {
tmplsDir: args.tmplsDir || '_templates',
marker: '/** @autogenerated-by init:self */'
}
}
}
2 changes: 1 addition & 1 deletion src/templates/init/self/new-generator-help.ejs.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
to: _templates/generator/help/index.ejs.t
to: <%= tmplsDir %>/generator/help/index.ejs.t
---
---
message: |
Expand Down
4 changes: 2 additions & 2 deletions src/templates/init/self/new-generator-with-prompt.ejs.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
to: _templates/generator/with-prompt/hello.ejs.t
to: <%= tmplsDir %>/generator/with-prompt/hello.ejs.t
---
---
to: _templates/<%%= name %%>/<%%= action || 'new' %%>/hello.ejs.t
to: <%= tmplsDir %>/<%%= name %%>/<%%= action || 'new' %%>/hello.ejs.t
---
---
to: app/hello.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
to: _templates/generator/with-prompt/prompt.ejs.t
to: <%= tmplsDir %>/generator/with-prompt/prompt.ejs.t
---
---
to: _templates/<%%= name %%>/<%%= action || 'new' %%>/prompt.js
to: <%= tmplsDir %>/<%%= name %%>/<%%= action || 'new' %%>/prompt.js
---

// see types of prompts:
Expand Down
4 changes: 2 additions & 2 deletions src/templates/init/self/new-generator.ejs.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
to: _templates/generator/new/hello.ejs.t
to: <%= tmplsDir %>/generator/new/hello.ejs.t
---
---
to: _templates/<%%= name %%>/<%%= action || 'new' %%>/hello.ejs.t
to: <%= tmplsDir %>/<%%= name %%>/<%%= action || 'new' %%>/hello.ejs.t
---
---
to: app/hello.js
Expand Down
10 changes: 10 additions & 0 deletions src/templates/init/self/new-hygen-js.ejs.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
to: "<%= locals.tmplsDir != '_templates' ? `${cwd}/.hygen.js` : null %>"
after: module.exports
skip_if: <%= marker %>
---
<%= marker %>

module.exports = {
templates: `${__dirname}/<%= tmplsDir %>`
}
2 changes: 1 addition & 1 deletion src/templates/init/self/new-repo.ejs.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
to: _templates/init/repo/new-repo.ejs.t
to: <%= tmplsDir %>/init/repo/new-repo.ejs.t
---
---
setup: <%%= name %%>
Expand Down