create-vite-vue 1.5.3 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/index.js +56 -7
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -34,6 +34,27 @@ if(compareVersion(currentVersion, requiredVersion) < 0) {
34
34
  const __filename = fileURLToPath(import.meta.url)
35
35
  const __dirname = path.dirname(__filename)
36
36
 
37
+ const pkgManager = detectPackageManager()
38
+
39
+ const pkgCommands = {
40
+ npm: {
41
+ install: 'npm install',
42
+ dev: 'npm run dev'
43
+ },
44
+ yarn: {
45
+ install: 'yarn',
46
+ dev: 'yarn dev'
47
+ },
48
+ pnpm: {
49
+ install: 'pnpm install',
50
+ dev: 'pnpm dev'
51
+ },
52
+ bun: {
53
+ install: 'bun install',
54
+ dev: 'bun run dev'
55
+ }
56
+ }
57
+
37
58
  ; (async () => {
38
59
  // 1️⃣ 输入项目名
39
60
  let projectName
@@ -117,7 +138,7 @@ const __dirname = path.dirname(__filename)
117
138
  const { runDev } = await prompts({
118
139
  type: 'select',
119
140
  name: 'runDev',
120
- message: '是否立即运行 npm run dev?',
141
+ message: `是否立即运行 ${pkgCommands[pkgManager].dev}?`,
121
142
  choices: [{ title: 'Yes', value: true }, { title: 'No', value: false }]
122
143
  })
123
144
 
@@ -242,6 +263,11 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
242
263
  if(extraPlugins.includes('vueuse')) optionalDeps['@vueuse/core'] = '^14.2.1'
243
264
  if(extraPlugins.includes('dayjs')) optionalDeps['dayjs'] = '^1.11.19'
244
265
  if(extraPlugins.includes('lodash')) optionalDeps['lodash'] = '^4.17.23'
266
+ if(extraPlugins.includes('tailwind')) {
267
+ optionalDeps['tailwindcss'] = '^4.2.1'
268
+ optionalDeps['@tailwindcss/postcss'] = '^4.2.1'
269
+ optionalDeps['postcss'] = '^8.5.8'
270
+ }
245
271
  if(autoRoute) optionalDeps['vite-plugin-pages'] = '^0.33.3'
246
272
 
247
273
  let depsStr = ''
@@ -360,10 +386,15 @@ export default createRouter({
360
386
 
361
387
  // 1️⃣0️⃣ 安装依赖
362
388
  console.log('📦 安装依赖中...')
363
- let installCmd = 'npm install'
364
389
 
365
- if(extraPlugins.includes('tailwind')) {
366
- installCmd += ' tailwindcss @tailwindcss/postcss postcss'
390
+ let installCmd = ''
391
+
392
+ if(pkgManager === 'pnpm') {
393
+ installCmd = 'pnpm install'
394
+ } else if(pkgManager === 'yarn') {
395
+ installCmd = 'yarn'
396
+ } else {
397
+ installCmd = 'npm install'
367
398
  }
368
399
 
369
400
  execSync(installCmd, { cwd: targetDir, stdio: 'inherit' })
@@ -371,8 +402,26 @@ export default createRouter({
371
402
  // 1️⃣1️⃣ 运行 dev
372
403
  if(runDev) {
373
404
  console.log('🚀 启动开发服务器...')
374
- execSync('npm run dev', { cwd: targetDir, stdio: 'inherit' })
405
+ execSync(pkgCommands[pkgManager].dev, {
406
+ cwd: targetDir,
407
+ stdio: 'inherit'
408
+ })
375
409
  } else {
376
- console.log(`\n✅ 项目创建完成\n👉 cd ${projectName}\n👉 npm run dev\n`)
410
+ console.log(`\n✅ 项目创建完成`)
411
+ console.log(`👉 cd ${projectName}`)
412
+ console.log(`👉 ${pkgCommands[pkgManager].dev}\n`)
377
413
  }
378
- })()
414
+ })()
415
+
416
+ function detectPackageManager () {
417
+ const userAgent = process.env.npm_config_user_agent || ''
418
+
419
+ if(userAgent.startsWith('pnpm')) return 'pnpm'
420
+ if(userAgent.startsWith('yarn')) return 'yarn'
421
+ if(userAgent.startsWith('npm')) return 'npm'
422
+
423
+ if(fs.existsSync('pnpm-lock.yaml')) return 'pnpm'
424
+ if(fs.existsSync('yarn.lock')) return 'yarn'
425
+
426
+ return 'npm'
427
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vite-vue",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "description": "基于Vite+Vue3创建基础项目模板",
5
5
  "main": "index.js",
6
6
  "author": "YwaiX",