jondot / hygen

The simple, fast, and scalable code generator that lives in your project.
http://www.hygen.io
MIT License
5.68k stars 256 forks source link

skip_if needs to support variable #438

Open u007 opened 10 months ago

u007 commented 10 months ago

i wish this could work:

---
skip_if: "<%=pluralName %>: "
---

ive my work around, but would love to see this instead

Maker-Mark commented 7 months ago

what's your workaround?

u007 commented 7 months ago

i return a boolean variable in prompt, and do a ternary on template like this. instead of writing to the actual file, i wrote it to the .tmp directory to avoid replacing the file

---
to: "<%= generateList ? 'pages/cp1/' : '.tmp/void/' %><%=pluralName%>/[<%=name%>Id]/index.vue"
---
Maker-Mark commented 7 months ago

@u007 You can just return null and it wont generate. That's a lot better than putting files into .tmp. https://www.hygen.io/docs/templates/#conditional-rendering