I'm trying to use yeoman to take this JSON file:
{
"models": {
"user": {
"properties": [
{
"name": {
"type": "string"
},
"surname": {
"type": "string"
},
"id": "number"
}
]
}
}
}
And turn it into something like:
Class User {
name : string
surname : string
id : number
}
Would it be possible to do some form of looping in the template? Here's what I have in mind...
export class <%= entityName %> extends Model {
<% forEach (property in props) { %>
<%= property.name %> : <% property.type %>;
<% } %>
}
The template language can run any JS code. So just use normal for
loop or iterations methods on arrays (arr.forEach()
)
export class <%= entityName %> extends Model {
<% for (property of props) { %>
<%= property.name %> : <% property.type %>;
<% } %>
}
Yeoman is using ejs as template engine. Visit their website for more information on the supported features.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With