@hr-components-dev/cli 1.1.4 → 1.1.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hr-components-dev/cli",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -32,7 +32,6 @@
32
32
  "vite.config.ts",
33
33
  "index.html",
34
34
  "tsconfig.build.json",
35
- "!scripts/**/*.ts",
36
35
  "!**/*.test.js",
37
36
  "!**/*.spec.js"
38
37
  ],
@@ -1,10 +1,49 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import { fileURLToPath } from 'node:url';
4
- import { dirname, join } from 'node:path';
4
+ import { dirname, join, resolve } from 'node:path';
5
+ import { existsSync, symlinkSync, unlinkSync } from 'node:fs';
5
6
  import { spawn } from 'node:child_process';
6
- import path from 'node:path';
7
7
  import consola from 'consola';
8
+
9
+ /**
10
+ * 创建软链接
11
+ */
12
+ function BuildSoftLink() {
13
+ consola.info('=== 开始构建软链接... ===');
14
+
15
+ try {
16
+ // 组件源目录 (项目根目录下的 src/components)
17
+ const source = resolve(process.cwd(), 'src/components');
18
+ // 目标链接位置 (cli 子包根目录下的 src/components)
19
+ const target = resolve(targetPackageDir, 'src/components');
20
+
21
+ consola.info(`源目录: ${source}`);
22
+ consola.info(`目标链接: ${target}`);
23
+
24
+ // 检查源目录是否存在
25
+ if (!existsSync(source)) {
26
+ consola.error('源目录不存在:', source);
27
+ process.exit(1);
28
+ }
29
+
30
+ // 如果目标链接已存在,则删除它
31
+ if (existsSync(target)) {
32
+ unlinkSync(target);
33
+ consola.info('已删除现有链接');
34
+ }
35
+
36
+ // 创建软链接
37
+ symlinkSync(source, target, 'junction'); // 使用 junction 在 Windows 上更兼容
38
+
39
+ consola.success('软链接创建成功!');
40
+ consola.info(`${target} -> ${source}`);
41
+
42
+ } catch (error) {
43
+ consola.error('创建软链接失败:', error);
44
+ process.exit(1);
45
+ }
46
+ }
8
47
  // 在文件顶部添加辅助函数
9
48
  function handleProcess(childProcess, name) {
10
49
  childProcess.on('error', (err) => {
@@ -28,10 +67,12 @@ const command = args[0];
28
67
  /**
29
68
  * cli 子包根目录
30
69
  */
31
- const targetPackageDir = path.resolve(__dirname, '../../');
70
+ const targetPackageDir = resolve(__dirname, '../../');
32
71
 
33
72
  switch (command) {
34
73
  case 'dev':
74
+ BuildSoftLink();
75
+
35
76
  // 启动开发服务器
36
77
  const viteProcess = spawn('npx', ['vite'], {
37
78
  cwd: targetPackageDir,
@@ -5,8 +5,8 @@ import consola from "consola";
5
5
  async function getAllComponents() {
6
6
  // 使用 import.meta.glob 动态导入 src/components 下的所有组件
7
7
  debugger;
8
- const modules = import.meta.glob('../../../src/components/*/index.ts');
9
- consola.info(`找到[${Object.keys(modules).length}]个组件`, '../../../src/components/*/index.ts');
8
+ const modules = import.meta.glob('/src/components/*/index.ts');
9
+ consola.info(`找到[${Object.keys(modules).length}]个组件`, '/src/components/*/index.ts');
10
10
  const components = [];
11
11
  for (const path in modules) {
12
12
  try {
@@ -1,6 +1,7 @@
1
1
  import consola from "consola";
2
2
  import type { ComponentType } from 'react'; // 引入 React 类型
3
3
 
4
+
4
5
  // 定义组件项的接口
5
6
  interface ComponentItem {
6
7
  组件名: string;
@@ -17,13 +18,13 @@ interface ComponentItem {
17
18
  */
18
19
  async function getAllComponents(): Promise<ComponentItem[]> {
19
20
  // 使用 import.meta.glob 动态导入 src/components 下的所有组件
20
- debugger
21
+ debugger;
21
22
  const modules = import.meta.glob<{
22
23
  default: (props: amis.AmisComponentPropsType) => ComponentType<any>,
23
24
  isFormItem: boolean
24
- }>('../../../src/components/*/index.ts');
25
+ }>('/src/components/*/index.ts');
26
+ consola.info(`找到[${Object.keys(modules).length}]个组件`, '/src/components/*/index.ts');
25
27
 
26
- consola.info(`找到[${Object.keys(modules).length}]个组件`, '../../../src/components/*/index.ts');
27
28
 
28
29
  const components: ComponentItem[] = [];
29
30
  for (const path in modules) {