@techdocs/cli
Version:
Utility CLI for managing TechDocs sites in Backstage.
11 lines (10 loc) • 9.95 kB
JavaScript
;(()=>{(self.webpackChunktechdocs_cli_embedded_app=self.webpackChunktechdocs_cli_embedded_app||[]).push([[5788,8803],{70048:($,f,t)=>{t.d(f,{K:()=>c});var e=t(18690);function c(R){return(0,e.g)()}},99538:($,f,t)=>{t.d(f,{T7:()=>j,TY:()=>p,tN:()=>S});var e=t(31085),c=t(6820),R=t(25862),m=t(43836),A=t(10602);const M=(0,m.tK)("entity-context"),j=g=>{const{children:v,entity:x,loading:O,error:D,refresh:C}=g,T={entity:x,loading:O,error:D,refresh:C};return(0,e.jsx)(M.Provider,{value:(0,A.B)({1:T}),children:(0,e.jsx)(R.Ig,{attributes:{...x?{entityRef:(0,c.U2)(x)}:void 0},children:v})})},B=g=>_jsx(j,{entity:g.entity,loading:!g.entity,error:void 0,refresh:void 0,children:g.children});function S(){const g=(0,m.qO)("entity-context");if(!g)throw new Error("Entity context is not available");const v=g.atVersion(1);if(!v)throw new Error("EntityContext v1 not available");if(!v.entity)throw new Error("useEntity hook is being called outside of an EntityLayout where the entity has not been loaded. If this is intentional, please use useAsyncEntity instead.");return{entity:v.entity}}function p(){const g=(0,m.qO)("entity-context");if(!g)throw new Error("Entity context is not available");const v=g.atVersion(1);if(!v)throw new Error("EntityContext v1 not available");const{entity:x,loading:O,error:D,refresh:C}=v;return{entity:x,loading:O,error:D,refresh:C}}},38803:($,f,t)=>{t.r(f),t.d(f,{EmbeddedDocsRouter:()=>z,LegacyEmbeddedDocsRouter:()=>y,Router:()=>G,TechDocsReaderRouter:()=>X,isTechDocsAvailable:()=>V});var e=t(31085),c=t(18690),R=t(6820),m=t(86202),A=t(65614),M=t(39278),j=t(13976),B=t(39299),S=t(14041),p=t(9222),g=t(82779);const v=n=>n.replace(/^\/+/,""),x=n=>n.replace(/\/+$/,"");function O(n){const{kind:o,name:a,namespace:r}=n,s=(0,p.S)(g.Oc),u=(0,p.S)(g.Ri);return(0,S.useMemo)(()=>{const d=x(s({kind:o,namespace:r,name:a})),i=x(u());return l=>{if(l.toLocaleLowerCase("en-US").startsWith(d.toLocaleLowerCase("en-US"))){const h=v(l.slice(d.length));return h.length===0||h.startsWith("#")?`${i}${h}`:`${i}/${h}`}return l}},[s,u,o,a,r])}const D=({entity:n,withSearch:o=!0})=>{let a=(0,R.sM)(n);const r=O(a);if(n.metadata.annotations?.[m.GO])try{a=(0,R.KU)(n.metadata.annotations?.[m.GO])}catch{}const s=(0,A.oN)(n);return(0,e.jsxs)(M.Wj,{entityRef:a,children:[(0,e.jsx)(B.Z,{}),(0,e.jsx)(j.p,{withSearch:o,searchResultUrlMapper:r,defaultPath:s})]})};var C=t(85788),T=t(93160),L=t(99538),N=t(10394),Y=t(64947),F=t(58837),H=t(72501),U=t(44186),K=t(77310),I=t(72072);const W=(0,F.A)(n=>({code:{borderRadius:6,margin:n.spacing(2,0),background:n.palette.type==="dark"?"#444":n.palette.common.white}}),{name:"BackstageMissingAnnotationEmptyState"});function Z(n,o){const a=o?.kind||"Component",r=o?.metadata.name||"example",s=o?.spec?.type||"website",u=o?.spec?.owner||"user:default/guest",E=`apiVersion: backstage.io/v1alpha1
kind: ${a}
metadata:
name: ${r}
annotations:${n.map(l=>`
${l}: value`).join("")}
spec:
type: ${s}
owner: ${u}`;let d=6;const i=[];return n.forEach(()=>{i.push(d),d++}),{yamlText:E,lineNumbers:i}}function J(n,o="Component"){const a=n.length<=1;return(0,e.jsxs)(e.Fragment,{children:["The ",a?"annotation":"annotations"," ",n.map(r=>(0,e.jsx)("code",{children:r})).reduce((r,s)=>(0,e.jsxs)(e.Fragment,{children:[r,", ",s]}))," ",a?"is":"are"," missing. You need to add the"," ",a?"annotation":"annotations"," to your ",o," if you want to enable this tool."]})}function Q(n){let o;try{o=(0,L.tN)().entity}catch{}const{annotation:a,readMoreUrl:r}=n,s=Array.isArray(a)?a:[a],u=r||"https://backstage.io/docs/features/software-catalog/well-known-annotations",E=W(),d=o?.kind||"Component",{yamlText:i,lineNumbers:l}=Z(s,o);return(0,e.jsx)(U.p,{missing:"field",title:"Missing Annotation",description:J(s,d),action:(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(H.A,{variant:"body1",children:["Add the annotation to your ",d," YAML as shown in the highlighted example below:"]}),(0,e.jsx)(N.A,{className:E.code,children:(0,e.jsx)(K.z,{text:i,language:"yaml",showLineNumbers:!0,highlightedNumbers:l,customStyle:{background:"inherit",fontSize:"115%"}})}),(0,e.jsx)(Y.A,{color:"primary",component:I.N_,to:u,children:"Read more"})]})})}const V=n=>!!n?.metadata?.annotations?.[m.As]||!!n?.metadata?.annotations?.[m.GO],G=()=>(0,e.jsxs)(c.BV,{children:[(0,e.jsx)(c.qh,{path:"/",element:(0,e.jsx)(C.TechDocsIndexPage,{})}),(0,e.jsx)(c.qh,{path:"/:namespace/:kind/:name/*",element:(0,e.jsx)(T.W,{})})]}),X=n=>{const{children:o}=n;return(0,c.Ye)([{path:"*",element:(0,e.jsx)(T.W,{}),children:[{path:"*",element:o}]}])},z=n=>{const{children:o,emptyState:a,withSearch:r=!0}=n,{entity:s}=(0,L.tN)(),u=(0,c.Ye)([{path:"/*",element:(0,e.jsx)(D,{entity:s,withSearch:r}),children:[{path:"*",element:o}]}]);return s.metadata.annotations?.[m.As]||s.metadata.annotations?.[m.GO]?u:a??(0,e.jsx)(Q,{annotation:[m.As]})},y=({children:n,withSearch:o=!0})=>(0,e.jsx)(z,{children:n,withSearch:o})},85788:($,f,t)=>{t.r(f),t.d(f,{TechDocsIndexPage:()=>m});var e=t(31085),c=t(18690),R=t(8915);const m=A=>(0,c.P1)()||(0,e.jsx)(R.K,{...A})},93160:($,f,t)=>{t.d(f,{b:()=>G,W:()=>z});var e=t(31085),c=t(14041),R=t(18690),m=t(24504),A=t(72020),M=t(88572),j=t(13976),B=t(45061),S=t(39299),p=t(82779),g=t(70048),v=t(19402),x=t(22020),O=t(82266),D=t(64947),C=t(72427),T=t(70795),L=t(57405),N=t(16261);function Y(y,n){const[o,a]=(0,c.useState)({status:"not-executed",error:void 0,result:n}),r=(0,c.useRef)(),s=(0,c.useRef)(),u=(0,N.J)({execute(...E){s.current=E;const d=y(...E);return r.current=d,a(i=>({...i,status:"loading"})),d.then(i=>{d===r.current&&a(l=>({...l,status:"success",error:void 0,result:i}))},i=>{d===r.current&&a(l=>({...l,status:"error",error:i}))}),d},reset(){a({status:"not-executed",error:void 0,result:n}),r.current=void 0,s.current=void 0}});return[o,(0,c.useMemo)(()=>({reset(){u.current.reset()},execute:(...E)=>u.current.execute(...E)}),[]),{promise:r.current,lastArgs:s.current}]}var F=t(76842),H=t(70835);const U="/.backstage/auth/v1/cookie",K=365*24*36e5;function I(y){const{pluginId:n}=y??{},o=(0,C.gf)(T.a),a=(0,C.gf)(L.I),r=(0,c.useMemo)(()=>"BroadcastChannel"in window?new BroadcastChannel(`${n}-auth-cookie-expires-at`):null,[n]),[s,u]=Y(async()=>{const l=`${await a.getBaseUrl(n)}${U}`,h=await o.fetch(`${l}`,{credentials:"include"});if(!h.ok){if(h.status===404)return{expiresAt:new Date(Date.now()+K)};throw await H.o.fromResponse(h)}const P=await h.json();if(!P.expiresAt)throw new Error("No expiration date found in response");return P});(0,F.u)(u.execute);const E=(0,c.useCallback)(()=>{u.execute()},[u]),d=(0,c.useCallback)(i=>{const l=(1+3*Math.random())*6e4,h=Date.parse(i.expiresAt)-Date.now()-l,P=setTimeout(E,h);return()=>clearTimeout(P)},[E]);return(0,c.useEffect)(()=>{if(s.status!=="success"||!s.result)return()=>{};r?.postMessage({action:"COOKIE_REFRESH_SUCCESS",payload:s.result});let i=d(s.result);const l=h=>{const{action:P,payload:b}=h.data;P==="COOKIE_REFRESH_SUCCESS"&&(i(),i=d(b))};return r?.addEventListener("message",l),()=>{i(),r?.removeEventListener("message",l)}},[s,d,r]),s.status==="not-executed"?{status:"loading"}:s.status==="loading"&&!s.result?{status:"loading"}:s.status==="loading"&&s.error?{status:"loading"}:s.status==="error"&&s.error?{status:"error",error:s.error,retry:E}:{status:"success",data:s.result}}function W(y){const{children:n,...o}=y,a=(0,O.n)(),{Progress:r}=a.getComponents(),s=I(o);return s.status==="loading"?(0,e.jsx)(r,{}):s.status==="error"?(0,e.jsx)(x.b,{error:s.error,children:(0,e.jsx)(D.A,{variant:"outlined",onClick:s.retry,children:"Retry"})}):(0,e.jsx)(e.Fragment,{children:n})}var Z=t(58502),J=t(54917),Q=t(98392),V=t(50868);const G=y=>{const{withSearch:n,withHeader:o=!0}=y;return(0,e.jsxs)(m.Y,{themeId:"documentation",children:[o&&(0,e.jsx)(B.T,{}),(0,e.jsx)(S.Z,{}),(0,e.jsx)(j.p,{withSearch:n})]})},X=(0,Z.A)(m.Y)({height:"inherit",overflowY:"visible"}),z=y=>{const n=(0,J.A)(),o=(0,Q.A)({...n,...y.overrideThemeOptions||{}}),{kind:a,name:r,namespace:s}=(0,g.K)(p.Oc),{children:u,entityRef:E={kind:a,name:r,namespace:s}}=y,d=(0,R.P1)();if(!u){const h=(d?c.Children.toArray(d.props.children):[]).flatMap(P=>P?.props?.children??[]).find(P=>!(0,v.E)(P,A.AF)&&!(0,v.E)(P,A.Wm));return(0,e.jsx)(V.A,{theme:o,children:(0,e.jsx)(W,{pluginId:"techdocs",children:(0,e.jsx)(M.R,{entityRef:E,children:h||(0,e.jsx)(G,{})})})})}return(0,e.jsx)(V.A,{theme:o,children:(0,e.jsx)(W,{pluginId:"techdocs",children:(0,e.jsx)(M.R,{entityRef:E,children:({metadata:i,entityMetadata:l,onReady:h})=>(0,e.jsx)(X,{themeId:"documentation",className:"techdocs-reader-page",children:u instanceof Function?u({entityRef:E,techdocsMetadataValue:i.value,entityMetadataValue:l.value,onReady:h}):u})})})})}},39299:($,f,t)=>{t.d(f,{Z:()=>O});var e=t(31085),c=t(14041),R=t(58837),m=t(29365),A=t(75173),M=t(71677),j=t(37757),B=t(10394),S=t(9684),p=t(88572),g=t(72020),v=t(99730);const x=(0,R.A)(D=>({root:{gridArea:"pageSubheader",flexDirection:"column",minHeight:"auto",padding:D.spacing(3,3,0),"@media print":{display:"none"}}})),O=D=>{const C=x(),[T,L]=(0,c.useState)(null),N=(0,c.useCallback)(W=>{L(W.currentTarget)},[]),Y=(0,c.useCallback)(()=>{L(null)},[]),{entityMetadata:{value:F,loading:H}}=(0,p.V)(),U=(0,g.YR)(),K=U.renderComponentsByLocation(v.e.Subheader),I=U.renderComponentsByLocation(v.e.Settings);return!K&&!I||H===!1&&!F?null:(0,e.jsx)(A.A,{classes:C,...D.toolbarProps,children:(0,e.jsxs)(B.A,{display:"flex",justifyContent:"flex-end",width:"100%",flexWrap:"wrap",children:[K,I?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(M.Ay,{title:"Settings",children:(0,e.jsx)(m.A,{"aria-controls":"tech-docs-reader-page-settings","aria-haspopup":"true",onClick:N,children:(0,e.jsx)(S.A,{})})}),(0,e.jsx)(j.A,{id:"tech-docs-reader-page-settings",getContentAnchorEl:null,anchorEl:T,anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!T,onClose:Y,keepMounted:!0,children:(0,e.jsx)("div",{children:I})})]}):null]})})}}}]);})();
//# sourceMappingURL=8803.48dd4e23.chunk.js.map