intools-cli 1.0.5 → 1.0.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/PLUGIN_API.md +52 -0
- package/dist/commands/pack.js +11 -0
- package/package.json +1 -1
package/PLUGIN_API.md
CHANGED
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
| description | string | | 插件描述 |
|
|
50
50
|
| main | string | ✓ | 后端入口文件 |
|
|
51
51
|
| ui | string | | UI 入口文件 |
|
|
52
|
+
| preload | string | | 自定义 preload 脚本(可使用 Node.js) |
|
|
52
53
|
| icon | string/object | | 插件图标(路径/URL/SVG) |
|
|
53
54
|
| features | array | ✓ | 功能入口列表 |
|
|
54
55
|
| pluginSetting | object | | 插件行为设置 |
|
|
@@ -140,6 +141,57 @@
|
|
|
140
141
|
"icon": { "type": "svg", "value": "<svg>...</svg>" }
|
|
141
142
|
```
|
|
142
143
|
|
|
144
|
+
## Preload 配置(自定义 Node.js 能力)
|
|
145
|
+
|
|
146
|
+
配置自定义 preload 脚本,可在渲染进程中直接使用 Node.js 能力。
|
|
147
|
+
|
|
148
|
+
### 配置方式
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"preload": "preload.js"
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### preload.js 示例
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
// preload.js - 遵循 CommonJS 规范
|
|
160
|
+
const fs = require('fs')
|
|
161
|
+
const os = require('os')
|
|
162
|
+
const path = require('path')
|
|
163
|
+
|
|
164
|
+
// 通过 window 暴露给前端
|
|
165
|
+
window.myApi = {
|
|
166
|
+
getHomeDir: () => os.homedir(),
|
|
167
|
+
readFile: (filePath) => fs.readFileSync(filePath, 'utf-8'),
|
|
168
|
+
platform: process.platform
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 前端调用
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
// 在 UI 组件中使用
|
|
176
|
+
const homeDir = window.myApi?.getHomeDir()
|
|
177
|
+
const content = window.myApi?.readFile('/path/to/file.txt')
|
|
178
|
+
|
|
179
|
+
// 核心 API 仍然可用
|
|
180
|
+
const text = await window.intools.clipboard.readText()
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### 注意事项
|
|
184
|
+
|
|
185
|
+
| 项目 | 说明 |
|
|
186
|
+
|------|------|
|
|
187
|
+
| 文件格式 | CommonJS 格式,使用 `require()` 导入模块 |
|
|
188
|
+
| 代码规范 | 必须是清晰可读的源码,**不能压缩/混淆** |
|
|
189
|
+
| 可用模块 | Node.js 原生模块 + 第三方 npm 模块 |
|
|
190
|
+
| API 暴露 | 通过 `window.xxx` 暴露自定义 API |
|
|
191
|
+
| 核心 API | `window.intools` 核心 API 仍然可用 |
|
|
192
|
+
| 安全性 | 有完整 Node.js 权限,需注意安全风险 |
|
|
193
|
+
| 打包 | 运行 `intools pack` 会自动包含 preload 文件 |
|
|
194
|
+
|
|
143
195
|
---
|
|
144
196
|
|
|
145
197
|
# 第二部分:API 参考
|
package/dist/commands/pack.js
CHANGED
|
@@ -81,6 +81,17 @@ async function createArchive(cwd, outputPath, manifest) {
|
|
|
81
81
|
if (fs.existsSync(uiDir)) {
|
|
82
82
|
archive.directory(uiDir, 'ui');
|
|
83
83
|
}
|
|
84
|
+
// 添加 preload 脚本(如果在 manifest 中配置了)
|
|
85
|
+
if (manifest.preload) {
|
|
86
|
+
const preloadPath = path.join(cwd, manifest.preload);
|
|
87
|
+
if (fs.existsSync(preloadPath)) {
|
|
88
|
+
archive.file(preloadPath, { name: manifest.preload });
|
|
89
|
+
console.log(chalk_1.default.gray(` + ${manifest.preload}`));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
console.log(chalk_1.default.yellow(`警告: preload 文件不存在: ${manifest.preload}`));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
84
95
|
// 添加 README.md(如果存在)
|
|
85
96
|
const readmePath = path.join(cwd, 'README.md');
|
|
86
97
|
if (fs.existsSync(readmePath)) {
|