Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(init): minor improvements #45

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { writeFile } from 'node:fs/promises'
import { downloadTemplate, startShell } from 'giget'
import type { DownloadTemplateResult } from 'giget'
import { relative } from 'pathe'
import { consola } from 'consola'
import { installDependencies } from 'nypm'
Expand Down Expand Up @@ -27,10 +28,10 @@ export default defineNuxtCommand({
}

// Download template
let t
let template: DownloadTemplateResult

try {
t = await downloadTemplate(templateName, {
template = await downloadTemplate(templateName, {
dir: args._[0] || '',
force: Boolean(args.force),
offline: Boolean(args.offline),
Expand All @@ -55,14 +56,15 @@ export default defineNuxtCommand({
})

// Get relative project path
const relativeProjectPath = relative(process.cwd(), t.dir)
const relativeProjectPath = relative(process.cwd(), template.dir)

// Write .nuxtrc with `shamefully-hoist=true` for pnpm
if (selectedPackageManager === 'pnpm') {
await writeFile(`${relativeProjectPath}/.npmrc`, 'shamefully-hoist=true')
}

// Install project dependencies or skip installation based on '--offline' flag
// Install project dependencies
// or skip installation based on the '--no-install' flag
if (args.install === false) {
pi0 marked this conversation as resolved.
Show resolved Hide resolved
consola.info('Skipping install dependencies step.')
} else {
Expand All @@ -89,7 +91,7 @@ export default defineNuxtCommand({

// Display next steps
consola.log(
`\n✨ Nuxt project has been created with the \`${t.name}\` template. Next steps:`
`\n✨ Nuxt project has been created with the \`${template.name}\` template. Next steps:`
)

const nextSteps = [
Expand All @@ -104,7 +106,7 @@ export default defineNuxtCommand({
}

if (args.shell) {
startShell(t.dir)
startShell(template.dir)
}
},
})
Loading