Extendable `nuxi add` with custom templates from modules
Describe the feature
(edited by @pi0) Original title: nuxi add content <name>
I am currently creating my website with nuxt content and realized that nuxi does not have a template for content (content pages).
I've been reviewing the code a bit and I would like to contribute with this.
Additional information
- [X] Would you be willing to help implement this feature?
- [ ] Could this feature be implemented as a module?
Final checks
- [X] Read the contribution guide.
- [X] Check existing discussions and issues.
What does the tag discussion mean? @danielroe
Greetings
Hi dear @ramsesgarate. I think that's a nice idea and can think of several ways to make it possible from modules injecting their templates. Dicussion tag means we are open to discuss about it and find possible solutions.
I understand, I think I got too complicated saying templates haha the truth is I had thought of something a little simpler, based on how it currently works creating pages with nuxi add, for content I would return something like
return {
path: `content/${name}.md`,
contents: `
# ${name} content v2
[Back home](/)
`
}
This would also be useful if you want to create a page with order prefixes like nuxi add content 1.about, ignore nuxi add content .1.about or partiarls nuxi add content _1.about.
It would be really nice to have some section like templates in the nuxt.config.ts which expects an array of interfaces from the source code
interface Template {
(options: TemplateOptions): { path: string, contents: string }
}
then we can load it either from a layer or module, etc.
Should we expect this feature in one of the subsequent releases? 🤔
I think this now part of nuxt kit: https://nuxt.com/docs/api/kit/templates
I think this now part of nuxt kit: https://nuxt.com/docs/api/kit/templates
@OrbisK I don't think it is:
Templates allows to generate extra files during development and build time.
But the initial feature request was to extend Nuxi CLI functionality to generate files from custom templates and not for build time.
For example, if I want to define a custom version of a composable or plugin with predefined functionality, there is no way to leverage those Kit templates.
Right now, those templates are hardcoded here - https://github.com/nuxt/cli/blob/main/packages/nuxi/src/utils/templates/index.ts#L29 and later used in add command - https://github.com/nuxt/cli/blob/main/packages/nuxi/src/commands/add.ts#L71
Yeah, you are right. I misread the topic 👍🏽