
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
template-codegen-cli
Advanced tools
Universal code generator with nested object support for dynamic form and component generation
🚀 Universal code generator with nested object support for dynamic form and component generation
Stop writing repetitive boilerplate code. Smart Codegen generates complete, production-ready code from simple JSON input with support for deeply nested structures.
Key Benefits:
.js configuration file (no TypeScript needed)npm install -g template-codegen-cli
codegen init
This creates codegen.config.js with example templates.
Create templates/vue-form/{{Name}}Form.vue:
<template>
<el-form :model="form" :rules="rules">
{{body:formItems}}
<el-form-item>
<el-button type="primary" @click="handleSubmit">Submit</el-button>
</el-form-item>
</el-form>
</template>
<script setup lang="ts">
{{body:interfaces}}
interface {{Name}}Form {
{{body:types}}
}
const form = reactive<{{Name}}Form>({
{{body:defaultValues}}
});
</script>
codegen generate vue-form user -b '{"name":"input","email":"input"}'
codegen generate vue-form user -b '{
"name": "input",
"email": "input",
"address": {
"city": "input",
"country": "select"
}
}'
codegen generate vue-form user
# Prompts will guide you through the process
Generated src/components/forms/UserForm.vue:
<template>
<el-form :model="form" :rules="rules">
<el-form-item label="Name" prop="name">
<FormInput v-model="form.name" />
</el-form-item>
<el-form-item label="Email" prop="email">
<FormInput v-model="form.email" />
</el-form-item>
<el-form-item label="City" prop="address.city">
<FormInput v-model="form.address.city" />
</el-form-item>
<el-form-item label="Country" prop="address.country">
<FormSelect v-model="form.address.country" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleSubmit">Submit</el-button>
</el-form-item>
</el-form>
</template>
<script setup lang="ts">
export interface Address {
city: string;
country: string;
}
interface UserForm {
name: string;
email: string;
address: Address;
}
const form = reactive<UserForm>({
name: '',
email: '',
address: {
city: '',
country: '',
},
});
</script>
Create codegen.config.js:
module.exports = {
templates: {
'vue-form': {
path: './templates/vue-form',
description: 'Vue form with dynamic fields',
output: './src/components/forms',
needsBody: true,
variables: {
input: `<el-form-item label="{{Name}}" prop="{{fullPath}}">
<FormInput v-model="form.{{fullPath}}" />
</el-form-item>`,
select: `<el-form-item label="{{Name}}" prop="{{fullPath}}">
<FormSelect v-model="form.{{fullPath}}" :options="{{name}}Options" />
</el-form-item>`,
textarea: `<el-form-item label="{{Name}}" prop="{{fullPath}}">
<el-input v-model="form.{{fullPath}}" type="textarea" :rows="3" />
</el-form-item>`,
},
},
},
};
# Interactive mode
codegen generate
# Short alias
cg generate
# Specify template and name
codegen generate vue-form user
# With JSON body
codegen generate vue-form user -b '{"name":"input","email":"input"}'
# Custom output directory
codegen generate vue-form user -o ./src/forms
# Dry run (preview only)
codegen generate vue-form user --dry-run
# Skip formatting
codegen generate vue-form user --no-format
codegen list
# or
cg ls
codegen validate vue-form
codegen init
codegen help
| Placeholder | Input | Output |
|---|---|---|
{{name}} | userProfile | userProfile |
{{Name}} | userProfile | UserProfile |
{{NAME}} | userProfile | USERPROFILE |
{{name-kebab}} | userProfile | user-profile |
{{name_snake}} | userProfile | user_profile |
{{name.camel}} | UserProfile | userProfile |
{{name.pascal}} | userProfile | UserProfile |
| Placeholder | Description |
|---|---|
{{body:formItems}} | Generated form items |
{{body:types}} | TypeScript type definitions |
{{body:interfaces}} | Nested interfaces |
{{body:defaultValues}} | Default values object |
{{body:fields}} | Array of field names |
| Placeholder | Description | Example |
|---|---|---|
{{name}} | Field name | city |
{{Name}} | Capitalized field name | City |
{{fullPath}} | Full path with dots | address.city |
codegen generate vue-form user -b '{
"personal": {
"firstName": "input",
"lastName": "input"
},
"contact": {
"email": "input",
"address": {
"street": "input",
"city": "input"
}
}
}'
module.exports = {
templates: {
'vue-form': {
variables: {
customField: `<el-form-item label="{{Name}}" prop="{{fullPath}}">
<CustomComponent v-model="form.{{fullPath}}" />
</el-form-item>`,
},
},
},
};
# Create body file
echo '{"name":"input","email":"input"}' > user-body.json
# Use it
codegen generate vue-form user -b "$(cat user-body.json)"
templates: {
'vue-admin-form': { /* ... */ },
'react-dashboard-widget': { /* ... */ },
'api-crud-route': { /* ... */ }
}
templates/
├── vue/
│ ├── form/
│ └── component/
├── react/
│ ├── component/
│ └── hook/
└── api/
└── route/
codegen generate vue-form test --dry-run -b '{"field":"input"}'
Commit codegen.config.js and templates/ to git.
# Make sure config file exists
ls codegen.config.js
# Re-initialize if needed
codegen init
# Validate template
codegen validate template-name
Use {{fullPath}} instead of {{name}} in variable templates:
// ❌ Wrong
variables: {
input: `<input v-model="form.{{name}}" />`;
}
// ✅ Correct
variables: {
input: `<input v-model="form.{{fullPath}}" />`;
}
Contributions are welcome! Please feel free to submit a Pull Request.
MIT © Mukhammadjon Solijonov
Made with ❤️ by Mukhammadjon Solijonov
FAQs
Universal code generator with nested object support for dynamic form and component generation
We found that template-codegen-cli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.