UNPKG

@techdocs/cli

Version:

Utility CLI for managing TechDocs sites in Backstage.

10 lines • 10.2 kB
"use strict";(self.webpackChunktechdocs_cli_embedded_app=self.webpackChunktechdocs_cli_embedded_app||[]).push([["3058"],{23490:function(e,t,n){n.d(t,{O:()=>r});var a=n(73557);function r(e){return(0,a.UO)()}},5e4:function(e,t,n){n.d(t,{X2:()=>u,ce:()=>d,h$:()=>c});var a=n(52322),r=n(39381),s=n(60214),o=n(18011),i=n(88260);let l=(0,o.CT)("entity-context"),c=e=>{let{children:t,entity:n,loading:o,error:c,refresh:u}=e;return(0,a.jsx)(l.Provider,{value:(0,i.E)({1:{entity:n,loading:o,error:c,refresh:u}}),children:(0,a.jsx)(s.fC,{attributes:{...n?{entityRef:(0,r.eE)(n)}:void 0},children:t})})};function u(){let e=(0,o.Vt)("entity-context");if(!e)throw Error("Entity context is not available");let t=e.atVersion(1);if(!t)throw Error("EntityContext v1 not available");if(!t.entity)throw 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:t.entity}}function d(){let e=(0,o.Vt)("entity-context");if(!e)throw Error("Entity context is not available");let t=e.atVersion(1);if(!t)throw Error("EntityContext v1 not available");let{entity:n,loading:a,error:r,refresh:s}=t;return{entity:n,loading:a,error:r,refresh:s}}},55195:function(e,t,n){n.r(t),n.d(t,{Router:()=>A,EmbeddedDocsRouter:()=>$,TechDocsReaderRouter:()=>M,LegacyEmbeddedDocsRouter:()=>I,isTechDocsAvailable:()=>Z});var a=n(52322),r=n(73557),s=n(39381),o=n(99503),i=n(25942),l=n(98248),c=n(37065),u=n(33741),d=n(2784),h=n(93048),p=n(51173);let m=e=>e.replace(/\/+$/,""),x=({entity:e,withSearch:t=!0})=>{let n=(0,s.iB)(e),r=function(e){let{kind:t,name:n,namespace:a}=e,r=(0,h.t)(p.Fw),s=(0,h.t)(p.pd);return(0,d.useMemo)(()=>{let e=m(r({kind:t,namespace:a,name:n})),o=m(s());return t=>{if(t.toLocaleLowerCase("en-US").startsWith(e.toLocaleLowerCase("en-US"))){let n=t.slice(e.length).replace(/^\/+/,"");return 0===n.length||n.startsWith("#")?`${o}${n}`:`${o}/${n}`}return t}},[r,s,t,n,a])}(n);if(e.metadata.annotations?.[o.Un])try{n=(0,s.of)(e.metadata.annotations?.[o.Un])}catch{}let x=(0,i.IG)(e);return(0,a.jsxs)(l.I6,{entityRef:n,children:[(0,a.jsx)(u.b,{}),(0,a.jsx)(c.F,{withSearch:t,searchResultUrlMapper:r,defaultPath:x})]})};var g=n(84377),f=n(49447),y=n(5e4),j=n(53244),w=n(77277),v=n(79692),b=n(90436),C=n(24780),E=n(12753),k=n(13039);let S=(0,v.Z)(e=>({code:{borderRadius:6,margin:e.spacing(2,0),background:"dark"===e.palette.type?"#444":e.palette.common.white}}),{name:"BackstageMissingAnnotationEmptyState"});function R(e){let t;try{t=(0,y.X2)().entity}catch(e){}let{annotation:n,readMoreUrl:r}=e,s=Array.isArray(n)?n:[n],o=S(),i=t?.kind||"Component",{yamlText:l,lineNumbers:c}=function(e,t){let n=t?.kind||"Component",a=t?.metadata.name||"example",r=t?.spec?.type||"website",s=t?.spec?.owner||"user:default/guest",o=`apiVersion: backstage.io/v1alpha1 kind: ${n} metadata: name: ${a} annotations:${e.map(e=>` ${e}: value`).join("")} spec: type: ${r} owner: ${s}`,i=6,l=[];return e.forEach(()=>{l.push(i),i++}),{yamlText:o,lineNumbers:l}}(s,t);return(0,a.jsx)(C.u,{missing:"field",title:"Missing Annotation",description:function(e,t="Component"){let n=e.length<=1;return(0,a.jsxs)(a.Fragment,{children:["The ",n?"annotation":"annotations"," ",e.map(e=>(0,a.jsx)("code",{children:e})).reduce((e,t)=>(0,a.jsxs)(a.Fragment,{children:[e,", ",t]}))," ",n?"is":"are"," missing. You need to add the"," ",n?"annotation":"annotations"," to your ",t," if you want to enable this tool."]})}(s,i),action:(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(b.Z,{variant:"body1",children:["Add the annotation to your ",i," YAML as shown in the highlighted example below:"]}),(0,a.jsx)(j.Z,{className:o.code,children:(0,a.jsx)(E.O,{text:l,language:"yaml",showLineNumbers:!0,highlightedNumbers:c,customStyle:{background:"inherit",fontSize:"115%"}})}),(0,a.jsx)(w.Z,{color:"primary",component:k.rU,to:r||"https://backstage.io/docs/features/software-catalog/well-known-annotations",children:"Read more"})]})})}let Z=e=>!!e?.metadata?.annotations?.[o.w5]||!!e?.metadata?.annotations?.[o.Un],A=()=>(0,a.jsxs)(r.Z5,{children:[(0,a.jsx)(r.AW,{path:"/",element:(0,a.jsx)(g.TechDocsIndexPage,{})}),(0,a.jsx)(r.AW,{path:"/:namespace/:kind/:name/*",element:(0,a.jsx)(f.I,{})})]}),M=e=>{let{children:t}=e;return(0,r.V$)([{path:"*",element:(0,a.jsx)(f.I,{}),children:[{path:"*",element:t}]}])},$=e=>{let{children:t,emptyState:n,withSearch:s=!0}=e,{entity:i}=(0,y.X2)(),l=(0,r.V$)([{path:"/*",element:(0,a.jsx)(x,{entity:i,withSearch:s}),children:[{path:"*",element:t}]}]);return i.metadata.annotations?.[o.w5]||i.metadata.annotations?.[o.Un]?l:n??(0,a.jsx)(R,{annotation:[o.w5]})},I=({children:e,withSearch:t=!0})=>(0,a.jsx)($,{children:e,withSearch:t})},84377:function(e,t,n){n.r(t),n.d(t,{TechDocsIndexPage:()=>o});var a=n(52322),r=n(73557),s=n(74556);let o=e=>(0,r.pC)()||(0,a.jsx)(s.u,{...e})},49447:function(e,t,n){n.d(t,{r:()=>T,I:()=>_});var a=n(52322),r=n(2784),s=n(73557),o=n(64796),i=n(25942),l=n(98049),c=n(31546),u=n(99503),d=n(4812),h=n(37065),p=n(99064),m=n(33741),x=n(51173),g=n(23490),f=n(16162),y=n(93048),j=n(32904),w=n(33414),v=n(40098),b=n(77277),C=n(42412),E=n(51943),k=n(6020),S=n(91246),R=n(26291);function Z(e){let{children:t,...n}=e,{Progress:s}=(0,v.q)().getComponents(),o=function(e){let{pluginId:t}=e??{},n=(0,f.h_)(C.g),a=(0,f.h_)(E.N),s=(0,r.useMemo)(()=>"BroadcastChannel"in window?new BroadcastChannel(`${t}-auth-cookie-expires-at`):null,[t]),[o,i]=function(e,t){let[n,a]=(0,r.useState)({status:"not-executed",error:void 0,result:void 0}),s=(0,r.useRef)(),o=(0,r.useRef)(),i=(0,k.x)({execute(...t){o.current=t;let n=e(...t);return s.current=n,a(e=>({...e,status:"loading"})),n.then(e=>{n===s.current&&a(t=>({...t,status:"success",error:void 0,result:e}))},e=>{n===s.current&&a(t=>({...t,status:"error",error:e}))}),n},reset(){a({status:"not-executed",error:void 0,result:void 0}),s.current=void 0,o.current=void 0}});return[n,(0,r.useMemo)(()=>({reset(){i.current.reset()},execute:(...e)=>i.current.execute(...e)}),[]),{promise:s.current,lastArgs:o.current}]}(async()=>{let e=await a.getBaseUrl(t),r=`${e}/.backstage/auth/v1/cookie`,s=await n.fetch(`${r}`,{credentials:"include"});if(!s.ok){if(404===s.status)return{expiresAt:new Date(Date.now()+31536e6)};throw await R.V.fromResponse(s)}let o=await s.json();if(!o.expiresAt)throw Error("No expiration date found in response");return o});(0,S.n)(i.execute);let l=(0,r.useCallback)(()=>{i.execute()},[i]),c=(0,r.useCallback)(e=>{let t=(1+3*Math.random())*6e4,n=setTimeout(l,Date.parse(e.expiresAt)-Date.now()-t);return()=>clearTimeout(n)},[l]);return((0,r.useEffect)(()=>{if("success"!==o.status||!o.result)return()=>{};s?.postMessage({action:"COOKIE_REFRESH_SUCCESS",payload:o.result});let e=c(o.result),t=t=>{let{action:n,payload:a}=t.data;"COOKIE_REFRESH_SUCCESS"===n&&(e(),e=c(a))};return s?.addEventListener("message",t),()=>{e(),s?.removeEventListener("message",t)}},[o,c,s]),"not-executed"===o.status||"loading"===o.status&&!o.result||"loading"===o.status&&o.error)?{status:"loading"}:"error"===o.status&&o.error?{status:"error",error:o.error,retry:l}:{status:"success",data:o.result}}(n);return"loading"===o.status?(0,a.jsx)(s,{}):"error"===o.status?(0,a.jsx)(w.y,{error:o.error,children:(0,a.jsx)(b.Z,{variant:"outlined",onClick:o.retry,children:"Retry"})}):(0,a.jsx)(a.Fragment,{children:t})}var A=n(84081),M=n(36363),$=n(60364),I=n(84620),L=n(41547),F=n(77344);let T=e=>{let{withSearch:t,withHeader:n=!0}=e;return(0,a.jsxs)(o.T,{themeId:"documentation",children:[n&&(0,a.jsx)(p.S,{}),(0,a.jsx)(m.b,{}),(0,a.jsx)(h.F,{withSearch:t})]})},U=(0,M.Z)(o.T)({height:"inherit",overflowY:"visible"}),_=e=>{let t=(0,$.Z)(),n=(0,r.useMemo)(()=>(0,I.Z)({...t,...e.overrideThemeOptions||{}}),[t,e.overrideThemeOptions]),{kind:o,name:h,namespace:p}=(0,g.O)(x.Fw),{children:m,entityRef:w={kind:o,name:h,namespace:p}}=e,v=(0,s.pC)(),b=(0,f.h_)(A.A),C=(0,s.s0)(),E=(0,y.t)(x.Fw),k=(0,r.useMemo)(()=>({kind:w.kind,name:w.name,namespace:w.namespace}),[w.kind,w.name,w.namespace]),S=(0,d.Z)(async()=>{try{let e=await b.getEntityByRef(k);if(e?.metadata?.annotations?.[u.Un])return(0,i.Li)(e,E)}catch(e){}},[k,b,E]),R=(0,r.useCallback)(e=>{C(e,{replace:!0})},[C]);(0,r.useEffect)(()=>{!S.loading&&S.value&&R(S.value)},[S.loading,S.value,R]);let M=(0,r.useMemo)(()=>m?null:(v?r.Children.toArray(v.props.children):[]).flatMap(e=>e?.props?.children??[]).find(e=>!(0,j.I)(e,l.Zz)&&!(0,j.I)(e,l.jM)),[m,v]);return S.loading||S.value?(0,a.jsx)(F.E,{}):m?(0,a.jsx)(L.Z,{theme:n,children:(0,a.jsx)(Z,{pluginId:"techdocs",children:(0,a.jsx)(c.Z,{entityRef:k,children:({metadata:e,entityMetadata:t,onReady:n})=>(0,a.jsx)(U,{themeId:"documentation",className:"techdocs-reader-page",children:m instanceof Function?m({entityRef:k,techdocsMetadataValue:e.value,entityMetadataValue:t.value,onReady:n}):m})})})}):(0,a.jsx)(L.Z,{theme:n,children:(0,a.jsx)(Z,{pluginId:"techdocs",children:(0,a.jsx)(c.Z,{entityRef:k,children:M||(0,a.jsx)(T,{})})})})}},33741:function(e,t,n){n.d(t,{b:()=>g});var a=n(52322),r=n(2784),s=n(79692),o=n(61837),i=n(15223),l=n(80030),c=n(48348),u=n(53244),d=n(47603),h=n(31546),p=n(98049),m=n(63424);let x=(0,s.Z)(e=>({root:{gridArea:"pageSubheader",flexDirection:"column",minHeight:"auto",padding:e.spacing(3,3,0),"@media print":{display:"none"}}})),g=e=>{let t=x(),[n,s]=(0,r.useState)(null),g=(0,r.useCallback)(e=>{s(e.currentTarget)},[]),f=(0,r.useCallback)(()=>{s(null)},[]),{entityMetadata:{value:y,loading:j}}=(0,h.x)(),w=(0,p.$L)(),v=w.renderComponentsByLocation(m.o.Subheader),b=w.renderComponentsByLocation(m.o.Settings);return(v||b)&&(!1!==j||y)?(0,a.jsx)(i.Z,{classes:t,...e.toolbarProps,children:(0,a.jsxs)(u.Z,{display:"flex",justifyContent:"flex-end",width:"100%",flexWrap:"wrap",children:[v,b?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(l.ZP,{title:"Settings",children:(0,a.jsx)(o.Z,{"aria-controls":"tech-docs-reader-page-settings","aria-haspopup":"true",onClick:g,children:(0,a.jsx)(d.default,{})})}),(0,a.jsx)(c.Z,{id:"tech-docs-reader-page-settings",getContentAnchorEl:null,anchorEl:n,anchorOrigin:{vertical:"bottom",horizontal:"right"},open:!!n,onClose:f,keepMounted:!0,children:(0,a.jsx)("div",{children:b})})]}):null]})}):null}}}]); //# sourceMappingURL=3058.4fcf00d8.chunk.js.map