@lwenh/rcn 1.0.0

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/cli.mjs +102 -0
  2. package/package.json +23 -0
package/bin/cli.mjs ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @lwenh/rcn CLI
5
+ *
6
+ * 用法:
7
+ * npx @lwenh/rcn add <component-name> [component-name...]
8
+ * npx @lwenh/rcn list
9
+ *
10
+ * 示例:
11
+ * npx @lwenh/rcn add button
12
+ * npx @lwenh/rcn add button data-table
13
+ * npx @lwenh/rcn list
14
+ */
15
+
16
+ import { execSync } from 'node:child_process'
17
+
18
+ const REGISTRY_BASE_URL = 'https://careerisx.github.io/rcn-vue/r'
19
+
20
+ const args = process.argv.slice(2)
21
+ const command = args[0]
22
+
23
+ function printHelp() {
24
+ console.log(`
25
+ @lwenh/rcn CLI - 自定义组件注册表
26
+
27
+ 用法:
28
+ npx @lwenh/rcn add <component> [component...] 安装组件到当前项目
29
+ npx @lwenh/rcn list 列出所有可用组件
30
+ npx @lwenh/rcn help 显示帮助信息
31
+
32
+ 示例:
33
+ npx @lwenh/rcn add button
34
+ npx @lwenh/rcn add button data-table
35
+ `)
36
+ }
37
+
38
+ async function listComponents() {
39
+ try {
40
+ const response = await fetch(`${REGISTRY_BASE_URL}/registry.json`)
41
+ if (!response.ok) {
42
+ console.error(`❌ 无法获取组件列表: HTTP ${response.status}`)
43
+ process.exit(1)
44
+ }
45
+ const registry = await response.json()
46
+ console.log('\n📦 可用组件:\n')
47
+ for (const item of registry.items) {
48
+ console.log(` ${item.name.padEnd(25)} ${item.description || ''}`)
49
+ }
50
+ console.log(`\n共 ${registry.items.length} 个组件\n`)
51
+ } catch (err) {
52
+ console.error('❌ 无法连接到 registry,请检查网络或 REGISTRY_BASE_URL 配置')
53
+ process.exit(1)
54
+ }
55
+ }
56
+
57
+ function addComponents(components) {
58
+ if (components.length === 0) {
59
+ console.error('❌ 请指定要安装的组件名称')
60
+ console.error(' 用法: npx @lwenh/rcn add <component-name>')
61
+ process.exit(1)
62
+ }
63
+
64
+ const urls = components.map(name => {
65
+ // 如果用户传入的是完整 URL,直接使用
66
+ if (name.startsWith('http://') || name.startsWith('https://')) {
67
+ return name
68
+ }
69
+ // 否则拼接 registry URL
70
+ return `${REGISTRY_BASE_URL}/${name}.json`
71
+ })
72
+
73
+ const cmd = `npx shadcn-vue@latest add ${urls.join(' ')}`
74
+ console.log(`\n🚀 正在安装组件: ${components.join(', ')}\n`)
75
+ console.log(` 执行命令: ${cmd}\n`)
76
+
77
+ try {
78
+ execSync(cmd, { stdio: 'inherit' })
79
+ } catch {
80
+ process.exit(1)
81
+ }
82
+ }
83
+
84
+ switch (command) {
85
+ case 'add':
86
+ addComponents(args.slice(1))
87
+ break
88
+ case 'list':
89
+ case 'ls':
90
+ listComponents()
91
+ break
92
+ case 'help':
93
+ case '--help':
94
+ case '-h':
95
+ case undefined:
96
+ printHelp()
97
+ break
98
+ default:
99
+ console.error(`❌ 未知命令: ${command}`)
100
+ printHelp()
101
+ process.exit(1)
102
+ }
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@lwenh/rcn",
3
+ "version": "1.0.0",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
7
+ "description": "CLI for installing rcn-vue registry components",
8
+ "type": "module",
9
+ "bin": {
10
+ "rcn": "./bin/cli.mjs"
11
+ },
12
+ "files": [
13
+ "bin"
14
+ ],
15
+ "keywords": [
16
+ "rcn-vue",
17
+ "shadcn-vue",
18
+ "vue",
19
+ "components",
20
+ "registry"
21
+ ],
22
+ "license": "MIT"
23
+ }