@kanonak-protocol/cli 3.27.1 → 3.27.2
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/dist/index.js +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -108,7 +108,7 @@ Examples:
|
|
|
108
108
|
|
|
109
109
|
# Materialize the JSON view (universal default unless overridden).
|
|
110
110
|
$ kanonak derive my-publisher.com/my-package/my-resource --format json
|
|
111
|
-
`).action(async(n,e)=>{try{await rs(n,e)}catch(t){console.error(`Error: ${t.message}`),process.exit(1)}})}async function rs(n,e){let t=x(n);if(!t||!t.instanceName)throw new Error(`Invalid resource URI "${n}". Expected publisher/package[@version]/instance.`);let o=new Yr,r=new Xr,a=await S(process.cwd(),o),s=await r.parseKanonaks(a),i=ss(s,t);if(!i)throw new Error(`Resource ${t.publisher}/${t.packageName}${t.version?`@${t.version}`:""}/${t.instanceName} not found in the workspace or cache.`);console.log(`Resource: ${Mn(i)}`);let c=is(e.format),l=cs(e.variant),m=Zr(i,c,l,s);if(!m)throw new Error(`No derivation found for resource ${Mn(i)} at (format=${e.format}, variant=${e.variant}). The class hierarchy declares no binding and no universal default applies.`);console.log(`Derivation: ${ls(m)} \u2192 ${Vn(m.transformation)}`);let u=as(s,m.transformation);if(!u)throw new Error(`Transformation ${Vn(m.transformation)} not found in the workspace or cache. The binding pointed at a transformation the resolver cannot locate.`);let d=os(e.format),y=await new Qr().run({transformation:u,instances:[i],allKanonaks:s,repository:a,parser:o,objectParser:r,outputFormat:d}),p=Jr(e.out);qr(p,{recursive:!0});let g=ts[e.format]??"";for(let f of y){let k=us(f.fileName),b=Gr(p,`${k}${g}`);Wr(b,f.content,"utf-8"),console.log(` wrote ${b}`)}console.log(`Done. ${y.length} artifact(s) written to ${p}`)}function ss(n,e){for(let t of n){if(!(t instanceof Bn)||t.name!==e.instanceName)continue;let o=t.namespace||"",r=`${e.publisher}/${e.packageName}@`;if(o.startsWith(r))if(e.version){if(o===`${e.publisher}/${e.packageName}@${e.version}`)return t}else return t}}function as(n,e){let t=`${e.publisher}/${e.package_}@${e.version}`;for(let o of n)if(o instanceof Bn&&o.name===e.name&&o.namespace===t)return o}function is(n){if(n.includes("/")){let e=x(n);if(!e||!e.instanceName)throw new Error(`Invalid --format URI "${n}".`);return{publisher:e.publisher,package_:e.packageName,name:e.instanceName}}return{...es,name:n}}function cs(n){if(n.includes("/")){let e=x(n);if(!e||!e.instanceName)throw new Error(`Invalid --variant URI "${n}".`);return{publisher:e.publisher,package_:e.packageName,name:e.instanceName}}return{...ns,name:n}}function Mn(n){return`${n.namespace}/${n.name}`}function Vn(n){return`${n.publisher}/${n.package_}@${n.version}/${n.name}`}function ls(n){return n.source==="instance"?"instance override":`class ${n.source.publisher}/${n.source.package_}/${n.source.name}`}function us(n){return n.replace(/[^a-zA-Z0-9._@-]+/g,"_")}import{Command as ps}from"commander";import{writeFileSync as ue,mkdirSync as He}from"fs";import{join as F,resolve as Wn}from"path";import{KanonakParser as ms,KanonakObjectParser as ds,SubjectKanonak as fs,LookRenderer as gs}from"@kanonak-protocol/sdk";import{TransformationEngine as hs}from"@kanonak-protocol/sdk/transformations";import{readFileSync as ks}from"fs";var ys=[{format:{publisher:"kanonak.org",package_:"formats",name:"html"},fileExtension:".html"},{format:{publisher:"kanonak.org",package_:"formats",name:"stylesheet"},fileExtension:".css"},{format:{publisher:"kanonak.org",package_:"formats",name:"svg"},fileExtension:".svg"}];function qn(){return new ps("publish").description("Generate a static Kanonak site from the local workspace. Walks every resource and renders HTML + stylesheet via the engine. Writes to --out in the canonical Kanonak URL hierarchy.").option("--workspace <dir>","Workspace directory containing .kan.yml package files. Defaults to current directory.",process.cwd()).option("--out <dir>","Output directory for the generated site. Defaults to _site.","_site").action(async n=>{await bs(n)})}async function bs(n){let e=Wn(n.workspace),t=Wn(n.out),o=new ms,r=new ds,a=[];W(e,a),a.length===0&&(console.error(`No .kan.yml files found under ${e}`),process.exit(1)),console.log(`Found ${a.length} local package file(s) under ${e}`);let s=new Set;for(let p of a)try{let g=ks(p,"utf-8"),k=o.parse(g).metadata?.namespace_;if(!k)continue;let b=k.version;s.add(`${k.publisher}/${k.package_}@${b.major}.${b.minor}.${b.patch}`)}catch(g){console.warn(` warning: failed to parse ${p}: ${g.message}`)}console.log(`Local namespaces: ${[...s].join(", ")}`);let i=await S(e,o),c=await r.parseKanonaks(i),l=c.filter(p=>{if(!(p instanceof fs)||!s.has(p.namespace||""))return!1;let f=(p.namespace||"").split("/")[1]?.split("@")[0];return p.name!==f});console.log(`Publishing ${l.length} resource(s) to ${t}`);let m=new hs(i,o,r),u=new gs(c),d=0,h=0;for(let p of l){let g=p.namespace||"",[f,k]=g.split("/");if(!f||!k)continue;let[b,w]=k.split("@");if(!b||!w)continue;let $=F(t,b,w);He($,{recursive:!0});let v=u.findCascadedLook(p),K=v&&!(v.sourceClass.publisher==="kanonak.org"&&v.sourceClass.package_==="core-rdf"&&v.sourceClass.name==="Resource"),E=w.split(".").map(Number),Q=E.length===3&&E.every(I=>!Number.isNaN(I))?{major:E[0],minor:E[1],patch:E[2]}:void 0;for(let I of ys){let N=I.format.name;try{let L,z;if(K&&(N==="html"||N==="stylesheet"))L=N==="html"?u.
|
|
111
|
+
`).action(async(n,e)=>{try{await rs(n,e)}catch(t){console.error(`Error: ${t.message}`),process.exit(1)}})}async function rs(n,e){let t=x(n);if(!t||!t.instanceName)throw new Error(`Invalid resource URI "${n}". Expected publisher/package[@version]/instance.`);let o=new Yr,r=new Xr,a=await S(process.cwd(),o),s=await r.parseKanonaks(a),i=ss(s,t);if(!i)throw new Error(`Resource ${t.publisher}/${t.packageName}${t.version?`@${t.version}`:""}/${t.instanceName} not found in the workspace or cache.`);console.log(`Resource: ${Mn(i)}`);let c=is(e.format),l=cs(e.variant),m=Zr(i,c,l,s);if(!m)throw new Error(`No derivation found for resource ${Mn(i)} at (format=${e.format}, variant=${e.variant}). The class hierarchy declares no binding and no universal default applies.`);console.log(`Derivation: ${ls(m)} \u2192 ${Vn(m.transformation)}`);let u=as(s,m.transformation);if(!u)throw new Error(`Transformation ${Vn(m.transformation)} not found in the workspace or cache. The binding pointed at a transformation the resolver cannot locate.`);let d=os(e.format),y=await new Qr().run({transformation:u,instances:[i],allKanonaks:s,repository:a,parser:o,objectParser:r,outputFormat:d}),p=Jr(e.out);qr(p,{recursive:!0});let g=ts[e.format]??"";for(let f of y){let k=us(f.fileName),b=Gr(p,`${k}${g}`);Wr(b,f.content,"utf-8"),console.log(` wrote ${b}`)}console.log(`Done. ${y.length} artifact(s) written to ${p}`)}function ss(n,e){for(let t of n){if(!(t instanceof Bn)||t.name!==e.instanceName)continue;let o=t.namespace||"",r=`${e.publisher}/${e.packageName}@`;if(o.startsWith(r))if(e.version){if(o===`${e.publisher}/${e.packageName}@${e.version}`)return t}else return t}}function as(n,e){let t=`${e.publisher}/${e.package_}@${e.version}`;for(let o of n)if(o instanceof Bn&&o.name===e.name&&o.namespace===t)return o}function is(n){if(n.includes("/")){let e=x(n);if(!e||!e.instanceName)throw new Error(`Invalid --format URI "${n}".`);return{publisher:e.publisher,package_:e.packageName,name:e.instanceName}}return{...es,name:n}}function cs(n){if(n.includes("/")){let e=x(n);if(!e||!e.instanceName)throw new Error(`Invalid --variant URI "${n}".`);return{publisher:e.publisher,package_:e.packageName,name:e.instanceName}}return{...ns,name:n}}function Mn(n){return`${n.namespace}/${n.name}`}function Vn(n){return`${n.publisher}/${n.package_}@${n.version}/${n.name}`}function ls(n){return n.source==="instance"?"instance override":`class ${n.source.publisher}/${n.source.package_}/${n.source.name}`}function us(n){return n.replace(/[^a-zA-Z0-9._@-]+/g,"_")}import{Command as ps}from"commander";import{writeFileSync as ue,mkdirSync as He}from"fs";import{join as F,resolve as Wn}from"path";import{KanonakParser as ms,KanonakObjectParser as ds,SubjectKanonak as fs,LookRenderer as gs}from"@kanonak-protocol/sdk";import{TransformationEngine as hs}from"@kanonak-protocol/sdk/transformations";import{readFileSync as ks}from"fs";var ys=[{format:{publisher:"kanonak.org",package_:"formats",name:"html"},fileExtension:".html"},{format:{publisher:"kanonak.org",package_:"formats",name:"stylesheet"},fileExtension:".css"},{format:{publisher:"kanonak.org",package_:"formats",name:"svg"},fileExtension:".svg"}];function qn(){return new ps("publish").description("Generate a static Kanonak site from the local workspace. Walks every resource and renders HTML + stylesheet via the engine. Writes to --out in the canonical Kanonak URL hierarchy.").option("--workspace <dir>","Workspace directory containing .kan.yml package files. Defaults to current directory.",process.cwd()).option("--out <dir>","Output directory for the generated site. Defaults to _site.","_site").action(async n=>{await bs(n)})}async function bs(n){let e=Wn(n.workspace),t=Wn(n.out),o=new ms,r=new ds,a=[];W(e,a),a.length===0&&(console.error(`No .kan.yml files found under ${e}`),process.exit(1)),console.log(`Found ${a.length} local package file(s) under ${e}`);let s=new Set;for(let p of a)try{let g=ks(p,"utf-8"),k=o.parse(g).metadata?.namespace_;if(!k)continue;let b=k.version;s.add(`${k.publisher}/${k.package_}@${b.major}.${b.minor}.${b.patch}`)}catch(g){console.warn(` warning: failed to parse ${p}: ${g.message}`)}console.log(`Local namespaces: ${[...s].join(", ")}`);let i=await S(e,o),c=await r.parseKanonaks(i),l=c.filter(p=>{if(!(p instanceof fs)||!s.has(p.namespace||""))return!1;let f=(p.namespace||"").split("/")[1]?.split("@")[0];return p.name!==f});console.log(`Publishing ${l.length} resource(s) to ${t}`);let m=new hs(i,o,r),u=new gs(c),d=0,h=0;for(let p of l){let g=p.namespace||"",[f,k]=g.split("/");if(!f||!k)continue;let[b,w]=k.split("@");if(!b||!w)continue;let $=F(t,b,w);He($,{recursive:!0});let v=u.findCascadedLook(p),K=v&&!(v.sourceClass.publisher==="kanonak.org"&&v.sourceClass.package_==="core-rdf"&&v.sourceClass.name==="Resource"),E=w.split(".").map(Number),Q=E.length===3&&E.every(I=>!Number.isNaN(I))?{major:E[0],minor:E[1],patch:E[2]}:void 0;for(let I of ys){let N=I.format.name;try{let L,z;if(K&&(N==="html"||N==="stylesheet"))L=N==="html"?u.renderDocument(p):u.renderStylesheet(p),z=`${p.name}${I.fileExtension}`;else{let ae={publisher:f,package_:b,name:p.name,...Q?{version:Q}:{}},ie=await m.render({resource:ae,format:I.format});L=ie.content,N==="html"?z=`${p.name}${I.fileExtension}`:z=ie.filename.includes(".")?ie.filename:`${ie.filename}${I.fileExtension}`}let ee=F($,z);ue(ee,L,"utf-8"),d+=1}catch(L){console.warn(` ${f}/${b}@${w}/${p.name} [${N}]: ${L.message}`),h+=1}}}console.log(`Done. ${d} artifact(s) written, ${h} skipped.`),h>0&&console.log("Skipped artifacts are typically resources with no derivation binding for the requested format (e.g. an instance class without an html transformation). This is expected for vocabulary-only packages \u2014 they have no instances to render.");let y=ws(t,l);console.log(`Wrote ${y} version-form redirect stub(s).`)}function ws(n,e){let t=new Map;for(let r of e){let a=r.namespace||"",[,s]=a.split("/");if(!s)continue;let[i,c]=s.split("@");if(!i||!c)continue;let l=c.split(".").map(Number);if(l.length!==3||l.some(u=>Number.isNaN(u)))continue;let m=`${i}/${r.name}`;t.has(m)||t.set(m,[]),t.get(m).push({verStr:c,major:l[0],minor:l[1],patch:l[2]})}let o=0;for(let[r,a]of t){let[s,i]=r.split("/");a.sort((u,d)=>d.major-u.major||d.minor-u.minor||d.patch-u.patch);let c=a[0];ue(F(n,s,`${i}.html`),Fe(`/${s}/${c.verStr}/${i}`),"utf-8"),o+=1;let l=new Set;for(let u of a){if(l.has(u.major))continue;l.add(u.major);let d=F(n,s,String(u.major));He(d,{recursive:!0}),ue(F(d,`${i}.html`),Fe(`/${s}/${u.verStr}/${i}`),"utf-8"),o+=1}let m=new Set;for(let u of a){let d=`${u.major}.${u.minor}`;if(m.has(d))continue;m.add(d);let h=F(n,s,d);He(h,{recursive:!0}),ue(F(h,`${i}.html`),Fe(`/${s}/${u.verStr}/${i}`),"utf-8"),o+=1}}return o}function Fe(n){let e=n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");return`<!doctype html>
|
|
112
112
|
<meta charset="utf-8">
|
|
113
113
|
<title>Redirecting\u2026</title>
|
|
114
114
|
<meta http-equiv="refresh" content="0; url=${e}">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanonak-protocol/cli",
|
|
3
|
-
"version": "3.27.
|
|
3
|
+
"version": "3.27.2",
|
|
4
4
|
"description": "Kanonak Protocol CLI - Validate and resolve Kanonak ontology packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"semantic-web"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@kanonak-protocol/sdk": "^3.27.
|
|
38
|
-
"@kanonak-protocol/types": "^3.27.
|
|
37
|
+
"@kanonak-protocol/sdk": "^3.27.2",
|
|
38
|
+
"@kanonak-protocol/types": "^3.27.2",
|
|
39
39
|
"commander": "^13.0.0",
|
|
40
40
|
"js-yaml": "^4.1.1"
|
|
41
41
|
},
|