create-jnrs-template-vue 1.0.3 → 1.0.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.
package/bin/create.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { fileURLToPath } from 'url'
2
2
  import { dirname, join, relative } from 'path'
3
- import { promises as fs } from 'fs'
3
+ import { promises as fs, existsSync } from 'fs' // ✅ 同时导入 promises 和 existsSync
4
4
  import { execSync, spawnSync } from 'child_process'
5
5
  import minimist from 'minimist'
6
6
  import prompts from 'prompts'
@@ -10,7 +10,6 @@ const __dirname = dirname(__filename)
10
10
 
11
11
  // 检测系统中可用的包管理器
12
12
  function detectPackageManager() {
13
- // 按优先级:pnpm > yarn > npm
14
13
  try {
15
14
  const pnpmVersion = spawnSync('pnpm', ['--version'], { stdio: 'ignore' })
16
15
  if (pnpmVersion.status === 0) return 'pnpm'
@@ -24,7 +23,6 @@ function detectPackageManager() {
24
23
  return 'npm'
25
24
  }
26
25
 
27
- // 获取安装命令
28
26
  function getInstallCommand(packageManager) {
29
27
  switch (packageManager) {
30
28
  case 'pnpm':
@@ -36,7 +34,6 @@ function getInstallCommand(packageManager) {
36
34
  }
37
35
  }
38
36
 
39
- // 获取运行命令(用于提示)
40
37
  function getRunCommand(packageManager, script) {
41
38
  switch (packageManager) {
42
39
  case 'pnpm':
@@ -66,6 +63,7 @@ async function main() {
66
63
  const argv = minimist(process.argv.slice(2), { string: ['_'] })
67
64
  let targetDir = argv._[0]
68
65
 
66
+ // 交互式输入项目名
69
67
  if (!targetDir) {
70
68
  const { name } = await prompts({
71
69
  type: 'text',
@@ -74,7 +72,7 @@ async function main() {
74
72
  initial: 'my-vue-app',
75
73
  validate: (input) => {
76
74
  if (!input) return 'Project name is required.'
77
- if (fs.existsSync(input)) return 'Directory already exists.'
75
+ if (existsSync(input)) return 'Directory already exists.' // ✅ 使用 existsSync
78
76
  if (!isValidPackageName(input)) {
79
77
  return 'Invalid package name. Use lowercase, hyphens, and no special characters.'
80
78
  }
@@ -84,42 +82,40 @@ async function main() {
84
82
  if (!name) process.exit(1)
85
83
  targetDir = name
86
84
  } else {
85
+ // 非交互模式:校验包名和目录
87
86
  if (!isValidPackageName(targetDir)) {
88
87
  console.error('❌ Invalid project name:', targetDir)
89
88
  console.error(' Package name must be valid (lowercase, no spaces, etc.)')
90
89
  process.exit(1)
91
90
  }
91
+ if (existsSync(join(process.cwd(), targetDir))) {
92
+ // ✅ 同步检查
93
+ console.error(`❌ Directory "${targetDir}" already exists.`)
94
+ process.exit(1)
95
+ }
92
96
  }
93
97
 
94
98
  const root = join(process.cwd(), targetDir.trim())
95
99
 
96
- try {
97
- await fs.access(root)
98
- console.error(`❌ Directory "${targetDir}" already exists.`)
99
- process.exit(1)
100
- } catch {}
101
-
102
100
  // 复制模板
103
101
  const templateDir = join(__dirname, '..', 'jnrs-template-vue')
104
102
  await fs.cp(templateDir, root, { recursive: true })
105
103
 
106
- // 更新 package.json name
104
+ // 更新 package.json
107
105
  const pkgPath = join(root, 'package.json')
108
106
  const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf8'))
109
107
  pkg.name = toValidPackageName(targetDir)
110
108
  await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2))
111
109
 
112
- // 自动写入 .npmrc(推荐 pnpm 用户启用 symlinked node linker
113
- const npmrcPath = join(root, '.npmrc')
114
- await fs.writeFile(npmrcPath, `# Config for pnpm\nshamefully-hoist=true\n`)
110
+ // 写入 .npmrc(适配 pnpm)
111
+ await fs.writeFile(join(root, '.npmrc'), '# Config for pnpm\nshamefully-hoist=true\n')
115
112
 
116
- // 检测包管理器
113
+ // 安装依赖
117
114
  const packageManager = detectPackageManager()
118
115
  console.log(`\n📦 Detected package manager: ${packageManager}`)
119
116
  console.log(`Installing dependencies with ${packageManager}...\n`)
120
117
 
121
118
  const [cmd, ...args] = getInstallCommand(packageManager)
122
-
123
119
  try {
124
120
  execSync(`${cmd} ${args.join(' ')}`, {
125
121
  cwd: root,
@@ -128,12 +124,12 @@ async function main() {
128
124
  })
129
125
  } catch (e) {
130
126
  console.error(
131
- `\n⚠️ Failed to install dependencies. Run manually:\n ${cmd} ${args.join(' ')}`
127
+ `\n⚠️ Failed to install dependencies. Run manually:\n cd ${relative(process.cwd(), root)} && ${cmd} ${args.join(' ')}`
132
128
  )
133
129
  process.exit(1)
134
130
  }
135
131
 
136
- // 输出成功信息
132
+ // 成功提示
137
133
  const relativePath = relative(process.cwd(), root)
138
134
  const devCmd = getRunCommand(packageManager, 'dev')
139
135
 
@@ -144,5 +140,6 @@ async function main() {
144
140
 
145
141
  main().catch((err) => {
146
142
  console.error(`\n🚨 Error: ${err.message}`)
143
+ console.trace(err) // 可选:开发时显示堆栈
147
144
  process.exit(1)
148
145
  })
package/bin/release.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author : TanRui
3
3
  * @WeChat : Tan578853789
4
4
  * @File : release.mjs
5
- * @Date : 2025/10/12
5
+ * @Date : 2025/11/12
6
6
  * @Desc. : 发布脚本:自动化版本更新、发布及提交
7
7
  */
8
8
 
@@ -40,6 +40,8 @@ function incrementPatchVersion(version) {
40
40
 
41
41
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
42
42
  const pkgPath = path.resolve(__dirname, '..', 'package.json')
43
+ // 新增:模板 package.json 路径
44
+ const templatePkgPath = path.resolve(__dirname, '..', 'jnrs-template-vue', 'package.json')
43
45
 
44
46
  try {
45
47
  // 读取原始 package.json
@@ -54,11 +56,60 @@ try {
54
56
  process.exit(1)
55
57
  }
56
58
 
57
- // 手动计算新版本
59
+ // ========== 新增逻辑开始:处理 jnrs-template-vue/package.json ==========
60
+ console.log('📦🔧 正在处理模板包 jnrs-template-vue/package.json...')
61
+
62
+ // 1. 读取模板 package.json
63
+ const templatePkgContent = await fs.readFile(templatePkgPath, 'utf8')
64
+ const templatePkg = JSON.parse(templatePkgContent)
65
+ const originalTemplateVersion = templatePkg.version
66
+ let hasModifiedTemplate = false
67
+
68
+ try {
69
+ // 2. 替换所有 "workspace:*" 为 "*"
70
+ const replaceWorkspaceRefs = (obj) => {
71
+ for (const key in obj) {
72
+ if (typeof obj[key] === 'string' && obj[key] === 'workspace:*') {
73
+ obj[key] = '*'
74
+ } else if (typeof obj[key] === 'object' && obj[key] !== null) {
75
+ replaceWorkspaceRefs(obj[key])
76
+ }
77
+ }
78
+ }
79
+
80
+ // 执行替换
81
+ replaceWorkspaceRefs(templatePkg.dependencies || {})
82
+ replaceWorkspaceRefs(templatePkg.devDependencies || {})
83
+ replaceWorkspaceRefs(templatePkg.optionalDependencies || {})
84
+ hasModifiedTemplate = true
85
+
86
+ // 3. version +1
87
+ templatePkg.version = incrementPatchVersion(originalTemplateVersion)
88
+
89
+ // 4. 写入修改后的模板 package.json
90
+ await fs.writeFile(templatePkgPath, JSON.stringify(templatePkg, null, 2) + '\n')
91
+ console.log(`📦 模板包版本已更新至 ${templatePkg.version},workspace:* 已替换为 *`)
92
+ } catch (err) {
93
+ // 回滚模板修改
94
+ console.log('↩️ 正在回滚 jnrs-template-vue/package.json 的修改...')
95
+ try {
96
+ if (hasModifiedTemplate) {
97
+ // 恢复 workspace:* 和原始 version
98
+ const rollbackPkg = JSON.parse(templatePkgContent)
99
+ await fs.writeFile(templatePkgPath, JSON.stringify(rollbackPkg, null, 2) + '\n')
100
+ }
101
+ } catch (e2) {
102
+ console.error('❌ 回滚模板文件时出错:', e2.message)
103
+ }
104
+ throw new Error(`处理模板包失败: ${err.message}`)
105
+ }
106
+ // ========== 新增逻辑结束 ==========
107
+
108
+ // 手动计算新版本(主包)
58
109
  const newVersion = incrementPatchVersion(originalVersion)
59
110
  console.log(`🆕 新版本: ${newVersion}`)
60
111
 
61
- // 写入新版本
112
+ // 写入新版本(主包)
62
113
  pkg.version = newVersion
63
114
  await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
64
115
 
@@ -76,19 +127,25 @@ try {
76
127
  try {
77
128
  console.log('💾 正在提交版本变更...')
78
129
  run('git add package.json')
130
+ run(`git add ${templatePkgPath.replace(/\\/g, '/')}`) // 确保路径兼容 Windows
79
131
  const commitMsg = `🅒🅘🅒🅓 ${pkg.name}@${newVersion} 发布成功!👌`
80
132
  run(`git commit -m "${commitMsg}"`)
81
133
  console.log(`\n✅ 包 ${pkg.name} 发布流程已完成!🎉🎉🎉`)
82
134
  } catch (err) {
83
- console.error('⚠️ 提交失败,但发布已成功。请手动提交 package.json:', err.message)
135
+ console.error('⚠️ 提交失败,但发布已成功。请手动提交 package.json 和模板包:', err.message)
84
136
  console.log(`\n✅ 包 ${pkg.name} 发布流程已完成!🎉🎉🎉`)
85
137
  }
86
138
  } else {
87
- // 回滚
88
- console.log('↩️ 正在回滚 version 修改...')
139
+ // 回滚主包
140
+ console.log('↩️ 正在回滚主包 version 修改...')
89
141
  pkg.version = originalVersion
90
142
  await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
91
- console.log('✅ 已还原 package.json 到原始版本')
143
+
144
+ // 回滚模板包
145
+ console.log('↩️ 正在回滚模板包修改...')
146
+ await fs.writeFile(templatePkgPath, templatePkgContent)
147
+
148
+ console.log('📦 已还原 package.json 和模板包到原始状态')
92
149
  process.exit(1)
93
150
  }
94
151
  } catch (err) {
@@ -2,6 +2,8 @@
2
2
  export {};
3
3
 
4
4
  ; declare global {
5
+ var __VLS_PROPS_FALLBACK: Record<string, unknown>;
6
+
5
7
  const __VLS_directiveBindingRestFields: { instance: null, oldValue: null, modifiers: any, dir: any };
6
8
  const __VLS_unref: typeof import('vue').unref;
7
9
  const __VLS_placeholder: any;
@@ -35,7 +37,7 @@ export {};
35
37
  attrs?: any;
36
38
  slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>;
37
39
  emit?: T extends { $emit: infer Emit } ? Emit : {};
38
- props?: (T extends { $props: infer Props } ? Props : {}) & Record<string, unknown>;
40
+ props?: typeof props;
39
41
  expose?: (exposed: T) => void;
40
42
  };
41
43
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-jnrs-template-vue",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "As the name suggests.",
5
5
  "author": "Talia-Tan",
6
6
  "private": true,
@@ -21,9 +21,9 @@
21
21
  "format": "prettier --write src/"
22
22
  },
23
23
  "dependencies": {
24
- "@jnrs/shared": "workspace:*",
25
- "@jnrs/core": "workspace:*",
26
- "@jnrs/vue-core": "workspace:*",
24
+ "@jnrs/shared": "*",
25
+ "@jnrs/core": "*",
26
+ "@jnrs/vue-core": "*",
27
27
  "@element-plus/icons-vue": "^2.3.2",
28
28
  "async-validator": "^4.2.5",
29
29
  "element-plus": "^2.11.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-jnrs-template-vue",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A Vue3 + Vite + TS project template with monorepo packages for JNRS.",
5
5
  "keywords": [
6
6
  "vue",