@alanwang-merit/meritdata-platform-skill-package 1.0.4 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alanwang-merit/meritdata-platform-skill-package",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/"
6
6
  },
@@ -1,20 +1,25 @@
1
- // scripts/postinstall.js
2
1
  const fs = require('fs');
3
2
  const path = require('path');
3
+ const getTopPackagePath = require('top-package');
4
4
 
5
- // 获取当前 npm 包所在的目录
6
- const packageRoot = __dirname.replace('scripts', '');
7
- // 获取执行安装命令的项目根目录
8
- const projectRoot = process.cwd();
5
+ // 1. 获取当前 npm 包所在的目录 (node_modules/@alanwang-merit/meritdata-platform-skill-package)
6
+ const currentPackagePath = path.resolve(__dirname, '..');
9
7
 
10
- // 定义需要复制的目录映射:源目录 -> 目标目录
8
+ // 2. 使用 top-package 精准定位到消费此包的项目根目录 (例如: E:\wllmh\ss)
9
+ const projectRoot = getTopPackagePath(currentPackagePath);
10
+
11
+ // 3. 定义需要复制的目录映射
11
12
  const copyMappings = [
12
13
  { source: 'skills', target: '.claude/skills' },
13
14
  { source: 'rules', target: '.claude/rules' }
14
15
  ];
15
16
 
17
+ // 4. 递归复制文件夹的函数
16
18
  function copyDir(src, dest) {
17
- if (!fs.existsSync(src)) return;
19
+ if (!fs.existsSync(src)) {
20
+ console.log(`⚠️ [postinstall] Source not found, skipping: ${src}`);
21
+ return;
22
+ }
18
23
 
19
24
  fs.mkdirSync(dest, { recursive: true });
20
25
  const entries = fs.readdirSync(src, { withFileTypes: true });
@@ -30,10 +35,13 @@ function copyDir(src, dest) {
30
35
  }
31
36
  }
32
37
 
33
- // 执行复制操作
38
+ // 5. 执行复制操作
39
+ console.log(`🚀 [postinstall] Project root detected: ${projectRoot}`);
34
40
  copyMappings.forEach(({ source, target }) => {
35
- const srcPath = path.join(packageRoot, source);
41
+ const srcPath = path.join(currentPackagePath, source);
36
42
  const destPath = path.join(projectRoot, target);
37
43
  copyDir(srcPath, destPath);
38
- console.log(`✅ [postinstall] Copied ${source} to ${target}`);
39
- });
44
+ console.log(`✅ [postinstall] Copied ${source} -> ${destPath}`);
45
+ });
46
+
47
+ console.log('🎉 [postinstall] Skill package installation completed!');