@makoojs/cli 0.5.0 → 0.6.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.
Files changed (50) hide show
  1. package/README.CN.md +43 -124
  2. package/README.md +43 -124
  3. package/dist/DevTerminal-BtHO2wRA.js +2396 -0
  4. package/dist/DevTerminal-DNh8U_O4.cjs +30 -0
  5. package/dist/bin.js +29 -491
  6. package/dist/bridge/protocol.d.ts +64 -0
  7. package/dist/bridge/runtime.cjs +1 -0
  8. package/dist/bridge/runtime.d.ts +38 -0
  9. package/dist/bridge/runtime.js +168 -0
  10. package/dist/bridge/server.d.ts +15 -0
  11. package/dist/bridge/store.d.ts +17 -0
  12. package/dist/commands/version.d.ts +1 -0
  13. package/dist/config/resolve.d.ts +1 -5
  14. package/dist/config/types.d.ts +40 -9
  15. package/dist/errors.d.ts +766 -0
  16. package/dist/index.cjs +2 -181
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +217 -2975
  19. package/dist/monkey/clipboard.d.ts +2 -0
  20. package/dist/monkey/download.d.ts +2 -0
  21. package/dist/monkey/index.d.ts +1 -0
  22. package/dist/monkey/info.d.ts +3 -0
  23. package/dist/monkey/menu.d.ts +3 -0
  24. package/dist/monkey/notification.d.ts +2 -0
  25. package/dist/monkey/request.d.ts +8 -0
  26. package/dist/monkey/resource.d.ts +3 -0
  27. package/dist/monkey/storage.d.ts +10 -0
  28. package/dist/monkey/style.d.ts +3 -0
  29. package/dist/monkey/tab.d.ts +5 -0
  30. package/dist/protocol-D8uLFi4g.cjs +1 -0
  31. package/dist/protocol-ZRHs80xs.js +4 -0
  32. package/dist/{cli/commands/dev → tui}/DevTerminal.d.ts +14 -8
  33. package/dist/tui/renderInjections.d.ts +2 -0
  34. package/dist/version-DiRsgSMp.js +19 -0
  35. package/dist/version-ENbM57wf.cjs +1 -0
  36. package/dist/vite/makoo.d.ts +3 -0
  37. package/dist/vite/makooDev.d.ts +28 -6
  38. package/package.json +5 -6
  39. package/dist/cli/tasks/renderTasks.d.ts +0 -2
  40. package/dist/cli/version.d.ts +0 -1
  41. package/dist/config/defaults.d.ts +0 -5
  42. package/dist/config/errors.d.ts +0 -14
  43. package/dist/config/validation.d.ts +0 -11
  44. package/dist/session/DevSession.d.ts +0 -13
  45. package/dist/session/types.d.ts +0 -22
  46. /package/dist/{cli → commands}/bin.d.ts +0 -0
  47. /package/dist/{cli/commands → commands}/build.d.ts +0 -0
  48. /package/dist/{cli/commands/dev → commands}/dev.d.ts +0 -0
  49. /package/dist/{cli/commands → commands}/preview.d.ts +0 -0
  50. /package/dist/{cli → tui}/terminalColor.d.ts +0 -0
package/README.CN.md CHANGED
@@ -1,154 +1,73 @@
1
1
  # @makoojs/cli
2
2
 
3
- `@makoojs/cli` 提供 Makoo 的 Vite 插件和 CLI 命令,并通过 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 提供 userscript 的开发与构建能力。
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/core` 的 `createMakoo()`、`inject()` 和 `listen()` 编排运行时行为;`@makoojs/cli` 负责 Vite 和 userscript 构建部分。
8
+ <p>
9
+ <a href="https://makoojs.github.io/Makoo/zh/api/vite">API 参考</a> •
10
+ <a href="https://github.com/makoojs/Makoo">Makoo</a> •
11
+ <a href="https://github.com/makoojs/Makoo/blob/main/packages/cli/README.md">English</a>
12
+ </p>
6
13
 
7
- ## 适用场景
8
-
9
- - 使用 Vite 开发 Makoo userscript 项目。
10
- - 通过 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 生成 userscript 元信息、开发入口和构建产物。
11
- - 使用 `makoo dev` 和 `makoo build` 命令。
12
- - 通过 `@makoojs/cli/monkey` 使用 GM API 的 Makoo 稳定入口。
14
+ Makoo 的工具链包。它提供 `makoo()` 与 `makooDev()` 两个 Vite 插件、`makoo dev` / `build` / `preview` 命令,以及在脚本中调用 GM API 的 `@makoojs/cli/monkey`。userscript 的元信息、开发服务与构建由 [vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 完成。
13
15
 
14
16
  ## 安装
15
17
 
16
- ```bash
17
- # npm install @makoojs/cli
18
- # yarn add @makoojs/cli
19
- pnpm add @makoojs/cli
18
+ ```sh
19
+ pnpm add -D @makoojs/cli vite
20
20
  ```
