@shiqianjiang/ceru-plugin-cli 0.3.15 → 3.0.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 (302) hide show
  1. package/README.md +26 -7
  2. package/assets/compatibility.json +18 -0
  3. package/dist/compatibility.d.ts +24 -0
  4. package/dist/compatibility.js +119 -0
  5. package/dist/component.d.ts +6 -0
  6. package/dist/component.js +60 -0
  7. package/dist/dev-music.d.ts +19 -0
  8. package/dist/dev-music.js +81 -0
  9. package/dist/dev-plugin-services.d.ts +10 -0
  10. package/dist/dev-plugin-services.js +67 -0
  11. package/dist/dev.d.ts +1 -9
  12. package/dist/dev.js +53 -713
  13. package/dist/frameworks.d.ts +5 -2
  14. package/dist/frameworks.js +43 -6
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +54 -23
  17. package/dist/init.js +3 -3
  18. package/dist/migrate.d.ts +3 -0
  19. package/dist/migrate.js +109 -0
  20. package/dist/project.d.ts +5 -2
  21. package/dist/project.js +131 -43
  22. package/dist/test-hooks.d.ts +1 -0
  23. package/dist/test-hooks.js +209 -0
  24. package/dist/test-services.d.ts +4 -0
  25. package/dist/test-services.js +54 -0
  26. package/dist/watch-vue-types.d.ts +17 -0
  27. package/dist/watch-vue-types.js +145 -0
  28. package/package.json +10 -6
  29. package/schemas/config.schema.json +954 -452
  30. package/templates/account-qrcode/js/.vscode/extensions.json +3 -0
  31. package/templates/account-qrcode/js/.vscode/launch.json +19 -0
  32. package/templates/account-qrcode/js/.vscode/settings.json +20 -0
  33. package/templates/account-qrcode/js/.vscode/tasks.json +43 -0
  34. package/templates/account-qrcode/js/README.md +15 -0
  35. package/templates/account-qrcode/js/_gitignore +6 -0
  36. package/templates/account-qrcode/js/ceru-plugin.code-workspace +8 -0
  37. package/templates/account-qrcode/js/ceru.plugin.json +62 -0
  38. package/templates/account-qrcode/js/package.json +24 -0
  39. package/templates/account-qrcode/js/src/Login.vue +25 -0
  40. package/templates/account-qrcode/js/src/index.js +25 -0
  41. package/templates/account-qrcode/js/src/login-html.js +23 -0
  42. package/templates/account-qrcode/js/tsconfig.json +17 -0
  43. package/templates/account-qrcode/ts/.vscode/extensions.json +3 -0
  44. package/templates/account-qrcode/ts/.vscode/launch.json +19 -0
  45. package/templates/account-qrcode/ts/.vscode/settings.json +20 -0
  46. package/templates/account-qrcode/ts/.vscode/tasks.json +43 -0
  47. package/templates/account-qrcode/ts/README.md +15 -0
  48. package/templates/account-qrcode/ts/_gitignore +6 -0
  49. package/templates/account-qrcode/ts/ceru-plugin.code-workspace +8 -0
  50. package/templates/account-qrcode/ts/ceru.plugin.json +62 -0
  51. package/templates/account-qrcode/ts/package.json +24 -0
  52. package/templates/account-qrcode/ts/src/Login.vue +25 -0
  53. package/templates/account-qrcode/ts/src/index.ts +25 -0
  54. package/templates/account-qrcode/ts/src/login-html.ts +23 -0
  55. package/templates/account-qrcode/ts/tsconfig.json +17 -0
  56. package/templates/connected-library/js/.vscode/launch.json +12 -29
  57. package/templates/connected-library/js/.vscode/tasks.json +2 -3
  58. package/templates/connected-library/js/README.md +26 -12
  59. package/templates/connected-library/js/ceru.plugin.json +122 -50
  60. package/templates/connected-library/js/package.json +5 -5
  61. package/templates/connected-library/js/src/index.js +46 -5
  62. package/templates/connected-library/js/src/settings.js +28 -0
  63. package/templates/connected-library/ts/.vscode/launch.json +12 -29
  64. package/templates/connected-library/ts/.vscode/tasks.json +2 -3
  65. package/templates/connected-library/ts/README.md +26 -12
  66. package/templates/connected-library/ts/ceru.plugin.json +122 -50
  67. package/templates/connected-library/ts/package.json +5 -5
  68. package/templates/connected-library/ts/src/index.ts +46 -5
  69. package/templates/connected-library/ts/src/settings.ts +28 -0
  70. package/templates/encrypted-source/README.md +86 -0
  71. package/templates/encrypted-source/js/.prettierrc.json +5 -0
  72. package/templates/encrypted-source/js/.vscode/ceru.code-snippets +55 -0
  73. package/templates/encrypted-source/js/.vscode/extensions.json +3 -0
  74. package/templates/encrypted-source/js/.vscode/launch.json +15 -0
  75. package/templates/encrypted-source/js/.vscode/settings.json +20 -0
  76. package/templates/encrypted-source/js/.vscode/tasks.json +40 -0
  77. package/templates/encrypted-source/js/DEMO.md +77 -0
  78. package/templates/encrypted-source/js/README.md +13 -0
  79. package/templates/encrypted-source/js/_gitignore +6 -0
  80. package/templates/encrypted-source/js/ceru-plugin.code-workspace +8 -0
  81. package/templates/encrypted-source/js/ceru.plugin.json +95 -0
  82. package/templates/encrypted-source/js/package.json +26 -0
  83. package/templates/encrypted-source/js/resources/xor-byte.wasm +0 -0
  84. package/templates/encrypted-source/js/resources/xor-byte.wat +5 -0
  85. package/templates/encrypted-source/js/src/demo.js +200 -0
  86. package/templates/encrypted-source/js/src/fixtures.js +118 -0
  87. package/templates/encrypted-source/js/src/index.js +4 -0
  88. package/templates/encrypted-source/js/tests/demo.test.mjs +357 -0
  89. package/templates/encrypted-source/js/tsconfig.json +16 -0
  90. package/templates/encrypted-source/ts/.prettierrc.json +5 -0
  91. package/templates/encrypted-source/ts/.vscode/ceru.code-snippets +55 -0
  92. package/templates/encrypted-source/ts/.vscode/extensions.json +3 -0
  93. package/templates/encrypted-source/ts/.vscode/launch.json +15 -0
  94. package/templates/encrypted-source/ts/.vscode/settings.json +20 -0
  95. package/templates/encrypted-source/ts/.vscode/tasks.json +40 -0
  96. package/templates/encrypted-source/ts/DEMO.md +77 -0
  97. package/templates/encrypted-source/ts/README.md +13 -0
  98. package/templates/encrypted-source/ts/_gitignore +6 -0
  99. package/templates/encrypted-source/ts/ceru-plugin.code-workspace +8 -0
  100. package/templates/encrypted-source/ts/ceru.plugin.json +95 -0
  101. package/templates/encrypted-source/ts/package.json +26 -0
  102. package/templates/encrypted-source/ts/resources/xor-byte.wasm +0 -0
  103. package/templates/encrypted-source/ts/resources/xor-byte.wat +5 -0
  104. package/templates/encrypted-source/ts/src/demo.ts +212 -0
  105. package/templates/encrypted-source/ts/src/fixtures.ts +125 -0
  106. package/templates/encrypted-source/ts/src/index.ts +4 -0
  107. package/templates/encrypted-source/ts/tests/demo.test.mjs +357 -0
  108. package/templates/encrypted-source/ts/tsconfig.json +17 -0
  109. package/templates/guest-adapter/js/.vscode/launch.json +12 -29
  110. package/templates/guest-adapter/js/.vscode/tasks.json +2 -3
  111. package/templates/guest-adapter/js/README.md +10 -10
  112. package/templates/guest-adapter/js/ceru.plugin.json +67 -62
  113. package/templates/guest-adapter/js/package.json +5 -5
  114. package/templates/guest-adapter/js/src/index.js +1 -1
  115. package/templates/guest-adapter/js/src/settings.js +8 -0
  116. package/templates/guest-adapter/ts/.vscode/launch.json +12 -29
  117. package/templates/guest-adapter/ts/.vscode/tasks.json +2 -3
  118. package/templates/guest-adapter/ts/README.md +10 -10
  119. package/templates/guest-adapter/ts/ceru.plugin.json +67 -62
  120. package/templates/guest-adapter/ts/package.json +5 -5
  121. package/templates/guest-adapter/ts/src/index.ts +1 -1
  122. package/templates/guest-adapter/ts/src/settings.ts +8 -0
  123. package/templates/importer/js/.vscode/launch.json +12 -29
  124. package/templates/importer/js/.vscode/tasks.json +2 -3
  125. package/templates/importer/js/README.md +10 -10
  126. package/templates/importer/js/ceru.plugin.json +23 -21
  127. package/templates/importer/js/package.json +5 -5
  128. package/templates/importer/ts/.vscode/launch.json +12 -29
  129. package/templates/importer/ts/.vscode/tasks.json +2 -3
  130. package/templates/importer/ts/README.md +10 -10
  131. package/templates/importer/ts/ceru.plugin.json +23 -21
  132. package/templates/importer/ts/package.json +5 -5
  133. package/templates/page-extension/js/.vscode/extensions.json +3 -0
  134. package/templates/page-extension/js/.vscode/launch.json +19 -0
  135. package/templates/page-extension/js/.vscode/settings.json +20 -0
  136. package/templates/page-extension/js/.vscode/tasks.json +43 -0
  137. package/templates/page-extension/js/README.md +9 -0
  138. package/templates/page-extension/js/_gitignore +6 -0
  139. package/templates/page-extension/js/ceru-plugin.code-workspace +8 -0
  140. package/templates/page-extension/js/ceru.plugin.json +94 -0
  141. package/templates/page-extension/js/package.json +24 -0
  142. package/templates/page-extension/js/src/Open.vue +6 -0
  143. package/templates/page-extension/js/src/Search.vue +62 -0
  144. package/templates/page-extension/js/src/index.js +54 -0
  145. package/templates/page-extension/js/tsconfig.json +17 -0
  146. package/templates/page-extension/ts/.vscode/extensions.json +3 -0
  147. package/templates/page-extension/ts/.vscode/launch.json +19 -0
  148. package/templates/page-extension/ts/.vscode/settings.json +20 -0
  149. package/templates/page-extension/ts/.vscode/tasks.json +43 -0
  150. package/templates/page-extension/ts/README.md +9 -0
  151. package/templates/page-extension/ts/_gitignore +6 -0
  152. package/templates/page-extension/ts/ceru-plugin.code-workspace +8 -0
  153. package/templates/page-extension/ts/ceru.plugin.json +94 -0
  154. package/templates/page-extension/ts/package.json +24 -0
  155. package/templates/page-extension/ts/src/Open.vue +6 -0
  156. package/templates/page-extension/ts/src/Search.vue +62 -0
  157. package/templates/page-extension/ts/src/index.ts +54 -0
  158. package/templates/page-extension/ts/tsconfig.json +17 -0
  159. package/templates/playback-hook/js/.prettierrc.json +5 -0
  160. package/templates/playback-hook/js/.vscode/extensions.json +3 -0
  161. package/templates/playback-hook/js/.vscode/launch.json +19 -0
  162. package/templates/playback-hook/js/.vscode/settings.json +20 -0
  163. package/templates/playback-hook/js/.vscode/tasks.json +50 -0
  164. package/templates/playback-hook/js/README.md +24 -0
  165. package/templates/playback-hook/js/_gitignore +6 -0
  166. package/templates/playback-hook/js/ceru-plugin.code-workspace +8 -0
  167. package/templates/playback-hook/js/ceru.plugin.json +36 -0
  168. package/templates/playback-hook/js/package.json +23 -0
  169. package/templates/playback-hook/js/src/index.js +25 -0
  170. package/templates/playback-hook/js/tests/hooks.json +316 -0
  171. package/templates/playback-hook/js/tsconfig.json +16 -0
  172. package/templates/playback-hook/ts/.prettierrc.json +5 -0
  173. package/templates/playback-hook/ts/.vscode/extensions.json +3 -0
  174. package/templates/playback-hook/ts/.vscode/launch.json +19 -0
  175. package/templates/playback-hook/ts/.vscode/settings.json +20 -0
  176. package/templates/playback-hook/ts/.vscode/tasks.json +50 -0
  177. package/templates/playback-hook/ts/README.md +24 -0
  178. package/templates/playback-hook/ts/_gitignore +6 -0
  179. package/templates/playback-hook/ts/ceru-plugin.code-workspace +8 -0
  180. package/templates/playback-hook/ts/ceru.plugin.json +36 -0
  181. package/templates/playback-hook/ts/package.json +23 -0
  182. package/templates/playback-hook/ts/src/index.ts +25 -0
  183. package/templates/playback-hook/ts/tests/hooks.json +316 -0
  184. package/templates/playback-hook/ts/tsconfig.json +16 -0
  185. package/templates/player-skin/js/.vscode/extensions.json +3 -0
  186. package/templates/player-skin/js/.vscode/launch.json +19 -0
  187. package/templates/player-skin/js/.vscode/settings.json +20 -0
  188. package/templates/player-skin/js/.vscode/tasks.json +43 -0
  189. package/templates/player-skin/js/README.md +11 -0
  190. package/templates/player-skin/js/_gitignore +6 -0
  191. package/templates/player-skin/js/assets/studio-preview.svg +15 -0
  192. package/templates/player-skin/js/ceru-plugin.code-workspace +8 -0
  193. package/templates/player-skin/js/ceru.plugin.json +77 -0
  194. package/templates/player-skin/js/package.json +24 -0
  195. package/templates/player-skin/js/src/Artwork.vue +9 -0
  196. package/templates/player-skin/js/src/Background.vue +15 -0
  197. package/templates/player-skin/js/src/BuiltinLyrics.vue +15 -0
  198. package/templates/player-skin/js/src/Lyrics.vue +28 -0
  199. package/templates/player-skin/js/tsconfig.json +17 -0
  200. package/templates/player-skin/ts/.vscode/extensions.json +3 -0
  201. package/templates/player-skin/ts/.vscode/launch.json +19 -0
  202. package/templates/player-skin/ts/.vscode/settings.json +20 -0
  203. package/templates/player-skin/ts/.vscode/tasks.json +43 -0
  204. package/templates/player-skin/ts/README.md +11 -0
  205. package/templates/player-skin/ts/_gitignore +6 -0
  206. package/templates/player-skin/ts/assets/studio-preview.svg +15 -0
  207. package/templates/player-skin/ts/ceru-plugin.code-workspace +8 -0
  208. package/templates/player-skin/ts/ceru.plugin.json +77 -0
  209. package/templates/player-skin/ts/package.json +24 -0
  210. package/templates/player-skin/ts/src/Artwork.vue +9 -0
  211. package/templates/player-skin/ts/src/Background.vue +15 -0
  212. package/templates/player-skin/ts/src/BuiltinLyrics.vue +15 -0
  213. package/templates/player-skin/ts/src/Lyrics.vue +28 -0
  214. package/templates/player-skin/ts/tsconfig.json +17 -0
  215. package/templates/react/js/.vscode/launch.json +12 -29
  216. package/templates/react/js/.vscode/tasks.json +2 -3
  217. package/templates/react/js/README.md +10 -10
  218. package/templates/react/js/ceru.plugin.json +27 -22
  219. package/templates/react/js/package.json +5 -5
  220. package/templates/react/js/src/index.js +1 -1
  221. package/templates/react/ts/.vscode/launch.json +12 -29
  222. package/templates/react/ts/.vscode/tasks.json +2 -3
  223. package/templates/react/ts/README.md +10 -10
  224. package/templates/react/ts/ceru.plugin.json +27 -22
  225. package/templates/react/ts/package.json +5 -5
  226. package/templates/react/ts/src/index.ts +1 -1
  227. package/templates/snapshot.json +152 -6
  228. package/templates/source/js/.vscode/launch.json +12 -29
  229. package/templates/source/js/.vscode/tasks.json +2 -3
  230. package/templates/source/js/README.md +12 -10
  231. package/templates/source/js/ceru.plugin.json +44 -26
  232. package/templates/source/js/package.json +5 -5
  233. package/templates/source/js/src/index.js +10 -8
  234. package/templates/source/ts/.vscode/launch.json +12 -29
  235. package/templates/source/ts/.vscode/tasks.json +2 -3
  236. package/templates/source/ts/README.md +12 -10
  237. package/templates/source/ts/ceru.plugin.json +44 -26
  238. package/templates/source/ts/package.json +5 -5
  239. package/templates/source/ts/src/index.ts +10 -8
  240. package/templates/vue/js/.vscode/launch.json +12 -29
  241. package/templates/vue/js/.vscode/tasks.json +2 -3
  242. package/templates/vue/js/README.md +10 -10
  243. package/templates/vue/js/ceru.plugin.json +27 -22
  244. package/templates/vue/js/package.json +5 -5
  245. package/templates/vue/js/src/index.js +1 -1
  246. package/templates/vue/ts/.vscode/launch.json +12 -29
  247. package/templates/vue/ts/.vscode/tasks.json +2 -3
  248. package/templates/vue/ts/README.md +10 -10
  249. package/templates/vue/ts/ceru.plugin.json +27 -22
  250. package/templates/vue/ts/package.json +5 -5
  251. package/templates/vue/ts/src/index.ts +1 -1
  252. package/templates/vue-tsx/js/.vscode/launch.json +12 -29
  253. package/templates/vue-tsx/js/.vscode/tasks.json +2 -3
  254. package/templates/vue-tsx/js/README.md +10 -10
  255. package/templates/vue-tsx/js/ceru.plugin.json +27 -22
  256. package/templates/vue-tsx/js/package.json +5 -5
  257. package/templates/vue-tsx/js/src/index.js +1 -1
  258. package/templates/vue-tsx/ts/.vscode/launch.json +12 -29
  259. package/templates/vue-tsx/ts/.vscode/tasks.json +2 -3
  260. package/templates/vue-tsx/ts/README.md +10 -10
  261. package/templates/vue-tsx/ts/ceru.plugin.json +27 -22
  262. package/templates/vue-tsx/ts/package.json +5 -5
  263. package/templates/vue-tsx/ts/src/index.ts +1 -1
  264. package/templates/web-dist/js/.vscode/launch.json +12 -29
  265. package/templates/web-dist/js/.vscode/tasks.json +2 -3
  266. package/templates/web-dist/js/README.md +10 -10
  267. package/templates/web-dist/js/ceru.plugin.json +27 -22
  268. package/templates/web-dist/js/package.json +5 -5
  269. package/templates/web-dist/js/src/index.js +1 -1
  270. package/templates/web-dist/ts/.vscode/launch.json +12 -29
  271. package/templates/web-dist/ts/.vscode/tasks.json +2 -3
  272. package/templates/web-dist/ts/README.md +10 -10
  273. package/templates/web-dist/ts/ceru.plugin.json +27 -22
  274. package/templates/web-dist/ts/package.json +5 -5
  275. package/templates/web-dist/ts/src/index.ts +1 -1
  276. package/templates/web-surface/js/.vscode/launch.json +12 -29
  277. package/templates/web-surface/js/.vscode/tasks.json +2 -3
  278. package/templates/web-surface/js/README.md +10 -10
  279. package/templates/web-surface/js/ceru.plugin.json +35 -35
  280. package/templates/web-surface/js/package.json +5 -5
  281. package/templates/web-surface/js/src/index.js +1 -1
  282. package/templates/web-surface/ts/.vscode/launch.json +12 -29
  283. package/templates/web-surface/ts/.vscode/tasks.json +2 -3
  284. package/templates/web-surface/ts/README.md +10 -10
  285. package/templates/web-surface/ts/ceru.plugin.json +35 -35
  286. package/templates/web-surface/ts/package.json +5 -5
  287. package/templates/web-surface/ts/src/index.ts +1 -1
  288. package/assets/core-contracts.js +0 -1
  289. package/assets/electron-app/main.cjs +0 -1
  290. package/assets/electron-app/package.json +0 -8
  291. package/assets/electron.cjs +0 -42
  292. package/assets/index.html +0 -94
  293. package/assets/native-view.js +0 -197
  294. package/assets/playground.js +0 -883
  295. package/assets/sandbox.js +0 -67
  296. package/assets/style.css +0 -337
  297. package/dist/socket-broker.d.ts +0 -23
  298. package/dist/socket-broker.js +0 -229
  299. package/templates/connected-library/js/ui/settings.json +0 -24
  300. package/templates/connected-library/ts/ui/settings.json +0 -24
  301. package/templates/guest-adapter/js/ui/settings.json +0 -14
  302. package/templates/guest-adapter/ts/ui/settings.json +0 -14
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Ceru Plugin CLI
2
2
 
