@makoojs/cli 0.4.1 → 0.5.1

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.
Files changed (61) hide show
  1. package/README.CN.md +48 -387
  2. package/README.md +48 -387
  3. package/dist/bin.js +594 -1141
  4. package/dist/cli/commands/build.d.ts +2 -0
  5. package/dist/cli/commands/dev/DevTerminal.d.ts +51 -0
  6. package/dist/cli/commands/dev/dev.d.ts +2 -0
  7. package/dist/cli/commands/preview.d.ts +2 -0
  8. package/dist/cli/injections/renderInjections.d.ts +2 -0
  9. package/dist/{shared → cli}/terminalColor.d.ts +2 -0
  10. package/dist/cli/version.d.ts +1 -0
  11. package/dist/config/defaults.d.ts +3 -24
  12. package/dist/config/errors.d.ts +3 -0
  13. package/dist/config/resolve.d.ts +6 -18
  14. package/dist/config/types.d.ts +8 -106
  15. package/dist/config/validation.d.ts +4 -7
  16. package/dist/index.cjs +89 -38
  17. package/dist/index.d.ts +3 -3
  18. package/dist/index.js +1008 -3255
  19. package/dist/session/DevSession.d.ts +14 -0
  20. package/dist/session/types.d.ts +47 -0
  21. package/dist/vite/makoo.d.ts +3 -0
  22. package/dist/vite/makooDev.d.ts +7 -0
  23. package/package.json +8 -13
  24. package/dist/command/_util.d.ts +0 -8
  25. package/dist/command/add.d.ts +0 -1
  26. package/dist/command/build.d.ts +0 -1
  27. package/dist/command/dev.d.ts +0 -1
  28. package/dist/command/inspect.d.ts +0 -35
  29. package/dist/config/config.d.ts +0 -3
  30. package/dist/error/MakooCliError.d.ts +0 -58
  31. package/dist/generator/generator.d.ts +0 -3
  32. package/dist/generator/render/import/importAdapter.d.ts +0 -3
  33. package/dist/generator/render/import/importComp.d.ts +0 -3
  34. package/dist/generator/render/import/importMakooRuntime.d.ts +0 -1
  35. package/dist/generator/render/import/importManifest.d.ts +0 -3
  36. package/dist/generator/render/import/importRuntimeSetup.d.ts +0 -1
  37. package/dist/generator/render/init/initMakooRuntime.d.ts +0 -4
  38. package/dist/generator/render/init/registerComp.d.ts +0 -3
  39. package/dist/generator/render/init/registerListener.d.ts +0 -4
  40. package/dist/generator/render/run/renderMakooStart.d.ts +0 -1
  41. package/dist/generator/render/util/match.d.ts +0 -1
  42. package/dist/generator/render/util/value.d.ts +0 -1
  43. package/dist/generator/types.d.ts +0 -27
  44. package/dist/manifest/index.cjs +0 -1
  45. package/dist/manifest/index.d.ts +0 -2
  46. package/dist/manifest/index.js +0 -7
  47. package/dist/scanner/collectDependenics.d.ts +0 -2
  48. package/dist/scanner/load/loadManifes.d.ts +0 -3
  49. package/dist/scanner/load/loadMeta.d.ts +0 -2
  50. package/dist/scanner/manifestBinding.d.ts +0 -14
  51. package/dist/scanner/scanner.d.ts +0 -3
  52. package/dist/scanner/types.d.ts +0 -50
  53. package/dist/scanner/util.d.ts +0 -2
  54. package/dist/scanner/validation.d.ts +0 -190
  55. package/dist/vitePlugin/hmrController.d.ts +0 -6
  56. package/dist/vitePlugin/makoo.d.ts +0 -3
  57. package/dist/vitePlugin/makooMonkey.d.ts +0 -3
  58. package/dist/vitePlugin/types.d.ts +0 -18
  59. package/dist/vitePlugin/virtualModule.d.ts +0 -2
  60. package/dist/vitePlugin/watchList.d.ts +0 -5
  61. /package/dist/{command → cli}/bin.d.ts +0 -0
package/README.md CHANGED
@@ -1,412 +1,73 @@
1
- # CLI API Reference
1
+ # @makoojs/cli
2
2
 
3
- ## API Index
3
+ <p>
4
+ <a href="https://www.npmjs.com/package/@makoojs/cli"><img alt="npm" src="https://img.shields.io/npm/v/@makoojs/cli?style=flat-square"></a>
5
+ <a href="https://github.com/makoojs/Makoo/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/badge/License-MIT-yellow?style=flat-square"></a>
6
+ </p>
4
7
 
