Skip to content

Commit

Permalink
refactor: use absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 2, 2023
1 parent e476a97 commit cbcc478
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFile } from 'node:fs/promises'
import { downloadTemplate, startShell } from 'giget'
import type { DownloadTemplateResult } from 'giget'
import { relative, resolve } from 'pathe'
import { join, relative, resolve } from 'pathe'
import { consola } from 'consola'
import { installDependencies } from 'nypm'
import type { PackageManagerName } from 'nypm'
Expand Down Expand Up @@ -109,15 +109,9 @@ export default defineCommand({
options: packageManagerOptions,
})

// Get relative project path
let relativeProjectPath = relative(process.cwd(), template.dir)
if (relativeProjectPath === '') {
relativeProjectPath = '.';
}

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

// Install project dependencies
Expand All @@ -129,7 +123,7 @@ export default defineCommand({

try {
await installDependencies({
cwd: relativeProjectPath,
cwd: template.dir,
packageManager: {
name: selectedPackageManager,
command: selectedPackageManager,
Expand Down Expand Up @@ -165,11 +159,11 @@ export default defineCommand({
consola.log(
`\n✨ Nuxt project has been created with the \`${template.name}\` template. Next steps:`,
)

const relativeTemplateDir = relative(process.cwd(), template.dir) || '.'
const nextSteps = [
!ctx.args.shell &&
relativeProjectPath.length > 1 &&
`\`cd ${relativeProjectPath}\``,
relativeTemplateDir.length > 1 &&
`\`cd ${relativeTemplateDir}\``,
`Start development server with \`${selectedPackageManager} run dev\``,
].filter(Boolean)

Expand Down

0 comments on commit cbcc478

Please sign in to comment.