Skip to content

Commit

Permalink
feat(init): allow installing modules after clone (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubicodes authored Feb 13, 2025
1 parent 36c920c commit 1afc06e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/nuxi/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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'

Expand Down Expand Up @@ -75,6 +76,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)
Expand Down Expand Up @@ -210,6 +217,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:`,
Expand Down
1 change: 1 addition & 0 deletions packages/nuxi/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ globalThis.__nuxt_cli__ = globalThis.__nuxt_cli__ || {

export const runMain = () => _runMain(main)

// To provide subcommands call it as `runCommand(<command>, [<subcommand>, ...])`
export async function runCommand(
name: string,
argv: string[] = process.argv.slice(2),
Expand Down

0 comments on commit 1afc06e

Please sign in to comment.