@makoojs/cli 0.5.0 → 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.
- package/README.CN.md +43 -124
- package/README.md +43 -124
- package/dist/bin.js +148 -59
- package/dist/cli/commands/dev/DevTerminal.d.ts +2 -2
- package/dist/cli/injections/renderInjections.d.ts +2 -0
- package/dist/config/errors.d.ts +1 -12
- package/dist/index.cjs +65 -97
- package/dist/index.js +197 -237
- package/dist/session/DevSession.d.ts +4 -3
- package/dist/session/types.d.ts +37 -12
- package/package.json +2 -2
- package/dist/cli/tasks/renderTasks.d.ts +0 -2
package/README.CN.md
CHANGED
|
@@ -1,154 +1,73 @@
|
|
|
1
1
|
# @makoojs/cli
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
17
|
-
|
|
18
|
-
# yarn add @makoojs/cli
|
|
19
|
-
pnpm add @makoojs/cli
|
|
18
|
+
```sh
|
|
19
|
+
pnpm add -D @makoojs/cli vite
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
> [!TIP]
|
|
23
|
+
> 用 `pnpm dlx @makoojs/create-makoo` 创建的项目已经配置好了它,不需要单独安装。
|
|
23
24
|
|
|
24
|
-
##
|
|
25
|
+
## 用法
|
|
25
26
|
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
51
|
+
```sh
|
|
52
|
+
makoo dev # 启动开发服务,从打印的地址安装开发脚本
|
|
53
|
+
makoo build # 构建出 .user.js
|
|
54
|
+
makoo preview # 预览构建产物
|
|
112
55
|
```
|
|
113
56
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
## 减小构建体积
|
|
57
|
+
### 调用 GM API
|
|
117
58
|
|
|
118
|
-
|
|
59
|
+
在浏览器代码中按能力导入,构建时会只为用到的 API 生成 `@grant`:
|
|
119
60
|
|
|
120
61
|
```ts
|
|
121
|
-
import {
|
|
122
|
-
import { cdn, makoo } from '@makoojs/cli';
|
|
62
|
+
import { gmStorage } from '@makoojs/cli/monkey';
|
|
123
63
|
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
17
|
-
|
|
18
|
-
# yarn add @makoojs/cli
|
|
19
|
-
pnpm add @makoojs/cli
|
|
18
|
+
```sh
|
|
19
|
+
pnpm add -D @makoojs/cli vite
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
> [!TIP]
|
|
23
|
+
> Projects created with `pnpm dlx @makoojs/create-makoo` already have it configured; no separate installation is needed.
|
|
23
24
|
|
|
24
|
-
##
|
|
25
|
+
## Usage
|
|
25
26
|
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
## Reduce Build Size
|
|
57
|
+
### Call GM APIs
|
|
117
58
|
|
|
118
|
-
|
|
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 {
|
|
122
|
-
import { cdn, makoo } from '@makoojs/cli';
|
|
62
|
+
import { gmStorage } from '@makoojs/cli/monkey';
|
|
123
63
|
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
| 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
|
-
|
|
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.
|