3
+ v3 新增 `ceru-plugin check-compat`(新工程也可 `npm run check:compat`),检查宿主 API、组件库范围与区域版本。可用 `--host profile.json` 指定目标宿主;未指定时仅与工具包参考版本比较。命令支持 `--json`,冲突返回非零退出码。它不代替类型检查或实际桌面验收,详见 [兼容性检查](../../docs/COMPATIBILITY.md)。
4
+
5
+ **本地 v3 候选开发包(尚未发布)**:不要用 npm 的 latest 验收本分支。维护者在工具链运行 `npm run build`、`npm run pack:all`、`npm run pack:devkit`。将生成的目录交给开发者,照目录内 README 在一个空目录创建独立项目,不需要全局 CLI 或工作区软链接。首次安装第三方依赖需要可用的 npm 缓存或网络。
6
+
7
+ 要做播放规则,选择 `--template playback-hook --lang ts`(也支持 js),安装后运行 `npm test`。可编辑 `tests/hooks.json` 新增场景。每个场景会在新 worker 中用真实 v3 契约执行,失败会报告场景名;不连接实际播放器。`npm run dev` 用于在桌面开发模式中复验。
8
+
3
9
  0.3.12 插件网络请求支持宿主注入代理:`requestNetwork` 新增 `setNetworkProxyResolver`,宿主可让搜索、歌词等请求遵循应用自身的网络代理设置。