5
- ### `@makoojs/cli`
8
+ <p>
9
+ <a href="https://makoojs.github.io/Makoo/api/vite">API Reference</a> •
10
+ <a href="https://github.com/makoojs/Makoo">Makoo</a> •
11
+ <a href="https://github.com/makoojs/Makoo/blob/main/packages/cli/README.CN.md">中文</a>
12
+ </p>
6
13
 
7
- - [`makoo()`](#makoo): creates the Makoo and userscript Vite plugins
8
- - [`cdn`](#cdn): creates CDN configuration for external dependencies
9
- - [Configuration types](#configuration-types): `MakooOptions`, `CliConfig`, and monkey configuration
14
+ The toolchain package for Makoo. It provides two Vite plugins, `makoo()` and `makooDev()`, the `makoo dev` / `build` / `preview` commands, and `@makoojs/cli/monkey` for calling GM APIs from your script. Userscript metadata, the dev server, and builds are handled by [vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey).
10
15
 
11
- ### `@makoojs/cli/manifest`
16
+ ## Installation
12
17
 
13
- - [`defineInjections()`](#defineinjections): declares a top-level manifest
14
- - [`defineInjection()`](#defineinjection): declares a module manifest
15
- - [Manifest types](#manifest-types)
16
-
17
- ### `@makoojs/cli/monkey`
18
-
19
- - [GM APIs](#gm-apis): userscript API wrappers
20
- - [GM types](#gm-types)
21
-
22
- ### Command line
23
-
24
- - [CLI commands](#cli-commands)
25
-
26
- ## `makoo()`
27
-
28
- Creates Vite plugins from Makoo configuration.
29
-
30
- ### Type
31
-
32
- ```ts
33
- function makoo(options: MakooOptions): Plugin[];
34
- ```
35
-
36
- ### Parameters
37
-
38
- `options` uses `MakooOptions`. Its `app` field is required.
39
-
40
- ### Returns
41
-
42
- Returns `Plugin[]`. Use spread syntax in the Vite configuration.
43
-
44
- ### Example
45
-
46
- ```ts
47
- export default defineConfig({
48
- plugins: [
49
- ...makoo({
50
- app: {
51
- name: 'my-script',
52
- version: '0.0.1'
53
- },
54
- monkey: {
55
- userscript: {
56
- match: ['https://example.com/*']
57
- }
58
- }
59
- })
60
- ]
61
- });
62
- ```
63
-
64
- ## `cdn`
65
-
66
- CDN configuration factories re-exported from `vite-plugin-monkey`.
67
-
68
- ### Type
69
-
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
- };
18
+ ```sh
19
+ pnpm add -D @makoojs/cli vite
88
20
  ```
89
21
 
90
- `bootcdn` and `staticfile` are marked as deprecated by `vite-plugin-monkey`.
22
+ > [!TIP]
23
+ > Projects created with `pnpm dlx @makoojs/create-makoo` already have it configured; no separate installation is needed.
91
24
 
92
- ## Configuration types
25
+ ## Usage
93
26
 
94
- ### `MakooOptions`
27
+ ### Configure Vite
95
28
 
96
29
  ```ts
97
- type MakooOptions = CliConfig & {
98
- root?: string;
99
- };
100
- ```
101
-
102
- ### `CliConfig`
103
-
104
- ```ts
105
- type CliConfig = {
106
- app: AppConfig;
107
- monkey?: MonkeyConfig;
108
- source?: SourceConfig;
109
- runtime?: {
110
- setup?: string | string[];
111
- };
112
- };
113
- ```
114
-
115
- ### `AppConfig`
116
-
117
- ```ts
118
- type AppConfig = {
119
- name: string;
120
- version: string;
121
- description?: string;
122
- };
123
- ```
124
-
125
- ### `SourceConfig`
126
-
127
- ```ts
128
- type SourceConfig = {
129
- include?: string[];
130
- exclude?: string[];
131
- };
132
- ```
133
-
134
- `include` and `exclude` match injection module directory names.
135
-
136
- ### `MonkeyConfig`
137
-
138
- ```ts
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
- };
150
- ```
151
-
152
- ### `MonkeyServerConfig`
153
-
154
- ```ts
155
- type MonkeyServerConfig = {
156
- open?: boolean;
157
- prefix?: string | ((name: string) => string) | false;
158
- };
159
- ```
160
-
161
- ### `MonkeyBuildConfig`
162
-
163
- ```ts
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
- };
178
- ```
179
-
180
- ## `defineInjections()`
181
-
182
- Declares a top-level `InjectionManifest` while preserving the specific type of the provided object.
183
-
184
- ### Type
30
+ // vite.config.ts
31
+ import { defineConfig } from 'vite';
32
+ import vue from '@vitejs/plugin-vue';
33
+ import { makoo, makooDev } from '@makoojs/cli';
185
34
 
186
- ```ts
187
- function defineInjections<T extends InjectionManifest>(
188
- manifest: StrictShape<InjectionManifest, T>
189
- ): T;
190
- ```
191
-
192
- ### Returns
193
-
194
- Returns `manifest` unchanged.
195
-
196
- ### Example
197
-
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
- capture: true,
214
- callback: onEscape
215
- }
216
- }
217
- });
218
- ```
219
-
220
- ## `defineInjection()`
221
-
222
- Declares one `InjectionModuleConfig` while preserving the specific type of the provided object.
223
-
224
- ### Type
225
-
226
- ```ts
227
- function defineInjection<T extends InjectionModuleConfig>(
228
- config: StrictShape<InjectionModuleConfig, T>
229
- ): T;
230
- ```
231
-
232
- ### Returns
233
-
234
- Returns `config` unchanged.
235
-
236
- ### Example
237
-
238
- ```ts
239
- export default defineInjection({
240
- name: 'panel',
241
- injectAt: 'body',
242
- component: './App.vue',
243
- hooks: {
244
- 'artifact:mountSuccess': onMounted
245
- },
246
- on: {
247
- listenAt: 'body',
248
- type: 'click',
249
- capture: true,
250
- callback: onClick
251
- }
35
+ export default defineConfig({
36
+ plugins: [
37
+ vue(),
38
+ makoo({
39
+ entry: './src/main.ts',
40
+ app: { name: 'my-script', version: '0.0.1' },
41
+ monkey: { userscript: { match: ['https://example.com/*'] } }
42
+ }),
43
+ // optional: view injection status in the dev terminal
44
+ makooDev()
45
+ ]
252
46
  });
253
47
  ```
254
48
 
255
- ## Manifest types
256
-
257
- ### `InjectionManifest`
258
-
259
- ```ts
260
- type InjectionManifest = {
261
- injectionDefaults?: InjectionDefaults;
262
- injections?: InjectionModuleConfig[] | Record<
263
- string,
264
- Omit<InjectionModuleConfig, 'name'>
265
- >;
266
- listeners?: InjectionListenerConfig[] | Record<
267
- string,
268
- Omit<InjectionListenerConfig, 'name'>
269
- >;
270
- };
271
- ```
272
-
273
- ### `InjectionDefaults`
274
-
275
- ```ts
276
- type InjectionDefaults = {
277
- alive?: boolean;
278
- scope?: 'local' | 'global';
279
- timeout?: number;
280
- hooks?: LifecycleHookMap;
281
- };
282
- ```
283
-
284
- ### `InjectionModuleConfig`
285
-
286
- ```ts
287
- type InjectionModuleConfig = {
288
- name?: string;
289
- injectAt: string;
290
- component: string;
291
- framework?: InjectionFramework;
292
- enabled?: boolean;
293
- match?: InjectionMatchConfig;
294
- alive?: boolean;
295
- scope?: 'local' | 'global';
296
- timeout?: number;
297
- hooks?: LifecycleHookMap;
298
- on?: InjectionModuleListenerConfig;
299
- };
300
- ```
301
-
302
- ### `InjectionListenerConfig`
49
+ ### Develop and Build
303
50
 
304
- ```ts
305
- type InjectionModuleListenerConfig = {
306
- listenAt: string;
307
- type: string;
308
- callback: EventListener;
309
- capture?: boolean;
310
- activitySignal?: () => ActivitySignalSource<boolean>;
311
- };
312
-
313
- type InjectionListenerConfig = InjectionModuleListenerConfig & {
314
- name?: string;
315
- enabled?: boolean;
316
- match?: InjectionMatchConfig;
317
- };
51
+ ```sh
52
+ makoo dev # start the dev server; install the dev script from the printed address
53
+ makoo build # build the .user.js
54
+ makoo preview # preview the build output
318
55
  ```
319
56
 
320
- Set `capture: true` to listen during the DOM capture phase. It defaults to `false`, so listeners
321
- use the bubbling phase unless explicitly configured. Makoo manages the event listener signal.
57
+ ### Call GM APIs
322
58
 
323
- ### `InjectionFramework`
59
+ Import by capability in browser code, and the build only generates `@grant` for the APIs you use:
324
60
 
325
61
  ```ts
326
- type InjectionFramework = 'auto' | 'Vue' | 'React';
327
- ```
328
-
329
- ### `InjectionMatchConfig`
62
+ import { gmStorage } from '@makoojs/cli/monkey';
330
63
 
331
- ```ts
332
- type InjectionMatchConfig =
333
- | string[]
334
- | {
335
- include?: string[];
336
- exclude?: string[];
337
- };
64
+ const runs = gmStorage.get<number>('runs', 0) + 1;
65
+ gmStorage.set('runs', runs);
338
66
  ```
339
67
 
340
- ## GM APIs
341
-
342
- The following values are exported from `@makoojs/cli/monkey`.
343
-
344
- | Export | Methods or value |
345
- | --- | --- |
346
- | `GMapi` | Contains `raw`, `info`, `log`, `storage`, `style`, `request`, `menu`, `clipboard`, `notification`, `tab`, `download`, and `resource` |
347
- | `gm` | Original `GM` object |
348
- | `gmInfo` | `GM_info` |
349
- | `gmLog` | `GM_log` |
350
- | `monkeyWindow` | Userscript window |
351
- | `unsafeWindow` | Page window |
352
- | `gmClipboard` | `set(data, type?, callback?)` |
353
- | `gmDownload` | `start` |
354
- | `gmMenu` | `register`, `unregister` |
355
- | `gmNotification` | `show` |
356
- | `gmRequest` | `send`, `get`, `post` |
357
- | `gmResource` | `text`, `url` |
358
- | `gmStorage` | `get`, `getMany`, `set`, `setMany`, `remove`, `removeMany`, `keys`, `watch`, `unwatch` |
359
- | `gmStyle` | `add`, `element` |
360
- | `gmTab` | `open`, `get`, `getAll`, `save` |
361
-
362
- ### `gmRequest.get()` / `gmRequest.post()`
363
-
364
- ```ts
365
- gmRequest.get<R extends GmResponseType = 'text', C = unknown>(
366
- url: string,
367
- options?: GmRequestOptions<R, C>
368
- ): GmAbortHandle;
369
-
370
- gmRequest.post<R extends GmResponseType = 'text', C = unknown>(
371
- url: string,
372
- options?: GmRequestOptions<R, C>
373
- ): GmAbortHandle;
374
- ```
375
-
376
- `get()` and `post()` set the request method to `GET` and `POST`, respectively.
377
-
378
- ## GM types
379
-
380
- ```ts
381
- type GmRequestOptions<R extends GmResponseType = 'text', C = unknown> = Omit<
382
- GmXmlhttpRequestOption<R, C>,
383
- 'url' | 'method'
384
- >;
385
- ```
386
-
387
- `@makoojs/cli/monkey` also re-exports these types from `vite-plugin-monkey`:
388
-
389
- - `GmAbortHandle`
390
- - `GmAddElementAttributes`
391
- - `GmDownloadOptions`
392
- - `GmInfoType`
393
- - `GmMenuCommandOptions`
394
- - `GmNotificationOptions`
395
- - `GmOpenInTabOptions`
396
- - `GmResponseEvent`
397
- - `GmResponseType`
398
- - `GmTabControl`
399
- - `GmType`
400
- - `GmValueListenerId`
401
- - `GmXmlhttpRequestOption`
402
- - `MonkeyWindow`
403
-
404
- ## CLI commands
68
+ ## Documentation
405
69
 
406
- | Command | Description |
407
- | --- | --- |
408
- | `makoo dev` | Starts the Vite development server |
409
- | `makoo build` | Runs a Vite build |
410
- | `makoo add <name>` | Creates a React injection module and updates the manifest |
411
- | `makoo add <name> --framework Vue` | Creates a Vue injection module and updates the manifest |
412
- | `makoo inspect` | Prints resolved configuration, scan results, and framework information |
70
+ - [Vite Plugins](https://makoojs.github.io/Makoo/api/vite): all `makoo()` options, defaults, and `makooDev()`.
71
+ - [CLI Commands](https://makoojs.github.io/Makoo/api/cli): options for each command.
72
+ - [Userscript API](https://makoojs.github.io/Makoo/api/monkey): the GM APIs exported by `@makoojs/cli/monkey`.
73
+ - [Project Configuration](https://makoojs.github.io/Makoo/docs/configuration): configuring match URLs, permissions, and external dependencies.