intools-cli 1.0.5 → 1.0.7
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
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 参考
|
|
@@ -163,7 +215,7 @@
|
|
|
163
215
|
| 方法 | 环境 | 说明 |
|
|
164
216
|
|------|------|------|
|
|
165
217
|
| `readFile(path, encoding?)` | R/B | 读取文件 → `Buffer | string` |
|
|
166
|
-
| `writeFile(path, data, encoding?)` | R/B | 写入文件 |
|
|
218
|
+
| `writeFile(path, data, encoding?)` | R/B | 写入文件 (`data`: `string \| Buffer \| ArrayBuffer`) |
|
|
167
219
|
| `exists(path)` | R/B | 检查是否存在 → `boolean` |
|
|
168
220
|
| `unlink(path)` | R/B | 删除文件 |
|
|
169
221
|
| `readdir(path)` | R/B | 读取目录 → `string[]` |
|
|
@@ -229,10 +281,10 @@
|
|
|
229
281
|
|
|
230
282
|
| 方法 | 环境 | 说明 |
|
|
231
283
|
|------|------|------|
|
|
232
|
-
| `request(options)` | R/B | 发起请求 → `HttpResponse` |
|
|
284
|
+
| `request(options)` | R/B | 发起请求 (`body`: `string \| object \| Buffer \| ArrayBuffer`) → `HttpResponse` |
|
|
233
285
|
| `get(url, headers?)` | R/B | GET 请求 |
|
|
234
|
-
| `post(url, body?, headers?)` | R/B | POST 请求 |
|
|
235
|
-
| `put(url, body?, headers?)` | R/B | PUT 请求 |
|
|
286
|
+
| `post(url, body?, headers?)` | R/B | POST 请求 (`body`: `string \| object \| Buffer \| ArrayBuffer`) |
|
|
287
|
+
| `put(url, body?, headers?)` | R/B | PUT 请求 (`body`: `string \| object \| Buffer \| ArrayBuffer`) |
|
|
236
288
|
| `delete(url, headers?)` | R/B | DELETE 请求 |
|
|
237
289
|
|
|
238
290
|
**HttpRequestOptions**: `url`, `method`, `headers`, `body`, `timeout`
|
|
@@ -280,7 +332,7 @@
|
|
|
280
332
|
| 方法 | 环境 | 说明 |
|
|
281
333
|
|------|------|------|
|
|
282
334
|
| `hideMainWindowPasteText(text)` | R/B | 粘贴文本到焦点应用 |
|
|
283
|
-
| `hideMainWindowPasteImage(image)` | R/B | 粘贴图片到焦点应用 |
|
|
335
|
+
| `hideMainWindowPasteImage(image)` | R/B | 粘贴图片到焦点应用 (`image`: `Path \| Buffer \| DataURL \| ArrayBuffer`) |
|
|
284
336
|
| `hideMainWindowPasteFile(paths)` | R/B | 粘贴文件到焦点应用 |
|
|
285
337
|
| `hideMainWindowTypeString(text)` | R/B | 模拟键入文本 |
|
|
286
338
|
| `simulateKeyboardTap(key, ...modifiers)` | R/B | 模拟按键 |
|
|
@@ -437,7 +489,7 @@
|
|
|
437
489
|
|------|------|------|
|
|
438
490
|
| `isEncryptionAvailable()` | R/B | 检查加密可用性 |
|
|
439
491
|
| `encryptString(plainText)` | R/B | 加密字符串 → `Buffer` |
|
|
440
|
-
| `decryptString(encrypted)` | R/B | 解密字符串 → `string` |
|
|
492
|
+
| `decryptString(encrypted)` | R/B | 解密字符串 (`encrypted`: `Buffer \| ArrayBuffer`) → `string` |
|
|
441
493
|
|
|
442
494
|
---
|
|
443
495
|
|
|
@@ -55,6 +55,14 @@ async function createBasicProject(targetDir, name) {
|
|
|
55
55
|
const mainTs = (0, basic_1.buildBasicMain)(name);
|
|
56
56
|
fs.writeFileSync(path.join(targetDir, 'src/main.ts'), mainTs);
|
|
57
57
|
console.log(chalk_1.default.green(' ✓ src/main.ts'));
|
|
58
|
+
// 创建 .gitignore
|
|
59
|
+
const gitignore = (0, basic_1.buildGitignore)();
|
|
60
|
+
fs.writeFileSync(path.join(targetDir, '.gitignore'), gitignore);
|
|
61
|
+
console.log(chalk_1.default.green(' ✓ .gitignore'));
|
|
62
|
+
// 创建 README.md
|
|
63
|
+
const readme = (0, basic_1.buildBasicReadme)(name);
|
|
64
|
+
fs.writeFileSync(path.join(targetDir, 'README.md'), readme);
|
|
65
|
+
console.log(chalk_1.default.green(' ✓ README.md'));
|
|
58
66
|
// 复制 API 参考文档
|
|
59
67
|
const apiDocSrc = path.join(__dirname, '../../..', 'PLUGIN_API.md');
|
|
60
68
|
if (fs.existsSync(apiDocSrc)) {
|
|
@@ -54,6 +54,8 @@ async function createReactProject(targetDir, name) {
|
|
|
54
54
|
createBackendMain(targetDir, name);
|
|
55
55
|
createReactUI(targetDir, name);
|
|
56
56
|
createIntoolsTypes(targetDir);
|
|
57
|
+
createGitignore(targetDir);
|
|
58
|
+
createReadme(targetDir, name);
|
|
57
59
|
// 复制 API 参考文档
|
|
58
60
|
const apiDocSrc = path.join(__dirname, '../../..', 'PLUGIN_API.md');
|
|
59
61
|
if (fs.existsSync(apiDocSrc)) {
|
|
@@ -110,3 +112,13 @@ function createIntoolsTypes(targetDir) {
|
|
|
110
112
|
fs.writeFileSync(path.join(targetDir, 'src/types/intools.d.ts'), typesDts);
|
|
111
113
|
console.log(chalk_1.default.green(' ✓ src/types/intools.d.ts'));
|
|
112
114
|
}
|
|
115
|
+
function createGitignore(targetDir) {
|
|
116
|
+
const gitignore = (0, react_1.buildGitignore)();
|
|
117
|
+
fs.writeFileSync(path.join(targetDir, '.gitignore'), gitignore);
|
|
118
|
+
console.log(chalk_1.default.green(' ✓ .gitignore'));
|
|
119
|
+
}
|
|
120
|
+
function createReadme(targetDir, name) {
|
|
121
|
+
const readme = (0, react_1.buildReactReadme)(name);
|
|
122
|
+
fs.writeFileSync(path.join(targetDir, 'README.md'), readme);
|
|
123
|
+
console.log(chalk_1.default.green(' ✓ README.md'));
|
|
124
|
+
}
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildBasicManifest = buildBasicManifest;
|
|
4
4
|
exports.buildBasicPackageJson = buildBasicPackageJson;
|
|
5
5
|
exports.buildBasicMain = buildBasicMain;
|
|
6
|
+
exports.buildGitignore = buildGitignore;
|
|
7
|
+
exports.buildBasicReadme = buildBasicReadme;
|
|
6
8
|
function buildBasicManifest(name) {
|
|
7
9
|
return {
|
|
8
10
|
id: name,
|
|
@@ -93,3 +95,68 @@ const plugin = { onLoad, onUnload, onEnable, onDisable, run }
|
|
|
93
95
|
export default plugin
|
|
94
96
|
`;
|
|
95
97
|
}
|
|
98
|
+
function buildGitignore() {
|
|
99
|
+
return `node_modules
|
|
100
|
+
dist
|
|
101
|
+
.DS_Store
|
|
102
|
+
*.log
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
function buildBasicReadme(name) {
|
|
106
|
+
return `# ${name}
|
|
107
|
+
|
|
108
|
+
插件描述
|
|
109
|
+
|
|
110
|
+
## 功能特性
|
|
111
|
+
|
|
112
|
+
- 功能 1
|
|
113
|
+
- 功能 2
|
|
114
|
+
- 功能 3
|
|
115
|
+
|
|
116
|
+
## 触发方式
|
|
117
|
+
|
|
118
|
+
- \`${name}\` - 主功能
|
|
119
|
+
|
|
120
|
+
## 开发
|
|
121
|
+
|
|
122
|
+
### 安装依赖
|
|
123
|
+
|
|
124
|
+
\`\`\`bash
|
|
125
|
+
npm install
|
|
126
|
+
\`\`\`
|
|
127
|
+
|
|
128
|
+
### 开发模式
|
|
129
|
+
|
|
130
|
+
\`\`\`bash
|
|
131
|
+
npm run dev
|
|
132
|
+
\`\`\`
|
|
133
|
+
|
|
134
|
+
### 构建
|
|
135
|
+
|
|
136
|
+
\`\`\`bash
|
|
137
|
+
npm run build
|
|
138
|
+
\`\`\`
|
|
139
|
+
|
|
140
|
+
### 打包
|
|
141
|
+
|
|
142
|
+
\`\`\`bash
|
|
143
|
+
npm run pack
|
|
144
|
+
\`\`\`
|
|
145
|
+
|
|
146
|
+
## 项目结构
|
|
147
|
+
|
|
148
|
+
\`\`\`
|
|
149
|
+
${name}/
|
|
150
|
+
├── manifest.json # 插件配置
|
|
151
|
+
├── package.json
|
|
152
|
+
├── src/
|
|
153
|
+
│ └── main.ts # 后端入口
|
|
154
|
+
├── dist/ # 构建输出
|
|
155
|
+
└── icon.png # 插件图标
|
|
156
|
+
\`\`\`
|
|
157
|
+
|
|
158
|
+
## 许可证
|
|
159
|
+
|
|
160
|
+
MIT License
|
|
161
|
+
`;
|
|
162
|
+
}
|
|
@@ -10,6 +10,8 @@ exports.buildMainTsx = buildMainTsx;
|
|
|
10
10
|
exports.buildAppTsx = buildAppTsx;
|
|
11
11
|
exports.buildStylesCss = buildStylesCss;
|
|
12
12
|
exports.buildUseIntools = buildUseIntools;
|
|
13
|
+
exports.buildGitignore = buildGitignore;
|
|
14
|
+
exports.buildReactReadme = buildReactReadme;
|
|
13
15
|
exports.buildIntoolsTypes = buildIntoolsTypes;
|
|
14
16
|
function buildReactManifest(name) {
|
|
15
17
|
return {
|
|
@@ -676,6 +678,82 @@ export function useIntools(pluginId?: string) {
|
|
|
676
678
|
}
|
|
677
679
|
`;
|
|
678
680
|
}
|
|
681
|
+
function buildGitignore() {
|
|
682
|
+
return `node_modules
|
|
683
|
+
dist
|
|
684
|
+
ui
|
|
685
|
+
.DS_Store
|
|
686
|
+
*.log
|
|
687
|
+
`;
|
|
688
|
+
}
|
|
689
|
+
function buildReactReadme(name) {
|
|
690
|
+
return `# ${name}
|
|
691
|
+
|
|
692
|
+
插件描述
|
|
693
|
+
|
|
694
|
+
## 功能特性
|
|
695
|
+
|
|
696
|
+
- 功能 1
|
|
697
|
+
- 功能 2
|
|
698
|
+
- 功能 3
|
|
699
|
+
|
|
700
|
+
## 触发方式
|
|
701
|
+
|
|
702
|
+
- \`${name}\` - 主功能
|
|
703
|
+
|
|
704
|
+
## 开发
|
|
705
|
+
|
|
706
|
+
### 安装依赖
|
|
707
|
+
|
|
708
|
+
\`\`\`bash
|
|
709
|
+
npm install
|
|
710
|
+
\`\`\`
|
|
711
|
+
|
|
712
|
+
### 开发模式
|
|
713
|
+
|
|
714
|
+
\`\`\`bash
|
|
715
|
+
npm run dev
|
|
716
|
+
\`\`\`
|
|
717
|
+
|
|
718
|
+
### 构建
|
|
719
|
+
|
|
720
|
+
\`\`\`bash
|
|
721
|
+
npm run build
|
|
722
|
+
\`\`\`
|
|
723
|
+
|
|
724
|
+
### 打包
|
|
725
|
+
|
|
726
|
+
\`\`\`bash
|
|
727
|
+
npm run pack
|
|
728
|
+
\`\`\`
|
|
729
|
+
|
|
730
|
+
## 项目结构
|
|
731
|
+
|
|
732
|
+
\`\`\`
|
|
733
|
+
${name}/
|
|
734
|
+
├── manifest.json # 插件配置
|
|
735
|
+
├── package.json
|
|
736
|
+
├── src/
|
|
737
|
+
│ ├── main.ts # 后端入口
|
|
738
|
+
│ ├── ui/
|
|
739
|
+
│ │ ├── App.tsx # 主应用
|
|
740
|
+
│ │ ├── main.tsx # UI 入口
|
|
741
|
+
│ │ ├── index.html # HTML 模板
|
|
742
|
+
│ │ ├── styles.css # 全局样式
|
|
743
|
+
│ │ ├── hooks/
|
|
744
|
+
│ │ │ └── useIntools.ts # InTools API Hook
|
|
745
|
+
│ │ └── types/
|
|
746
|
+
│ │ └── intools.d.ts # 类型定义
|
|
747
|
+
├── dist/ # 后端构建输出
|
|
748
|
+
├── ui/ # UI 构建输出
|
|
749
|
+
└── icon.png # 插件图标
|
|
750
|
+
\`\`\`
|
|
751
|
+
|
|
752
|
+
## 许可证
|
|
753
|
+
|
|
754
|
+
MIT License
|
|
755
|
+
`;
|
|
756
|
+
}
|
|
679
757
|
function buildIntoolsTypes() {
|
|
680
758
|
return `// InTools API 类型定义
|
|
681
759
|
|
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)) {
|