@shiqianjiang/ceru-plugin-cli 0.2.3 → 0.2.5
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.md +3 -1
- package/assets/sandbox.js +1 -1
- package/dist/dev.js +23 -6
- package/dist/index.js +1 -1
- package/dist/project.d.ts +2 -0
- package/dist/project.js +190 -24
- package/package.json +4 -4
- package/schemas/config.schema.json +34 -1
- package/templates/connected-library/js/package.json +2 -2
- package/templates/connected-library/js/tsconfig.json +1 -1
- package/templates/connected-library/ts/package.json +2 -2
- package/templates/connected-library/ts/tsconfig.json +1 -1
- package/templates/guest-adapter/js/package.json +2 -2
- package/templates/guest-adapter/js/tsconfig.json +1 -1
- package/templates/guest-adapter/ts/package.json +2 -2
- package/templates/guest-adapter/ts/tsconfig.json +1 -1
- package/templates/importer/js/package.json +2 -2
- package/templates/importer/js/tsconfig.json +1 -1
- package/templates/importer/ts/package.json +2 -2
- package/templates/importer/ts/tsconfig.json +1 -1
- package/templates/react/js/package.json +2 -2
- package/templates/react/js/tsconfig.json +1 -1
- package/templates/react/ts/package.json +2 -2
- package/templates/react/ts/tsconfig.json +1 -1
- package/templates/snapshot.json +1 -1
- package/templates/source/js/README.md +4 -0
- package/templates/source/js/ceru.plugin.json +10 -0
- package/templates/source/js/package.json +2 -2
- package/templates/source/js/src/index.js +6 -2
- package/templates/source/js/src/plugin.config.js +14 -0
- package/templates/source/js/tsconfig.json +1 -1
- package/templates/source/ts/README.md +5 -0
- package/templates/source/ts/ceru.plugin.json +10 -0
- package/templates/source/ts/package.json +2 -2
- package/templates/source/ts/src/index.ts +4 -2
- package/templates/source/ts/src/plugin.config.ts +14 -0
- package/templates/source/ts/tsconfig.json +1 -1
- package/templates/vue/js/package.json +2 -2
- package/templates/vue/js/tsconfig.json +1 -1
- package/templates/vue/ts/package.json +2 -2
- package/templates/vue/ts/tsconfig.json +1 -1
- package/templates/vue-tsx/js/package.json +2 -2
- package/templates/vue-tsx/js/tsconfig.json +1 -1
- package/templates/vue-tsx/ts/package.json +2 -2
- package/templates/vue-tsx/ts/tsconfig.json +1 -1
- package/templates/web-dist/js/package.json +2 -2
- package/templates/web-dist/js/tsconfig.json +1 -1
- package/templates/web-dist/ts/package.json +2 -2
- package/templates/web-dist/ts/tsconfig.json +1 -1
- package/templates/web-surface/js/package.json +2 -2
- package/templates/web-surface/js/tsconfig.json +1 -1
- package/templates/web-surface/ts/package.json +2 -2
- package/templates/web-surface/ts/tsconfig.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,9 @@ ceru-plugin sign dist/plugin.js --key .keys/publisher.private.pem
|
|
|
24
24
|
|
|
25
25
|
Vue/React 生产运行代码会直接打入发行文件,不依赖宿主提供框架。执行 `ceru-plugin preview dist/plugin.js` 可以只加载最终文件验证页面。0.2.0 起发行格式使用静态 `exports.manifest / exports.activate / exports.surfaces`,并支持手写单文件插件。
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
构建产物先用 `const` 定义具名入口(如 `LogicMain`、`UiStudioSurface`)及模块表,再在文件末尾集中写入 `exports.activate / exports.surfaces / exports.resources`,方便阅读单文件产物和定位错误堆栈。插件源码仍可按需要使用函数或 class;构建器不会强制某一种编程风格。
|
|
28
|
+
|
|
29
|
+
`ceru.plugin.json` 的顶层 `config` 可直接写 JSON 对象,也可写 `@./path/config.ts` 引用 JSON/JS/TS 配置模块。字符串 `@@value` 表示字面量 `@value`。构建器递归展开引用,校验为 JSON 兼容对象,并合并到单文件的 `exports.manifest.config` 中。dev/build 会生成不包含配置值的 `@ceru/plugin-config` 类型声明。
|
|
28
30
|
|
|
29
31
|
在多根/父目录工作区中,请打开生成的 ceru-plugin.code-workspace 或把插件工程本身加入工作区。已经运行 dev 时选择 Attach to Ceru plugin;Launch 会启动或复用当前项目的 Host。
|
|
30
32
|
|
package/assets/sandbox.js
CHANGED
|
@@ -64,4 +64,4 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
64
64
|
* Released under MIT license <https://lodash.com/license>
|
|
65
65
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
66
66
|
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
67
|
-
*/var C1=["platform.tx","platform.kg","platform.kw","platform.wy","platform.mg","platform.local","platform.all","search","music-note","library","cloud","server","import","chart","settings","play","pause","download","share","account","heart","refresh","close","add","info"],E1=["app.logo","placeholder.cover","placeholder.avatar"];var F1=["chunk","compact","concat","difference","drop","dropRight","flatten","flattenDeep","head","last","intersection","uniq","uniqBy","union","zip","take","takeRight","groupBy","keyBy","countBy","orderBy","sortBy","partition","shuffle","sample","map","filter","find","some","every","reduce","includes","get","has","pick","omit","mapKeys","mapValues","cloneDeep","isEqual","isEmpty","isNil","isString","isNumber","isArray","isPlainObject","camelCase","kebabCase","snakeCase","startCase","capitalize","escape","unescape","trim","truncate","debounce","throttle","once","memoize","clamp","range","sum","sumBy","round"];var jl=class extends Error{constructor(t,o){super(`${o} returned HTTP ${t.status}`);this.response=t;this.origin=o}response;origin;name="HttpError";get status(){return this.response.status}};function Fp(r,e){let t=new Map;async function o(i,a,u){u.signal.throwIfAborted();let f=await r.permissions.query({key:i});if(f.status==="granted")return;if(f.status!=="prompt"||!e.requestPermission)throw new Error(`Network permission ${i}: ${f.status}`);let m=i,s=t.get(m);s||(s=(async()=>{let p=await r.permissions.request({key:i,intent:u.userIntent});if(p.status!=="granted")throw new Error(`Network permission ${i}: ${p.status}`)})().finally(()=>t.delete(m)),t.set(m,s)),await s,u.signal.throwIfAborted()}async function n(i,a){let u=new URL(i,e.baseURL);if(!["https:","http:"].includes(u.protocol)||u.username||u.password)throw new Error("Invalid HTTP URL");for(let[d,h]of Object.entries(a.query??{})){u.searchParams.delete(d);for(let D of Array.isArray(h)?h:[h])D!=null&&u.searchParams.append(d,String(D))}if([a.json,a.form,a.body].filter(d=>d!==void 0).length>1)throw new Error("Choose one of json, form or body");let f=a.permissionKey??(typeof e.permissionKey=="function"?e.permissionKey(u):e.permissionKey??"network");await o(f,u.origin,a.operation);let m={...e.headers,...a.headers},s=a.body;a.json!==void 0&&(s=JSON.stringify(a.json),Object.keys(m).some(d=>d.toLowerCase()==="content-type")||(m["Content-Type"]="application/json")),a.form&&(s=new URLSearchParams(Object.entries(a.form).filter(([,d])=>d!=null).map(([d,h])=>[d,String(h)])).toString(),Object.keys(m).some(d=>d.toLowerCase()==="content-type")||(m["Content-Type"]="application/x-www-form-urlencoded"));let p=await r.http.request({permissionKey:f,url:u.href,method:(a.method??"GET").toUpperCase(),headers:m,body:s,credential:a.credential,timeoutMs:a.timeoutMs,operation:a.operation});a.operation.signal.throwIfAborted();let l={status:p.status,headers:p.headers,data:p.body};if(a.throwHttpErrors!==!1&&(p.status<200||p.status>=300))throw new jl(l,u.origin);return l}return{request:n,authorize:o,async get(i,a){return(await n(i,{...a,method:"GET"})).data},async post(i,a){return(await n(i,{...a,method:"POST"})).data}}}var B1={capabilities:["list","get"],account:["getSession","getProfile","openLogin"],app:["getInfo","openSettings","openExternal"],player:["getState","play","pause","next","previous","seek","setVolume","setMode"],queue:["get","append","replace","remove","reorder"],favorites:["contains","add","remove"],history:["list"],downloads:["list","create","pause","resume","cancel","retry","reveal"],files:["pick","pickDirectory","readText","readBase64","saveText","writeText"],clipboard:["readText","writeText"],localMusic:["list","scan","getTags","writeTags"],settings:["get","update"],window:["control"],hotkeys:["register"],sharing:["create","revoke","resolve"],rooms:["getState","join","leave","requestTrack"],devices:["list","select"],ai:["generate"],tasks:["schedule","cancel"]};var im={};Vi(im,{constants:()=>nm,createCipheriv:()=>n2,createDecipheriv:()=>i2,createHash:()=>t2,default:()=>vS,publicEncrypt:()=>f2,randomBytes:()=>a2,randomUUID:()=>u2});var lt=Zi(Th(),1),St=Zi(om(),1),Hi=r=>lt.default.enc.Hex.parse(St.Buffer.from(r).toString("hex")),e2=r=>St.Buffer.from(r.toString(lt.default.enc.Hex),"hex");function t2(r){let e={md5:lt.default.algo.MD5,sha1:lt.default.algo.SHA1,sha256:lt.default.algo.SHA256}[r.toLowerCase()];if(!e)throw new Error("Unsupported digest: "+r);let t=e.create();return{update(o){return t.update(Hi(o)),this},digest(o){let n=e2(t.finalize());return o?n.toString(o):n}}}function o2(r,e,t,o){if(!/^aes-(128|192|256)-(cbc|ecb)$/i.test(r))throw new Error("Unsupported cipher: "+r);let n=[];return{update(i){return n.push(St.Buffer.from(i)),St.Buffer.alloc(0)},final(){let i=Hi(St.Buffer.concat(n)),a={mode:r.endsWith("ecb")?lt.default.mode.ECB:lt.default.mode.CBC,iv:Hi(t||""),padding:lt.default.pad.Pkcs7};return e2(o?lt.default.AES.decrypt({ciphertext:i},Hi(e),a):lt.default.AES.encrypt(i,Hi(e),a).ciphertext)}}}var n2=(r,e,t)=>o2(r,e,t,!1),i2=(r,e,t)=>o2(r,e,t,!0),a2=r=>St.Buffer.from(globalThis.crypto.getRandomValues(new Uint8Array(r))),u2=()=>globalThis.crypto.randomUUID(),nm={RSA_NO_PADDING:3};function f2(r,e){if(r.padding!==nm.RSA_NO_PADDING)throw new Error("Unsupported RSA padding");let t=St.Buffer.from(r.key.replace(/-----[^-]+-----|\s/g,""),"base64"),o=0;function n(){let D=t[o++],g=t[o++];if(g&128){let v=g&127;for(g=0;v--;)g=g*256+t[o++]}let x=o;if(o+=g,o>t.length)throw new Error("Invalid RSA key");return{tag:D,start:x,end:o}}o=n().start,n(),o=n().start+1,o=n().start;let f=n(),m=n(),s=BigInt("0x"+t.subarray(f.start,f.end).toString("hex")),p=BigInt("0x"+t.subarray(m.start,m.end).toString("hex")),l=BigInt("0x"+St.Buffer.from(e).toString("hex")),d=1n;if(l>=s)throw new Error("RSA input exceeds modulus");for(;p;)p&1n&&(d=d*l%s),l=l*l%s,p>>=1n;let h=Math.ceil(s.toString(16).length/2);return St.Buffer.from(d.toString(16).padStart(h*2,"0"),"hex")}var vS={createHash:t2,createCipheriv:n2,createDecipheriv:i2,publicEncrypt:f2,randomBytes:a2,randomUUID:u2,constants:nm};var mm={};Vi(mm,{default:()=>LS,inflate:()=>g2,unzipSync:()=>v2});var Ke=Uint8Array,Ei=Uint16Array,gS=Int32Array,s2=new Ke([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),p2=new Ke([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),DS=new Ke([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l2=function(r,e){for(var t=new Ei(31),o=0;o<31;++o)t[o]=e+=1<<r[o-1];for(var n=new gS(t[30]),o=1;o<30;++o)for(var i=t[o];i<t[o+1];++i)n[i]=i-t[o]<<5|o;return{b:t,r:n}},m2=l2(s2,2),c2=m2.b,AS=m2.r;c2[28]=258,AS[258]=28;var x2=l2(p2,0),yS=x2.b,UAr=x2.r,fm=new Ei(32768);for(Fr=0;Fr<32768;++Fr)Ht=(Fr&43690)>>1|(Fr&21845)<<1,Ht=(Ht&52428)>>2|(Ht&13107)<<2,Ht=(Ht&61680)>>4|(Ht&3855)<<4,fm[Fr]=((Ht&65280)>>8|(Ht&255)<<8)>>1;var Ht,Fr,qi=(function(r,e,t){for(var o=r.length,n=0,i=new Ei(e);n<o;++n)r[n]&&++i[r[n]-1];var a=new Ei(e);for(n=1;n<e;++n)a[n]=a[n-1]+i[n-1]<<1;var u;if(t){u=new Ei(1<<e);var f=15-e;for(n=0;n<o;++n)if(r[n])for(var m=n<<4|r[n],s=e-r[n],p=a[r[n]-1]++<<s,l=p|(1<<s)-1;p<=l;++p)u[fm[p]>>f]=m}else for(u=new Ei(o),n=0;n<o;++n)r[n]&&(u[n]=fm[a[r[n]-1]++]>>15-r[n]);return u}),zi=new Ke(288);for(Fr=0;Fr<144;++Fr)zi[Fr]=8;var Fr;for(Fr=144;Fr<256;++Fr)zi[Fr]=9;var Fr;for(Fr=256;Fr<280;++Fr)zi[Fr]=7;var Fr;for(Fr=280;Fr<288;++Fr)zi[Fr]=8;var Fr,d2=new Ke(32);for(Fr=0;Fr<32;++Fr)d2[Fr]=5;var Fr;var CS=qi(zi,9,1);var ES=qi(d2,5,1),am=function(r){for(var e=r[0],t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},mt=function(r,e,t){var o=e/8|0;return(r[o]|r[o+1]<<8)>>(e&7)&t},um=function(r,e){var t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},FS=function(r){return(r+7)/8|0},BS=function(r,e,t){return(e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new Ke(r.subarray(e,t))};var bS=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Ge=function(r,e,t){var o=new Error(e||bS[r]);if(o.code=r,Error.captureStackTrace&&Error.captureStackTrace(o,Ge),!t)throw o;return o},sm=function(r,e,t,o){var n=r.length,i=o?o.length:0;if(!n||e.f&&!e.l)return t||new Ke(0);var a=!t,u=a||e.i!=2,f=e.i;a&&(t=new Ke(n*3));var m=function(Ae){var Jr=t.length;if(Ae>Jr){var Sr=new Ke(Math.max(Jr*2,Ae));Sr.set(t),t=Sr}},s=e.f||0,p=e.p||0,l=e.b||0,d=e.l,h=e.d,D=e.m,g=e.n,x=n*8;do{if(!d){s=mt(r,p,1);var v=mt(r,p+1,3);if(p+=3,v)if(v==1)d=CS,h=ES,D=9,g=5;else if(v==2){var F=mt(r,p,31)+257,O=mt(r,p+10,15)+4,R=F+mt(r,p+5,31)+1;p+=14;for(var k=new Ke(R),z=new Ke(19),B=0;B<O;++B)z[DS[B]]=mt(r,p+B*3,7);p+=O*3;for(var M=am(z),q=(1<<M)-1,I=qi(z,M,1),B=0;B<R;){var X=I[mt(r,p,q)];p+=X&15;var C=X>>4;if(C<16)k[B++]=C;else{var K=0,Q=0;for(C==16?(Q=3+mt(r,p,3),p+=2,K=k[B-1]):C==17?(Q=3+mt(r,p,7),p+=3):C==18&&(Q=11+mt(r,p,127),p+=7);Q--;)k[B++]=K}}var sr=k.subarray(0,F),w=k.subarray(F);D=am(sr),g=am(w),d=qi(sr,D,1),h=qi(w,g,1)}else Ge(1);else{var C=FS(p)+4,A=r[C-4]|r[C-3]<<8,E=C+A;if(E>n){f&&Ge(0);break}u&&m(l+A),t.set(r.subarray(C,E),l),e.b=l+=A,e.p=p=E*8,e.f=s;continue}if(p>x){f&&Ge(0);break}}u&&m(l+131072);for(var T=(1<<D)-1,L=(1<<g)-1,P=p;;P=p){var K=d[um(r,p)&T],vr=K>>4;if(p+=K&15,p>x){f&&Ge(0);break}if(K||Ge(2),vr<256)t[l++]=vr;else if(vr==256){P=p,d=null;break}else{var yr=vr-254;if(vr>264){var B=vr-257,$r=s2[B];yr=mt(r,p,(1<<$r)-1)+c2[B],p+=$r}var tr=h[um(r,p)&L],$e=tr>>4;tr||Ge(3),p+=tr&15;var w=yS[$e];if($e>3){var $r=p2[$e];w+=um(r,p)&(1<<$r)-1,p+=$r}if(p>x){f&&Ge(0);break}u&&m(l+131072);var ct=l+yr;if(l<w){var qt=i-w,It=Math.min(w,ct);for(qt+l<0&&Ge(3);l<It;++l)t[l]=o[qt+l]}for(;l<ct;++l)t[l]=t[l-w]}}e.l=d,e.p=P,e.b=l,e.f=s,d&&(s=1,e.m=D,e.d=h,e.n=g)}while(!s);return l!=t.length&&a?BS(t,0,l):t.subarray(0,l)};var _S=new Ke(0);var wS=function(r){(r[0]!=31||r[1]!=139||r[2]!=8)&&Ge(6,"invalid gzip data");var e=r[3],t=10;e&4&&(t+=(r[10]|r[11]<<8)+2);for(var o=(e>>3&1)+(e>>4&1);o>0;o-=!r[t++]);return t+(e&2)},SS=function(r){var e=r.length;return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0};var IS=function(r,e){return((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&Ge(6,"invalid zlib data"),(r[1]>>5&1)==+!e&&Ge(6,"invalid zlib data: "+(r[1]&32?"need":"unexpected")+" dictionary"),(r[1]>>3&4)+2};function RS(r,e){return sm(r,{i:2},e&&e.out,e&&e.dictionary)}function PS(r,e){var t=wS(r);return t+8>r.length&&Ge(6,"invalid gzip data"),sm(r.subarray(t,-8),{i:2},e&&e.out||new Ke(SS(r)),e&&e.dictionary)}function pm(r,e){return sm(r.subarray(IS(r,e&&e.dictionary),-4),{i:2},e&&e.out,e&&e.dictionary)}function h2(r,e){return r[0]==31&&r[1]==139&&r[2]==8?PS(r,e):(r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31?RS(r,e):pm(r,e)}var OS=typeof TextDecoder<"u"&&new TextDecoder,TS=0;try{OS.decode(_S,{stream:!0}),TS=1}catch{}var lm=Zi(om(),1),v2=r=>lm.Buffer.from(h2(r));function g2(r,e){try{e(null,lm.Buffer.from(pm(r)))}catch(t){e(t)}}var LS={unzipSync:v2,inflate:g2};var cm={};Vi(cm,{default:()=>kS});var kS={decode:(r,e)=>new TextDecoder(e).decode(r)};var A2=Zi(D2(),1);function y2(r){let e=Fp(r,{permissionKey:"network",requestPermission:!0}),t,o=Promise.resolve();function n(f,m){let s=o.then(async()=>{f.signal.throwIfAborted(),t=f;try{return await m()}finally{t=void 0}});return o=s.catch(()=>{}),s}function i(){return"network"}let a=e.authorize;function u(f,m={}){let s=t,p=!1;return{promise:(async()=>{if(!s)throw new Error("\u8BF7\u6C42\u7F3A\u5C11\u64CD\u4F5C\u4E0A\u4E0B\u6587");s.signal.throwIfAborted();let d=new URL(f),h=i();if(await a(h,d.origin,s),p)throw new Error("\u8BF7\u6C42\u5DF2\u53D6\u6D88");let D={"User-Agent":"Mozilla/5.0"};for(let[A,E]of Object.entries(m.headers??{}))E!=null&&!/^(host|connection|content-length|transfer-encoding|accept-encoding|proxy-.*|upgrade)$/i.test(A)&&(D[A]=String(E));let g;m.form?(D["Content-Type"]="application/x-www-form-urlencoded",g=new URLSearchParams(Object.entries(m.form).map(([A,E])=>[A,String(E)])).toString()):m.body!=null&&(typeof m.body=="string"?g=m.body:(g=JSON.stringify(m.body),D["Content-Type"]="application/json"));let x=await r.http.request({permissionKey:h,url:d.href,method:(m.method??"GET").toUpperCase(),headers:D,body:g,timeoutMs:Number(m.timeout)||void 0,operation:s}),v=x.headers.location;for(let A=0;x.status>=300&&x.status<400&&x.headers.location;A++){if(A>=4)throw new Error("\u5E73\u53F0\u91CD\u5B9A\u5411\u6B21\u6570\u8FC7\u591A");let E=new URL(x.headers.location,d);if(!["http:","https:"].includes(E.protocol))throw new Error("\u5E73\u53F0\u91CD\u5B9A\u5411\u534F\u8BAE\u4E0D\u53D7\u652F\u6301");await a(i(),E.origin,s),x=await r.http.request({permissionKey:i(),url:E.href,method:"GET",operation:s}),d.href=E.href}if(s.signal.throwIfAborted(),p)throw new Error("\u8BF7\u6C42\u5DF2\u53D6\u6D88");if(x.status>=400)throw new Error(d.hostname+" \u8FD4\u56DE HTTP "+x.status);let C=x.body;if(typeof C=="string"){let A=C.trim().replace(/^[\w.$]+\s*\((\{[\s\S]*\})\)\s*;?$/,"$1");try{C=A2.default.parse(A)}catch{}}return{body:C,statusCode:x.status,headers:{...x.headers,...v?{location:d.href}:{}},raw:x.body,url:d.href}})(),cancelHttp(){p=!0}}}return{httpFetch:u,withOperation:n,ensurePermission:a,permissionKey:i}}var ne,vm,C2=!1,MS=0,ml=new Map,gm=new Map,Dm=new Map,Am=new Map,hm=new Map,ym=new Set,Cm=[],Em=new Map,Fm={"tracks.search":"search","tracks.resolve":"resolve","tracks.lyrics":"lyrics","playlists.categories":"categories","playlists.list":"list","playlists.get":"list","sharing.describe":"share"};function WS(r,e){let t=e.split("."),o=t.slice(0,-1).reduce((i,a)=>i?.[a],r),n=o?.[t.at(-1)];return typeof n=="function"?n.bind(o):typeof r?.[Fm[e]]=="function"?r[Fm[e]].bind(r):void 0}function US(r){let e=new Set;for(let[t,o]of Object.entries(r??{}))if(typeof o=="function")e.add(t);else if(o&&typeof o=="object")for(let[n,i]of Object.entries(o))typeof i=="function"&&e.add(t+"."+n);for(let[t,o]of Object.entries(Fm))typeof r?.[o]=="function"&&e.add(t);return[...e]}var NS=r=>{let e=new WeakSet;try{return JSON.parse(JSON.stringify(r,(t,o)=>{if(/password|secret|api.?key|authorization|token|credential/i.test(t))return"[redacted]";if(o instanceof Error)return{name:o.name,message:o.message,stack:o.stack};if(typeof o=="object"&&o){if(e.has(o))return"[circular]";e.add(o)}return typeof o=="function"?"[function]":typeof o=="bigint"?String(o):o})??"null")}catch{return String(r)}},he=(r,e={})=>parent.postMessage({type:r,data:e,generation:ne?.generation},"*");for(let r of["debug","log","info","warn","error"]){let e=console[r].bind(console);console[r]=(...t)=>{e(...t),he("log",{level:r,values:NS(t)})}}function wr(r,e={}){let t="rpc-"+ ++MS;return new Promise((o,n)=>{ml.set(t,{resolve:o,reject:n,timer:setTimeout(()=>{ml.delete(t),n(new Error("Host RPC timed out: "+r))},2e4)}),he("rpc",{id:t,method:r,data:e})})}function HS(){let r={};for(let e of F1)r[e]=zl[e];return{host:Object.freeze({apiVersion:"2.0.0",libraries:{lodash:"4.18.1",icons:"1.0.0",assets:"1.0.0",...ne.catalog.libraries},mode:"development"}),utils:{lodash:Object.freeze(r)},icons:{list:()=>C1,url:async e=>{let t=ne.catalog.icons[e];if(!t)throw new Error("Unknown Host icon: "+e);return"data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(t)))}},assets:{list:()=>E1,url:async e=>{if(typeof e=="string"){let o=ne.catalog.assets[e];if(!o)throw new Error("Unknown Host asset: "+e);return o}let t=ne.resources[e.id];if(!t||t.type==="json")throw new Error("Unknown image/text resource");return"data:"+(t.mime||"text/plain")+";base64,"+(t.type==="base64"?t.value:btoa(unescape(encodeURIComponent(t.value))))}}}}function qS(){if(ne.kind==="web")for(let r of ne.manifest.contributes?.styles??[]){if(!(r.scope==="surface"||r.scope==="slot"&&ne.mount?.kind==="slot"&&r.slots?.includes(ne.mount.slot)))continue;let t=ne.resources[r.resource];if(t?.type!=="text")continue;let o=document.createElement("style");o.dataset.ceruStyle=r.id,o.textContent=t.value,document.head.append(o)}}function zS(){let r=HS();if(ne.kind==="web")return qS(),{...r,root:document.getElementById("plugin-root"),mount:ne.mount??{kind:"page"},invoke:(t,o)=>wr("surface.invoke",{action:t,input:o}),subscribe:t=>(ym.add(t),()=>ym.delete(t))};if(ne.kind==="guest")return{host:r.host,utils:r.utils,guestId:"development-guest",expose:(t,o)=>{if(["__proto__","constructor","prototype"].includes(t))throw new Error("Unsafe global");globalThis[t]=o},invokeHost:(t,o)=>wr("guest."+t,o)};let e=ne.manifest;return{...r,...Object.fromEntries(Object.entries(B1).map(([t,o])=>[t,Object.fromEntries(o.map(n=>[n,(...i)=>wr("services."+t+"."+n,{args:i})]))])),events:{on:()=>{throw new Error("Application events require a connected desktop Host")}},plugin:{id:e.id,version:e.version},config:{get:()=>wr("config.get")},playlistImporters:{register:(t,o)=>{if(!e.contributes?.playlistImporters?.some(n=>n.id===t))throw new Error("Undeclared playlist importer: "+t);return Dm.set(t,o),he("register",{kind:"playlist-importer",id:t,methods:Object.keys(o)}),()=>{Dm.delete(t),he("unregister",{kind:"playlist-importer",id:t})}}},library:{playlists:Object.fromEntries(["list","getTracks","import"].map(t=>[t,o=>wr("library.playlists."+t,{...o,operation:{id:o.operation?.id,deadlineAt:o.operation?.deadlineAt,userIntent:o.operation?.userIntent}})]))},providers:{register:(t,o)=>{if(!e.contributes?.providers?.some(n=>n.id===t))throw new Error("Undeclared provider: "+t);return gm.set(t,o),he("register",{kind:"provider",id:t,methods:US(o)}),()=>{gm.delete(t),he("unregister",{kind:"provider",id:t})}}},actions:{register:(t,o)=>{if(!e.contributes?.commands?.some(n=>n.action===t))throw new Error("Undeclared action: "+t);return Am.set(t,o),he("register",{kind:"action",id:t}),()=>{Am.delete(t),he("unregister",{kind:"action",id:t})}}},permissions:{getGranted:()=>wr("permissions.getGranted"),requestGroup:t=>wr("permissions.requestGroup",t),query:t=>wr("permissions.query",t),request:t=>wr("permissions.request",t)},http:{create:t=>Fp({http:{request:o=>wr("http.request",{...o,operation:{id:o.operation?.id,deadlineAt:o.operation?.deadlineAt}})},permissions:{query:o=>wr("permissions.query",o),request:o=>wr("permissions.request",o)}},t),request:t=>wr("http.request",{...t,operation:{id:t.operation?.id,deadlineAt:t.operation?.deadlineAt}})},credentials:{get:()=>Promise.resolve(null)},sockets:{connect:async t=>{let o=t.permissionKey??"network.socket",n=await wr("permissions.query",{key:o});if(n.status==="prompt"&&(n=await wr("permissions.request",{key:o,intent:t.operation?.userIntent})),n.status!=="granted")throw new Error("Socket permission is not granted");t.operation?.signal?.throwIfAborted();let{id:i}=await wr("sockets.connect",{...t,permissionKey:o,operation:{id:t.operation?.id,deadlineAt:t.operation?.deadlineAt}}),a=new Map;Em.set(i,a);let u=async()=>{Em.delete(i),await wr("sockets.disconnect",{id:i})};return Cm.push(u),{id:i,on:(f,m)=>{let s=a.get(f);return s||(s=new Set,a.set(f,s)),s.add(m),()=>{s?.delete(m)}},emit:(f,m)=>wr("sockets.send",{id:i,event:f,data:m}),send:f=>wr("sockets.send",{id:i,event:"message",data:f}),disconnect:u}}},playback:{failure:t=>({ok:!1,error:t})},ui:{dialogs:{confirm:t=>wr("ui.dialogs.confirm",t),prompt:t=>wr("ui.dialogs.prompt",t),pickPlaylist:t=>wr("ui.dialogs.pickPlaylist",t)},navigation:{open:t=>wr("ui.navigation.open",t)},notifications:{show:(t,o)=>wr("ui.notifications.show",{...t,call:o})},progress:Object.fromEntries(["create","update","close"].map(t=>[t,(...o)=>wr("ui.progress."+t,{args:o})])),toast:t=>(he("notify",{key:"toast",level:"info",...t}),Promise.resolve()),playlistImport:{open:t=>wr("ui.playlistImport.open",t)},setState:(t,o)=>(he("state",{surfaceId:t,state:o}),Promise.resolve()),notify:t=>(he("notify",t),Promise.resolve()),openView:t=>(he("open-view",{surfaceId:t}),Promise.resolve())},storage:{get:t=>wr("storage.get",{key:t}),set:(t,o)=>wr("storage.set",{key:t,value:o}),delete:t=>wr("storage.delete",{key:t})},guests:{list:()=>Promise.resolve([]),prepareInstall:()=>Promise.reject(new Error("Guest installation requires the production Host; inspect the bootstrap module separately in this playground.")),requestInstall:()=>Promise.reject(new Error("Guest installation is unavailable in this playground.")),invoke:()=>Promise.reject(new Error("No Guest instance is installed."))},log:Object.fromEntries(["debug","info","warn","error"].map(t=>[t,(o,n)=>console[t](o,n)])),effects:{add:t=>Cm.push(t)}}}async function E2(){if(!(!ne||!vm||C2)){C2=!0;try{let r=zS(),e={ceru:r,"@ceru/tools":r.utils,lodash:r.utils?.lodash,"@ceru/crypto":im,"@ceru/compression":mm,"@ceru/encoding":cm,"@ceru/legacy-http":{createLegacyHttpBridge:y2}};ne.kind==="logic"&&Object.assign(e,{"@ceru/http":r.http,"@ceru/ui":r.ui,"@ceru/socket":r.sockets,"@ceru/library":r.library,"@ceru/account":r.account,"@ceru/player":r.player});let t=n=>{if(!Object.hasOwn(e,n))throw new Error("Module is not provided by this Host: "+n);return e[n]};r.modules={require:t},globalThis.__ceruRequire=t,globalThis.require=t,globalThis.__ceruContext=r;let o=await vm(r);typeof o=="function"&&Cm.push(o),he("active")}catch(r){console.error(r),he("failed",{message:String(r)})}}}globalThis.__ceruStart=r=>{vm=r,E2()};window.addEventListener("message",async r=>{if(r.source!==parent)return;let e=r.data;if(e?.type==="init"&&!ne){ne=e.data,E2();return}if(!(!ne||e?.generation!==ne.generation)){if(e.type==="rpc-result"){let t=ml.get(e.data.id);t&&(clearTimeout(t.timer),ml.delete(e.data.id),e.data.error?t.reject(new Error(e.data.error)):t.resolve(e.data.value))}if(e.type==="state")for(let t of ym)t(e.data);if(e.type==="socket-event"){let{id:t,event:o,data:n}=e.data;for(let i of Em.get(t)?.get(o)??[])try{i(n)}catch(a){console.error(a)}}if(e.type==="cancel"&&(hm.get(e.data.id)?.abort(),wr("operations.cancel",{id:e.data.id}).catch(()=>{})),e.type==="invoke"){let{id:t,kind:o,target:n,method:i,args:a}=e.data,u=new AbortController;hm.set(t,u);let f=setTimeout(()=>u.abort(),15e3),m={id:t,deadlineAt:Date.now()+15e3,signal:u.signal,userIntent:{kind:"user-intent",id:t}};try{let s=o==="action"?Am.get(n):o==="playlist-importer"?Dm.get(n)?.[i]:WS(gm.get(n),i);if(typeof s!="function")throw new Error("Method is not registered");let p=await s(...a,m);he("invoke-result",{id:t,value:p})}catch(s){he("invoke-result",{id:t,error:s instanceof Error?s.message:String(s)})}finally{clearTimeout(f),hm.delete(t)}}}});window.addEventListener("error",r=>he("failed",{message:r.message}));window.addEventListener("unhandledrejection",r=>console.error(r.reason));he("ready");})();
|
|
67
|
+
*/var C1=["platform.tx","platform.kg","platform.kw","platform.wy","platform.mg","platform.local","platform.all","search","music-note","library","cloud","server","import","chart","settings","play","pause","download","share","account","heart","refresh","close","add","info"],E1=["app.logo","placeholder.cover","placeholder.avatar"];var F1=["chunk","compact","concat","difference","drop","dropRight","flatten","flattenDeep","head","last","intersection","uniq","uniqBy","union","zip","take","takeRight","groupBy","keyBy","countBy","orderBy","sortBy","partition","shuffle","sample","map","filter","find","some","every","reduce","includes","get","has","pick","omit","mapKeys","mapValues","cloneDeep","isEqual","isEmpty","isNil","isString","isNumber","isArray","isPlainObject","camelCase","kebabCase","snakeCase","startCase","capitalize","escape","unescape","trim","truncate","debounce","throttle","once","memoize","clamp","range","sum","sumBy","round"];var jl=class extends Error{constructor(t,o){super(`${o} returned HTTP ${t.status}`);this.response=t;this.origin=o}response;origin;name="HttpError";get status(){return this.response.status}};function Fp(r,e){let t=new Map;async function o(i,a,u){u.signal.throwIfAborted();let f=await r.permissions.query({key:i});if(f.status==="granted")return;if(f.status!=="prompt"||!e.requestPermission)throw new Error(`Network permission ${i}: ${f.status}`);let m=i,s=t.get(m);s||(s=(async()=>{let p=await r.permissions.request({key:i,intent:u.userIntent});if(p.status!=="granted")throw new Error(`Network permission ${i}: ${p.status}`)})().finally(()=>t.delete(m)),t.set(m,s)),await s,u.signal.throwIfAborted()}async function n(i,a){let u=new URL(i,e.baseURL);if(!["https:","http:"].includes(u.protocol)||u.username||u.password)throw new Error("Invalid HTTP URL");for(let[d,h]of Object.entries(a.query??{})){u.searchParams.delete(d);for(let D of Array.isArray(h)?h:[h])D!=null&&u.searchParams.append(d,String(D))}if([a.json,a.form,a.body].filter(d=>d!==void 0).length>1)throw new Error("Choose one of json, form or body");let f=a.permissionKey??(typeof e.permissionKey=="function"?e.permissionKey(u):e.permissionKey??"network");await o(f,u.origin,a.operation);let m={...e.headers,...a.headers},s=a.body;a.json!==void 0&&(s=JSON.stringify(a.json),Object.keys(m).some(d=>d.toLowerCase()==="content-type")||(m["Content-Type"]="application/json")),a.form&&(s=new URLSearchParams(Object.entries(a.form).filter(([,d])=>d!=null).map(([d,h])=>[d,String(h)])).toString(),Object.keys(m).some(d=>d.toLowerCase()==="content-type")||(m["Content-Type"]="application/x-www-form-urlencoded"));let p=await r.http.request({permissionKey:f,url:u.href,method:(a.method??"GET").toUpperCase(),headers:m,body:s,credential:a.credential,timeoutMs:a.timeoutMs,operation:a.operation});a.operation.signal.throwIfAborted();let l={status:p.status,headers:p.headers,data:p.body};if(a.throwHttpErrors!==!1&&(p.status<200||p.status>=300))throw new jl(l,u.origin);return l}return{request:n,authorize:o,async get(i,a){return(await n(i,{...a,method:"GET"})).data},async post(i,a){return(await n(i,{...a,method:"POST"})).data}}}var B1={capabilities:["list","get"],account:["getSession","getProfile","openLogin"],app:["getInfo","openSettings","openExternal"],player:["getState","play","pause","next","previous","seek","setVolume","setMode"],queue:["get","append","replace","remove","reorder"],favorites:["contains","add","remove"],history:["list"],downloads:["list","create","pause","resume","cancel","retry","reveal"],files:["pick","pickDirectory","readText","readBase64","saveText","writeText"],clipboard:["readText","writeText"],localMusic:["list","scan","getTags","writeTags"],settings:["get","update"],window:["control"],hotkeys:["register"],sharing:["create","revoke","resolve"],rooms:["getState","join","leave","requestTrack"],devices:["list","select"],ai:["generate"],tasks:["schedule","cancel"]};var im={};Vi(im,{constants:()=>nm,createCipheriv:()=>n2,createDecipheriv:()=>i2,createHash:()=>t2,default:()=>vS,publicEncrypt:()=>f2,randomBytes:()=>a2,randomUUID:()=>u2});var lt=Zi(Th(),1),St=Zi(om(),1),Hi=r=>lt.default.enc.Hex.parse(St.Buffer.from(r).toString("hex")),e2=r=>St.Buffer.from(r.toString(lt.default.enc.Hex),"hex");function t2(r){let e={md5:lt.default.algo.MD5,sha1:lt.default.algo.SHA1,sha256:lt.default.algo.SHA256}[r.toLowerCase()];if(!e)throw new Error("Unsupported digest: "+r);let t=e.create();return{update(o){return t.update(Hi(o)),this},digest(o){let n=e2(t.finalize());return o?n.toString(o):n}}}function o2(r,e,t,o){if(!/^aes-(128|192|256)-(cbc|ecb)$/i.test(r))throw new Error("Unsupported cipher: "+r);let n=[];return{update(i){return n.push(St.Buffer.from(i)),St.Buffer.alloc(0)},final(){let i=Hi(St.Buffer.concat(n)),a={mode:r.endsWith("ecb")?lt.default.mode.ECB:lt.default.mode.CBC,iv:Hi(t||""),padding:lt.default.pad.Pkcs7};return e2(o?lt.default.AES.decrypt({ciphertext:i},Hi(e),a):lt.default.AES.encrypt(i,Hi(e),a).ciphertext)}}}var n2=(r,e,t)=>o2(r,e,t,!1),i2=(r,e,t)=>o2(r,e,t,!0),a2=r=>St.Buffer.from(globalThis.crypto.getRandomValues(new Uint8Array(r))),u2=()=>globalThis.crypto.randomUUID(),nm={RSA_NO_PADDING:3};function f2(r,e){if(r.padding!==nm.RSA_NO_PADDING)throw new Error("Unsupported RSA padding");let t=St.Buffer.from(r.key.replace(/-----[^-]+-----|\s/g,""),"base64"),o=0;function n(){let D=t[o++],g=t[o++];if(g&128){let v=g&127;for(g=0;v--;)g=g*256+t[o++]}let x=o;if(o+=g,o>t.length)throw new Error("Invalid RSA key");return{tag:D,start:x,end:o}}o=n().start,n(),o=n().start+1,o=n().start;let f=n(),m=n(),s=BigInt("0x"+t.subarray(f.start,f.end).toString("hex")),p=BigInt("0x"+t.subarray(m.start,m.end).toString("hex")),l=BigInt("0x"+St.Buffer.from(e).toString("hex")),d=1n;if(l>=s)throw new Error("RSA input exceeds modulus");for(;p;)p&1n&&(d=d*l%s),l=l*l%s,p>>=1n;let h=Math.ceil(s.toString(16).length/2);return St.Buffer.from(d.toString(16).padStart(h*2,"0"),"hex")}var vS={createHash:t2,createCipheriv:n2,createDecipheriv:i2,publicEncrypt:f2,randomBytes:a2,randomUUID:u2,constants:nm};var mm={};Vi(mm,{default:()=>LS,inflate:()=>g2,unzipSync:()=>v2});var Ke=Uint8Array,Ei=Uint16Array,gS=Int32Array,s2=new Ke([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),p2=new Ke([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),DS=new Ke([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),l2=function(r,e){for(var t=new Ei(31),o=0;o<31;++o)t[o]=e+=1<<r[o-1];for(var n=new gS(t[30]),o=1;o<30;++o)for(var i=t[o];i<t[o+1];++i)n[i]=i-t[o]<<5|o;return{b:t,r:n}},m2=l2(s2,2),c2=m2.b,AS=m2.r;c2[28]=258,AS[258]=28;var x2=l2(p2,0),yS=x2.b,UAr=x2.r,fm=new Ei(32768);for(Fr=0;Fr<32768;++Fr)Ht=(Fr&43690)>>1|(Fr&21845)<<1,Ht=(Ht&52428)>>2|(Ht&13107)<<2,Ht=(Ht&61680)>>4|(Ht&3855)<<4,fm[Fr]=((Ht&65280)>>8|(Ht&255)<<8)>>1;var Ht,Fr,qi=(function(r,e,t){for(var o=r.length,n=0,i=new Ei(e);n<o;++n)r[n]&&++i[r[n]-1];var a=new Ei(e);for(n=1;n<e;++n)a[n]=a[n-1]+i[n-1]<<1;var u;if(t){u=new Ei(1<<e);var f=15-e;for(n=0;n<o;++n)if(r[n])for(var m=n<<4|r[n],s=e-r[n],p=a[r[n]-1]++<<s,l=p|(1<<s)-1;p<=l;++p)u[fm[p]>>f]=m}else for(u=new Ei(o),n=0;n<o;++n)r[n]&&(u[n]=fm[a[r[n]-1]++]>>15-r[n]);return u}),zi=new Ke(288);for(Fr=0;Fr<144;++Fr)zi[Fr]=8;var Fr;for(Fr=144;Fr<256;++Fr)zi[Fr]=9;var Fr;for(Fr=256;Fr<280;++Fr)zi[Fr]=7;var Fr;for(Fr=280;Fr<288;++Fr)zi[Fr]=8;var Fr,d2=new Ke(32);for(Fr=0;Fr<32;++Fr)d2[Fr]=5;var Fr;var CS=qi(zi,9,1);var ES=qi(d2,5,1),am=function(r){for(var e=r[0],t=1;t<r.length;++t)r[t]>e&&(e=r[t]);return e},mt=function(r,e,t){var o=e/8|0;return(r[o]|r[o+1]<<8)>>(e&7)&t},um=function(r,e){var t=e/8|0;return(r[t]|r[t+1]<<8|r[t+2]<<16)>>(e&7)},FS=function(r){return(r+7)/8|0},BS=function(r,e,t){return(e==null||e<0)&&(e=0),(t==null||t>r.length)&&(t=r.length),new Ke(r.subarray(e,t))};var bS=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],Ge=function(r,e,t){var o=new Error(e||bS[r]);if(o.code=r,Error.captureStackTrace&&Error.captureStackTrace(o,Ge),!t)throw o;return o},sm=function(r,e,t,o){var n=r.length,i=o?o.length:0;if(!n||e.f&&!e.l)return t||new Ke(0);var a=!t,u=a||e.i!=2,f=e.i;a&&(t=new Ke(n*3));var m=function(Ae){var Jr=t.length;if(Ae>Jr){var Sr=new Ke(Math.max(Jr*2,Ae));Sr.set(t),t=Sr}},s=e.f||0,p=e.p||0,l=e.b||0,d=e.l,h=e.d,D=e.m,g=e.n,x=n*8;do{if(!d){s=mt(r,p,1);var v=mt(r,p+1,3);if(p+=3,v)if(v==1)d=CS,h=ES,D=9,g=5;else if(v==2){var F=mt(r,p,31)+257,O=mt(r,p+10,15)+4,R=F+mt(r,p+5,31)+1;p+=14;for(var k=new Ke(R),z=new Ke(19),B=0;B<O;++B)z[DS[B]]=mt(r,p+B*3,7);p+=O*3;for(var M=am(z),q=(1<<M)-1,I=qi(z,M,1),B=0;B<R;){var X=I[mt(r,p,q)];p+=X&15;var C=X>>4;if(C<16)k[B++]=C;else{var K=0,Q=0;for(C==16?(Q=3+mt(r,p,3),p+=2,K=k[B-1]):C==17?(Q=3+mt(r,p,7),p+=3):C==18&&(Q=11+mt(r,p,127),p+=7);Q--;)k[B++]=K}}var sr=k.subarray(0,F),w=k.subarray(F);D=am(sr),g=am(w),d=qi(sr,D,1),h=qi(w,g,1)}else Ge(1);else{var C=FS(p)+4,A=r[C-4]|r[C-3]<<8,E=C+A;if(E>n){f&&Ge(0);break}u&&m(l+A),t.set(r.subarray(C,E),l),e.b=l+=A,e.p=p=E*8,e.f=s;continue}if(p>x){f&&Ge(0);break}}u&&m(l+131072);for(var T=(1<<D)-1,L=(1<<g)-1,P=p;;P=p){var K=d[um(r,p)&T],vr=K>>4;if(p+=K&15,p>x){f&&Ge(0);break}if(K||Ge(2),vr<256)t[l++]=vr;else if(vr==256){P=p,d=null;break}else{var yr=vr-254;if(vr>264){var B=vr-257,$r=s2[B];yr=mt(r,p,(1<<$r)-1)+c2[B],p+=$r}var tr=h[um(r,p)&L],$e=tr>>4;tr||Ge(3),p+=tr&15;var w=yS[$e];if($e>3){var $r=p2[$e];w+=um(r,p)&(1<<$r)-1,p+=$r}if(p>x){f&&Ge(0);break}u&&m(l+131072);var ct=l+yr;if(l<w){var qt=i-w,It=Math.min(w,ct);for(qt+l<0&&Ge(3);l<It;++l)t[l]=o[qt+l]}for(;l<ct;++l)t[l]=t[l-w]}}e.l=d,e.p=P,e.b=l,e.f=s,d&&(s=1,e.m=D,e.d=h,e.n=g)}while(!s);return l!=t.length&&a?BS(t,0,l):t.subarray(0,l)};var _S=new Ke(0);var wS=function(r){(r[0]!=31||r[1]!=139||r[2]!=8)&&Ge(6,"invalid gzip data");var e=r[3],t=10;e&4&&(t+=(r[10]|r[11]<<8)+2);for(var o=(e>>3&1)+(e>>4&1);o>0;o-=!r[t++]);return t+(e&2)},SS=function(r){var e=r.length;return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0};var IS=function(r,e){return((r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31)&&Ge(6,"invalid zlib data"),(r[1]>>5&1)==+!e&&Ge(6,"invalid zlib data: "+(r[1]&32?"need":"unexpected")+" dictionary"),(r[1]>>3&4)+2};function RS(r,e){return sm(r,{i:2},e&&e.out,e&&e.dictionary)}function PS(r,e){var t=wS(r);return t+8>r.length&&Ge(6,"invalid gzip data"),sm(r.subarray(t,-8),{i:2},e&&e.out||new Ke(SS(r)),e&&e.dictionary)}function pm(r,e){return sm(r.subarray(IS(r,e&&e.dictionary),-4),{i:2},e&&e.out,e&&e.dictionary)}function h2(r,e){return r[0]==31&&r[1]==139&&r[2]==8?PS(r,e):(r[0]&15)!=8||r[0]>>4>7||(r[0]<<8|r[1])%31?RS(r,e):pm(r,e)}var OS=typeof TextDecoder<"u"&&new TextDecoder,TS=0;try{OS.decode(_S,{stream:!0}),TS=1}catch{}var lm=Zi(om(),1),v2=r=>lm.Buffer.from(h2(r));function g2(r,e){try{e(null,lm.Buffer.from(pm(r)))}catch(t){e(t)}}var LS={unzipSync:v2,inflate:g2};var cm={};Vi(cm,{default:()=>kS});var kS={decode:(r,e)=>new TextDecoder(e).decode(r)};var A2=Zi(D2(),1);function y2(r){let e=Fp(r,{permissionKey:"network",requestPermission:!0}),t,o=Promise.resolve();function n(f,m){let s=o.then(async()=>{f.signal.throwIfAborted(),t=f;try{return await m()}finally{t=void 0}});return o=s.catch(()=>{}),s}function i(){return"network"}let a=e.authorize;function u(f,m={}){let s=t,p=!1;return{promise:(async()=>{if(!s)throw new Error("\u8BF7\u6C42\u7F3A\u5C11\u64CD\u4F5C\u4E0A\u4E0B\u6587");s.signal.throwIfAborted();let d=new URL(f),h=i();if(await a(h,d.origin,s),p)throw new Error("\u8BF7\u6C42\u5DF2\u53D6\u6D88");let D={"User-Agent":"Mozilla/5.0"};for(let[A,E]of Object.entries(m.headers??{}))E!=null&&!/^(host|connection|content-length|transfer-encoding|accept-encoding|proxy-.*|upgrade)$/i.test(A)&&(D[A]=String(E));let g;m.form?(D["Content-Type"]="application/x-www-form-urlencoded",g=new URLSearchParams(Object.entries(m.form).map(([A,E])=>[A,String(E)])).toString()):m.body!=null&&(typeof m.body=="string"?g=m.body:(g=JSON.stringify(m.body),D["Content-Type"]="application/json"));let x=await r.http.request({permissionKey:h,url:d.href,method:(m.method??"GET").toUpperCase(),headers:D,body:g,timeoutMs:Number(m.timeout)||void 0,operation:s}),v=x.headers.location;for(let A=0;x.status>=300&&x.status<400&&x.headers.location;A++){if(A>=4)throw new Error("\u5E73\u53F0\u91CD\u5B9A\u5411\u6B21\u6570\u8FC7\u591A");let E=new URL(x.headers.location,d);if(!["http:","https:"].includes(E.protocol))throw new Error("\u5E73\u53F0\u91CD\u5B9A\u5411\u534F\u8BAE\u4E0D\u53D7\u652F\u6301");await a(i(),E.origin,s),x=await r.http.request({permissionKey:i(),url:E.href,method:"GET",operation:s}),d.href=E.href}if(s.signal.throwIfAborted(),p)throw new Error("\u8BF7\u6C42\u5DF2\u53D6\u6D88");if(x.status>=400)throw new Error(d.hostname+" \u8FD4\u56DE HTTP "+x.status);let C=x.body;if(typeof C=="string"){let A=C.trim().replace(/^[\w.$]+\s*\((\{[\s\S]*\})\)\s*;?$/,"$1");try{C=A2.default.parse(A)}catch{}}return{body:C,statusCode:x.status,headers:{...x.headers,...v?{location:d.href}:{}},raw:x.body,url:d.href}})(),cancelHttp(){p=!0}}}return{httpFetch:u,withOperation:n,ensurePermission:a,permissionKey:i}}var ne,vm,C2=!1,MS=0,ml=new Map,gm=new Map,Dm=new Map,Am=new Map,hm=new Map,ym=new Set,Cm=[],Em=new Map,Fm={"tracks.search":"search","tracks.resolve":"resolve","tracks.lyrics":"lyrics","playlists.categories":"categories","playlists.list":"list","playlists.get":"list","sharing.describe":"share"};function WS(r,e){let t=e.split("."),o=t.slice(0,-1).reduce((i,a)=>i?.[a],r),n=o?.[t.at(-1)];return typeof n=="function"?n.bind(o):typeof r?.[Fm[e]]=="function"?r[Fm[e]].bind(r):void 0}function US(r){let e=new Set;for(let[t,o]of Object.entries(r??{}))if(typeof o=="function")e.add(t);else if(o&&typeof o=="object")for(let[n,i]of Object.entries(o))typeof i=="function"&&e.add(t+"."+n);for(let[t,o]of Object.entries(Fm))typeof r?.[o]=="function"&&e.add(t);return[...e]}var NS=r=>{let e=new WeakSet;try{return JSON.parse(JSON.stringify(r,(t,o)=>{if(/password|secret|api.?key|authorization|token|credential/i.test(t))return"[redacted]";if(o instanceof Error)return{name:o.name,message:o.message,stack:o.stack};if(typeof o=="object"&&o){if(e.has(o))return"[circular]";e.add(o)}return typeof o=="function"?"[function]":typeof o=="bigint"?String(o):o})??"null")}catch{return String(r)}},he=(r,e={})=>parent.postMessage({type:r,data:e,generation:ne?.generation},"*");for(let r of["debug","log","info","warn","error"]){let e=console[r].bind(console);console[r]=(...t)=>{e(...t),he("log",{level:r,values:NS(t)})}}function wr(r,e={}){let t="rpc-"+ ++MS;return new Promise((o,n)=>{ml.set(t,{resolve:o,reject:n,timer:setTimeout(()=>{ml.delete(t),n(new Error("Host RPC timed out: "+r))},2e4)}),he("rpc",{id:t,method:r,data:e})})}function HS(){let r={};for(let e of F1)r[e]=zl[e];return{host:Object.freeze({apiVersion:"2.0.0",libraries:{lodash:"4.18.1",icons:"1.0.0",assets:"1.0.0",...ne.catalog.libraries},mode:"development"}),utils:{lodash:Object.freeze(r)},icons:{list:()=>C1,url:async e=>{let t=ne.catalog.icons[e];if(!t)throw new Error("Unknown Host icon: "+e);return"data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(t)))}},assets:{list:()=>E1,url:async e=>{if(typeof e=="string"){let o=ne.catalog.assets[e];if(!o)throw new Error("Unknown Host asset: "+e);return o}let t=ne.resources[e.id];if(!t||t.type==="json")throw new Error("Unknown image/text resource");return"data:"+(t.mime||"text/plain")+";base64,"+(t.type==="base64"?t.value:btoa(unescape(encodeURIComponent(t.value))))}}}}function qS(){if(ne.kind==="web")for(let r of ne.manifest.contributes?.styles??[]){if(!(r.scope==="surface"||r.scope==="slot"&&ne.mount?.kind==="slot"&&r.slots?.includes(ne.mount.slot)))continue;let t=ne.resources[r.resource];if(t?.type!=="text")continue;let o=document.createElement("style");o.dataset.ceruStyle=r.id,o.textContent=t.value,document.head.append(o)}}function zS(){let r=HS();if(ne.kind==="web")return qS(),{...r,root:document.getElementById("plugin-root"),mount:ne.mount??{kind:"page"},invoke:(t,o)=>wr("surface.invoke",{action:t,input:o}),subscribe:t=>(ym.add(t),()=>ym.delete(t))};if(ne.kind==="guest")return{host:r.host,utils:r.utils,guestId:"development-guest",expose:(t,o)=>{if(["__proto__","constructor","prototype"].includes(t))throw new Error("Unsafe global");globalThis[t]=o},invokeHost:(t,o)=>wr("guest."+t,o)};let e=ne.manifest;return{...r,...Object.fromEntries(Object.entries(B1).map(([t,o])=>[t,Object.fromEntries(o.map(n=>[n,(...i)=>wr("services."+t+"."+n,{args:i})]))])),events:{on:()=>{throw new Error("Application events require a connected desktop Host")}},plugin:{id:e.id,version:e.version,manifest:e},config:{get:()=>wr("config.get")},playlistImporters:{register:(t,o)=>{if(!e.contributes?.playlistImporters?.some(n=>n.id===t))throw new Error("Undeclared playlist importer: "+t);return Dm.set(t,o),he("register",{kind:"playlist-importer",id:t,methods:Object.keys(o)}),()=>{Dm.delete(t),he("unregister",{kind:"playlist-importer",id:t})}}},library:{playlists:Object.fromEntries(["list","getTracks","import"].map(t=>[t,o=>wr("library.playlists."+t,{...o,operation:{id:o.operation?.id,deadlineAt:o.operation?.deadlineAt,userIntent:o.operation?.userIntent}})]))},providers:{register:(t,o)=>{if(!e.contributes?.providers?.some(n=>n.id===t))throw new Error("Undeclared provider: "+t);return gm.set(t,o),he("register",{kind:"provider",id:t,methods:US(o)}),()=>{gm.delete(t),he("unregister",{kind:"provider",id:t})}}},actions:{register:(t,o)=>{if(!e.contributes?.commands?.some(n=>n.action===t))throw new Error("Undeclared action: "+t);return Am.set(t,o),he("register",{kind:"action",id:t}),()=>{Am.delete(t),he("unregister",{kind:"action",id:t})}}},permissions:{getGranted:()=>wr("permissions.getGranted"),requestGroup:t=>wr("permissions.requestGroup",t),query:t=>wr("permissions.query",t),request:t=>wr("permissions.request",t)},http:{create:t=>Fp({http:{request:o=>wr("http.request",{...o,operation:{id:o.operation?.id,deadlineAt:o.operation?.deadlineAt}})},permissions:{query:o=>wr("permissions.query",o),request:o=>wr("permissions.request",o)}},t),request:t=>wr("http.request",{...t,operation:{id:t.operation?.id,deadlineAt:t.operation?.deadlineAt}})},credentials:{get:()=>Promise.resolve(null)},sockets:{connect:async t=>{let o=t.permissionKey??"network.socket",n=await wr("permissions.query",{key:o});if(n.status==="prompt"&&(n=await wr("permissions.request",{key:o,intent:t.operation?.userIntent})),n.status!=="granted")throw new Error("Socket permission is not granted");t.operation?.signal?.throwIfAborted();let{id:i}=await wr("sockets.connect",{...t,permissionKey:o,operation:{id:t.operation?.id,deadlineAt:t.operation?.deadlineAt}}),a=new Map;Em.set(i,a);let u=async()=>{Em.delete(i),await wr("sockets.disconnect",{id:i})};return Cm.push(u),{id:i,on:(f,m)=>{let s=a.get(f);return s||(s=new Set,a.set(f,s)),s.add(m),()=>{s?.delete(m)}},emit:(f,m)=>wr("sockets.send",{id:i,event:f,data:m}),send:f=>wr("sockets.send",{id:i,event:"message",data:f}),disconnect:u}}},playback:{failure:t=>({ok:!1,error:t})},ui:{dialogs:{confirm:t=>wr("ui.dialogs.confirm",t),prompt:t=>wr("ui.dialogs.prompt",t),pickPlaylist:t=>wr("ui.dialogs.pickPlaylist",t)},navigation:{open:t=>wr("ui.navigation.open",t)},notifications:{show:(t,o)=>wr("ui.notifications.show",{...t,call:o})},progress:Object.fromEntries(["create","update","close"].map(t=>[t,(...o)=>wr("ui.progress."+t,{args:o})])),toast:t=>(he("notify",{key:"toast",level:"info",...t}),Promise.resolve()),playlistImport:{open:t=>wr("ui.playlistImport.open",t)},setState:(t,o)=>(he("state",{surfaceId:t,state:o}),Promise.resolve()),notify:t=>(he("notify",t),Promise.resolve()),openView:t=>(he("open-view",{surfaceId:t}),Promise.resolve())},storage:{get:t=>wr("storage.get",{key:t}),set:(t,o)=>wr("storage.set",{key:t,value:o}),delete:t=>wr("storage.delete",{key:t})},guests:{list:()=>Promise.resolve([]),prepareInstall:()=>Promise.reject(new Error("Guest installation requires the production Host; inspect the bootstrap module separately in this playground.")),requestInstall:()=>Promise.reject(new Error("Guest installation is unavailable in this playground.")),invoke:()=>Promise.reject(new Error("No Guest instance is installed."))},log:Object.fromEntries(["debug","info","warn","error"].map(t=>[t,(o,n)=>console[t](o,n)])),effects:{add:t=>Cm.push(t)}}}async function E2(){if(!(!ne||!vm||C2)){C2=!0;try{let r=zS(),e={ceru:r,"@ceru/tools":r.utils,lodash:r.utils?.lodash,"@ceru/crypto":im,"@ceru/compression":mm,"@ceru/encoding":cm,"@ceru/legacy-http":{createLegacyHttpBridge:y2}};ne.kind==="logic"&&Object.assign(e,{"@ceru/http":r.http,"@ceru/ui":r.ui,"@ceru/socket":r.sockets,"@ceru/library":r.library,"@ceru/account":r.account,"@ceru/player":r.player});let t=n=>{if(!Object.hasOwn(e,n))throw new Error("Module is not provided by this Host: "+n);return e[n]};r.modules={require:t},globalThis.__ceruRequire=t,globalThis.require=t,globalThis.__ceruContext=r;let o=await vm(r);typeof o=="function"&&Cm.push(o),he("active")}catch(r){console.error(r),he("failed",{message:String(r)})}}}globalThis.__ceruStart=r=>{vm=r,E2()};window.addEventListener("message",async r=>{if(r.source!==parent)return;let e=r.data;if(e?.type==="init"&&!ne){ne=e.data,E2();return}if(!(!ne||e?.generation!==ne.generation)){if(e.type==="rpc-result"){let t=ml.get(e.data.id);t&&(clearTimeout(t.timer),ml.delete(e.data.id),e.data.error?t.reject(new Error(e.data.error)):t.resolve(e.data.value))}if(e.type==="state")for(let t of ym)t(e.data);if(e.type==="socket-event"){let{id:t,event:o,data:n}=e.data;for(let i of Em.get(t)?.get(o)??[])try{i(n)}catch(a){console.error(a)}}if(e.type==="cancel"&&(hm.get(e.data.id)?.abort(),wr("operations.cancel",{id:e.data.id}).catch(()=>{})),e.type==="invoke"){let{id:t,kind:o,target:n,method:i,args:a}=e.data,u=new AbortController;hm.set(t,u);let f=setTimeout(()=>u.abort(),15e3),m={id:t,deadlineAt:Date.now()+15e3,signal:u.signal,userIntent:{kind:"user-intent",id:t}};try{let s=o==="action"?Am.get(n):o==="playlist-importer"?Dm.get(n)?.[i]:WS(gm.get(n),i);if(typeof s!="function")throw new Error("Method is not registered");let p=await s(...a,m);he("invoke-result",{id:t,value:p})}catch(s){he("invoke-result",{id:t,error:s instanceof Error?s.message:String(s)})}finally{clearTimeout(f),hm.delete(t)}}}});window.addEventListener("error",r=>he("failed",{message:r.message}));window.addEventListener("unhandledrejection",r=>console.error(r.reason));he("ready");})();
|
package/dist/dev.js
CHANGED
|
@@ -11,9 +11,23 @@ import { fileURLToPath } from 'node:url';
|
|
|
11
11
|
import { createRequire } from 'node:module';
|
|
12
12
|
import { randomBytes, createHash } from 'node:crypto';
|
|
13
13
|
import { spawn } from 'node:child_process';
|
|
14
|
-
import { readArtifact, parseJsonStrict } from '@shiqianjiang/ceru-plugin-issuer';
|
|
14
|
+
import { readArtifact, parseJsonStrict, resolveArtifactConfig, } from '@shiqianjiang/ceru-plugin-issuer';
|
|
15
15
|
import { buildProject } from './project.js';
|
|
16
16
|
const asset = (name) => fileURLToPath(new URL('../assets/' + name, import.meta.url));
|
|
17
|
+
function mergeConfig(base, override) {
|
|
18
|
+
const result = structuredClone(base);
|
|
19
|
+
for (const [key, value] of Object.entries(override))
|
|
20
|
+
result[key] =
|
|
21
|
+
value &&
|
|
22
|
+
typeof value === 'object' &&
|
|
23
|
+
!Array.isArray(value) &&
|
|
24
|
+
result[key] &&
|
|
25
|
+
typeof result[key] === 'object' &&
|
|
26
|
+
!Array.isArray(result[key])
|
|
27
|
+
? mergeConfig(result[key], value)
|
|
28
|
+
: structuredClone(value);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
17
31
|
async function readDebugTargets(port) {
|
|
18
32
|
const response = await fetch('http://127.0.0.1:' + port + '/json/list', {
|
|
19
33
|
signal: AbortSignal.timeout(750),
|
|
@@ -210,16 +224,17 @@ export async function runDev(project, options = {}) {
|
|
|
210
224
|
const token = randomBytes(24).toString('hex');
|
|
211
225
|
const nonce = randomBytes(24).toString('base64');
|
|
212
226
|
const catalog = JSON.parse(await readFile(asset('catalog.json'), 'utf8'));
|
|
213
|
-
let
|
|
227
|
+
let configOverride = {};
|
|
214
228
|
try {
|
|
215
229
|
const configPath = resolve(root, '.ceru-dev/config.json');
|
|
216
|
-
|
|
230
|
+
configOverride = parseJsonStrict(await readFile(configPath, 'utf8'));
|
|
217
231
|
}
|
|
218
232
|
catch (error) {
|
|
219
233
|
if (!(error instanceof Error) || !('code' in error) || error.code !== 'ENOENT')
|
|
220
234
|
throw error;
|
|
221
235
|
}
|
|
222
236
|
const grants = new Map();
|
|
237
|
+
const effectiveConfig = () => mergeConfig(resolveArtifactConfig(artifact.header), configOverride);
|
|
223
238
|
const sockets = new SocketBroker();
|
|
224
239
|
const operations = new Map();
|
|
225
240
|
const storage = new Map();
|
|
@@ -330,7 +345,7 @@ export async function runDev(project, options = {}) {
|
|
|
330
345
|
migrationWarnings: artifact.migrationWarnings,
|
|
331
346
|
resources: artifact.resources,
|
|
332
347
|
catalog,
|
|
333
|
-
config,
|
|
348
|
+
config: effectiveConfig(),
|
|
334
349
|
grants: Object.fromEntries(grants),
|
|
335
350
|
});
|
|
336
351
|
return;
|
|
@@ -343,7 +358,7 @@ export async function runDev(project, options = {}) {
|
|
|
343
358
|
if (url.pathname === '/api/config') {
|
|
344
359
|
if (!input || typeof input !== 'object' || Array.isArray(input))
|
|
345
360
|
throw new Error('Config must be an object');
|
|
346
|
-
|
|
361
|
+
configOverride = input;
|
|
347
362
|
json(200, { ok: true });
|
|
348
363
|
return;
|
|
349
364
|
}
|
|
@@ -408,7 +423,9 @@ export async function runDev(project, options = {}) {
|
|
|
408
423
|
throw new Error('此独立开发 Host 尚未连接澜音的歌单服务。本地歌单和云歌单由澜音管理;请在正式 Host 中调用此能力。开发环境不会创建替代歌单库。');
|
|
409
424
|
}
|
|
410
425
|
if (input.method === 'config.get') {
|
|
411
|
-
json(200, {
|
|
426
|
+
json(200, {
|
|
427
|
+
value: effectiveConfig(),
|
|
428
|
+
});
|
|
412
429
|
return;
|
|
413
430
|
}
|
|
414
431
|
if (input.method === 'storage.get') {
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createTemplate, generateSigningKeys, parseJsonStrict, PreparedIssuer, r
|
|
|
6
6
|
import { buildProject, scaffoldProject, TEMPLATES, writeAtomic } from './project.js';
|
|
7
7
|
import { runDev } from './dev.js';
|
|
8
8
|
export { buildProject, loadProject, scaffoldProject, TEMPLATES } from './project.js';
|
|
9
|
-
const VERSION = '0.2.
|
|
9
|
+
const VERSION = '0.2.5';
|
|
10
10
|
const HELP = 'Ceru Plugin CLI ' +
|
|
11
11
|
VERSION +
|
|
12
12
|
'\n\n' +
|
package/dist/project.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ArtifactHeader } from '@shiqianjiang/ceru-plugin-issuer';
|
|
2
|
+
import type { JsonObject } from '@shiqianjiang/ceru-plugin-sdk';
|
|
2
3
|
export interface BuildConfig {
|
|
3
4
|
manifest: ArtifactHeader['manifest'];
|
|
5
|
+
config?: JsonObject;
|
|
4
6
|
entries: Record<string, string>;
|
|
5
7
|
resources?: Record<string, {
|
|
6
8
|
path: string;
|
package/dist/project.js
CHANGED
|
@@ -8,14 +8,118 @@ import { spawnSync } from 'node:child_process';
|
|
|
8
8
|
import { createRequire } from 'node:module';
|
|
9
9
|
import { stylesheetPlugin, vuePlugin, webDistEntry } from './frameworks.js';
|
|
10
10
|
import { hostModulesPlugin, assertBundledDependencies } from './dependencies.js';
|
|
11
|
-
import { encodeArtifact, parseJsonStrict, readArtifact, validateManifest, LIMITS, } from '@shiqianjiang/ceru-plugin-issuer';
|
|
11
|
+
import { canonical, encodeArtifact, parseJsonStrict, readArtifact, validateManifest, LIMITS, } from '@shiqianjiang/ceru-plugin-issuer';
|
|
12
|
+
async function resolveConfigValue(root, value, stack = new Set(), depth = 0) {
|
|
13
|
+
if (depth > 32)
|
|
14
|
+
throw new Error('Plugin config references are too deeply nested');
|
|
15
|
+
if (typeof value === 'string') {
|
|
16
|
+
if (value.startsWith('@@'))
|
|
17
|
+
return value.slice(1);
|
|
18
|
+
if (!value.startsWith('@'))
|
|
19
|
+
return value;
|
|
20
|
+
const request = value.slice(1);
|
|
21
|
+
if (!request)
|
|
22
|
+
throw new Error('Plugin config reference cannot be empty');
|
|
23
|
+
const path = await inside(root, request);
|
|
24
|
+
if (stack.has(path))
|
|
25
|
+
throw new Error('Circular plugin config reference: ' + request);
|
|
26
|
+
stack.add(path);
|
|
27
|
+
try {
|
|
28
|
+
const extension = extname(path).toLowerCase();
|
|
29
|
+
let loaded;
|
|
30
|
+
if (extension === '.json') {
|
|
31
|
+
loaded = parseJsonStrict(await readFile(path, 'utf8'));
|
|
32
|
+
}
|
|
33
|
+
else if (['.js', '.mjs', '.cjs', '.ts', '.mts', '.cts'].includes(extension)) {
|
|
34
|
+
const result = await build({
|
|
35
|
+
absWorkingDir: root,
|
|
36
|
+
entryPoints: [path],
|
|
37
|
+
bundle: true,
|
|
38
|
+
write: false,
|
|
39
|
+
format: 'esm',
|
|
40
|
+
platform: 'node',
|
|
41
|
+
target: 'node22',
|
|
42
|
+
logLevel: 'silent',
|
|
43
|
+
});
|
|
44
|
+
if (result.outputFiles.length !== 1)
|
|
45
|
+
throw new Error('Config module emitted sidecar files: ' + request);
|
|
46
|
+
const url = 'data:text/javascript;base64,' +
|
|
47
|
+
Buffer.from(result.outputFiles[0].text).toString('base64') +
|
|
48
|
+
'#' +
|
|
49
|
+
randomUUID();
|
|
50
|
+
const module = await import(url);
|
|
51
|
+
if (!Object.hasOwn(module, 'default'))
|
|
52
|
+
throw new Error('Config module must export default: ' + request);
|
|
53
|
+
loaded = module.default;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw new Error('Config reference must be JSON, JS or TS: ' + request);
|
|
57
|
+
}
|
|
58
|
+
return resolveConfigValue(root, loaded, stack, depth + 1);
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
stack.delete(path);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'number')
|
|
65
|
+
return value;
|
|
66
|
+
if (Array.isArray(value))
|
|
67
|
+
return Promise.all(value.map((item) => resolveConfigValue(root, item, stack, depth + 1)));
|
|
68
|
+
if (value && typeof value === 'object') {
|
|
69
|
+
const result = Object.create(null);
|
|
70
|
+
for (const [key, child] of Object.entries(value)) {
|
|
71
|
+
if (['__proto__', 'prototype', 'constructor'].includes(key))
|
|
72
|
+
throw new Error('Unsafe plugin config key: ' + key);
|
|
73
|
+
result[key] = await resolveConfigValue(root, child, stack, depth + 1);
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
throw new Error('Plugin config must contain only JSON-compatible values');
|
|
78
|
+
}
|
|
79
|
+
function validatePluginConfig(value) {
|
|
80
|
+
if (value === undefined)
|
|
81
|
+
return undefined;
|
|
82
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
83
|
+
throw new Error('Plugin config root must resolve to an object');
|
|
84
|
+
return parseJsonStrict(canonical(value));
|
|
85
|
+
}
|
|
86
|
+
function configType(value, depth = 0) {
|
|
87
|
+
if (depth > 24)
|
|
88
|
+
return 'JsonValue';
|
|
89
|
+
if (value === null)
|
|
90
|
+
return 'null';
|
|
91
|
+
if (typeof value === 'string')
|
|
92
|
+
return 'string';
|
|
93
|
+
if (typeof value === 'number')
|
|
94
|
+
return 'number';
|
|
95
|
+
if (typeof value === 'boolean')
|
|
96
|
+
return 'boolean';
|
|
97
|
+
if (Array.isArray(value)) {
|
|
98
|
+
const members = [...new Set(value.map((item) => configType(item, depth + 1)))];
|
|
99
|
+
return 'readonly (' + (members.join(' | ') || 'JsonValue') + ')[]';
|
|
100
|
+
}
|
|
101
|
+
const fields = Object.entries(value).map(([key, child]) => 'readonly ' + JSON.stringify(key) + ': ' + configType(child, depth + 1) + ';');
|
|
102
|
+
return '{ ' + fields.join(' ') + ' }';
|
|
103
|
+
}
|
|
104
|
+
async function writeConfigTypes(root, config) {
|
|
105
|
+
const path = resolve(root, '.ceru-dev/types/plugin-config.d.ts');
|
|
106
|
+
const source = "declare module '@ceru/plugin-config' {\n" +
|
|
107
|
+
" type JsonValue = import('@shiqianjiang/ceru-plugin-sdk').JsonValue\n" +
|
|
108
|
+
' export type PluginConfig = ' +
|
|
109
|
+
configType(config) +
|
|
110
|
+
'\n const config: PluginConfig\n export default config\n}\n';
|
|
111
|
+
await mkdir(dirname(path), { recursive: true });
|
|
112
|
+
await writeFile(path, source);
|
|
113
|
+
return path;
|
|
114
|
+
}
|
|
12
115
|
function entryFunctionName(id, suffix) {
|
|
13
116
|
const words = id.split(/[^a-zA-Z0-9]+/).filter(Boolean);
|
|
14
117
|
const name = words
|
|
15
118
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
16
119
|
.join('');
|
|
17
120
|
const base = name || 'Plugin';
|
|
18
|
-
|
|
121
|
+
const safe = /^[A-Za-z_$]/.test(base) ? base : 'Plugin' + base;
|
|
122
|
+
return safe.startsWith(suffix) || safe.endsWith(suffix) ? safe : safe + suffix;
|
|
19
123
|
}
|
|
20
124
|
export async function writeAtomic(path, data, overwrite = false, mode = 0o644) {
|
|
21
125
|
await mkdir(dirname(path), { recursive: true });
|
|
@@ -48,10 +152,16 @@ async function inside(root, path) {
|
|
|
48
152
|
}
|
|
49
153
|
export async function loadProject(project) {
|
|
50
154
|
const root = await realpath(resolve(project));
|
|
51
|
-
const
|
|
155
|
+
const source = parseJsonStrict(await readFile(resolve(root, 'ceru.plugin.json'), 'utf8'));
|
|
156
|
+
const expanded = await resolveConfigValue(root, source);
|
|
157
|
+
if (!expanded || typeof expanded !== 'object' || Array.isArray(expanded))
|
|
158
|
+
throw new Error('ceru.plugin.json must resolve to an object');
|
|
159
|
+
const raw = expanded;
|
|
52
160
|
for (const key of Object.keys(raw))
|
|
53
161
|
if (![
|
|
162
|
+
'$schema',
|
|
54
163
|
'manifest',
|
|
164
|
+
'config',
|
|
55
165
|
'entries',
|
|
56
166
|
'resources',
|
|
57
167
|
'output',
|
|
@@ -64,6 +174,11 @@ export async function loadProject(project) {
|
|
|
64
174
|
// to standalone bundles, without requiring authors to rewrite their source.
|
|
65
175
|
if (raw.manifest?.engines)
|
|
66
176
|
delete raw.manifest.engines.libraries;
|
|
177
|
+
if (raw.config !== undefined && raw.manifest?.config !== undefined)
|
|
178
|
+
throw new Error('Define config either at the project root or manifest.config, not both');
|
|
179
|
+
raw.config = validatePluginConfig(raw.config ?? raw.manifest?.config);
|
|
180
|
+
if (raw.config !== undefined)
|
|
181
|
+
raw.manifest.config = raw.config;
|
|
67
182
|
if (raw.framework && !['vanilla', 'vue', 'react'].includes(raw.framework))
|
|
68
183
|
throw new Error('Unsupported framework');
|
|
69
184
|
validateManifest(raw.manifest);
|
|
@@ -77,13 +192,16 @@ export async function loadProject(project) {
|
|
|
77
192
|
}
|
|
78
193
|
return { root, config: raw };
|
|
79
194
|
}
|
|
80
|
-
function checkTypes(root) {
|
|
195
|
+
function checkTypes(root, extraFiles = []) {
|
|
81
196
|
const path = resolve(root, 'tsconfig.json');
|
|
82
197
|
const read = ts.readConfigFile(path, ts.sys.readFile);
|
|
83
198
|
if (read.error)
|
|
84
199
|
throw new Error(ts.flattenDiagnosticMessageText(read.error.messageText, '\n'));
|
|
85
200
|
const config = ts.parseJsonConfigFileContent(read.config, ts.sys, root);
|
|
86
|
-
const program = ts.createProgram(config.fileNames,
|
|
201
|
+
const program = ts.createProgram([...new Set([...config.fileNames, ...extraFiles])], {
|
|
202
|
+
...config.options,
|
|
203
|
+
noEmit: true,
|
|
204
|
+
});
|
|
87
205
|
const diagnostics = [...config.errors, ...ts.getPreEmitDiagnostics(program)];
|
|
88
206
|
if (diagnostics.length) {
|
|
89
207
|
throw new Error(ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
@@ -102,9 +220,22 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
102
220
|
if (result.status !== 0)
|
|
103
221
|
throw new Error(result.stdout + result.stderr);
|
|
104
222
|
}
|
|
105
|
-
const
|
|
223
|
+
const configTypes = await writeConfigTypes(root, config.config ?? {});
|
|
224
|
+
const program = checkTypes(root, [configTypes]);
|
|
106
225
|
const checker = program.getTypeChecker();
|
|
107
226
|
const chunks = new Map();
|
|
227
|
+
const chunkNames = new Map();
|
|
228
|
+
const usedNames = new Set();
|
|
229
|
+
const uniqueEntryName = (id, suffix) => {
|
|
230
|
+
const base = entryFunctionName(id, suffix);
|
|
231
|
+
let name = base;
|
|
232
|
+
let counter = 2;
|
|
233
|
+
while (usedNames.has(name))
|
|
234
|
+
name = base + counter++;
|
|
235
|
+
usedNames.add(name);
|
|
236
|
+
chunkNames.set(id, name);
|
|
237
|
+
return name;
|
|
238
|
+
};
|
|
108
239
|
const devModules = {};
|
|
109
240
|
const surfaceEntries = new Set((config.manifest.modules.surfaces ?? [])
|
|
110
241
|
.filter((surface) => surface.kind === 'web')
|
|
@@ -164,13 +295,12 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
164
295
|
throw new Error('Unbundled import in ' + id);
|
|
165
296
|
const source = result.outputFiles[0].text.replace(/(^|\n)var __ceru_entry =/, '$1const __ceru_entry =');
|
|
166
297
|
assertBundledDependencies(source);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
'(ctx) {\n' +
|
|
298
|
+
const entryName = uniqueEntryName(id, id === config.manifest.modules.logic?.entry
|
|
299
|
+
? 'Logic'
|
|
300
|
+
: surfaceEntries.has(id)
|
|
301
|
+
? 'Surface'
|
|
302
|
+
: 'Module');
|
|
303
|
+
chunks.set(id, 'async function ' + entryName + '(ctx) {\n' +
|
|
174
304
|
source +
|
|
175
305
|
'\nif (typeof __ceru_entry.default !== "function") throw new Error("Entry must default-export a function");\nreturn __ceru_entry.default(ctx);\n}');
|
|
176
306
|
if (options.development) {
|
|
@@ -231,7 +361,8 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
231
361
|
throw new Error('webDist emitted an external file');
|
|
232
362
|
const source = result.outputFiles[0].text.replace(/(^|\n)var __ceru_entry =/, '$1const __ceru_entry =');
|
|
233
363
|
assertBundledDependencies(source);
|
|
234
|
-
|
|
364
|
+
const entryName = uniqueEntryName(id, 'Surface');
|
|
365
|
+
chunks.set(id, 'async function ' + entryName + '(ctx) {\n' +
|
|
235
366
|
source +
|
|
236
367
|
'\nreturn __ceru_entry.default(ctx);\n}');
|
|
237
368
|
if (options.development) {
|
|
@@ -274,39 +405,74 @@ export async function buildProject(project = '.', options = {}) {
|
|
|
274
405
|
};
|
|
275
406
|
}
|
|
276
407
|
const emitted = new Set();
|
|
277
|
-
const
|
|
408
|
+
const definitions = [];
|
|
409
|
+
const exports = [];
|
|
278
410
|
const logicEntry = config.manifest.modules.logic?.entry;
|
|
279
411
|
if (logicEntry) {
|
|
280
412
|
const logic = chunks.get(logicEntry);
|
|
413
|
+
const name = chunkNames.get(logicEntry);
|
|
281
414
|
if (!logic)
|
|
282
415
|
throw new Error('Missing compiled logic entry: ' + logicEntry);
|
|
283
|
-
|
|
416
|
+
if (!name)
|
|
417
|
+
throw new Error('Missing compiled logic name: ' + logicEntry);
|
|
418
|
+
definitions.push('// Invisible plugin logic\nconst ' +
|
|
419
|
+
name +
|
|
420
|
+
' = /* @ceru-self-contained */ ' +
|
|
421
|
+
logic +
|
|
422
|
+
';');
|
|
423
|
+
exports.push('exports.activate = ' + name + ';');
|
|
284
424
|
emitted.add(logicEntry);
|
|
285
425
|
}
|
|
286
426
|
const visibleSurfaces = (config.manifest.modules.surfaces ?? []).filter((surface) => surface.kind === 'web');
|
|
287
427
|
if (visibleSurfaces.length) {
|
|
288
428
|
const entries = visibleSurfaces.map((surface) => {
|
|
289
429
|
const entry = chunks.get(surface.entry);
|
|
430
|
+
const name = chunkNames.get(surface.entry);
|
|
290
431
|
if (!entry)
|
|
291
432
|
throw new Error('Missing compiled Surface entry: ' + surface.entry);
|
|
433
|
+
if (!name)
|
|
434
|
+
throw new Error('Missing compiled Surface name: ' + surface.entry);
|
|
292
435
|
emitted.add(surface.entry);
|
|
293
|
-
|
|
436
|
+
definitions.push('// Visible plugin surface: ' +
|
|
437
|
+
surface.id +
|
|
438
|
+
'\nconst ' +
|
|
439
|
+
name +
|
|
440
|
+
' = /* @ceru-self-contained */ ' +
|
|
441
|
+
entry +
|
|
442
|
+
';');
|
|
443
|
+
return JSON.stringify(surface.id) + ': ' + name;
|
|
294
444
|
});
|
|
295
|
-
|
|
445
|
+
definitions.push('const surfaces = {\n' + entries.join(',\n') + '\n};');
|
|
446
|
+
exports.push('exports.surfaces = surfaces;');
|
|
296
447
|
}
|
|
297
448
|
const modules = [...chunks].filter(([id]) => !emitted.has(id));
|
|
298
|
-
if (modules.length)
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
449
|
+
if (modules.length) {
|
|
450
|
+
const entries = modules.map(([id, entry]) => {
|
|
451
|
+
const name = chunkNames.get(id);
|
|
452
|
+
if (!name)
|
|
453
|
+
throw new Error('Missing compiled module name: ' + id);
|
|
454
|
+
definitions.push('// Additional plugin module: ' +
|
|
455
|
+
id +
|
|
456
|
+
'\nconst ' +
|
|
457
|
+
name +
|
|
458
|
+
' = /* @ceru-self-contained */ ' +
|
|
459
|
+
entry +
|
|
460
|
+
';');
|
|
461
|
+
return JSON.stringify(id) + ': ' + name;
|
|
462
|
+
});
|
|
463
|
+
definitions.push('const modules = {\n' + entries.join(',\n') + '\n};');
|
|
464
|
+
exports.push('exports.modules = modules;');
|
|
465
|
+
}
|
|
466
|
+
definitions.push('// Embedded static resources\nconst resources = ' + JSON.stringify(resources) + ';');
|
|
467
|
+
exports.push('exports.resources = resources;');
|
|
468
|
+
const body = [...definitions, '// Public plugin exports', ...exports].join('\n\n') + '\n';
|
|
303
469
|
const header = {
|
|
304
470
|
formatVersion: 2,
|
|
305
471
|
syntax: 'js',
|
|
306
472
|
manifest: config.manifest,
|
|
307
473
|
signature: null,
|
|
308
474
|
};
|
|
309
|
-
const artifact = encodeArtifact(header, body
|
|
475
|
+
const artifact = encodeArtifact(header, body);
|
|
310
476
|
readArtifact(artifact);
|
|
311
477
|
const output = resolve(root, options.out ?? config.output ?? 'dist/plugin.js');
|
|
312
478
|
if (extname(output) !== '.js')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shiqianjiang/ceru-plugin-cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
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",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"ceru-plugin": "
|
|
16
|
+
"ceru-plugin": "dist/bin.js"
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/core": "^7.29.7",
|
|
35
|
-
"@shiqianjiang/ceru-plugin-issuer": "0.2.
|
|
36
|
-
"@shiqianjiang/ceru-plugin-sdk": "0.2.
|
|
35
|
+
"@shiqianjiang/ceru-plugin-issuer": "0.2.3",
|
|
36
|
+
"@shiqianjiang/ceru-plugin-sdk": "0.2.3",
|
|
37
37
|
"@vue/babel-plugin-jsx": "^2.0.1",
|
|
38
38
|
"@vue/compiler-sfc": "3.5.43",
|
|
39
39
|
"axios": "^1.20.0",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"properties": {
|
|
6
6
|
"$schema": {
|
|
7
7
|
"type": "string",
|
|
8
|
-
"
|
|
8
|
+
"description": "Optional editor schema reference; ignored by the build runtime."
|
|
9
9
|
},
|
|
10
10
|
"manifest": {
|
|
11
11
|
"type": "object",
|
|
@@ -46,6 +46,15 @@
|
|
|
46
46
|
"minLength": 1,
|
|
47
47
|
"maxLength": 4096
|
|
48
48
|
},
|
|
49
|
+
"homepage": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"minLength": 1,
|
|
52
|
+
"maxLength": 4096
|
|
53
|
+
},
|
|
54
|
+
"config": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"additionalProperties": true
|
|
57
|
+
},
|
|
49
58
|
"engines": {
|
|
50
59
|
"type": "object",
|
|
51
60
|
"properties": {
|
|
@@ -511,6 +520,16 @@
|
|
|
511
520
|
"maxItems": 128,
|
|
512
521
|
"uniqueItems": true
|
|
513
522
|
},
|
|
523
|
+
"qualities": {
|
|
524
|
+
"type": "array",
|
|
525
|
+
"items": {
|
|
526
|
+
"type": "string",
|
|
527
|
+
"minLength": 1,
|
|
528
|
+
"maxLength": 4096
|
|
529
|
+
},
|
|
530
|
+
"maxItems": 128,
|
|
531
|
+
"uniqueItems": true
|
|
532
|
+
},
|
|
514
533
|
"connectionMode": {
|
|
515
534
|
"enum": [
|
|
516
535
|
"none",
|
|
@@ -884,6 +903,20 @@
|
|
|
884
903
|
],
|
|
885
904
|
"additionalProperties": false
|
|
886
905
|
},
|
|
906
|
+
"config": {
|
|
907
|
+
"oneOf": [
|
|
908
|
+
{
|
|
909
|
+
"type": "object",
|
|
910
|
+
"description": "JSON-compatible defaults exposed through ctx.config.",
|
|
911
|
+
"additionalProperties": true
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
"type": "string",
|
|
915
|
+
"pattern": "^@.+",
|
|
916
|
+
"description": "Build-time JSON/JS/TS config reference, for example @./src/plugin.config.ts."
|
|
917
|
+
}
|
|
918
|
+
]
|
|
919
|
+
},
|
|
887
920
|
"entries": {
|
|
888
921
|
"type": "object",
|
|
889
922
|
"description": "Map stable module IDs to TS/TSX/JS source files",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2",
|
package/templates/snapshot.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 1,
|
|
3
3
|
"source": "https://github.com/CeruMusic/CeruMusic-Plugin-Template",
|
|
4
|
-
"digest": "sha256:
|
|
4
|
+
"digest": "sha256:7eeb9eec7c3fe051c7f1feed458e2a24124b016eda67bd4636711b5126a28d21",
|
|
5
5
|
"files": [
|
|
6
6
|
"connected-library/js/_gitignore",
|
|
7
7
|
"connected-library/js/.prettierrc.json",
|
|
@@ -19,6 +19,10 @@ VS Code 按 F5 选择 Launch Ceru plugin;已有调试窗口时选择 Attach to
|
|
|
19
19
|
激活代码已经执行时,可点击“重新运行”再次命中断点。
|
|
20
20
|
配置文件有 JSON Schema 提示,SDK 提供参数类型、图标名称与 Lodash 方法补全。
|
|
21
21
|
|
|
22
|
+
`ceru.plugin.json` 的 `config` 直接写普通对象。业务代码可用
|
|
23
|
+
`import('@ceru/plugin-config').PluginConfig` 声明配置类型。dev/build 会生成不含值的
|
|
24
|
+
`.ceru-dev/types/plugin-config.d.ts`,JSDoc 可引用 `@ceru/plugin-config`。
|
|
25
|
+
|
|
22
26
|
## 宿主资源
|
|
23
27
|
|
|
24
28
|
- 平台图标:icon: { kind: 'host', name: 'platform.tx' }。
|
|
@@ -52,6 +52,16 @@
|
|
|
52
52
|
"state": 1
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
+
"config": {
|
|
56
|
+
"displayName": "Ceru Demo",
|
|
57
|
+
"apiOrigin": "https://music.example.com",
|
|
58
|
+
"sources": {
|
|
59
|
+
"demo": {
|
|
60
|
+
"name": "Demo Source",
|
|
61
|
+
"qualities": ["320k", "flac"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
55
65
|
"entries": {
|
|
56
66
|
"logic.main": "src/index.js"
|
|
57
67
|
},
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { definePlugin } from '@shiqianjiang/ceru-plugin-sdk'
|
|
2
2
|
|
|
3
|
+
/** @typedef {import('@ceru/plugin-config').PluginConfig} PluginConfig */
|
|
4
|
+
|
|
3
5
|
// 本地演示数据。请在接入真实音源时声明所需的网络权限。
|
|
4
6
|
const tracks = [
|
|
5
7
|
{ id: 'morning', title: 'Morning Light', artist: 'Ceru Demo' },
|
|
@@ -7,12 +9,14 @@ const tracks = [
|
|
|
7
9
|
{ id: 'night', title: 'Night Walk', artist: 'Ceru Demo' },
|
|
8
10
|
]
|
|
9
11
|
|
|
10
|
-
export default definePlugin((ctx) => {
|
|
12
|
+
export default definePlugin(async (ctx) => {
|
|
13
|
+
/** @type {Readonly<PluginConfig>} */
|
|
14
|
+
const config = await ctx.config.get()
|
|
11
15
|
ctx.actions.register('hello', async () => {
|
|
12
16
|
await ctx.ui.notify({
|
|
13
17
|
key: 'welcome',
|
|
14
18
|
level: 'info',
|
|
15
|
-
message:
|
|
19
|
+
message: `${config.displayName} 已就绪。试试搜索 Morning、Rain 或 Night。`,
|
|
16
20
|
})
|
|
17
21
|
})
|
|
18
22
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { definePluginConfig } from '@shiqianjiang/ceru-plugin-sdk'
|
|
2
|
+
|
|
3
|
+
const losslessQualities = ['flac']
|
|
4
|
+
|
|
5
|
+
export default definePluginConfig({
|
|
6
|
+
displayName: 'Ceru Demo',
|
|
7
|
+
apiOrigin: 'https://music.example.com',
|
|
8
|
+
sources: {
|
|
9
|
+
demo: {
|
|
10
|
+
name: 'Demo Source',
|
|
11
|
+
qualities: ['320k', ...losslessQualities],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
})
|
|
@@ -19,6 +19,11 @@ VS Code 按 F5 选择 Launch Ceru plugin;已有调试窗口时选择 Attach to
|
|
|
19
19
|
激活代码已经执行时,可点击“重新运行”再次命中断点。
|
|
20
20
|
配置文件有 JSON Schema 提示,SDK 提供参数类型、图标名称与 Lodash 方法补全。
|
|
21
21
|
|
|
22
|
+
`ceru.plugin.json` 的 `config` 直接写普通对象,业务代码从
|
|
23
|
+
`@ceru/plugin-config` 导入自动生成的 `PluginConfig`,再通过
|
|
24
|
+
`await ctx.config.get<PluginConfig>()` 读取。dev/build 会生成不含值的
|
|
25
|
+
`.ceru-dev/types/plugin-config.d.ts`;可从 `@ceru/plugin-config` 导入 `PluginConfig`。
|
|
26
|
+
|
|
22
27
|
## 宿主资源
|
|
23
28
|
|
|
24
29
|
- 平台图标:icon: { kind: 'host', name: 'platform.tx' }。
|
|
@@ -52,6 +52,16 @@
|
|
|
52
52
|
"state": 1
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
+
"config": {
|
|
56
|
+
"displayName": "Ceru Demo",
|
|
57
|
+
"apiOrigin": "https://music.example.com",
|
|
58
|
+
"sources": {
|
|
59
|
+
"demo": {
|
|
60
|
+
"name": "Demo Source",
|
|
61
|
+
"qualities": ["320k", "flac"]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
55
65
|
"entries": {
|
|
56
66
|
"logic.main": "src/index.ts"
|
|
57
67
|
},
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { definePlugin } from '@shiqianjiang/ceru-plugin-sdk'
|
|
2
|
+
import type { PluginConfig } from '@ceru/plugin-config'
|
|
2
3
|
|
|
3
4
|
// 本地演示数据。请在接入真实音源时声明所需的网络权限。
|
|
4
5
|
const tracks = [
|
|
@@ -7,12 +8,13 @@ const tracks = [
|
|
|
7
8
|
{ id: 'night', title: 'Night Walk', artist: 'Ceru Demo' },
|
|
8
9
|
]
|
|
9
10
|
|
|
10
|
-
export default definePlugin((ctx) => {
|
|
11
|
+
export default definePlugin(async (ctx) => {
|
|
12
|
+
const config = await ctx.config.get<PluginConfig>()
|
|
11
13
|
ctx.actions.register('hello', async () => {
|
|
12
14
|
await ctx.ui.notify({
|
|
13
15
|
key: 'welcome',
|
|
14
16
|
level: 'info',
|
|
15
|
-
message:
|
|
17
|
+
message: `${config.displayName} 已就绪。试试搜索 Morning、Rain 或 Night。`,
|
|
16
18
|
})
|
|
17
19
|
})
|
|
18
20
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { definePluginConfig } from '@shiqianjiang/ceru-plugin-sdk'
|
|
2
|
+
|
|
3
|
+
const losslessQualities = ['flac'] as const
|
|
4
|
+
|
|
5
|
+
export default definePluginConfig({
|
|
6
|
+
displayName: 'Ceru Demo',
|
|
7
|
+
apiOrigin: 'https://music.example.com',
|
|
8
|
+
sources: {
|
|
9
|
+
demo: {
|
|
10
|
+
name: 'Demo Source',
|
|
11
|
+
qualities: ['320k', ...losslessQualities],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
})
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"preview": "ceru-plugin preview dist/plugin.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@shiqianjiang/ceru-plugin-sdk": "^0.2.
|
|
14
|
+
"@shiqianjiang/ceru-plugin-sdk": "^0.2.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@shiqianjiang/ceru-plugin-cli": "^0.2.
|
|
17
|
+
"@shiqianjiang/ceru-plugin-cli": "^0.2.5",
|
|
18
18
|
"typescript": "~5.9.3",
|
|
19
19
|
"electron": "^44.4.2",
|
|
20
20
|
"prettier": "^3.6.2"
|