21
21
 
22
- 如果你使用 `@makoojs/create-makoo` 创建项目,通常会自动配置好 `@makoojs/cli`。
22
+ > [!TIP]
23
+ > 用 `pnpm dlx @makoojs/create-makoo` 创建的项目已经配置好了它,不需要单独安装。
23
24
 
24
- ## 最小 Vite 配置
25
+ ## 用法
25
26
 
26
- 在 Vite 配置中使用 `makoo()`:
27
+ ### 配置 Vite
27
28
 
28
29
  ```ts
30
+ // vite.config.ts
29
31
  import { defineConfig } from 'vite';
30
- import { makoo } from '@makoojs/cli';
31
32
  import vue from '@vitejs/plugin-vue';
33
+ import { makoo, makooDev } from '@makoojs/cli';
32
34
 
33
35
  export default defineConfig({
34
- plugins: [
35
- vue(),
36
- makoo({
37
- entry: './src/app.ts',
38
- app: {
39
- name: 'my-userscript',
40
- version: '0.0.1',
41
- description: 'My first Makoo script'
42
- },
43
- monkey: {
44
- userscript: {
45
- namespace: 'https://example.com',
46
- // 这里只是示例,请替换为 userscript 实际支持的页面。
47
- match: ['https://www.google.com/']
48
- }
49
- }
50
- })
51
- ]
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
+ // 可选:在开发终端查看注入状态
44
+ makooDev()
45
+ ]
52
46
  });
53
47
  ```
54
48
 
55
- `makoo()` 将配置交给 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 完成 userscript 的开发与构建。
56
-
57
- ## 配置概览
58
-
59
- `makoo()` 的主要配置分为三块:
60
-
61
- ```ts
62
- makoo({
63
- entry: './src/app.ts',
64
- app: {
65
- name: 'my-script',
66
- version: '0.0.1',
67
- description: 'demo script'
68
- },
69
- monkey: {
70
- userscript: {
71
- match: ['https://www.google.com/']
72
- }
73
- }
74
- });
75
- ```
76
-
77
- | 配置 | 说明 |
78
- | --- | --- |
79
- | `entry` | 交给 Vite 构建的应用模块 |
80
- | `app` | 用于生成 userscript 的 `name`、`version`、`description` |
81
- | `monkey` | 大多数配置会透传给 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) |
82
-
83
- 默认情况下,`monkey.build.autoGrant` 为 `true`,[lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 会根据最终代码生成 `@grant`。
84
-
85
- ## CLI 命令
86
-
87
- 安装后可以使用 `makoo` 命令:
88
-
89
- | 命令 | 说明 |
90
- | --- | --- |
91
- | `makoo dev` | 启动 Vite dev server,并打印本地访问地址 |
92
- | `makoo build` | 执行 Vite build,生成 userscript 构建产物 |
93
- | `makoo preview` | 使用 Vite preview server 预览构建后的 userscript |
94
-
95
- ## 使用 GM API
96
-
97
- `@makoojs/cli` 提供 `@makoojs/cli/monkey` 子入口,作为 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) GM API 的 Makoo 稳定封装。
98
-
99
- ```ts
100
- import { gmStorage, gmStyle } from '@makoojs/cli/monkey';
101
-
102
- gmStyle.add('.makoo-panel { z-index: 999999; }');
103
- gmStorage.set('enabled', true);
104
- ```
105
-
106
- 也可以使用聚合入口:
49
+ ### 开发与构建
107
50
 
108
- ```ts
109
- import { GMapi } from '@makoojs/cli/monkey';
110
-
111
- GMapi.storage.set('enabled', true);
51
+ ```sh
52
+ makoo dev # 启动开发服务,从打印的地址安装开发脚本
53
+ makoo build # 构建出 .user.js
54
+ makoo preview # 预览构建产物
112
55
  ```
113
56
 
114
- 如果希望生成的 `@grant` 范围尽量小,可以按能力导入。完整 GM API 见 CLI API 文档。
115
-
116
- ## 减小构建体积
57
+ ### 调用 GM API
117
58
 
118
- `@makoojs/cli` 重新导出了 [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) 的 `cdn`。可以配合 `monkey.build.externalGlobals` 使用 CDN 外部依赖,减小 userscript 构建体积。
59
+ 在浏览器代码中按能力导入,构建时会只为用到的 API 生成 `@grant`:
119
60
 
120
61
  ```ts
