cli icon indicating copy to clipboard operation
cli copied to clipboard

Extendable `nuxi add` with custom templates from modules

Open ramsesgarate opened this issue 3 years ago • 7 comments

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

ramsesgarate avatar Oct 13 '22 00:10 ramsesgarate

What does the tag discussion mean? @danielroe

Greetings

ramsesgarate avatar Oct 13 '22 20:10 ramsesgarate

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.

pi0 avatar Oct 14 '22 08:10 pi0

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.

ramsesgarate avatar Oct 14 '22 10:10 ramsesgarate

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? 🤔

manchenkoff avatar May 13 '23 22:05 manchenkoff

I think this now part of nuxt kit: https://nuxt.com/docs/api/kit/templates

OrbisK avatar Jun 18 '25 19:06 OrbisK

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

manchenkoff avatar Jun 18 '25 21:06 manchenkoff

Yeah, you are right. I misread the topic 👍🏽

OrbisK avatar Jun 18 '25 21:06 OrbisK