Skip to content

Commit 584b4b8

Browse files
committed
fix(init): prompt for directory if it is not provided
1 parent 4eed2cd commit 584b4b8

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

packages/nuxi/src/commands/init.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import { colors } from 'consola/utils'
99
import { downloadTemplate, startShell } from 'giget'
1010
import { installDependencies } from 'nypm'
1111
import { relative, resolve } from 'pathe'
12+
import { hasTTY } from 'std-env'
1213
import { x } from 'tinyexec'
1314

1415
import { runCommand } from '../run'
16+
import { nuxtIcon } from '../utils/ascii'
1517
import { logger } from '../utils/logger'
1618
import { cwdArgs } from './_shared'
1719

@@ -84,11 +86,22 @@ export default defineCommand({
8486
},
8587
},
8688
async run(ctx) {
87-
const cwd = resolve(ctx.args.cwd)
88-
89-
let templateDownloadPath = resolve(cwd, ctx.args.dir)
89+
if (hasTTY) {
90+
process.stdout.write(`${nuxtIcon}\n`)
91+
}
9092

9193
logger.info(colors.bold(`Welcome to Nuxt!`.split('').map(m => `\x1B[38;5;79m${m}`).join('')))
94+
95+
if (ctx.args.dir === '') {
96+
ctx.args.dir = await logger.prompt('Where would you like to create your project?', {
97+
placeholder: './nuxt-app',
98+
type: 'text',
99+
default: 'nuxt-app',
100+
})
101+
}
102+
103+
const cwd = resolve(ctx.args.cwd)
104+
let templateDownloadPath = resolve(cwd, ctx.args.dir)
92105
logger.info(`Creating a new project in ${colors.cyan(relative(cwd, templateDownloadPath) || templateDownloadPath)}.`)
93106

94107
// Get template name

packages/nuxi/src/main.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import { resolve } from 'node:path'
22
import process from 'node:process'
33

44
import { defineCommand } from 'citty'
5-
import { hasTTY, provider } from 'std-env'
5+
import { provider } from 'std-env'
66

77
import { description, name, version } from '../package.json'
88
import { commands } from './commands'
99
import { cwdArgs } from './commands/_shared'
10-
import { nuxtIcon } from './utils/ascii'
1110
import { setupGlobalConsole } from './utils/console'
1211
import { checkEngines } from './utils/engines'
1312
import { logger } from './utils/logger'
@@ -31,10 +30,6 @@ export const main = defineCommand({
3130
const dev = command === 'dev'
3231
setupGlobalConsole({ dev })
3332

34-
if (hasTTY && (!command || command === 'init')) {
35-
process.stdout.write(`${nuxtIcon}\n`)
36-
}
37-
3833
// Check Node.js version and CLI updates in background
3934
let backgroundTasks: Promise<any> | undefined
4035
if (command !== '_dev' && provider !== 'stackblitz') {

0 commit comments

Comments
 (0)