121
- import { defineConfig } from 'vite';
122
- import { cdn, makoo } from '@makoojs/cli';
62
+ import { gmStorage } from '@makoojs/cli/monkey';
123
63
 
124
- export default defineConfig({
125
- plugins: [
126
- makoo({
127
- entry: './src/app.ts',
128
- app: {
129
- name: 'my-script',
130
- version: '0.0.1'
131
- },
132
- monkey: {
133
- build: {
134
- externalGlobals: {
135
- vue: cdn.jsdelivr('Vue', 'dist/vue.global.prod.js')
136
- }
137
- }
138
- }
139
- })
140
- ]
141
- });
64
+ const runs = gmStorage.get<number>('runs', 0) + 1;
65
+ gmStorage.set('runs', runs);
142
66
  ```
143
67
 
144
- ## 与其他包的关系
145
-
146
- | 包 | 职责 |
147
- | --- | --- |
148
- | `@makoojs/cli` | Vite 插件、CLI 命令和 userscript 构建接入 |
149
- | `@makoojs/core` | 框架无关的注入运行时内核 |
150
- | `@makoojs/vue` | Vue adapter 与 Vue 插件注册 |
151
- | `@makoojs/react` | React adapter |
152
- | `@makoojs/create-makoo` | 项目脚手架 |
68
+ ## 文档
153
69
 
154
- 运行时行为由应用代码通过 `@makoojs/core` 进行编排。
70
+ - [Vite 插件](https://makoojs.github.io/Makoo/zh/api/vite):`makoo()` 的全部配置、默认值与 `makooDev()`。
71
+ - [CLI 命令](https://makoojs.github.io/Makoo/zh/api/cli):各命令的参数。
72
+ - [Userscript API](https://makoojs.github.io/Makoo/zh/api/monkey):`@makoojs/cli/monkey` 导出的 GM API。
73
+ - [项目配置](https://makoojs.github.io/Makoo/zh/docs/configuration):匹配网址、权限与外部依赖的配置方法。
package/README.md CHANGED
@@ -1,154 +1,73 @@
1
1
  # @makoojs/cli
2
2
 
3
- `@makoojs/cli` provides Makoo's Vite plugin and CLI commands, with userscript development and build capabilities powered by [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey).
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
- Application code composes runtime behavior through `createMakoo()`, `inject()`, and `listen()` from `@makoojs/core`. `@makoojs/cli` handles the Vite and userscript build integration.
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
- ## Use Cases
8
-
9
- - Develop Makoo userscript projects with Vite.
10
- - Generate userscript metadata, dev entries, and build output through [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey).
11
- - Use the `makoo dev` and `makoo build` commands.
12
- - Use Makoo's stable GM API entry through `@makoojs/cli/monkey`.
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).
13
15
 
14
16
  ## Installation
15
17
 
16
- ```bash
17
- # npm install @makoojs/cli
18
- # yarn add @makoojs/cli
19
- pnpm add @makoojs/cli
18
+ ```sh
19
+ pnpm add -D @makoojs/cli vite
20
20
  ```
21
21
 
22
- If you create a project with `@makoojs/create-makoo`, `@makoojs/cli` is usually configured for you.
22
+ > [!TIP]
23
+ > Projects created with `pnpm dlx @makoojs/create-makoo` already have it configured; no separate installation is needed.
23
24
 
24
- ## Minimal Vite Config
25
+ ## Usage
25
26
 
26
- Use `makoo()` in the Vite configuration:
27
+ ### Configure Vite
27
28
 
28
29
  ```ts
30
+ // vite.config.ts
29
31
  import { defineConfig } from 'vite';
30
- import { makoo } from '@makoojs/cli';
31
32
  import vue from '@vitejs/plugin-vue';
33
+ import { makoo, makooDev } from '@makoojs/cli';
32
34
 
33
35
  export default defineConfig({
34
- plugins: [
35
- vue(),
36
- makoo({
37
- entry: './src/app.ts',
38
- app: {
39
- name: 'my-userscript',
40
- version: '0.0.1',
41
- description: 'My first Makoo script'
42
- },
43
- monkey: {
44
- userscript: {
45
- namespace: 'https://example.com',
46
- // This is only an example. Replace it with the pages supported by the userscript.
47
- match: ['https://www.google.com/']
48
- }
49
- }
50
- })
51
- ]
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
+ ]
52
46
  });
53
47
  ```
