From 68c14c364ada358935d4c85e1ce013196eabdd80 Mon Sep 17 00:00:00 2001 From: Kubi Date: Thu, 13 Feb 2025 19:09:47 +0100 Subject: [PATCH 1/5] feat(init): modules flag on init --- packages/nuxi/src/commands/init.ts | 13 +++++++++++++ packages/nuxi/src/run.ts | 1 + 2 files changed, 14 insertions(+) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index 94cb899e8..be8654139 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -10,6 +10,7 @@ import { installDependencies } from 'nypm' import { relative, resolve } from 'pathe' import { x } from 'tinyexec' +import { runCommand } from '../run' import { logger } from '../utils/logger' import { cwdArgs } from './_shared' @@ -74,6 +75,12 @@ export default defineCommand({ type: 'string', description: 'Package manager choice (npm, pnpm, yarn, bun)', }, + modules: { + type: 'string', + required: false, + description: 'Modules to install', + alias: 'M', + }, }, async run(ctx) { const cwd = resolve(ctx.args.cwd) @@ -205,6 +212,12 @@ export default defineCommand({ } } + // Add modules when -M flag is provided + const modules = !ctx.args.modules ? [] : ctx.args.modules.split(' ').filter(name => !!name) + if (modules.length > 0) { + await runCommand('module', ['add', ...modules]) + } + // Display next steps logger.log( `\n✨ Nuxt project has been created with the \`${template.name}\` template. Next steps:`, diff --git a/packages/nuxi/src/run.ts b/packages/nuxi/src/run.ts index 01fa7e028..16536689c 100644 --- a/packages/nuxi/src/run.ts +++ b/packages/nuxi/src/run.ts @@ -21,6 +21,7 @@ globalThis.__nuxt_cli__ = globalThis.__nuxt_cli__ || { export const runMain = () => _runMain(main) +// To provide subcommands call it as `runCommand(, [, ...])` export async function runCommand( name: string, argv: string[] = process.argv.slice(2), From 69f6a9e549fe8d864483b779db34a9cbd90f2310 Mon Sep 17 00:00:00 2001 From: Kubi Date: Thu, 13 Feb 2025 21:58:11 +0100 Subject: [PATCH 2/5] chore: assume comma separated modules input --- packages/nuxt-cli/playground/nuxt.config.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/nuxt-cli/playground/nuxt.config.ts b/packages/nuxt-cli/playground/nuxt.config.ts index cc7f72933..35709d919 100644 --- a/packages/nuxt-cli/playground/nuxt.config.ts +++ b/packages/nuxt-cli/playground/nuxt.config.ts @@ -1,9 +1,6 @@ // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ - compatibilityDate: '2024-09-05', - nitro: { - experimental: { - websocket: true, - }, - }, -}) + compatibilityDate: '2024-11-01', + devtools: { enabled: true }, + modules: ['@nuxtjs/tailwindcss', '@nuxt/eslint'] +}) \ No newline at end of file From d5684b9bfa1c90d326ab1052885812a62c87ef2a Mon Sep 17 00:00:00 2001 From: Kubi Date: Thu, 13 Feb 2025 21:59:50 +0100 Subject: [PATCH 3/5] chore: revert wrong file change and assume comma separated modules input --- packages/nuxi/src/commands/init.ts | 4 ++-- packages/nuxt-cli/playground/nuxt.config.ts | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index be8654139..1bfee6be6 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -78,7 +78,7 @@ export default defineCommand({ modules: { type: 'string', required: false, - description: 'Modules to install', + description: 'Nuxt modules to install (comma separated without spaces)', alias: 'M', }, }, @@ -213,7 +213,7 @@ export default defineCommand({ } // Add modules when -M flag is provided - const modules = !ctx.args.modules ? [] : ctx.args.modules.split(' ').filter(name => !!name) + const modules = !ctx.args.modules ? [] : ctx.args.modules.split(',').map(module => module.trim()) if (modules.length > 0) { await runCommand('module', ['add', ...modules]) } diff --git a/packages/nuxt-cli/playground/nuxt.config.ts b/packages/nuxt-cli/playground/nuxt.config.ts index 35709d919..cc7f72933 100644 --- a/packages/nuxt-cli/playground/nuxt.config.ts +++ b/packages/nuxt-cli/playground/nuxt.config.ts @@ -1,6 +1,9 @@ // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ - compatibilityDate: '2024-11-01', - devtools: { enabled: true }, - modules: ['@nuxtjs/tailwindcss', '@nuxt/eslint'] -}) \ No newline at end of file + compatibilityDate: '2024-09-05', + nitro: { + experimental: { + websocket: true, + }, + }, +}) From ea2a50e4d158d8fbd4c76b9533bc2e6260358ff0 Mon Sep 17 00:00:00 2001 From: Kubi Date: Thu, 13 Feb 2025 22:17:56 +0100 Subject: [PATCH 4/5] chore: use trim function for module list --- packages/nuxi/src/commands/init.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index 1bfee6be6..847286509 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -213,7 +213,7 @@ export default defineCommand({ } // Add modules when -M flag is provided - const modules = !ctx.args.modules ? [] : ctx.args.modules.split(',').map(module => module.trim()) + const modules = !ctx.args.modules ? [] : ctx.args.modules.split(',').filter(module => !!module.trim()) if (modules.length > 0) { await runCommand('module', ['add', ...modules]) } From 53a403aba5034dd28953cd7d371d86fd5c643772 Mon Sep 17 00:00:00 2001 From: kubicodes <65826609+kubicodes@users.noreply.github.com> Date: Thu, 13 Feb 2025 22:24:20 +0100 Subject: [PATCH 5/5] chore: use map and filter function for module resolving Co-authored-by: Daniel Roe --- packages/nuxi/src/commands/init.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index 847286509..04d404a1d 100644 --- a/packages/nuxi/src/commands/init.ts +++ b/packages/nuxi/src/commands/init.ts @@ -213,7 +213,7 @@ export default defineCommand({ } // Add modules when -M flag is provided - const modules = !ctx.args.modules ? [] : ctx.args.modules.split(',').filter(module => !!module.trim()) + const modules = !ctx.args.modules ? [] : ctx.args.modules.split(',').map(module => module.trim()).filter(Boolean) if (modules.length > 0) { await runCommand('module', ['add', ...modules]) }