@makoojs/cli 0.3.2 → 0.4.0
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.CN.md +298 -261
- package/README.md +298 -261
- package/dist/bin.js +278 -15
- package/dist/command/inspect.d.ts +2 -1
- package/dist/config/resolve.d.ts +4 -1
- package/dist/config/types.d.ts +20 -1
- package/dist/error/{error.d.ts → MakooCliError.d.ts} +13 -1
- package/dist/generator/render/import/importManifest.d.ts +3 -0
- package/dist/generator/render/init/initMakooRuntime.d.ts +3 -2
- package/dist/generator/render/init/registerComp.d.ts +3 -2
- package/dist/generator/render/init/registerListener.d.ts +4 -0
- package/dist/generator/render/util/match.d.ts +1 -0
- package/dist/generator/types.d.ts +6 -0
- package/dist/index.cjs +21 -18
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1002 -917
- package/dist/manifest/index.cjs +1 -0
- package/dist/manifest/index.d.ts +2 -0
- package/dist/manifest/index.js +7 -0
- package/dist/scanner/manifestBinding.d.ts +14 -0
- package/dist/scanner/types.d.ts +25 -1
- package/dist/scanner/validation.d.ts +67 -5
- package/dist/shared/terminalColor.d.ts +1 -0
- package/package.json +9 -4
package/README.CN.md
CHANGED
|
@@ -1,49 +1,58 @@
|
|
|
1
|
-
#
|
|
1
|
+
# CLI API
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## API 索引
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### `@makoojs/cli`
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- [`makoo()`](#makoo):创建 Makoo 与 userscript Vite plugins
|
|
8
|
+
- [`cdn`](#cdn):生成外部依赖的 CDN 配置
|
|
9
|
+
- [配置类型](#配置类型):`MakooOptions`、`CliConfig` 和 monkey 配置
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
- 从 `injections` 目录扫描注入模块并生成运行时代码。
|
|
11
|
-
- 编写 `injections/manifest.ts` 和模块级 `manifest.ts`。
|
|
12
|
-
- 通过 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 生成 userscript 元信息、开发入口和构建产物。
|
|
13
|
-
- 使用 `makoo dev`、`makoo build`、`makoo add`、`makoo inspect` 等命令。
|
|
14
|
-
- 通过 `@makoojs/cli/monkey` 使用 GM API 的 Makoo 稳定入口。
|
|
11
|
+
### `@makoojs/cli/manifest`
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
- [`defineInjections()`](#defineinjections):声明顶层 manifest
|
|
14
|
+
- [`defineInjection()`](#defineinjection):声明模块 manifest
|
|
15
|
+
- [Manifest 类型](#manifest-类型)
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
### `@makoojs/cli/monkey`
|
|
18
|
+
|
|
19
|
+
- [GM API](#gm-api):userscript API 封装
|
|
20
|
+
- [GM 类型](#gm-类型)
|
|
21
|
+
|
|
22
|
+
### 命令行
|
|
23
|
+
|
|
24
|
+
- [CLI 命令](#cli-命令)
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
## `makoo()`
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
根据 Makoo 配置创建 Vite plugins。
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
### Type
|
|
29
31
|
|
|
30
32
|
```ts
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
function makoo(options: MakooOptions): Plugin[];
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Parameters
|
|
37
|
+
|
|
38
|
+
`options` 使用 `MakooOptions`,其中 `app` 为必填字段。
|
|
34
39
|
|
|
40
|
+
### Returns
|
|
41
|
+
|
|
42
|
+
返回一个 `Plugin[]`。在 Vite 配置中需要使用展开语法。
|
|
43
|
+
|
|
44
|
+
### Example
|
|
45
|
+
|
|
46
|
+
```ts
|
|
35
47
|
export default defineConfig({
|
|
36
48
|
plugins: [
|
|
37
|
-
vue(),
|
|
38
49
|
...makoo({
|
|
39
50
|
app: {
|
|
40
|
-
name: 'my-
|
|
41
|
-
version: '0.0.1'
|
|
42
|
-
description: 'My first Makoo script'
|
|
51
|
+
name: 'my-script',
|
|
52
|
+
version: '0.0.1'
|
|
43
53
|
},
|
|
44
54
|
monkey: {
|
|
45
55
|
userscript: {
|
|
46
|
-
namespace: 'https://example.com',
|
|
47
56
|
match: ['https://example.com/*']
|
|
48
57
|
}
|
|
49
58
|
}
|
|
@@ -52,318 +61,346 @@ export default defineConfig({
|
|
|
52
61
|
});
|
|
53
62
|
```
|
|
54
63
|
|
|
55
|
-
`
|
|
64
|
+
## `cdn`
|
|
56
65
|
|
|
57
|
-
|
|
66
|
+
从 `vite-plugin-monkey` 重新导出的 CDN 配置生成器。
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
### Type
|
|
60
69
|
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
```ts
|
|
71
|
+
type CdnFactory = (
|
|
72
|
+
exportVarName?: string,
|
|
73
|
+
pathname?: string
|
|
74
|
+
) => [string, ModuleToUrlFc];
|
|
75
|
+
|
|
76
|
+
const cdn: {
|
|
77
|
+
jsdelivr: CdnFactory;
|
|
78
|
+
jsdelivrFastly: CdnFactory;
|
|
79
|
+
unpkg: CdnFactory;
|
|
80
|
+
cdnjs: CdnFactory;
|
|
81
|
+
zhimg: CdnFactory;
|
|
82
|
+
elemecdn: CdnFactory;
|
|
83
|
+
bdstatic: CdnFactory;
|
|
84
|
+
npmmirror: CdnFactory;
|
|
85
|
+
bootcdn: CdnFactory;
|
|
86
|
+
staticfile: CdnFactory;
|
|
87
|
+
};
|
|
72
88
|
```
|
|
73
89
|
|
|
74
|
-
|
|
90
|
+
`bootcdn` 和 `staticfile` 由 `vite-plugin-monkey` 标记为 deprecated。
|
|
75
91
|
|
|
76
|
-
##
|
|
92
|
+
## 配置类型
|
|
77
93
|
|
|
78
|
-
|
|
94
|
+
### `MakooOptions`
|
|
79
95
|
|
|
80
|
-
|
|
96
|
+
```ts
|
|
97
|
+
type MakooOptions = CliConfig & {
|
|
98
|
+
root?: string;
|
|
99
|
+
};
|
|
100
|
+
```
|
|
81
101
|
|
|
82
|
-
|
|
102
|
+
### `CliConfig`
|
|
83
103
|
|
|
84
104
|
```ts
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
injections: {
|
|
94
|
-
profile: {
|
|
95
|
-
injectAt: '#app',
|
|
96
|
-
component: './profile-card/app.vue',
|
|
97
|
-
framework: 'Vue',
|
|
98
|
-
match: {
|
|
99
|
-
include: ['https://example.com/users/*'],
|
|
100
|
-
exclude: ['https://example.com/users/settings']
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
badge: {
|
|
104
|
-
injectAt: 'body',
|
|
105
|
-
component: './react-badge/app.tsx',
|
|
106
|
-
framework: 'React'
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
105
|
+
type CliConfig = {
|
|
106
|
+
app: AppConfig;
|
|
107
|
+
monkey?: MonkeyConfig;
|
|
108
|
+
source?: SourceConfig;
|
|
109
|
+
runtime?: {
|
|
110
|
+
setup?: string | string[];
|
|
111
|
+
};
|
|
112
|
+
};
|
|
110
113
|
```
|
|
111
114
|
|
|
112
|
-
|
|
115
|
+
### `AppConfig`
|
|
113
116
|
|
|
114
117
|
```ts
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
name: 'profile',
|
|
121
|
-
injectAt: '#app',
|
|
122
|
-
component: './profile-card/app.vue',
|
|
123
|
-
framework: 'Vue'
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
});
|
|
118
|
+
type AppConfig = {
|
|
119
|
+
name: string;
|
|
120
|
+
version: string;
|
|
121
|
+
description?: string;
|
|
122
|
+
};
|
|
127
123
|
```
|
|
128
124
|
|
|
129
|
-
|
|
125
|
+
### `SourceConfig`
|
|
130
126
|
|
|
131
127
|
```ts
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
component: './app.vue',
|
|
137
|
-
framework: 'Vue',
|
|
138
|
-
alive: true
|
|
139
|
-
});
|
|
128
|
+
type SourceConfig = {
|
|
129
|
+
include?: string[];
|
|
130
|
+
exclude?: string[];
|
|
131
|
+
};
|
|
140
132
|
```
|
|
141
133
|
|
|
142
|
-
|
|
134
|
+
`include` 和 `exclude` 匹配 injection 模块目录名。
|
|
143
135
|
|
|
144
|
-
|
|
145
|
-
| --- | --- |
|
|
146
|
-
| `injectAt` | 目标 DOM 选择器 |
|
|
147
|
-
| `component` | 组件路径,相对于顶层 manifest 或模块目录 |
|
|
148
|
-
| `framework` | `Vue`、`React` 或 `auto`;省略时根据文件扩展名推断 |
|
|
149
|
-
| `enabled` | 是否启用该模块,默认 `true` |
|
|
150
|
-
| `match` | 模块级 URL 匹配规则 |
|
|
151
|
-
| `alive` | 目标 DOM 被移除后是否尝试重注入 |
|
|
152
|
-
| `scope` | alive 观察范围,支持 `local` 和 `global` |
|
|
153
|
-
| `timeout` | 等待目标 DOM 的超时时间 |
|
|
154
|
-
| `hooks` | 传给 `@makoojs/core` 的生命周期观察 hooks |
|
|
155
|
-
|
|
156
|
-
`match` 支持数组简写:
|
|
136
|
+
### `MonkeyConfig`
|
|
157
137
|
|
|
158
138
|
```ts
|
|
159
|
-
|
|
139
|
+
type MonkeyConfig = {
|
|
140
|
+
userscript?: MonkeyUserScript;
|
|
141
|
+
align?: number | false;
|
|
142
|
+
generate?: (options: {
|
|
143
|
+
userscript: string;
|
|
144
|
+
mode: 'serve' | 'build' | 'meta';
|
|
145
|
+
}) => string | Promise<string>;
|
|
146
|
+
styleImport?: boolean;
|
|
147
|
+
server?: MonkeyServerConfig;
|
|
148
|
+
build?: MonkeyBuildConfig;
|
|
149
|
+
};
|
|
160
150
|
```
|
|
161
151
|
|
|
162
|
-
|
|
152
|
+
### `MonkeyServerConfig`
|
|
163
153
|
|
|
164
154
|
```ts
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
155
|
+
type MonkeyServerConfig = {
|
|
156
|
+
open?: boolean;
|
|
157
|
+
prefix?: string | ((name: string) => string) | false;
|
|
158
|
+
};
|
|
169
159
|
```
|
|
170
160
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
## 配置概览
|
|
174
|
-
|
|
175
|
-
`makoo()` 的主要配置分为四块:
|
|
161
|
+
### `MonkeyBuildConfig`
|
|
176
162
|
|
|
177
163
|
```ts
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
userscript: {
|
|
193
|
-
match: ['https://example.com/*']
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
});
|
|
164
|
+
type MonkeyBuildConfig = {
|
|
165
|
+
fileName?: string;
|
|
166
|
+
metaFileName?: string | boolean | ((fileName: string) => string);
|
|
167
|
+
externalGlobals?: ExternalGlobals;
|
|
168
|
+
autoGrant?: boolean;
|
|
169
|
+
externalResource?: ExternalResource;
|
|
170
|
+
systemjs?: 'inline' | ((
|
|
171
|
+
version: string,
|
|
172
|
+
packageName: string,
|
|
173
|
+
importName?: string,
|
|
174
|
+
resolveName?: string
|
|
175
|
+
) => string);
|
|
176
|
+
cssSideEffects?: string | ((css: string) => void);
|
|
177
|
+
};
|
|
197
178
|
```
|
|
198
179
|
|
|
199
|
-
|
|
200
|
-
| --- | --- |
|
|
201
|
-
| `app` | 用于生成 userscript 的 `name`、`version`、`description` |
|
|
202
|
-
| `source` | 控制扫描哪些 injection 模块目录 |
|
|
203
|
-
| `runtime` | 控制 Makoo 生成入口里的运行时前置 setup import |
|
|
204
|
-
| `monkey` | 大多数配置会透传给 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) |
|
|
180
|
+
## `defineInjections()`
|
|
205
181
|
|
|
206
|
-
|
|
182
|
+
声明顶层 `InjectionManifest`,并保留传入对象的具体类型。
|
|
207
183
|
|
|
208
|
-
|
|
184
|
+
### Type
|
|
209
185
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
186
|
+
```ts
|
|
187
|
+
function defineInjections<T extends InjectionManifest>(
|
|
188
|
+
manifest: StrictShape<InjectionManifest, T>
|
|
189
|
+
): T;
|
|
190
|
+
```
|
|
213
191
|
|
|
214
|
-
|
|
192
|
+
### Returns
|
|
215
193
|
|
|
216
|
-
|
|
194
|
+
原样返回 `manifest`。
|
|
217
195
|
|
|
218
|
-
|
|
196
|
+
### Example
|
|
219
197
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
198
|
+
```ts
|
|
199
|
+
export default defineInjections({
|
|
200
|
+
injectionDefaults: {
|
|
201
|
+
alive: true
|
|
202
|
+
},
|
|
203
|
+
injections: {
|
|
204
|
+
panel: {
|
|
205
|
+
injectAt: 'body',
|
|
206
|
+
component: './panel/App.vue'
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
listeners: {
|
|
210
|
+
escape: {
|
|
211
|
+
listenAt: 'body',
|
|
212
|
+
type: 'keydown',
|
|
213
|
+
callback: onEscape
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
```
|
|
232
218
|
|
|
233
|
-
|
|
219
|
+
## `defineInjection()`
|
|
234
220
|
|
|
235
|
-
|
|
236
|
-
2. 扫描 `injections` 下符合 `source.include` / `source.exclude` 的模块目录。
|
|
237
|
-
3. 读取模块级 `manifest.ts`,并与顶层 manifest 合并。
|
|
238
|
-
4. 解析组件路径、模块 ID、framework、match、alive、scope、timeout 等配置。
|
|
239
|
-
5. 根据实际使用到的 framework 生成 adapter import。
|
|
240
|
-
6. 生成虚拟入口,创建 Makoo runtime,声明任务并执行 `start()`。
|
|
241
|
-
7. 把虚拟入口交给 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 打包成 userscript。
|
|
221
|
+
声明单个 `InjectionModuleConfig`,并保留传入对象的具体类型。
|
|
242
222
|
|
|
243
|
-
|
|
223
|
+
### Type
|
|
244
224
|
|
|
245
|
-
|
|
225
|
+
```ts
|
|
226
|
+
function defineInjection<T extends InjectionModuleConfig>(
|
|
227
|
+
config: StrictShape<InjectionModuleConfig, T>
|
|
228
|
+
): T;
|
|
229
|
+
```
|
|
246
230
|
|
|
247
|
-
|
|
231
|
+
### Returns
|
|
248
232
|
|
|
249
|
-
|
|
250
|
-
| --- | --- |
|
|
251
|
-
| 顶层 `injections/manifest.ts` 修改 | 重新扫描并更新虚拟入口 |
|
|
252
|
-
| 模块级 `injections/<module>/manifest.ts` 修改 | 重新扫描并更新虚拟入口 |
|
|
253
|
-
| manifest 静态导入的本地 helper 修改 | 追踪依赖并重新扫描更新虚拟入口 |
|
|
254
|
-
| 模块目录新增或删除 | 重新扫描并更新虚拟入口 |
|
|
255
|
-
| 普通组件文件修改 | 交给 Vite 原生 HMR 处理 |
|
|
256
|
-
| 第三方依赖变化 | 不作为 Makoo 结构扫描依赖 |
|
|
233
|
+
原样返回 `config`。
|
|
257
234
|
|
|
258
|
-
|
|
235
|
+
### Example
|
|
259
236
|
|
|
260
|
-
|
|
237
|
+
```ts
|
|
238
|
+
export default defineInjection({
|
|
239
|
+
name: 'panel',
|
|
240
|
+
injectAt: 'body',
|
|
241
|
+
component: './App.vue',
|
|
242
|
+
hooks: {
|
|
243
|
+
'artifact:mountSuccess': onMounted
|
|
244
|
+
},
|
|
245
|
+
on: {
|
|
246
|
+
listenAt: 'body',
|
|
247
|
+
type: 'click',
|
|
248
|
+
callback: onClick
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
```
|
|
261
252
|
|
|
262
|
-
|
|
253
|
+
## Manifest 类型
|
|
263
254
|
|
|
264
|
-
|
|
255
|
+
### `InjectionManifest`
|
|
265
256
|
|
|
266
257
|
```ts
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
runtime: {
|
|
279
|
-
setup: ['./injections/vue-setup.ts']
|
|
280
|
-
},
|
|
281
|
-
monkey: {
|
|
282
|
-
userscript: {
|
|
283
|
-
match: ['https://example.com/*']
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
})
|
|
287
|
-
]
|
|
288
|
-
});
|
|
258
|
+
type InjectionManifest = {
|
|
259
|
+
injectionDefaults?: InjectionDefaults;
|
|
260
|
+
injections?: InjectionModuleConfig[] | Record<
|
|
261
|
+
string,
|
|
262
|
+
Omit<InjectionModuleConfig, 'name'>
|
|
263
|
+
>;
|
|
264
|
+
listeners?: InjectionListenerConfig[] | Record<
|
|
265
|
+
string,
|
|
266
|
+
Omit<InjectionListenerConfig, 'name'>
|
|
267
|
+
>;
|
|
268
|
+
};
|
|
289
269
|
```
|
|
290
270
|
|
|
291
|
-
|
|
292
|
-
// injections/vue-setup.ts
|
|
293
|
-
import { VuePlugin } from '@makoojs/vue';
|
|
294
|
-
import router from './router';
|
|
295
|
-
import i18n from './i18n';
|
|
271
|
+
### `InjectionDefaults`
|
|
296
272
|
|
|
297
|
-
|
|
273
|
+
```ts
|
|
274
|
+
type InjectionDefaults = {
|
|
275
|
+
alive?: boolean;
|
|
276
|
+
scope?: 'local' | 'global';
|
|
277
|
+
timeout?: number;
|
|
278
|
+
hooks?: LifecycleHookMap;
|
|
279
|
+
};
|
|
298
280
|
```
|
|
299
281
|
|
|
300
|
-
`
|
|
282
|
+
### `InjectionModuleConfig`
|
|
301
283
|
|
|
302
284
|
```ts
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
285
|
+
type InjectionModuleConfig = {
|
|
286
|
+
name?: string;
|
|
287
|
+
injectAt: string;
|
|
288
|
+
component: string;
|
|
289
|
+
framework?: InjectionFramework;
|
|
290
|
+
enabled?: boolean;
|
|
291
|
+
match?: InjectionMatchConfig;
|
|
292
|
+
alive?: boolean;
|
|
293
|
+
scope?: 'local' | 'global';
|
|
294
|
+
timeout?: number;
|
|
295
|
+
hooks?: LifecycleHookMap;
|
|
296
|
+
on?: InjectionModuleListenerConfig;
|
|
297
|
+
};
|
|
309
298
|
```
|
|
310
299
|
|
|
311
|
-
|
|
300
|
+
### `InjectionListenerConfig`
|
|
312
301
|
|
|
313
|
-
|
|
302
|
+
```ts
|
|
303
|
+
type InjectionModuleListenerConfig = {
|
|
304
|
+
listenAt: string;
|
|
305
|
+
type: string;
|
|
306
|
+
callback: EventListener;
|
|
307
|
+
activitySignal?: () => ActivitySignalSource<boolean>;
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
type InjectionListenerConfig = InjectionModuleListenerConfig & {
|
|
311
|
+
name?: string;
|
|
312
|
+
enabled?: boolean;
|
|
313
|
+
match?: InjectionMatchConfig;
|
|
314
|
+
};
|
|
315
|
+
```
|
|
314
316
|
|
|
315
|
-
|
|
317
|
+
### `InjectionFramework`
|
|
316
318
|
|
|
317
319
|
```ts
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
gmStyle.add('.makoo-panel { z-index: 999999; }');
|
|
321
|
-
gmStorage.set('enabled', true);
|
|
320
|
+
type InjectionFramework = 'auto' | 'Vue' | 'React';
|
|
322
321
|
```
|
|
323
322
|
|
|
324
|
-
|
|
323
|
+
### `InjectionMatchConfig`
|
|
325
324
|
|
|
326
325
|
```ts
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
326
|
+
type InjectionMatchConfig =
|
|
327
|
+
| string[]
|
|
328
|
+
| {
|
|
329
|
+
include?: string[];
|
|
330
|
+
exclude?: string[];
|
|
331
|
+
};
|
|
330
332
|
```
|
|
331
333
|
|
|
332
|
-
|
|
334
|
+
## GM API
|
|
333
335
|
|
|
334
|
-
|
|
336
|
+
以下值从 `@makoojs/cli/monkey` 导出。
|
|
335
337
|
|
|
336
|
-
|
|
338
|
+
| 导出 | 方法或值 |
|
|
339
|
+
| --- | --- |
|
|
340
|
+
| `GMapi` | 包含 `raw`、`info`、`log`、`storage`、`style`、`request`、`menu`、`clipboard`、`notification`、`tab`、`download` 和 `resource` |
|
|
341
|
+
| `gm` | 原始 `GM` 对象 |
|
|
342
|
+
| `gmInfo` | `GM_info` |
|
|
343
|
+
| `gmLog` | `GM_log` |
|
|
344
|
+
| `monkeyWindow` | userscript window |
|
|
345
|
+
| `unsafeWindow` | 页面 window |
|
|
346
|
+
| `gmClipboard` | `set(data, type?, callback?)` |
|
|
347
|
+
| `gmDownload` | `start` |
|
|
348
|
+
| `gmMenu` | `register`、`unregister` |
|
|
349
|
+
| `gmNotification` | `show` |
|
|
350
|
+
| `gmRequest` | `send`、`get`、`post` |
|
|
351
|
+
| `gmResource` | `text`、`url` |
|
|
352
|
+
| `gmStorage` | `get`、`getMany`、`set`、`setMany`、`remove`、`removeMany`、`keys`、`watch`、`unwatch` |
|
|
353
|
+
| `gmStyle` | `add`、`element` |
|
|
354
|
+
| `gmTab` | `open`、`get`、`getAll`、`save` |
|
|
355
|
+
|
|
356
|
+
### `gmRequest.get()` / `gmRequest.post()`
|
|
337
357
|
|
|
338
358
|
```ts
|
|
339
|
-
|
|
340
|
-
|
|
359
|
+
gmRequest.get<R extends GmResponseType = 'text', C = unknown>(
|
|
360
|
+
url: string,
|
|
361
|
+
options?: GmRequestOptions<R, C>
|
|
362
|
+
): GmAbortHandle;
|
|
363
|
+
|
|
364
|
+
gmRequest.post<R extends GmResponseType = 'text', C = unknown>(
|
|
365
|
+
url: string,
|
|
366
|
+
options?: GmRequestOptions<R, C>
|
|
367
|
+
): GmAbortHandle;
|
|
368
|
+
```
|
|
341
369
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
vue: cdn.jsdelivr('Vue', 'dist/vue.global.prod.js')
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
})
|
|
356
|
-
});
|
|
370
|
+
`get()` 和 `post()` 分别固定请求方法为 `GET` 和 `POST`。
|
|
371
|
+
|
|
372
|
+
## GM 类型
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
type GmRequestOptions<R extends GmResponseType = 'text', C = unknown> = Omit<
|
|
376
|
+
GmXmlhttpRequestOption<R, C>,
|
|
377
|
+
'url' | 'method'
|
|
378
|
+
>;
|
|
357
379
|
```
|
|
358
380
|
|
|
359
|
-
|
|
381
|
+
`@makoojs/cli/monkey` 还重新导出以下 `vite-plugin-monkey` 类型:
|
|
382
|
+
|
|
383
|
+
- `GmAbortHandle`
|
|
384
|
+
- `GmAddElementAttributes`
|
|
385
|
+
- `GmDownloadOptions`
|
|
386
|
+
- `GmInfoType`
|
|
387
|
+
- `GmMenuCommandOptions`
|
|
388
|
+
- `GmNotificationOptions`
|
|
389
|
+
- `GmOpenInTabOptions`
|
|
390
|
+
- `GmResponseEvent`
|
|
391
|
+
- `GmResponseType`
|
|
392
|
+
- `GmTabControl`
|
|
393
|
+
- `GmType`
|
|
394
|
+
- `GmValueListenerId`
|
|
395
|
+
- `GmXmlhttpRequestOption`
|
|
396
|
+
- `MonkeyWindow`
|
|
360
397
|
|
|
361
|
-
|
|
362
|
-
| --- | --- |
|
|
363
|
-
| `@makoojs/cli` | Vite 插件、CLI 命令、扫描、代码生成和 userscript 构建接入 |
|
|
364
|
-
| `@makoojs/core` | 框架无关的注入运行时内核 |
|
|
365
|
-
| `@makoojs/vue` | Vue adapter 与 Vue 插件注册辅助 |
|
|
366
|
-
| `@makoojs/react` | React adapter |
|
|
367
|
-
| `@makoojs/create-makoo` | 项目脚手架 |
|
|
398
|
+
## CLI 命令
|
|
368
399
|
|
|
369
|
-
|
|
400
|
+
| 命令 | 说明 |
|
|
401
|
+
| --- | --- |
|
|
402
|
+
| `makoo dev` | 启动 Vite 开发服务器 |
|
|
403
|
+
| `makoo build` | 执行 Vite 构建 |
|
|
404
|
+
| `makoo add <name>` | 创建 React injection 模块并更新 manifest |
|
|
405
|
+
| `makoo add <name> --framework Vue` | 创建 Vue injection 模块并更新 manifest |
|
|
406
|
+
| `makoo inspect` | 输出解析后的配置、扫描结果和 framework 信息 |
|