54
48
 
55
- `makoo()` passes the configuration to [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) for userscript development and builds.
56
-
57
- ## Configuration Overview
58
-
59
- `makoo()` has three main configuration areas:
60
-
61
- ```ts
62
- makoo({
63
- entry: './src/app.ts',
64
- app: {
65
- name: 'my-script',
66
- version: '0.0.1',
67
- description: 'demo script'
68
- },
69
- monkey: {
70
- userscript: {
71
- match: ['https://www.google.com/']
72
- }
73
- }
74
- });
75
- ```
76
-
77
- | Config | Description |
78
- | --- | --- |
79
- | `entry` | Application module passed to Vite for building |
80
- | `app` | Generates userscript `name`, `version`, and `description` |
81
- | `monkey` | Most options are passed through to [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) |
82
-
83
- By default, `monkey.build.autoGrant` is `true`, so [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) generates `@grant` from the final code.
84
-
85
- ## CLI Commands
86
-
87
- After installation, you can use the `makoo` command:
88
-
89
- | Command | Description |
90
- | --- | --- |
91
- | `makoo dev` | Starts the Vite dev server and prints the local URL |
92
- | `makoo build` | Runs Vite build and generates userscript output |
93
- | `makoo preview` | Previews the built userscript with the Vite preview server |
94
-
95
- ## Use GM APIs
96
-
97
- `@makoojs/cli` provides the `@makoojs/cli/monkey` subpath as Makoo's stable wrapper around [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey) GM APIs.
98
-
99
- ```ts
100
- import { gmStorage, gmStyle } from '@makoojs/cli/monkey';
101
-
102
- gmStyle.add('.makoo-panel { z-index: 999999; }');
103
- gmStorage.set('enabled', true);
104
- ```
105
-
106
- You can also use the grouped entry:
49
+ ### Develop and Build
107
50
 
108
- ```ts
109
- import { GMapi } from '@makoojs/cli/monkey';
110
-
111
- GMapi.storage.set('enabled', true);
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
112
55
  ```
113
56
 
114
- Use capability-level imports when you want the generated `@grant` surface to stay as small as possible. See the CLI API documentation for the complete GM API.
115
-
116
- ## Reduce Build Size
57
+ ### Call GM APIs
117
58
 
118
- `@makoojs/cli` re-exports `cdn` from [lisonge/vite-plugin-monkey](https://github.com/lisonge/vite-plugin-monkey). Use it with `monkey.build.externalGlobals` to load external dependencies from a CDN and reduce userscript bundle size.
59
+ Import by capability in browser code, and the build only generates `@grant` for the APIs you use:
119
60
 
120
61
  ```ts
121
- import { defineConfig } from 'vite';
122
- import { cdn, makoo } from '@makoojs/cli';
62
+ import { gmStorage } from '@makoojs/cli/monkey';
123
63
 
124
- export default defineConfig({
125
- plugins: [
126
- makoo({
127
- entry: './src/app.ts',
128
- app: {
129
- name: 'my-script',
130
- version: '0.0.1'
131
- },
132
- monkey: {
133
- build: {
134
- externalGlobals: {
135
- vue: cdn.jsdelivr('Vue', 'dist/vue.global.prod.js')
136
- }
137
- }
138
- }
139
- })
140
- ]
141
- });
64
+ const runs = gmStorage.get<number>('runs', 0) + 1;
65
+ gmStorage.set('runs', runs);
142
66
  ```
143
67
 
144
- ## Relationship To Other Packages
145
-
146
- | Package | Responsibility |
147
- | --- | --- |
148
- | `@makoojs/cli` | Vite plugin, CLI commands, and userscript build integration |
149
- | `@makoojs/core` | Framework-agnostic injection runtime core |
150
- | `@makoojs/vue` | Vue adapter and Vue plugin registration |
151
- | `@makoojs/react` | React adapter |
152
- | `@makoojs/create-makoo` | Project scaffold |
68
+ ## Documentation
153
69
 
154
- Application code composes runtime behavior through `@makoojs/core`.
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.