jondot / hygen

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

skip_if needs to support variable #438

Open u007 opened 6 months ago

u007 commented 6 months ago

i wish this could work:

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

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

Maker-Mark commented 3 months ago

what's your workaround?

u007 commented 3 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 3 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