import{writeFileSync as f}from"node:fs";import m from"path";import{PAGE_COUNT_OUTPUT_FILE_NAME as g}from"../../constants/common.js";import{EntitlementsProvider as d}from"../../entitlements/entitlements-provider.js";import{getBilledPagesCount as h,isPathIgnored as w,readEnvVariable as P}from"../../utils/index.js";import o from"../../utils/reporter/logger.js";import{isGraphqlDoc as T}from"../graphql-docs/is-graphql-doc.js";import{isMarkdownPage as A}from"../markdown/is-markdown-page.js";import{isOpenapiDoc as F}from"../openapi-docs/is-openapi-doc.js";import{isReactPage as O}from"../pages/is-react-page.js";import{PRODUCT_NAME as s}from"../../../config/product-gates.js";async function C(){return{id:"entitlements",async afterRoutesCreated(c,p){const t=d.instance(),r=[],n=[],i=[],a=[];for(const{relativePath:e}of await p.fs.scan())w(e)||(A(e)?r.push(e):T(e)?i.push(e):O(e)?a.push(e):await F(e,p)&&n.push(e));r.length>0&&!t.canAccessFeature("markdown")&&o.warn(`The product you are using ("${s}") does not support Markdown pages. The following Markdown files were detected but will be ignored: ${r.map(()=>"%rp").join(", ")}`,...r),n.length>0&&!t.canAccessFeature("openapi")&&o.warn(`The product you are using ("${s}") does not support OpenAPI documents. The following files are ignored: ${n.map(()=>"%rp").join(", ")}`,...n),i.length>0&&!t.canAccessFeature("graphql")&&o.warn(`The product you are using ("${s}") does not support GraphQL documents. The following files are ignored: ${i.map(()=>"%rp").join(", ")}`,...i),a.length>0&&!t.canAccessFeature("reactPages")&&o.warn(`The product you are using ("${s}") does not support React pages. The following files are ignored: ${a.map(()=>"%rp").join(", ")}`,...a);const u=h(c.getAllRoutes()),l=P("REDOCLY_METADATA_OUTPUT_FOLDER");l&&(o.info("Save total pages..."),f(m.join(l,g),JSON.stringify({totalPages:u},null)))}}}export{C as entitlementsPlugin};
