@shiqianjiang/ceru-plugin-cli 0.3.6 → 0.3.7
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/assets/core-contracts.js +1 -1
- package/assets/sandbox.js +27 -27
- package/dist/dev.js +89 -33
- package/package.json +3 -3
- package/templates/source/js/src/index.js +9 -1
- package/templates/source/ts/src/index.ts +9 -1
package/dist/dev.js
CHANGED
|
@@ -15,6 +15,86 @@ import { readArtifact, parseJsonStrict, resolveArtifactConfig, } from '@shiqianj
|
|
|
15
15
|
import { buildProject } from './project.js';
|
|
16
16
|
import { DevelopmentStorage } from './storage.js';
|
|
17
17
|
const asset = (name) => fileURLToPath(new URL('../assets/' + name, import.meta.url));
|
|
18
|
+
const developmentServiceMethods = {
|
|
19
|
+
account: ['getSession', 'getProfile'],
|
|
20
|
+
app: ['getInfo'],
|
|
21
|
+
player: ['getState'],
|
|
22
|
+
queue: ['get'],
|
|
23
|
+
history: ['list'],
|
|
24
|
+
downloads: ['list'],
|
|
25
|
+
localMusic: ['list'],
|
|
26
|
+
settings: ['get'],
|
|
27
|
+
rooms: ['getState'],
|
|
28
|
+
devices: ['list'],
|
|
29
|
+
};
|
|
30
|
+
const hostServiceNames = [
|
|
31
|
+
'account',
|
|
32
|
+
'app',
|
|
33
|
+
'library',
|
|
34
|
+
'player',
|
|
35
|
+
'queue',
|
|
36
|
+
'favorites',
|
|
37
|
+
'history',
|
|
38
|
+
'downloads',
|
|
39
|
+
'files',
|
|
40
|
+
'clipboard',
|
|
41
|
+
'localMusic',
|
|
42
|
+
'settings',
|
|
43
|
+
'window',
|
|
44
|
+
'hotkeys',
|
|
45
|
+
'sharing',
|
|
46
|
+
'rooms',
|
|
47
|
+
'devices',
|
|
48
|
+
'ai',
|
|
49
|
+
'tasks',
|
|
50
|
+
];
|
|
51
|
+
const developmentAvailability = (service) => {
|
|
52
|
+
const methods = developmentServiceMethods[service] ?? [];
|
|
53
|
+
return {
|
|
54
|
+
service,
|
|
55
|
+
version: '1.0.0',
|
|
56
|
+
available: methods.length > 0,
|
|
57
|
+
...(methods.length ? { methods } : { reason: 'host-not-connected' }),
|
|
58
|
+
permissionGroups: [],
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const developmentServiceValue = (method, args) => {
|
|
62
|
+
if (method === 'services.account.getSession')
|
|
63
|
+
return { loggedIn: false, profile: null };
|
|
64
|
+
if (method === 'services.account.getProfile')
|
|
65
|
+
return null;
|
|
66
|
+
if (method === 'services.app.getInfo')
|
|
67
|
+
return {
|
|
68
|
+
name: 'Ceru Plugin Development Host',
|
|
69
|
+
version: '0.3.6',
|
|
70
|
+
platform: process.platform,
|
|
71
|
+
locale: 'zh-CN',
|
|
72
|
+
theme: 'light',
|
|
73
|
+
hostApi: '2.0.0',
|
|
74
|
+
};
|
|
75
|
+
if (method === 'services.player.getState')
|
|
76
|
+
return {
|
|
77
|
+
status: 'idle',
|
|
78
|
+
track: null,
|
|
79
|
+
positionMs: 0,
|
|
80
|
+
durationMs: 0,
|
|
81
|
+
volume: 1,
|
|
82
|
+
muted: false,
|
|
83
|
+
repeat: 'off',
|
|
84
|
+
shuffle: false,
|
|
85
|
+
};
|
|
86
|
+
if (method === 'services.queue.get')
|
|
87
|
+
return { items: [], currentIndex: -1, revision: 'development-empty' };
|
|
88
|
+
if (method === 'services.history.list' || method === 'services.localMusic.list')
|
|
89
|
+
return { items: [], totalEstimate: 0 };
|
|
90
|
+
if (method === 'services.downloads.list' || method === 'services.devices.list')
|
|
91
|
+
return [];
|
|
92
|
+
if (method === 'services.settings.get')
|
|
93
|
+
return Object.fromEntries((Array.isArray(args[0]) ? args[0] : []).map((key) => [key, null]));
|
|
94
|
+
if (method === 'services.rooms.getState')
|
|
95
|
+
return { joined: false };
|
|
96
|
+
return undefined;
|
|
97
|
+
};
|
|
18
98
|
function mergeConfig(base, override) {
|
|
19
99
|
const result = structuredClone(base);
|
|
20
100
|
for (const [key, value] of Object.entries(override))
|
|
@@ -463,48 +543,24 @@ export async function runDev(project, options = {}) {
|
|
|
463
543
|
}
|
|
464
544
|
if (input.method === 'services.capabilities.list') {
|
|
465
545
|
json(200, {
|
|
466
|
-
value:
|
|
467
|
-
'account',
|
|
468
|
-
'library',
|
|
469
|
-
'player',
|
|
470
|
-
'queue',
|
|
471
|
-
'favorites',
|
|
472
|
-
'history',
|
|
473
|
-
'downloads',
|
|
474
|
-
'files',
|
|
475
|
-
'clipboard',
|
|
476
|
-
'localMusic',
|
|
477
|
-
'settings',
|
|
478
|
-
'window',
|
|
479
|
-
'hotkeys',
|
|
480
|
-
'sharing',
|
|
481
|
-
'rooms',
|
|
482
|
-
'devices',
|
|
483
|
-
'ai',
|
|
484
|
-
'tasks',
|
|
485
|
-
].map((service) => ({
|
|
486
|
-
service,
|
|
487
|
-
version: '1.0.0',
|
|
488
|
-
available: false,
|
|
489
|
-
reason: 'host-not-connected',
|
|
490
|
-
permissionGroups: [],
|
|
491
|
-
})),
|
|
546
|
+
value: hostServiceNames.map(developmentAvailability),
|
|
492
547
|
});
|
|
493
548
|
return;
|
|
494
549
|
}
|
|
495
550
|
if (input.method === 'services.capabilities.get') {
|
|
496
551
|
const service = String(data.args?.[0] ?? '');
|
|
497
552
|
json(200, {
|
|
498
|
-
value:
|
|
499
|
-
service,
|
|
500
|
-
version: '1.0.0',
|
|
501
|
-
available: false,
|
|
502
|
-
reason: 'host-not-connected',
|
|
503
|
-
permissionGroups: [],
|
|
504
|
-
},
|
|
553
|
+
value: developmentAvailability(service),
|
|
505
554
|
});
|
|
506
555
|
return;
|
|
507
556
|
}
|
|
557
|
+
if (input.method.startsWith('services.')) {
|
|
558
|
+
const value = developmentServiceValue(input.method, data.args ?? []);
|
|
559
|
+
if (value === undefined)
|
|
560
|
+
throw new Error('此独立开发 Host 尚未连接该宿主服务;请先通过 capabilities.get() 检查 methods,并在正式桌面 Host 中验证。');
|
|
561
|
+
json(200, { value });
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
508
564
|
if (input.method === 'http.request') {
|
|
509
565
|
const declaration = artifact.header.manifest.permissions?.find((p) => p.key === data.permissionKey && p.name === 'network.request');
|
|
510
566
|
const grant = declaration && grants.get(declaration.key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shiqianjiang/ceru-plugin-cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "TypeScript scaffolding, single-file build, watch, validation, signing and issuance for Ceru plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/core": "^7.29.7",
|
|
35
|
-
"@shiqianjiang/ceru-plugin-issuer": "0.3.
|
|
36
|
-
"@shiqianjiang/ceru-plugin-sdk": "0.3.
|
|
35
|
+
"@shiqianjiang/ceru-plugin-issuer": "0.3.7",
|
|
36
|
+
"@shiqianjiang/ceru-plugin-sdk": "0.3.7",
|
|
37
37
|
"@vue/babel-plugin-jsx": "^2.0.1",
|
|
38
38
|
"@vue/compiler-sfc": "3.5.43",
|
|
39
39
|
"axios": "^1.20.0",
|
|
@@ -13,10 +13,15 @@ export default definePlugin(async (ctx) => {
|
|
|
13
13
|
/** @type {Readonly<PluginConfig>} */
|
|
14
14
|
const config = await ctx.config.get()
|
|
15
15
|
ctx.actions.register('hello', async () => {
|
|
16
|
+
const appCapability = await ctx.capabilities.get('app')
|
|
17
|
+
const appInfo =
|
|
18
|
+
appCapability.available && appCapability.methods?.includes('getInfo')
|
|
19
|
+
? await ctx.app.getInfo()
|
|
20
|
+
: null
|
|
16
21
|
await ctx.ui.notify({
|
|
17
22
|
key: 'welcome',
|
|
18
23
|
level: 'info',
|
|
19
|
-
message: `${config.displayName}
|
|
24
|
+
message: `${config.displayName} 已就绪${appInfo ? `,宿主版本 ${appInfo.version}` : ''}。试试搜索 Morning、Rain 或 Night。`,
|
|
20
25
|
})
|
|
21
26
|
})
|
|
22
27
|
|
|
@@ -39,6 +44,9 @@ export default definePlugin(async (ctx) => {
|
|
|
39
44
|
title: track.title,
|
|
40
45
|
subtitle: track.artist,
|
|
41
46
|
playable: false,
|
|
47
|
+
// durationMs 使用毫秒;qualitySizes 只放真实字节数。
|
|
48
|
+
// 只有展示大小时使用 qualitySizeLabels;未知大小或 hash 省略。
|
|
49
|
+
// 公共平台歌曲在 ref 中声明 scope: 'provider';私有 ID 保留所属插件/connectionId。
|
|
42
50
|
metadata: { artists: [track.artist] },
|
|
43
51
|
capabilities: [],
|
|
44
52
|
})),
|
|
@@ -11,10 +11,15 @@ const tracks = [
|
|
|
11
11
|
export default definePlugin(async (ctx) => {
|
|
12
12
|
const config = await ctx.config.get<PluginConfig>()
|
|
13
13
|
ctx.actions.register('hello', async () => {
|
|
14
|
+
const appCapability = await ctx.capabilities.get('app')
|
|
15
|
+
const appInfo =
|
|
16
|
+
appCapability.available && appCapability.methods?.includes('getInfo')
|
|
17
|
+
? await ctx.app.getInfo()
|
|
18
|
+
: null
|
|
14
19
|
await ctx.ui.notify({
|
|
15
20
|
key: 'welcome',
|
|
16
21
|
level: 'info',
|
|
17
|
-
message: `${config.displayName}
|
|
22
|
+
message: `${config.displayName} 已就绪${appInfo ? `,宿主版本 ${appInfo.version}` : ''}。试试搜索 Morning、Rain 或 Night。`,
|
|
18
23
|
})
|
|
19
24
|
})
|
|
20
25
|
|
|
@@ -37,6 +42,9 @@ export default definePlugin(async (ctx) => {
|
|
|
37
42
|
title: track.title,
|
|
38
43
|
subtitle: track.artist,
|
|
39
44
|
playable: false,
|
|
45
|
+
// durationMs 使用毫秒;qualitySizes 只放真实字节数。
|
|
46
|
+
// 只有展示大小时使用 qualitySizeLabels;未知大小或 hash 省略。
|
|
47
|
+
// 公共平台歌曲在 ref 中声明 scope: 'provider';私有 ID 保留所属插件/connectionId。
|
|
40
48
|
metadata: { artists: [track.artist] },
|
|
41
49
|
capabilities: [],
|
|
42
50
|
})),
|