diff --git a/packages/nuxi/src/commands/init.ts b/packages/nuxi/src/commands/init.ts index 94cb899e8..04d404a1d 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: 'Nuxt modules to install (comma separated without spaces)', + 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(',').map(module => module.trim()).filter(Boolean) + 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),