uniky 1.0.21 → 1.0.22
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/README.md +45 -1
- package/package.json +4 -1
- package/scripts/postinstall.js +1 -5
- package/src/plugin/index.ts +13 -3
package/README.md
CHANGED
|
@@ -19,6 +19,26 @@ pnpm add uniky
|
|
|
19
19
|
yarn add uniky
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## 安装后设置
|
|
23
|
+
|
|
24
|
+
### 自动安装(推荐)
|
|
25
|
+
|
|
26
|
+
安装 `uniky` 后,插件文件会自动安装到项目根目录的 `.uniky` 文件夹。
|
|
27
|
+
|
|
28
|
+
如果自动安装失败或删除了 `.uniky` 文件夹,可以手动触发安装:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# 使用 npx
|
|
32
|
+
npx uniky-install
|
|
33
|
+
|
|
34
|
+
# 或者直接运行
|
|
35
|
+
node node_modules/uniky/scripts/postinstall.js
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 自动检测安装
|
|
39
|
+
|
|
40
|
+
如果 `.uniky` 文件夹缺失,在首次运行 Vite 时,插件会自动检测并安装所需文件。
|
|
41
|
+
|
|
22
42
|
## 使用
|
|
23
43
|
|
|
24
44
|
### 库功能
|
|
@@ -97,11 +117,35 @@ _To.back();
|
|
|
97
117
|
在 `main.ts` 中安装全局定义:
|
|
98
118
|
|
|
99
119
|
```typescript
|
|
100
|
-
import { installGlobals } from './
|
|
120
|
+
import { installGlobals } from './_unikey/global.install';
|
|
101
121
|
|
|
102
122
|
installGlobals();
|
|
103
123
|
```
|
|
104
124
|
|
|
125
|
+
## 目录结构
|
|
126
|
+
|
|
127
|
+
安装后,项目根目录会生成 `.uniky` 文件夹:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
your-project/
|
|
131
|
+
├── .uniky/
|
|
132
|
+
│ ├── index.ts
|
|
133
|
+
│ └── plugin/
|
|
134
|
+
│ ├── index.ts
|
|
135
|
+
│ ├── pages.defined.ts
|
|
136
|
+
│ ├── global.defined.ts
|
|
137
|
+
│ ├── http.defined.ts
|
|
138
|
+
│ └── lib.defined.ts
|
|
139
|
+
├── src/
|
|
140
|
+
│ └── _unikey/ # 插件自动生成的文件
|
|
141
|
+
│ ├── global/
|
|
142
|
+
│ │ ├── pages.ts
|
|
143
|
+
│ │ └── ky.ts
|
|
144
|
+
│ ├── global.d.ts
|
|
145
|
+
│ └── global.install.ts
|
|
146
|
+
└── vite.config.ts
|
|
147
|
+
```
|
|
148
|
+
|
|
105
149
|
## 故障排除
|
|
106
150
|
|
|
107
151
|
### ESM 相关错误
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uniky",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"description": "uni-app 开发工具库,包含 hooks、http 请求和 vite 插件",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/lib/index.ts",
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"import": "./src/plugin/index.ts"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"uniky-install": "./scripts/postinstall.js"
|
|
21
|
+
},
|
|
19
22
|
"sideEffects": false,
|
|
20
23
|
"files": [
|
|
21
24
|
"src/lib",
|
package/scripts/postinstall.js
CHANGED
package/src/plugin/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// created by zhuxietong on 2026-01-30 16:37
|
|
2
2
|
import type { Plugin } from 'vite';
|
|
3
|
-
import { copyFileSync, mkdirSync, existsSync, readdirSync, statSync } from 'fs';
|
|
3
|
+
import { copyFileSync, mkdirSync, existsSync, readdirSync, statSync, writeFileSync } from 'fs';
|
|
4
4
|
import { join, dirname } from 'path';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
|
|
@@ -40,11 +40,16 @@ function ensurePluginInstalled(projectRoot: string): void {
|
|
|
40
40
|
const unikyDir = join(projectRoot, '.uniky');
|
|
41
41
|
const pluginDir = join(unikyDir, 'plugin');
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
// 检查关键文件是否存在
|
|
44
|
+
const keyFiles = ['index.ts', 'pages.defined.ts', 'global.defined.ts'];
|
|
45
|
+
const needsInstall = !existsSync(pluginDir) ||
|
|
46
|
+
keyFiles.some(file => !existsSync(join(pluginDir, file)));
|
|
47
|
+
|
|
48
|
+
if (!needsInstall) {
|
|
44
49
|
return;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
console.log('[uniky]
|
|
52
|
+
console.log('[uniky] 检测到插件文件缺失,正在自动安装...');
|
|
48
53
|
|
|
49
54
|
if (!existsSync(unikyDir)) {
|
|
50
55
|
mkdirSync(unikyDir, { recursive: true });
|
|
@@ -65,6 +70,11 @@ function ensurePluginInstalled(projectRoot: string): void {
|
|
|
65
70
|
|
|
66
71
|
const copiedCount = copyDirectoryRecursive(sourceDir, pluginDir);
|
|
67
72
|
|
|
73
|
+
const indexContent = `// created by zhuxietong on 2026-01-30 16:37
|
|
74
|
+
export * from './plugin/index.js';
|
|
75
|
+
`;
|
|
76
|
+
writeFileSync(join(unikyDir, 'index.ts'), indexContent, 'utf-8');
|
|
77
|
+
|
|
68
78
|
console.log(`[uniky] ✅ 插件文件已自动安装到 ${unikyDir} (${copiedCount} 个文件)`);
|
|
69
79
|
} catch (error) {
|
|
70
80
|
console.warn('[uniky] 插件自动安装失败:', error);
|