4
10
 
5
11
  0.3.11 用户 Ctrl+C/Esc 取消时正常退出(不再返回 130 让 `npm create` 报错)。
@@ -14,28 +20,31 @@
14
20
 
15
21
  0.3.3 支持原生 Surface、账号退出菜单、登录弹框关闭及浏览器公共播放服务。
16
22
 
17
- 构建、调试和发行单文件 Ceru v2 插件。支持 TS/JS、Vue SFC、Vue TSX、React 和已有网页产物。
23
+ 构建、调试和发行单文件 Ceru v3 插件。支持 TS/JS、Vue SFC、Vue TSX、React 和已有网页产物。
18
24
 
19
25
  ```bash
20
- npm create ceru-plugin@latest my-plugin -- --template vue --lang ts
26
+ ceru-plugin init my-plugin --template vue --lang ts
21
27
  cd my-plugin
22
28
  npm install
23
29
  npm run dev
24
30
  npm run build
25
31
  ```
26
32
 
27
- Dev 启动独立 Electron 工作台,实际执行插件并支持 TS 源码断点、日志、搜索/解析、页面预览、权限模拟和宿主资源。VS Code 配置由脚手架生成。
33
+ dev 只监听并构建。在澜音「设置 → 插件 → 插件开发者模式」添加终端打印的文件;保存源码后由真实宿主重载。F5 的 Watch Ceru plugin 启动相同监听器。
34
+
35
+ 用 `ceru-plugin init my-page --template page-extension --lang ts` 可生成带侧栏、设置页和歌单按钮的 Vue 示例。`dev` 会复用已通过的检查结果;若脚本、模板表达式或模板结构无效,终端会报错,桌面保持上次可用的产物。修正后无需重启监听。安装或更换依赖后请重启监听;交付前仍应运行 `ceru-plugin build` 做完整检查。
28
36
 
