morghulis 1.0.46 → 1.0.47

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.
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+
3
+ // 使用CommonJS语法确保最大兼容性
4
+ const { execSync } = require('child_process');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ /**
9
+ * 确保element-plus被安装
10
+ */
11
+ function ensureElementPlusInstalled() {
12
+ try {
13
+ // 尝试找到package.json
14
+ const projectRoot = findPackageJson(process.cwd());
15
+ if (!projectRoot) {
16
+ console.log('未找到package.json文件,无法安装element-plus');
17
+ return;
18
+ }
19
+
20
+ // 检查package.json中是否已经有element-plus
21
+ const packageJsonPath = path.join(projectRoot, 'package.json');
22
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
23
+ const deps = packageJson.dependencies || {};
24
+ const devDeps = packageJson.devDependencies || {};
25
+
26
+ // 如果已经安装了element-plus,则不需要再安装
27
+ if (deps['element-plus'] || devDeps['element-plus']) {
28
+ console.log('element-plus已经在package.json中,跳过安装步骤');
29
+ return;
30
+ }
31
+
32
+ console.log('正在安装element-plus...');
33
+
34
+ try {
35
+ // 先检查npm是否可用
36
+ execSync('npm --version', { stdio: 'ignore' });
37
+
38
+ // 使用npm安装element-plus
39
+ execSync('npm install element-plus --save', {
40
+ stdio: 'inherit',
41
+ cwd: projectRoot
42
+ });
43
+
44
+ console.log('element-plus安装成功');
45
+ } catch (npmError) {
46
+ // 如果npm不可用,尝试使用yarn
47
+ try {
48
+ execSync('yarn --version', { stdio: 'ignore' });
49
+
50
+ execSync('yarn add element-plus', {
51
+ stdio: 'inherit',
52
+ cwd: projectRoot
53
+ });
54
+
55
+ console.log('使用yarn安装element-plus成功');
56
+ } catch (yarnError) {
57
+ console.error('无法使用npm或yarn安装element-plus');
58
+ console.error('请手动安装: npm install element-plus --save');
59
+ }
60
+ }
61
+ } catch (error) {
62
+ console.error('安装element-plus时出错:', error.message);
63
+ console.error('请手动安装: npm install element-plus --save');
64
+ }
65
+ }
66
+
67
+ /**
68
+ * 递归向上查找package.json所在目录
69
+ */
70
+ function findPackageJson(dir) {
71
+ if (fs.existsSync(path.join(dir, 'package.json'))) {
72
+ return dir;
73
+ }
74
+
75
+ const parentDir = path.dirname(dir);
76
+ // 到达根目录,停止查找
77
+ if (parentDir === dir) {
78
+ return null;
79
+ }
80
+
81
+ return findPackageJson(parentDir);
82
+ }
83
+
84
+ // 执行安装
85
+ ensureElementPlusInstalled();
package/package.json CHANGED
@@ -1,14 +1,18 @@
1
1
  {
2
2
  "name": "morghulis",
3
- "version": "1.0.46",
3
+ "version": "1.0.47",
4
4
  "description": "数据库模型",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
10
+ "bin": {
11
+ "install-element-plus": "./install-deps.cjs"
12
+ },
10
13
  "files": [
11
- "dist"
14
+ "dist",
15
+ "install-deps.cjs"
12
16
  ],
13
17
  "scripts": {
14
18
  "dev": "vite",
@@ -18,6 +22,7 @@
18
22
  "type-check": "vue-tsc --build",
19
23
  "prepare": "npm run build",
20
24
  "prepublishOnly": "npm run build",
25
+ "postinstall": "node install-deps.cjs",
21
26
  "generate-types": "node copy-dts.js"
22
27
  },
23
28
  "dependencies": {