29
37
  `connected-library` 模板包含原生歌单网格、歌曲列表、账号菜单、导入与播放动作示例。`kind: 'native'` 的 Surface 使用逻辑端 `defineNativeView` 返回标准内容数据,工作台在 Host DOM 中预览;澜音用现有组件渲染并接入原生详情页和播放器。Vue/React 仍可用于插件自己的账号或设置页面。详见[原生 Surface 教程](https://github.com/CeruMusic/CeruMusic-Plugin-Cli/blob/main/docs/NATIVE-SURFACES.md)。
30
38
 
31
39
  0.3.1 的播放解析结果可返回 `requestHeaders`。适用于要求 `Referer`、`Origin`、`User-Agent` 或认证头的临时媒体 URL;这些值由 Host 按完整 URL 注入,不应写入页面状态、日志或分享数据。
32
40
 
33
- 0.3.0 的 `web-surface` 模板包含通用页面生命周期示例。`modules.surfaces[]` 可声明 `title`、`presentation: { kind: 'drawer', placement: 'right', size: 480 }` 和 `lifecycle: { openAction: 'page.open', closeAction: 'page.close' }`。生命周期动作须在 `contributes.commands` 声明;打开完成后执行 openAction,关闭时取消页面请求并执行 closeAction。扫码、轮询、账号表单和校验全部写在插件工程中,Vue/React 也打包进最终单文件。
41
+ `web-surface` 模板包含通用页面生命周期示例。`entry.views[]` 可声明 `title`、`presentation: { kind: 'drawer', placement: 'right', size: 480 }` 和 `lifecycle: { openAction: 'page.open', closeAction: 'page.close' }`。生命周期动作须在 `provides.actions` 声明;打开完成后执行 openAction,关闭时取消页面请求并执行 closeAction。扫码、轮询、账号表单和校验全部写在插件工程中,Vue/React 也打包进最终单文件。
34
42
 
35
43
  预览的“关闭页面”可验证清理逻辑。`ctx.ui.setState(id, state)` 只发送给对应页面;`ctx.subscribe` 接收最新状态。开发存储保存在工程 `.ceru-dev/storage/`,重启保留且不打入产物;修改 `manifest.id` 会使用独立存储。生产宿主提供自己的隔离存储和通用播放器服务,开发无需启动澜音。
36
44
 
37
45
  ```text
38
46
  ceru-plugin list-templates
47
+ ceru-plugin migrate --project path/to/v2-project
39
48
  ceru-plugin build --out dist/plugin.js
40
49
  ceru-plugin validate dist/plugin.js --json
41
50
  ceru-plugin keygen --out .keys/publisher
@@ -44,16 +53,26 @@ ceru-plugin sign dist/plugin.js --key .keys/publisher.private.pem
44
53
 
45
54
  最终交付单个 `.js`。JSX/TSX/Vue 只作为开发源码;编译器、node_modules 和开发服务器不进入产物。
46
55
 
47
- Vue/React 生产运行代码会直接打入发行文件,不依赖宿主提供框架。执行 `ceru-plugin preview dist/plugin.js` 可以只加载最终文件验证页面。0.2.0 起发行格式使用静态 `exports.manifest / exports.activate / exports.surfaces`,并支持手写单文件插件。
56
+ `component` 视图引用宿主提供的 Vue、TDesign 与 SDK 组件,不把这些运行库或软件业务组件复制进插件;`web` 视图中的 Vue/React 页面可将自己的运行库打入发行文件。执行 `ceru-plugin preview dist/plugin.js` 只校验最终文件并显示桌面预览路径,不再启动独立窗口。发行格式使用静态 `exports.manifest / exports.activate / exports.surfaces`,并支持手写单文件插件。
48
57
 
49
58
  构建产物先用 `const` 定义具名入口(如 `LogicMain`、`UiStudioSurface`)及模块表,再在文件末尾集中写入 `exports.activate / exports.surfaces / exports.resources`,方便阅读单文件产物和定位错误堆栈。插件源码仍可按需要使用函数或 class;构建器不会强制某一种编程风格。
50
59
 
51
60
  `ceru.plugin.json` 的顶层 `config` 可直接写 JSON 对象,也可写 `@./path/config.ts` 引用 JSON/JS/TS 配置模块。字符串 `@@value` 表示字面量 `@value`。构建器递归展开引用,校验为 JSON 兼容对象,并合并到单文件的 `exports.manifest.config` 中。dev/build 会生成不包含配置值的 `@ceru/plugin-config` 类型声明。
52
61
 
53
- 在多根/父目录工作区中,请打开生成的 ceru-plugin.code-workspace 或把插件工程本身加入工作区。已经运行 dev 时选择 Attach to Ceru plugin;Launch 会启动或复用当前项目的 Host。
62
+ 在多根/父目录工作区中,请打开生成的 ceru-plugin.code-workspace 或把插件工程本身加入工作区。已在终端运行 dev 时不需要再启动监听器。
54
63
 
55
- 当前 v1 Host 不能直接安装 v2 产物。开发工作台不代替生产凭据保险箱、完整音乐业务或 Guest 安装。
64
+ v2 Host 不能直接安装 v3 产物。开发工作台不代替生产凭据保险箱、完整音乐业务或 Guest 安装。
56
65
 
57
66
  源码 MIT;复用的预览图标/图片保留原项目 AGPL-3.0-only,见 ASSET_LICENSE 和 NOTICE。
58
67
 
59
68
  [完整指南](https://github.com/CeruMusic/CeruMusic-Plugin-Cli#readme)
69
+
70
+ ## 调试跨插件服务
71
+
72
+ 在桌面开发者模式分别添加两个插件的构建产物,可验证真实权限、依赖、暂停与恢复。若用 CLI 的旧产物预览做离线联调,可在工程根目录的 `ceru.config.json` 设置固定 JSON 响应,例如:
73
+
74
+ ```json
75
+ {"mockServices":[{"pluginId":"example.provider","service":"echo","version":"1.2.0","returns":{"reply":{"text":"模拟响应"}}}]}
76
+ ```
77
+
78
+ 模拟服务仍检查清单依赖、版本和 `services.consume` 授权,不执行脚本,不被打进正式产物,也不改变真实桌面插件。
@@ -0,0 +1,18 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "hostApi": "3.0.0",
4
+ "logicRuntime": "ceru-js@1",
5
+ "componentLibraries": {
6
+ "vue": "3.5.43",
7
+ "tdesign-vue-next": "1.15.4"
8
+ },
9
+ "regions": [
10
+ "player.lyrics@1",
11
+ "player.artwork@1",
12
+ "player.background@1",
13
+ "player.visualizer@1",
14
+ "player.songInfo@1",
15
+ "player.stage@1",
16
+ "desktopLyric@1"
17
+ ]
18
+ }
@@ -0,0 +1,24 @@
1
+ export interface HostCompatibility {
2
+ schemaVersion: 1;
3
+ hostApi: string;
4
+ logicRuntime: string;
5
+ componentLibraries: Record<'vue' | 'tdesign-vue-next', string>;
6
+ regions: string[];
7
+ appVersion?: string;
8
+ }
9
+ export interface CompatibilityIssue {
10
+ level: 'error' | 'warning';
11
+ code: string;
12
+ message: string;
13
+ }
14
+ export declare function readHostCompatibility(value: unknown): HostCompatibility;
15
+ /** Read declarations only: do not import plugin/config code or run installation scripts. */
16
+ export declare function checkCompatibility(project?: string, hostFile?: string): Promise<{
17
+ compatible: boolean;
18
+ target: string;
19
+ host: HostCompatibility;
20
+ pluginId: any;
21
+ componentViews: number;
22
+ issues: CompatibilityIssue[];
23
+ }>;
24
+ export declare function formatCompatibility(result: Awaited<ReturnType<typeof checkCompatibility>>): string;
@@ -0,0 +1,119 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { createRequire } from 'node:module';
3
+ import { dirname, resolve } from 'node:path';
4
+ import { satisfies, valid, validRange } from 'semver';
5
+ import { parseJsonStrict } from '@shiqianjiang/ceru-plugin-issuer';
6
+ import { parsePlayerRegion } from '@shiqianjiang/ceru-plugin-sdk';
7
+ const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
8
+ export function readHostCompatibility(value) {
9
+ if (!object(value) ||
10
+ value.schemaVersion !== 1 ||
11
+ !valid(value.hostApi) ||
12
+ typeof value.logicRuntime !== 'string' ||
13
+ !value.logicRuntime ||
14
+ !object(value.componentLibraries) ||
15
+ !['vue', 'tdesign-vue-next'].every((name) => valid(value.componentLibraries[name])) ||
16
+ !Array.isArray(value.regions) ||
17
+ !value.regions.every((name) => typeof name === 'string' && parsePlayerRegion(name)))
18
+ throw Error('Invalid host compatibility profile (schemaVersion, hostApi, logicRuntime, componentLibraries, regions)');
19
+ return {
20
+ schemaVersion: 1,
21
+ hostApi: value.hostApi,
22
+ logicRuntime: value.logicRuntime,
23
+ componentLibraries: {
24
+ vue: value.componentLibraries.vue,
25
+ 'tdesign-vue-next': value.componentLibraries['tdesign-vue-next'],
26
+ },
27
+ regions: [...value.regions],
28
+ ...(typeof value.appVersion === 'string' && valid(value.appVersion)
29
+ ? { appVersion: value.appVersion }
30
+ : {}),
31
+ };
32
+ }
33
+ /** Read declarations only: do not import plugin/config code or run installation scripts. */
34
+ export async function checkCompatibility(project = '.', hostFile) {
35
+ const root = resolve(project);
36
+ const profilePath = hostFile
37
+ ? resolve(hostFile)
38
+ : new URL('../assets/compatibility.json', import.meta.url);
39
+ const profileText = await readFile(profilePath, 'utf8');
40
+ if (profileText.length > 64 * 1024)
41
+ throw Error('Host compatibility profile is too large');
42
+ const host = readHostCompatibility(parseJsonStrict(profileText));
43
+ const source = parseJsonStrict(await readFile(resolve(root, 'ceru.plugin.json'), 'utf8'));
44
+ const manifest = source?.manifest;
45
+ if (!object(manifest) || !object(manifest.engines))
46
+ throw Error('Missing manifest.engines in ceru.plugin.json');
47
+ const issues = [];
48
+ const issue = (level, code, message) => issues.push({ level, code, message });
49
+ const checkRange = (name, version, range) => {
50
+ if (typeof range !== 'string' || !validRange(range))
51
+ issue('error', 'invalid-range', `${name}: invalid version range ${String(range)}`);
52
+ else if (!satisfies(version, range))
53
+ issue('error', 'version-mismatch', `${name}: host ${version} does not satisfy ${range}`);
54
+ };
55
+ checkRange('hostApi', host.hostApi, manifest.engines.hostApi);
56
+ if (manifest.engines.logicRuntime !== host.logicRuntime)
57
+ issue('error', 'logic-runtime', `logicRuntime: host ${host.logicRuntime}, project ${String(manifest.engines.logicRuntime)}`);
58
+ const views = manifest.entry?.views ?? [];
59
+ if (!Array.isArray(views))
60
+ throw Error('manifest.entry.views must be an array');
61
+ const componentViews = views.filter((view) => view?.kind === 'component');
62
+ if (componentViews.length) {
63
+ const pkg = parseJsonStrict(await readFile(resolve(root, 'package.json'), 'utf8'));
64
+ const requireProject = createRequire(resolve(root, 'package.json'));
65
+ const sdkEntry = createRequire(import.meta.url).resolve('@shiqianjiang/ceru-plugin-sdk');
66
+ const sdk = JSON.parse(await readFile(resolve(dirname(sdkEntry), '../package.json'), 'utf8'));
67
+ for (const name of ['vue', 'tdesign-vue-next']) {
68
+ checkRange(`SDK peer ${name}`, host.componentLibraries[name], sdk.peerDependencies?.[name]);
69
+ const range = pkg.dependencies?.[name] ?? pkg.devDependencies?.[name] ?? pkg.peerDependencies?.[name];
70
+ if (range === undefined)
71
+ issue('warning', 'missing-declaration', `${name}: declare the host library as a development dependency for editor/types support`);
72
+ else
73
+ checkRange(name, host.componentLibraries[name], range);
74
+ try {
75
+ const installed = JSON.parse(await readFile(requireProject.resolve(name + '/package.json'), 'utf8')).version;
76
+ if (!valid(installed))
77
+ throw Error('Invalid installed version');
78
+ if (installed !== host.componentLibraries[name])
79
+ issue('warning', 'types-runtime-differ', `${name}: local types ${installed}, host runtime ${host.componentLibraries[name]}; run typecheck and test against this host`);
80
+ }
81
+ catch {
82
+ issue('warning', 'dependency-unavailable', `${name}: local package unavailable; install project dependencies before typecheck`);
83
+ }
84
+ }
85
+ }
86
+ const regions = manifest.ui?.regions ?? [];
87
+ if (!Array.isArray(regions))
88
+ throw Error('manifest.ui.regions must be an array');
89
+ for (const entry of regions) {
90
+ const requested = typeof entry?.region === 'string' ? parsePlayerRegion(entry.region) : null;
91
+ if (!requested ||
92
+ !host.regions.some((name) => {
93
+ const supported = parsePlayerRegion(name);
94
+ return supported.name === requested.name && supported.version === requested.version;
95
+ }))
96
+ issue('error', 'region-unavailable', `Region ${String(entry?.region)} is not supported by this host`);
97
+ }
98
+ return {
99
+ compatible: !issues.some((item) => item.level === 'error'),
100
+ target: hostFile ? 'host-profile' : 'bundled-runtime-reference',
101
+ host,
102
+ pluginId: manifest.id,
103
+ componentViews: componentViews.length,
104
+ issues,
105
+ };
106
+ }
107
+ export function formatCompatibility(result) {
108
+ return [
109
+ `${result.compatible ? 'Compatible declarations' : 'Incompatible declarations'}: ${result.pluginId}`,
110
+ `Target: ${result.target}; host API ${result.host.hostApi}; ${result.host.logicRuntime}`,
111
+ ...result.issues.map((item) => `${item.level.toUpperCase()} [${item.code}] ${item.message}`),
112
+ 'This checks declared versions and regions only. Run typecheck/build and verify in the target desktop.',
113
+ ...(result.target === 'bundled-runtime-reference'
114
+ ? [
115
+ 'No desktop profile supplied; this is the bundled runtime reference, not a detected installation.',
116
+ ]
117
+ : []),
118
+ ].join('\n');
119
+ }
@@ -0,0 +1,6 @@
1
+ export type WatchComponentCache = Map<string, {
2
+ source: string;
3
+ name: string;
4
+ factory: string;
5
+ }>;
6
+ export declare function buildComponent(root: string, entry: string, name: string, define: Record<string, string>, cache?: WatchComponentCache): Promise<string>;
@@ -0,0 +1,60 @@
1
+ import { build } from 'esbuild';
2
+ import { parse } from 'acorn';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { vuePlugin, stylesheetPlugin } from './frameworks.js';
5
+ import { assertBundledDependencies } from './dependencies.js';
6
+ const deps = new Map([['vue', 'vue'], ['tdesign-vue-next', 'tdesign'], ['@shiqianjiang/ceru-plugin-sdk/vue', 'sdk'], ['@shiqianjiang/ceru-plugin-sdk/vue/region', 'sdk']]);
7
+ export async function buildComponent(root, entry, name, define, cache) {
8
+ const cached = cache?.get(entry);
9
+ if (cached && cached.name === name && cached.source === await readFile(entry, 'utf8'))
10
+ return cached.factory;
11
+ cache?.delete(entry);
12
+ let standalone = entry.endsWith('.vue');
13
+ let source;
14
+ const styles = new Set();
15
+ const track = cache ? { dependency: () => { standalone = false; }, source: (file, text) => { if (file === entry)
16
+ source = text; } } : undefined;
17
+ const result = await build({ absWorkingDir: root, entryPoints: [entry], outfile: 'component.js', format: 'esm', platform: 'browser', bundle: true, write: false, metafile: !!cache, external: [...deps.keys()], define, target: 'es2022', legalComments: 'none', plugins: [vuePlugin(root, 'vue', styles, track), stylesheetPlugin(styles)], loader: { '.png': 'dataurl', '.svg': 'dataurl', '.webp': 'dataurl', '.woff2': 'dataurl' } });
18
+ if (result.outputFiles.length !== 1)
19
+ throw Error('Component must build to a single module');
20
+ const text = result.outputFiles[0].text;
21
+ const tree = parse(text, { ecmaVersion: 'latest', sourceType: 'module' });
22
+ const declarations = [];
23
+ let exported;
24
+ const hooks = [];
25
+ const body = tree.body.flatMap((statement) => {
26
+ if (statement.type === 'ImportDeclaration') {
27
+ const key = deps.get(statement.source.value);
28
+ if (!key)
29
+ throw Error('Unexpected external component dependency: ' + statement.source.value);
30
+ for (const specifier of statement.specifiers) {
31
+ const target = '__ceruDeps.' + key;
32
+ const value = specifier.type === 'ImportNamespaceSpecifier' ? target : specifier.type === 'ImportDefaultSpecifier' ? target + '.default' : target + '[' + JSON.stringify(specifier.imported.name ?? specifier.imported.value) + ']';
33
+ declarations.push('const ' + specifier.local.name + ' = ' + value + ';');
34
+ }
35
+ return [];
36
+ }
37
+ if (statement.type === 'ExportNamedDeclaration' && !statement.source && !statement.declaration) {
38
+ for (const specifier of statement.specifiers) {
39
+ if (specifier.exported.name === 'default')
40
+ exported = specifier.local.name;
41
+ else if (['onEnter', 'onLeave'].includes(specifier.exported.name))
42
+ hooks.push(specifier.exported.name + ':' + specifier.local.name);
43
+ }
44
+ return [];
45
+ }
46
+ if (statement.type.startsWith('Export'))
47
+ throw Error('Component must have one default export');
48
+ return [text.slice(statement.start, statement.end)];
49
+ });
50
+ if (!exported)
51
+ throw Error('Missing default component export');
52
+ const style = [...styles].join('\n');
53
+ const mount = entry.endsWith('.vue') ? '__ceruDeps.sdk.mountComponent(' + exported + ',bridge)' : 'typeof ' + exported + ' === "function" ? ' + exported + '(bridge) : __ceruDeps.sdk.mountComponent(' + exported + ',bridge)';
54
+ const entryFunction = 'function(bridge){' + (style ? 'const style=bridge.root.ownerDocument.createElement("style");style.textContent=' + JSON.stringify(style) + ';bridge.root.append(style);bridge.onDispose(()=>style.remove());' : '') + 'return ' + mount + ';}';
55
+ const factory = 'function ' + name + '(__ceruDeps){\n' + declarations.join('\n') + '\n' + body.join('\n') + '\nreturn ' + (hooks.length ? 'Object.assign(' + entryFunction + ',{' + hooks.join(',') + '})' : entryFunction) + ';}';
56
+ assertBundledDependencies('(' + factory + ')');
57
+ if (standalone && source !== undefined && result.metafile && Object.keys(result.metafile.inputs).length === 1)
58
+ cache?.set(entry, { source, name, factory });
59
+ return factory;
60
+ }
@@ -0,0 +1,19 @@
1
+ export declare function developmentMusic(): {
2
+ 'music.sources': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
3
+ 'music.search': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
4
+ 'music.suggest': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
5
+ 'music.hotSearch': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
6
+ 'music.tracks.resolve': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
7
+ 'music.tracks.lyrics': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
8
+ 'music.tracks.artwork': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
9
+ 'music.playlists.search': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
10
+ 'music.playlists.categories': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
11
+ 'music.playlists.list': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
12
+ 'music.playlists.get': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
13
+ 'music.charts.list': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
14
+ 'music.charts.getTracks': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
15
+ 'music.importers.list': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
16
+ 'music.importers.parse': (data: any, hooks: import("@shiqianjiang/ceru-plugin-core/dispatch").DispatchHooks) => Promise<any>;
17
+ 'music.play': () => Promise<never>;
18
+ 'music.enqueue': () => Promise<never>;
19
+ };
@@ -0,0 +1,81 @@
1
+ import { MusicRegistry } from '@shiqianjiang/ceru-plugin-core/music';
2
+ export function developmentMusic() {
3
+ const registry = new MusicRegistry();
4
+ const ref = { id: 'sample', providerId: 'dev', scope: 'provider', kind: 'track' };
5
+ const track = {
6
+ ref,
7
+ title: 'Development Track',
8
+ metadata: { artists: ['Ceru'] },
9
+ capabilities: ['play'],
10
+ };
11
+ const empty = { items: [] };
12
+ registry.register({
13
+ pluginId: 'development',
14
+ providerId: 'dev',
15
+ runtime: 3,
16
+ declaration: { id: 'dev', name: '开发示例音源', protocols: ['tracks.search'] },
17
+ methods: [
18
+ 'tracks.search',
19
+ 'tracks.suggest',
20
+ 'tracks.hotSearch',
21
+ 'tracks.resolve',
22
+ 'tracks.lyrics',
23
+ 'tracks.artwork',
24
+ 'playlists.search',
25
+ 'playlists.categories',
26
+ 'playlists.list',
27
+ 'playlists.get',
28
+ 'charts.list',
29
+ 'charts.getTracks',
30
+ ],
31
+ }, async (method, args) => {
32
+ if (method === 'tracks.search')
33
+ return {
34
+ items: track.title.toLowerCase().includes(args[0].query.toLowerCase()) ? [track] : [],
35
+ };
36
+ if (method === 'tracks.suggest' || method === 'tracks.hotSearch')
37
+ return [track.title];
38
+ if (method === 'tracks.resolve')
39
+ return { ok: false, error: { code: 'UNSUPPORTED', message: '开发示例不提供真实媒体' } };
40
+ if (method === 'tracks.lyrics')
41
+ return {
42
+ format: 'crlyric',
43
+ version: 1,
44
+ track: ref,
45
+ offsetMs: 0,
46
+ lines: [],
47
+ plainText: track.title,
48
+ };
49
+ if (method === 'tracks.artwork')
50
+ return undefined;
51
+ return empty;
52
+ });
53
+ const handle = (method) => (data, ctx) => registry.invoke(method, data.args, ctx.pluginId, {
54
+ id: 'dev',
55
+ deadlineAt: Date.now() + 30000,
56
+ signal: ctx.signal,
57
+ });
58
+ return {
59
+ 'music.sources': handle('music.sources'),
60
+ 'music.search': handle('music.search'),
61
+ 'music.suggest': handle('music.suggest'),
62
+ 'music.hotSearch': handle('music.hotSearch'),
63
+ 'music.tracks.resolve': handle('music.tracks.resolve'),
64
+ 'music.tracks.lyrics': handle('music.tracks.lyrics'),
65
+ 'music.tracks.artwork': handle('music.tracks.artwork'),
66
+ 'music.playlists.search': handle('music.playlists.search'),
67
+ 'music.playlists.categories': handle('music.playlists.categories'),
68
+ 'music.playlists.list': handle('music.playlists.list'),
69
+ 'music.playlists.get': handle('music.playlists.get'),
70
+ 'music.charts.list': handle('music.charts.list'),
71
+ 'music.charts.getTracks': handle('music.charts.getTracks'),
72
+ 'music.importers.list': handle('music.importers.list'),
73
+ 'music.importers.parse': handle('music.importers.parse'),
74
+ 'music.play': async () => {
75
+ throw Error('开发示例不连接播放器,请在桌面宿主试听');
76
+ },
77
+ 'music.enqueue': async () => {
78
+ throw Error('开发示例不连接播放队列,请在桌面宿主验证');
79
+ },
80
+ };
81
+ }
@@ -0,0 +1,10 @@
1
+ import type { HostServices } from '@shiqianjiang/ceru-plugin-core/dispatch';
2
+ import type { PluginManifest, JsonValue } from '@shiqianjiang/ceru-plugin-sdk';
3
+ export type MockService = {
4
+ pluginId: string;
5
+ service: string;
6
+ version: string;
7
+ returns: Record<string, JsonValue>;
8
+ };
9
+ export declare function readMockServices(root: string): Promise<MockService[]>;
10
+ export declare function developmentPluginServices(manifest: PluginManifest, rows: MockService[]): Partial<HostServices>;
@@ -0,0 +1,67 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { ServiceRouter } from '@shiqianjiang/ceru-plugin-core/services';
4
+ import { RPC } from '@shiqianjiang/ceru-plugin-core/contract';
5
+ import { parseJsonStrict } from '@shiqianjiang/ceru-plugin-issuer';
6
+ export async function readMockServices(root) {
7
+ try {
8
+ const config = parseJsonStrict(await readFile(join(root, 'ceru.config.json'), 'utf8'));
9
+ const rows = config.mockServices ?? [];
10
+ if (!Array.isArray(rows) || rows.length > 128)
11
+ throw Error('Invalid mockServices');
12
+ return rows;
13
+ }
14
+ catch (error) {
15
+ if (error.code === 'ENOENT')
16
+ return [];
17
+ throw error;
18
+ }
19
+ }
20
+ export function developmentPluginServices(manifest, rows) {
21
+ const router = new ServiceRouter(), grouped = new Map();
22
+ for (const row of rows) {
23
+ if (!row ||
24
+ !row.pluginId ||
25
+ !row.service ||
26
+ !row.version ||
27
+ !row.returns ||
28
+ typeof row.returns !== 'object' ||
29
+ Array.isArray(row.returns))
30
+ throw Error('Invalid mock service');
31
+ const group = grouped.get(row.pluginId) ?? [];
32
+ group.push(row);
33
+ grouped.set(row.pluginId, group);
34
+ }
35
+ for (const [id, records] of grouped) {
36
+ const mock = router.connect({
37
+ ...manifest,
38
+ id,
39
+ provides: {
40
+ services: records.map((row) => ({
41
+ id: row.service,
42
+ version: row.version,
43
+ methods: Object.keys(row.returns),
44
+ })),
45
+ },
46
+ uses: {},
47
+ }, async (service, method) => records.find((row) => row.service === service).returns[method], () => { });
48
+ for (const row of records)
49
+ mock.register(row.service, Object.keys(row.returns));
50
+ mock.attach();
51
+ }
52
+ const missing = router.missing(manifest.uses?.plugins ?? []);
53
+ if (missing)
54
+ throw Error('Missing plugin dependency: ' + missing.pluginId + ' / ' + missing.service + ' ' + missing.version);
55
+ const caller = router.connect(manifest, async () => {
56
+ throw Error('Use the desktop Host to call the current plugin');
57
+ }, () => { });
58
+ return {
59
+ [RPC.plugins.list]: async () => caller.list(),
60
+ [RPC.plugins.use]: async (data) => caller.use(data.pluginId, data.service),
61
+ [RPC.plugins.registerService]: async (data) => {
62
+ caller.register(data.id, data.methods);
63
+ return null;
64
+ },
65
+ [RPC.plugins.invoke]: (data, ctx) => caller.invoke(data.pluginId, data.service, data.method, data.input, ctx.signal),
66
+ };
67
+ }
package/dist/dev.d.ts CHANGED
@@ -1,9 +1 @@
1
- export declare function runDev(project: string, options?: {
2
- port?: number;
3
- noOpen?: boolean;
4
- debugPort?: number;
5
- hidden?: boolean;
6
- electron?: string;
7
- artifact?: string;
8
- ensureRunning?: boolean;
9
- }): Promise<void>;
1
+ export declare function watchProject(project: string, signal: AbortSignal, report?: (message: string) => void): Promise<void>;