@wtdlee/repomap 0.3.1 → 0.3.3
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/analyzers/index.js +1 -1
- package/dist/{chunk-M6YNU536.js → chunk-53ANJE42.js} +27 -714
- package/dist/chunk-6F4PWJZI.js +0 -1
- package/dist/{chunk-E4WRODSI.js → chunk-H4YGP3GL.js} +35 -108
- package/dist/chunk-J2CM7T7U.js +1 -0
- package/dist/{chunk-3YFXZAP7.js → chunk-MOEA75XK.js} +170 -359
- package/dist/chunk-PTR5IROV.js +36 -0
- package/dist/chunk-VV3A3UE3.js +1 -0
- package/dist/chunk-XWZH2RDG.js +19 -0
- package/dist/cli.js +29 -395
- package/dist/env-detector-BIWJ7OYF.js +1 -0
- package/dist/generators/assets/common.css +564 -23
- package/dist/generators/index.js +1 -2
- package/dist/index.js +1 -8
- package/dist/page-map-generator-XNZ4TDJT.js +1 -0
- package/dist/rails-FFISZ4AE.js +1 -0
- package/dist/rails-map-generator-UFLCMFAT.js +1 -0
- package/dist/server/index.js +1 -7
- package/dist/types.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3PWXDB7B.js +0 -153
- package/dist/chunk-GNBMJMET.js +0 -2519
- package/dist/chunk-OWM6WNLE.js +0 -2610
- package/dist/chunk-SSU6QFTX.js +0 -1058
- package/dist/env-detector-EEMVUEIA.js +0 -1
- package/dist/page-map-generator-6MJGPBVA.js +0 -1
- package/dist/rails-UWSDRS33.js +0 -1
- package/dist/rails-map-generator-D2URLMVJ.js +0 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import*as G from'fs';import*as x from'path';import {Parser,Language}from'web-tree-sitter';import {fileURLToPath}from'url';import {createRequire}from'module';import {glob}from'glob';import*as A from'fs/promises';var ue=createRequire(import.meta.url);var me=fileURLToPath(import.meta.url);x.dirname(me);var te=false,O=null,D=null;async function se(){if(D&&O)return D;te||(await Parser.init(),te=true),D=new Parser;let l=null;try{let e=ue.resolve("tree-sitter-wasms/package.json");l=x.join(x.dirname(e),"out/tree-sitter-ruby.wasm");}catch{let e=x.join(process.cwd(),"node_modules/tree-sitter-wasms/out/tree-sitter-ruby.wasm");G.existsSync(e)&&(l=e);}if(!l||!G.existsSync(l))throw new Error("tree-sitter-ruby.wasm not found. Please ensure tree-sitter-wasms package is installed.");return O=await Language.load(l),D.setLanguage(O),D}async function ne(l){let t=(await se()).parse(l);if(!t)throw new Error("Failed to parse Ruby code");return t}async function N(l){let e=G.readFileSync(l,"utf-8");return ne(e)}function R(l,e){let t=[];l.type===e&&t.push(l);for(let o=0;o<l.childCount;o++){let s=l.child(o);s&&t.push(...R(s,e));}return t}function L(l,e){for(let t=0;t<l.childCount;t++){let o=l.child(t);if(o&&o.type===e)return o}return null}function w(l,e){let t=[];for(let o=0;o<l.childCount;o++){let s=l.child(o);s&&s.type===e&&t.push(s);}return t}function S(l){let e=l.childForFieldName("arguments");if(!e)return [];let t=[];for(let o=0;o<e.childCount;o++){let s=e.child(o);s&&s.type!=="("&&s.type!==")"&&s.type!==","&&t.push(s);}return t}function F(l){let e=l.childForFieldName("name");return e?e.text:null}function M(l){let e=l.childForFieldName("superclass");if(!e)return null;let t=L(e,"constant")||L(e,"scope_resolution");return t?t.text:null}function U(l){let e=l.childForFieldName("name");return e?e.text:null}function Z(l){let e=l.childForFieldName("parameters");if(!e)return [];let t=[];for(let o=0;o<e.childCount;o++){let s=e.child(o);if(s&&(s.type==="identifier"||s.type==="keyword_parameter"||s.type==="optional_parameter"||s.type==="splat_parameter")){let n=s.childForFieldName("name")||s;n.type==="identifier"?t.push(n.text):t.push(s.text);}}return t}var k=class{constructor(e){this.rootPath=e;this.routesDir=x.join(e,"config","routes");}routesDir;routes=[];namespaces=[];resources=[];mountedEngines=[];drawnFiles=[];errors=[];async analyze(){let e=x.join(this.rootPath,"config","routes.rb");if(!G.existsSync(e))return {routes:[],namespaces:[],resources:[],mountedEngines:[],drawnFiles:[],errors:[`routes.rb not found at ${e}`]};try{await this.parseRoutesFile(e,[]);}catch(t){this.errors.push(`Error parsing ${e}: ${t}`);}return {routes:this.routes,namespaces:[...new Set(this.namespaces)],resources:this.resources,mountedEngines:this.mountedEngines,drawnFiles:this.drawnFiles,errors:this.errors}}async parseRoutesFile(e,t){let s=(await N(e)).rootNode,n=R(s,"call");for(let r of n){let a=r.childForFieldName("method");if(!a)continue;let c=a.text,i=r.startPosition.row+1;switch(c){case "get":case "post":case "put":case "patch":case "delete":case "match":this.parseHttpRoute(r,c,t,i);break;case "resources":case "resource":await this.parseResources(r,t,i,c==="resource");break;case "namespace":await this.parseNamespace(r,t,e);break;case "mount":this.parseMount(r,i);break;case "draw":await this.parseDraw(r,t);break;case "devise_for":this.parseDeviseFor(r,t,i);break;case "root":this.parseRoot(r,t,i);break}}}parseHttpRoute(e,t,o,s){let n=S(e);if(n.length===0)return;let r=n[0],a=this.extractStringValue(r);if(!a)return;let c="",i="";for(let u of n)if(u.type==="hash"||u.type==="pair"){let m=u.type==="hash"?w(u,"pair"):[u];for(let d of m){let y=d.child(0)?.text?.replace(/^:/,""),f=d.child(2);if(y==="to"&&f){let g=this.extractStringValue(f);g&&g.includes("#")&&([c,i]=g.split("#"));}}}else if(u.type==="string"||u.type==="string_content"){let m=this.extractStringValue(u);m&&m.includes("#")&&!c&&([c,i]=m.split("#"));}if(!c&&!i){let u=a.replace(/^\//,"").split("/");c=u[0]||"",i=u[1]||"index";}o.length>0&&c&&!c.includes("/")&&(c=`${o.join("/")}/${c}`);let p=this.buildPath(o,a);this.routes.push({method:t==="match"?"ALL":t.toUpperCase(),path:p,controller:c,action:i,namespace:o.join("/")||void 0,line:s});}async parseResources(e,t,o,s){let n=S(e);if(n.length===0)return;let a=n[0].text.replace(/^:/,""),c={name:a,controller:t.length>0?`${t.join("/")}/${a}`:a,nested:[],memberRoutes:[],collectionRoutes:[],line:o};for(let p of n)if(p.type==="hash"){let u=w(p,"pair");for(let m of u){let d=m.child(0)?.text?.replace(/^:/,""),y=m.child(2);d==="only"&&y?c.only=this.extractArrayValues(y):d==="except"&&y&&(c.except=this.extractArrayValues(y));}}this.generateResourceRoutes(c,t,s),this.resources.push(c);let i=e.childForFieldName("block");if(i){let p=R(i,"call");for(let u of p){let m=u.childForFieldName("method")?.text;if(m==="member"){let d=u.childForFieldName("block");d&&this.parseMemberCollectionRoutes(d,c,t,"member");}else if(m==="collection"){let d=u.childForFieldName("block");d&&this.parseMemberCollectionRoutes(d,c,t,"collection");}}}}parseMemberCollectionRoutes(e,t,o,s){let n=R(e,"call");for(let r of n){let a=r.childForFieldName("method");if(!a)continue;let c=a.text;if(!["get","post","put","patch","delete"].includes(c))continue;let i=S(r);if(i.length===0)continue;let p=i[0].text.replace(/^:/,""),u=s==="member"?`/${t.name}/:id/${p}`:`/${t.name}/${p}`,m={method:c.toUpperCase(),path:this.buildPath(o,u),controller:t.controller,action:p,namespace:o.join("/")||void 0,line:r.startPosition.row+1};s==="member"?t.memberRoutes.push(m):t.collectionRoutes.push(m),this.routes.push(m);}}async parseNamespace(e,t,o){let s=S(e);if(s.length===0)return;let n=s[0].text.replace(/^:/,"");this.namespaces.push(n);let r=[...t,n],a=e.childForFieldName("block");if(a){let c=R(a,"call");for(let i of c){let p=i.childForFieldName("method");if(!p)continue;let u=p.text,m=i.startPosition.row+1;switch(u){case "get":case "post":case "put":case "patch":case "delete":case "match":this.parseHttpRoute(i,u,r,m);break;case "resources":case "resource":await this.parseResources(i,r,m,u==="resource");break;case "draw":await this.parseDraw(i,r);break}}}}parseMount(e,t){let o=S(e);if(o.length===0)return;let n=o[0].text,r="/";for(let a of o)if(a.type==="hash"||a.type==="pair"){let c=a.type==="hash"?w(a,"pair"):[a];for(let i of c){let p=i.child(0)?.text?.replace(/^:/,""),u=i.child(2);p==="at"&&u&&(r=this.extractStringValue(u)||r);}}else if(a.type==="string"){let c=this.extractStringValue(a);c&&c.startsWith("/")&&(r=c);}this.mountedEngines.push({engine:n,mountPath:r,line:t});}async parseDraw(e,t){let o=S(e);if(o.length===0)return;let s=o[0].text.replace(/^:/,""),n=x.join(this.routesDir,`${s}.rb`);if(G.existsSync(n)){this.drawnFiles.push(n);try{await this.parseRoutesFile(n,t);}catch(r){this.errors.push(`Error parsing drawn file ${n}: ${r}`);}}}parseDeviseFor(e,t,o){let s=S(e);if(s.length===0)return;let n=s[0].text.replace(/^:/,""),r=[{method:"GET",path:`/${n}/sign_in`,action:"new",controller:"devise/sessions"},{method:"POST",path:`/${n}/sign_in`,action:"create",controller:"devise/sessions"},{method:"DELETE",path:`/${n}/sign_out`,action:"destroy",controller:"devise/sessions"},{method:"GET",path:`/${n}/password/new`,action:"new",controller:"devise/passwords"},{method:"POST",path:`/${n}/password`,action:"create",controller:"devise/passwords"},{method:"GET",path:`/${n}/sign_up`,action:"new",controller:"devise/registrations"},{method:"POST",path:`/${n}`,action:"create",controller:"devise/registrations"}];for(let a of r)this.routes.push({method:a.method,path:this.buildPath(t,a.path),controller:a.controller,action:a.action,namespace:t.join("/")||void 0,line:o,authenticated:false});}parseRoot(e,t,o){let s=S(e),n="",r="index";for(let a of s)if(a.type==="string"){let c=this.extractStringValue(a);c&&c.includes("#")&&([n,r]=c.split("#"));}else if(a.type==="hash"||a.type==="pair"){let c=a.type==="hash"?w(a,"pair"):[a];for(let i of c){let p=i.child(0)?.text?.replace(/^:/,""),u=i.child(2);if(p==="to"&&u){let m=this.extractStringValue(u);m&&m.includes("#")&&([n,r]=m.split("#"));}}}n&&this.routes.push({method:"GET",path:this.buildPath(t,"/"),controller:n,action:r,namespace:t.join("/")||void 0,line:o});}generateResourceRoutes(e,t,o){let s=this.buildPath(t,`/${e.name}`),n=o?["show","new","create","edit","update","destroy"]:["index","show","new","create","edit","update","destroy"],r=e.only||(e.except?n.filter(i=>!e.except.includes(i)):n),a=[];o||r.includes("index")&&a.push({method:"GET",path:s,action:"index"}),r.includes("new")&&a.push({method:"GET",path:`${s}/new`,action:"new"}),r.includes("create")&&a.push({method:"POST",path:s,action:"create"});let c=o?s:`${s}/:id`;r.includes("show")&&a.push({method:"GET",path:c,action:"show"}),r.includes("edit")&&a.push({method:"GET",path:`${c}/edit`,action:"edit"}),r.includes("update")&&(a.push({method:"PUT",path:c,action:"update"}),a.push({method:"PATCH",path:c,action:"update"})),r.includes("destroy")&&a.push({method:"DELETE",path:c,action:"destroy"});for(let i of a)this.routes.push({method:i.method,path:i.path,controller:e.controller,action:i.action,namespace:t.join("/")||void 0,line:e.line});}buildPath(e,t){return t.startsWith("/")?t:`${e.length>0?`/${e.join("/")}`:""}/${t}`}extractStringValue(e){if(e.type==="string"){let t=L(e,"string_content");return t?t.text:e.text.replace(/^["']|["']$/g,"")}return e.type==="string_content"?e.text:e.type==="simple_symbol"||e.type==="symbol"?e.text.replace(/^:/,""):e.text.replace(/^["']|["']$/g,"")}extractArrayValues(e){let t=[];if(e.type==="array")for(let o=0;o<e.childCount;o++){let s=e.child(o);if(s&&s.type!=="["&&s.type!=="]"&&s.type!==","){let n=this.extractStringValue(s);n&&t.push(n);}}else {let o=this.extractStringValue(e);o&&t.push(o);}return t}};async function de(){let l=process.argv[2]||process.cwd();console.log(`Analyzing routes in: ${l}`);let t=await new k(l).analyze();if(console.log(`
|
|
2
|
+
=== Rails Routes Analysis ===
|
|
3
|
+
`),console.log(`Total routes: ${t.routes.length}`),console.log(`Namespaces: ${t.namespaces.join(", ")||"(none)"}`),console.log(`Resources: ${t.resources.length}`),console.log(`Mounted engines: ${t.mountedEngines.length}`),console.log(`External route files: ${t.drawnFiles.length}`),t.errors.length>0){console.log(`
|
|
4
|
+
--- Errors ---`);for(let o of t.errors)console.log(` \u274C ${o}`);}console.log(`
|
|
5
|
+
--- Sample Routes (first 30) ---`);for(let o of t.routes.slice(0,30))console.log(` ${o.method.padEnd(7)} ${o.path.padEnd(50)} => ${o.controller}#${o.action}`);console.log(`
|
|
6
|
+
--- Mounted Engines ---`);for(let o of t.mountedEngines)console.log(` ${o.engine} => ${o.mountPath}`);console.log(`
|
|
7
|
+
--- External Route Files ---`);for(let o of t.drawnFiles)console.log(` ${x.basename(o)}`);}var fe=import.meta.url===`file://${process.argv[1]}`;fe&&de().catch(console.error);var V=class{constructor(e){this.rootPath=e;this.controllersDir=x.join(e,"app","controllers");}controllersDir;controllers=[];errors=[];async analyze(){if(!G.existsSync(this.controllersDir))return {controllers:[],totalActions:0,namespaces:[],concerns:[],errors:[`Controllers directory not found at ${this.controllersDir}`]};let e=await glob("**/*_controller.rb",{cwd:this.controllersDir,ignore:["concerns/**"]});for(let n of e){let r=x.join(this.controllersDir,n);try{let a=await this.parseControllerFile(r,n);a&&this.controllers.push(a);}catch(a){this.errors.push(`Error parsing ${n}: ${a}`);}}let t=[...new Set(this.controllers.filter(n=>n.namespace).map(n=>n.namespace))],o=[...new Set(this.controllers.flatMap(n=>n.concerns))],s=this.controllers.reduce((n,r)=>n+r.actions.length,0);return {controllers:this.controllers,totalActions:s,namespaces:t,concerns:o,errors:this.errors}}async parseControllerFile(e,t){let s=(await N(e)).rootNode,n=t.replace(/_controller\.rb$/,"").split("/"),r=n.length>1?n.slice(0,-1).join("/"):void 0,a=n[n.length-1],c=R(s,"class");if(c.length===0)return null;let i=c[0],p=F(i),u=M(i);if(!p)return null;let m={name:a,filePath:t,className:p,parentClass:u||"ApplicationController",namespace:r,actions:[],beforeActions:[],afterActions:[],aroundActions:[],skipBeforeActions:[],concerns:[],helpers:[],rescueFrom:[],line:i.startPosition.row+1},d=R(i,"call");for(let h of d){let b=h.childForFieldName("method");if(!b)continue;let v=b.text,C=h.startPosition.row+1;switch(v){case "before_action":case "before_filter":this.parseFilter(h,m.beforeActions,C);break;case "after_action":case "after_filter":this.parseFilter(h,m.afterActions,C);break;case "around_action":case "around_filter":this.parseFilter(h,m.aroundActions,C);break;case "skip_before_action":case "skip_before_filter":this.parseFilter(h,m.skipBeforeActions,C);break;case "include":this.parseInclude(h,m.concerns);break;case "helper":this.parseHelper(h,m.helpers);break;case "layout":m.layoutInfo=this.parseLayout(h);break;case "rescue_from":this.parseRescueFrom(h,m.rescueFrom,C);break}}R(i,"method");let f="public",g=i.childForFieldName("body");if(g)for(let h=0;h<g.childCount;h++){let b=g.child(h);if(b){if(b.type==="identifier"){let v=b.text;v==="private"?f="private":v==="protected"?f="protected":v==="public"&&(f="public");}else if(b.type==="method"){let v=this.parseMethod(b,f);v&&m.actions.push(v);}}}return m}parseFilter(e,t,o){let s=this.getCallArguments(e);if(s.length===0)return;let a={name:s[0].text.replace(/^:/,""),line:o};for(let c of s.slice(1))if(c.type==="hash"){let i=w(c,"pair");for(let p of i){let u=p.child(0)?.text?.replace(/^:/,""),m=p.child(2);if(!(!u||!m))switch(u){case "only":a.only=this.extractArrayValues(m);break;case "except":a.except=this.extractArrayValues(m);break;case "if":a.if=m.text;break;case "unless":a.unless=m.text;break}}}t.push(a);}parseInclude(e,t){let o=this.getCallArguments(e);for(let s of o)(s.type==="constant"||s.type==="scope_resolution")&&t.push(s.text);}parseHelper(e,t){let o=this.getCallArguments(e);for(let s of o){let n=s.text.replace(/^:/,"");t.push(n);}}parseLayout(e){let t=this.getCallArguments(e);if(t.length===0)return;let o=t[0],s=o.text.replace(/^["']|["']$/g,"");s.startsWith(":")&&(s=s.substring(1)),(o.type==="lambda"||o.type==="proc")&&(s="(dynamic)");let n={name:s};for(let r of t.slice(1))r.type==="hash"&&(n.conditions=r.text);return n}parseRescueFrom(e,t,o){let s=this.getCallArguments(e);if(s.length===0)return;let n=s[0].text,r="unknown";for(let a of s.slice(1))if(a.type==="hash"||a.type==="pair"){let c=a.type==="hash"?w(a,"pair"):[a];for(let i of c){let p=i.child(0)?.text?.replace(/^:/,""),u=i.child(2);p==="with"&&u&&(r=u.text.replace(/^:/,""));}}t.push({exception:n,handler:r,line:o});}parseMethod(e,t){let o=U(e);if(!o||e.text.includes("def self."))return null;let s={name:o,line:e.startPosition.row+1,visibility:t,parameters:Z(e),servicesCalled:[],modelsCalled:[],methodCalls:[],instanceVarAssignments:[]},n=e.text,r=/@([a-z_][a-z0-9_]*)\s*=\s*([^\n]+)/gi,a;for(;(a=r.exec(n))!==null;){let p=a[1],u=a[2].trim().slice(0,100),m,d=u.match(/^([A-Z][a-zA-Z0-9]+)\.(find|find_by|find_by!|where|all|first|last|new|create|create!|build)/);d&&(m=d[1]);let y=u.match(/^@([a-z_]+)\.([a-z_]+)/);y&&!m&&(m=`${y[1]}.${y[2]}`);let f=u.match(/^current_([a-z_]+)/);f&&!m&&(m=f[1].charAt(0).toUpperCase()+f[1].slice(1));let g=u.match(/^([A-Z][a-zA-Z0-9]+Service)\.(call|new|perform)/);g&&!m&&(m=`Service:${g[1]}`),s.instanceVarAssignments&&s.instanceVarAssignments.push({name:p,assignedType:m,assignedValue:u.length>60?u.slice(0,57)+"...":u});}(n.includes("render json:")||n.includes("render :json"))&&(s.rendersJson=true),n.includes("render")&&!s.rendersJson&&(s.rendersHtml=true);let c=n.match(/redirect_to\s+([^,\n]+)/);if(c&&(s.redirectsTo=c[1].trim()),n.includes("respond_to")){let p=[];n.includes("format.html")&&p.push("html"),n.includes("format.json")&&p.push("json"),n.includes("format.xml")&&p.push("xml"),n.includes("format.js")&&p.push("js"),n.includes("format.csv")&&p.push("csv"),n.includes("format.pdf")&&p.push("pdf"),p.length>0&&(s.respondsTo=p);}let i=R(e,"call");for(let p of i){let u=p.childForFieldName("receiver"),m=p.childForFieldName("method");if(u&&m){let d=u.text,y=m.text;d.endsWith("Service")&&["call","new","perform","execute"].includes(y)&&(s.servicesCalled.includes(d)||s.servicesCalled.push(d));let f=["find","find_by","find_by!","where","all","first","last","create","create!","new","update","update!","destroy","delete"];/^[A-Z][a-zA-Z]+$/.test(d)&&f.includes(y)&&(["Rails","ActiveRecord","ActionController","ApplicationRecord"].includes(d)||s.modelsCalled.includes(d)||s.modelsCalled.push(d)),s.methodCalls.push(`${d}.${y}`);}else m&&!u&&s.methodCalls.push(m.text);}return s}getCallArguments(e){let t=e.childForFieldName("arguments");if(!t){let s=[];for(let n=0;n<e.childCount;n++){let r=e.child(n);r&&!["identifier","(",")",",","call"].includes(r.type)&&r!==e.childForFieldName("method")&&r!==e.childForFieldName("receiver")&&s.push(r);}return s}let o=[];for(let s=0;s<t.childCount;s++){let n=t.child(s);n&&n.type!=="("&&n.type!==")"&&n.type!==","&&o.push(n);}return o}extractArrayValues(e){let t=[];if(e.type==="array")for(let o=0;o<e.childCount;o++){let s=e.child(o);s&&s.type!=="["&&s.type!=="]"&&s.type!==","&&t.push(s.text.replace(/^:/,""));}else t.push(e.text.replace(/^:/,""));return t}};async function ge(){let l=process.argv[2]||process.cwd();console.log(`Analyzing controllers in: ${l}`);let t=await new V(l).analyze();if(console.log(`
|
|
8
|
+
=== Rails Controllers Analysis ===
|
|
9
|
+
`),console.log(`Total controllers: ${t.controllers.length}`),console.log(`Total actions: ${t.totalActions}`),console.log(`Namespaces: ${t.namespaces.join(", ")||"(none)"}`),console.log(`Shared concerns: ${t.concerns.length}`),t.errors.length>0){console.log(`
|
|
10
|
+
--- Errors (${t.errors.length}) ---`);for(let n of t.errors.slice(0,5))console.log(` \u274C ${n}`);t.errors.length>5&&console.log(` ... and ${t.errors.length-5} more`);}console.log(`
|
|
11
|
+
--- Sample Controllers (first 10) ---`);for(let n of t.controllers.slice(0,10))console.log(`
|
|
12
|
+
\u{1F4C1} ${n.className} (${n.filePath})`),console.log(` Parent: ${n.parentClass}`),console.log(` Actions (${n.actions.length}): ${n.actions.map(r=>r.name).slice(0,5).join(", ")}${n.actions.length>5?"...":""}`),n.beforeActions.length>0&&console.log(` Before: ${n.beforeActions.map(r=>r.name).join(", ")}`),n.concerns.length>0&&console.log(` Concerns: ${n.concerns.join(", ")}`);let o=t.controllers.flatMap(n=>n.actions.filter(r=>r.visibility==="public")),s=t.controllers.flatMap(n=>n.actions.filter(r=>r.visibility==="private"));console.log(`
|
|
13
|
+
--- Action Visibility Summary ---`),console.log(` Public: ${o.length}`),console.log(` Private: ${s.length}`);}var ye=import.meta.url===`file://${process.argv[1]}`;ye&&ge().catch(console.error);var j=class{constructor(e){this.rootPath=e;this.modelsDir=x.join(e,"app","models");}modelsDir;models=[];errors=[];async analyze(){if(!G.existsSync(this.modelsDir))return {models:[],totalAssociations:0,totalValidations:0,concerns:[],namespaces:[],errors:[`Models directory not found at ${this.modelsDir}`]};let e=await glob("**/*.rb",{cwd:this.modelsDir,ignore:["concerns/**","application_record.rb"]});for(let r of e){let a=x.join(this.modelsDir,r);try{let c=await this.parseModelFile(a,r);c&&this.models.push(c);}catch(c){this.errors.push(`Error parsing ${r}: ${c}`);}}let t=[...new Set(this.models.flatMap(r=>r.concerns))],o=[...new Set(this.models.map(r=>{let a=r.filePath.split("/");return a.length>1?a.slice(0,-1).join("/"):null}).filter(r=>r!==null))],s=this.models.reduce((r,a)=>r+a.associations.length,0),n=this.models.reduce((r,a)=>r+a.validations.length,0);return {models:this.models,totalAssociations:s,totalValidations:n,concerns:t,namespaces:o,errors:this.errors}}async parseModelFile(e,t){let s=(await N(e)).rootNode,n=R(s,"class");if(n.length===0)return null;let r=n[0],a=F(r),c=M(r);if(!a)return null;c&&this.isActiveRecordModel(c);let i={name:a.replace(/.*::/,""),filePath:t,className:a,parentClass:c||"ApplicationRecord",associations:[],validations:[],callbacks:[],scopes:[],concerns:[],enums:[],attributes:[],classMethodsCount:0,instanceMethodsCount:0,line:r.startPosition.row+1};i.tableName=this.parseTableName(r);let p=R(r,"call");for(let d of p){let y=d.childForFieldName("method");if(!y)continue;let f=y.text,g=d.startPosition.row+1;["belongs_to","has_one","has_many","has_and_belongs_to_many"].includes(f)?this.parseAssociation(d,f,i.associations,g):f.startsWith("validates")||f==="validate"?this.parseValidation(d,f,i.validations,g):this.isCallback(f)?this.parseCallback(d,f,i.callbacks,g):f==="scope"?this.parseScope(d,i.scopes,g):f==="include"?this.parseInclude(d,i.concerns):f==="enum"?this.parseEnum(d,i.enums,g):f==="attribute"&&this.parseAttribute(d,i.attributes,g);}let u=R(r,"method"),m=R(r,"singleton_method");return i.instanceMethodsCount=u.length,i.classMethodsCount=m.length,i}isActiveRecordModel(e){return ["ApplicationRecord","ActiveRecord::Base","ActiveRecord"].some(o=>e.includes(o))}parseTableName(e){let t=R(e,"call");for(let s of t)if(s.childForFieldName("method")?.text==="table_name="){let r=this.getCallArguments(s);if(r.length>0)return r[0].text.replace(/^["']|["']$/g,"")}let o=R(e,"assignment");for(let s of o)if(s.child(0)?.text?.includes("table_name")){let r=s.child(2);if(r)return r.text.replace(/^["']|["']$/g,"")}}parseAssociation(e,t,o,s){let n=this.getCallArguments(e);if(n.length===0)return;let a=n[0].text.replace(/^:/,""),c={type:t,name:a,line:s};for(let i of n.slice(1))if(i.type==="hash"){let p=w(i,"pair");for(let u of p){let m=u.child(0)?.text?.replace(/^:/,""),d=u.child(2);if(!(!m||!d))switch(m){case "class_name":c.className=d.text.replace(/^["']|["']$/g,"");break;case "foreign_key":c.foreignKey=d.text.replace(/^["']|["']$/g,"").replace(/^:/,"");break;case "through":c.through=d.text.replace(/^:/,"");break;case "polymorphic":c.polymorphic=d.text==="true";break;case "dependent":c.dependent=d.text.replace(/^:/,"");break;case "optional":c.optional=d.text==="true";break}}}o.push(c);}parseValidation(e,t,o,s){let n=this.getCallArguments(e);if(n.length===0)return;let r=[],a={},c=t;for(let i of n)if(i.type==="simple_symbol"||i.type==="symbol")r.push(i.text.replace(/^:/,""));else if(i.type==="hash"){let p=w(i,"pair");for(let u of p){let m=u.child(0)?.text?.replace(/^:/,""),d=u.child(2);m&&d&&(["presence","uniqueness","numericality","length","format","inclusion","exclusion","acceptance","confirmation"].includes(m)&&(c=m),a[m]=d.text);}}(r.length>0||t==="validate")&&o.push({type:c,attributes:r,options:Object.keys(a).length>0?a:void 0,line:s});}isCallback(e){return ["before_validation","after_validation","before_save","around_save","after_save","before_create","around_create","after_create","before_update","around_update","after_update","before_destroy","around_destroy","after_destroy","after_commit","after_rollback","after_initialize","after_find","after_touch"].includes(e)}parseCallback(e,t,o,s){let n=this.getCallArguments(e);if(n.length===0)return;let a=n[0].text.replace(/^:/,""),c={type:t,method:a,line:s};for(let i of n.slice(1))if(i.type==="hash"){let p=w(i,"pair");for(let u of p){let m=u.child(0)?.text?.replace(/^:/,""),d=u.child(2);m&&d&&["if","unless"].includes(m)&&(c.conditions=`${m}: ${d.text}`);}}o.push(c);}parseScope(e,t,o){let s=this.getCallArguments(e);if(s.length===0)return;let r=s[0].text.replace(/^:/,""),a=s.length>1&&(s[1].type==="lambda"||s[1].text.includes("->"));t.push({name:r,lambda:a,line:o});}parseInclude(e,t){let o=this.getCallArguments(e);for(let s of o)(s.type==="constant"||s.type==="scope_resolution")&&t.push(s.text);}parseEnum(e,t,o){let s=this.getCallArguments(e);if(s.length!==0){for(let n of s)if(n.type==="hash"){let r=w(n,"pair");for(let a of r){let c=a.child(0)?.text?.replace(/^:/,""),i=a.child(2);if(c&&i&&i.type==="hash"){let p=[],u=w(i,"pair");for(let m of u){let d=m.child(0)?.text?.replace(/^:/,"");d&&p.push(d);}t.push({name:c,values:p,line:o});}else if(c&&i&&i.type==="array"){let p=[];for(let u=0;u<i.childCount;u++){let m=i.child(u);m&&m.type!=="["&&m.type!=="]"&&m.type!==","&&p.push(m.text.replace(/^:/,""));}t.push({name:c,values:p,line:o});}}}}}parseAttribute(e,t,o){let s=this.getCallArguments(e);if(s.length===0)return;let a={name:s[0].text.replace(/^:/,""),line:o};if(s.length>1){let c=s[1];a.type=c.text.replace(/^:/,"");}for(let c of s)if(c.type==="hash"){let i=w(c,"pair");for(let p of i){let u=p.child(0)?.text?.replace(/^:/,""),m=p.child(2);u==="default"&&m&&(a.default=m.text);}}t.push(a);}getCallArguments(e){let t=e.childForFieldName("arguments");if(!t){let s=[];for(let n=0;n<e.childCount;n++){let r=e.child(n);r&&!["identifier","(",")",",","call"].includes(r.type)&&r!==e.childForFieldName("method")&&r!==e.childForFieldName("receiver")&&s.push(r);}return s}let o=[];for(let s=0;s<t.childCount;s++){let n=t.child(s);n&&n.type!=="("&&n.type!==")"&&n.type!==","&&o.push(n);}return o}};async function xe(){let l=process.argv[2]||process.cwd();console.log(`Analyzing models in: ${l}`);let t=await new j(l).analyze();if(console.log(`
|
|
14
|
+
=== Rails Models Analysis ===
|
|
15
|
+
`),console.log(`Total models: ${t.models.length}`),console.log(`Total associations: ${t.totalAssociations}`),console.log(`Total validations: ${t.totalValidations}`),console.log(`Shared concerns: ${t.concerns.length}`),console.log(`Namespaces: ${t.namespaces.join(", ")||"(none)"}`),t.errors.length>0){console.log(`
|
|
16
|
+
--- Errors (${t.errors.length}) ---`);for(let a of t.errors.slice(0,5))console.log(` \u274C ${a}`);t.errors.length>5&&console.log(` ... and ${t.errors.length-5} more`);}console.log(`
|
|
17
|
+
--- Sample Models (first 15) ---`);for(let a of t.models.slice(0,15)){if(console.log(`
|
|
18
|
+
\u{1F4E6} ${a.className} (${a.filePath})`),console.log(` Parent: ${a.parentClass}`),a.associations.length>0){let c=a.associations.slice(0,3).map(i=>`${i.type} :${i.name}`);console.log(` Associations: ${c.join(", ")}${a.associations.length>3?"...":""}`);}if(a.validations.length>0&&console.log(` Validations: ${a.validations.length}`),a.scopes.length>0){let c=a.scopes.slice(0,3).map(i=>i.name);console.log(` Scopes: ${c.join(", ")}${a.scopes.length>3?"...":""}`);}if(a.enums.length>0){let c=a.enums.map(i=>`${i.name}(${i.values.length})`);console.log(` Enums: ${c.join(", ")}`);}a.concerns.length>0&&console.log(` Concerns: ${a.concerns.slice(0,3).join(", ")}${a.concerns.length>3?"...":""}`);}let o=t.models.flatMap(a=>a.associations),s=o.filter(a=>a.type==="belongs_to").length,n=o.filter(a=>a.type==="has_many").length,r=o.filter(a=>a.type==="has_one").length;console.log(`
|
|
19
|
+
--- Association Summary ---`),console.log(` belongs_to: ${s}`),console.log(` has_many: ${n}`),console.log(` has_one: ${r}`);}var Re=import.meta.url===`file://${process.argv[1]}`;Re&&xe().catch(console.error);var T=class{constructor(e){this.rootPath=e;this.grpcDir=x.join(e,"app","grpc_services");}grpcDir;services=[];errors=[];async analyze(){if(!G.existsSync(this.grpcDir))return {services:[],totalRpcs:0,namespaces:[],errors:[`gRPC services directory not found at ${this.grpcDir}`]};let e=await glob("**/*_grpc_service.rb",{cwd:this.grpcDir});for(let s of e){let n=x.join(this.grpcDir,s);try{let r=await this.parseServiceFile(n,s);r&&this.services.push(r);}catch(r){this.errors.push(`Error parsing ${s}: ${r}`);}}let t=[...new Set(this.services.filter(s=>s.namespace).map(s=>s.namespace))],o=this.services.reduce((s,n)=>s+n.rpcs.length,0);return {services:this.services,totalRpcs:o,namespaces:t,errors:this.errors}}async parseServiceFile(e,t){let s=(await N(e)).rootNode,n=t.replace(/_grpc_service\.rb$/,"").split("/"),r=n.length>1?n.slice(0,-1).join("/"):void 0,a=n[n.length-1],c=R(s,"class");if(c.length===0)return null;let i=c[0],p=F(i),u=M(i);if(!p)return null;let m={name:a,filePath:t,className:p,parentClass:u||"Unknown",namespace:r,rpcs:[],policies:[],serializers:[],concerns:[],line:i.startPosition.row+1};u&&u.match(/(\w+)::Service$/)&&(m.protoService=u.replace("::Service",""));let d=R(i,"call");for(let h of d)if(h.childForFieldName("method")?.text==="include"){let v=this.getCallArguments(h);for(let C of v)(C.type==="constant"||C.type==="scope_resolution")&&m.concerns.push(C.text);}R(i,"method");let f="public",g=i.childForFieldName("body");if(g)for(let h=0;h<g.childCount;h++){let b=g.child(h);if(b){if(b.type==="identifier"){let v=b.text;v==="private"?f="private":v==="protected"?f="protected":v==="public"&&(f="public");}else if(b.type==="method"&&f==="public"){let v=this.parseRpcMethod(b);if(v){let C=R(b,"call");for(let X of C){let B=X.childForFieldName("method")?.text,P=X.childForFieldName("receiver")?.text;(B==="authorize!"||B==="new")&&P?.includes("Policy")&&(m.policies.includes(P)||m.policies.push(P),v.policyMethod="authorize!"),P?.includes("Serializer")&&B==="new"&&(m.serializers.includes(P)||m.serializers.push(P));}m.rpcs.push(v);}}}}return m}parseRpcMethod(e){let t=U(e);if(!t||["initialize","to_s","inspect","call","perform","execute"].includes(t))return null;Z(e);let n=e.text,r={name:t,line:e.startPosition.row+1,streaming:"none",modelsUsed:[],servicesUsed:[]},a=n.match(/@param\s+\[([^\]]+)\]\s+req/);a&&(r.requestType=a[1]);let c=n.match(/@return\s+\[([^\]]+)\]/);c&&(r.responseType=c[1]);let i=n.matchAll(/\b([A-Z][a-zA-Z]+)\.(find|find_by|where|all|first|last|create|joins|includes)\b/g);for(let u of i){let m=u[1];!["Rails","ActiveRecord","GRPC","Visit","Google"].includes(m)&&!r.modelsUsed.includes(m)&&r.modelsUsed.push(m);}let p=n.matchAll(/\b(\w+Service)\.(call|new|perform)\b/g);for(let u of p){let m=u[1];r.servicesUsed.includes(m)||r.servicesUsed.push(m);}return r}getCallArguments(e){let t=e.childForFieldName("arguments");if(!t){let s=[];for(let n=0;n<e.childCount;n++){let r=e.child(n);r&&!["identifier","(",")",",","call"].includes(r.type)&&r!==e.childForFieldName("method")&&r!==e.childForFieldName("receiver")&&s.push(r);}return s}let o=[];for(let s=0;s<t.childCount;s++){let n=t.child(s);n&&n.type!=="("&&n.type!==")"&&n.type!==","&&o.push(n);}return o}};async function we(){let l=process.argv[2]||process.cwd();console.log(`Analyzing gRPC services in: ${l}`);let t=await new T(l).analyze();if(console.log(`
|
|
20
|
+
=== Rails gRPC Services Analysis ===
|
|
21
|
+
`),console.log(`Total services: ${t.services.length}`),console.log(`Total RPCs: ${t.totalRpcs}`),console.log(`Namespaces: ${t.namespaces.join(", ")||"(none)"}`),t.errors.length>0){console.log(`
|
|
22
|
+
--- Errors (${t.errors.length}) ---`);for(let n of t.errors.slice(0,5))console.log(` \u274C ${n}`);}console.log(`
|
|
23
|
+
--- Sample Services (first 15) ---`);for(let n of t.services.slice(0,15))console.log(`
|
|
24
|
+
\u{1F4E1} ${n.className} (${n.filePath})`),console.log(` Proto: ${n.protoService||"unknown"}`),console.log(` RPCs (${n.rpcs.length}): ${n.rpcs.map(r=>r.name).join(", ")}`),n.policies.length>0&&console.log(` Policies: ${n.policies.join(", ")}`),n.serializers.length>0&&console.log(` Serializers: ${n.serializers.join(", ")}`);let o=t.services.flatMap(n=>n.rpcs),s=o.filter(n=>n.modelsUsed.length>0);console.log(`
|
|
25
|
+
--- RPC Summary ---`),console.log(` Total RPCs: ${o.length}`),console.log(` RPCs using models: ${s.length}`);}var Ae=import.meta.url===`file://${process.argv[1]}`;Ae&&we().catch(console.error);async function K(l){let e=x.join(l,"app/views"),t=x.join(l,"app/controllers");try{await A.access(e);}catch{return {views:[],pages:[],summary:{totalViews:0,totalPages:0,byController:{},byTemplate:{}}}}let o=await glob("**/*.{haml,erb,html.haml,html.erb,yml}",{cwd:e,nodir:true}),s=[],n={},r={};for(let c of o){let i=await Ce(e,c);i&&(s.push(i),n[i.controller]=(n[i.controller]||0)+1,r[i.template]=(r[i.template]||0)+1);}let a=await Fe(t,s,l);return {views:s,pages:a,summary:{totalViews:s.length,totalPages:a.length,byController:n,byTemplate:r}}}async function Ce(l,e){let t=x.join(l,e);try{let o=await A.readFile(t,"utf-8"),s=e.split("/");if(s.some(g=>g.endsWith("_mailer")||g==="layouts"||g==="shared"||g==="devise"))return null;let n=s.pop()||"",r=s.join("/")||"application",a=n.split("."),c=a[0].replace(/^_/,""),i=n.startsWith("_"),p;n.endsWith(".yml")?p="yml":n.endsWith(".haml")?p="haml":n.endsWith(".erb")?p="erb":p="other";let u=a.length>2?a[1]:"html";if(i)return null;let m=[],d=[],y=[],f=[];return p==="yml"?(y=Pe(o),f=[{name:"App",ssr:!0,propsVar:"@yml_data"}]):(m=Ne(o,p),d=Se(o,p),y=_e(o),f=$e(o,p)),{name:c,path:e,controller:r,action:c,format:u,template:p,partials:m,helpers:d,instanceVars:y,reactComponents:f}}catch{return null}}function Ne(l,e){let t=[];if(e==="haml"){let o=l.matchAll(/=\s*render\s+(?:partial:\s*)?['"]([^'"]+)['"]/g);for(let s of o)t.push(s[1]);}else if(e==="erb"){let o=l.matchAll(/<%=?\s*render\s+(?:partial:\s*)?['"]([^'"]+)['"]/g);for(let s of o)t.push(s[1]);}return [...new Set(t)]}function Se(l,e){let t=[],o=/\b(link_to|form_for|form_with|image_tag|content_for|yield|render|t|l|raw|html_safe|simple_form_for)\b/g,s=l.matchAll(o);for(let n of s)t.push(n[1]);return [...new Set(t)]}function $e(l,e){let t=[],o=/render_react_component\s*\(?\s*["']([^"']+)["'](?:,\s*\{[^}]*\})?\s*(?:,\s*ssr:\s*(true|false))?\)?/g,s;for(;(s=o.exec(l))!==null;)t.push({name:s[1],ssr:s[2]==="true"});let n=/data:\s*\{\s*react_component:\s*["']([^"']+)["'](?:,\s*react_component_props:\s*(@?\w+)(?:\.to_json)?)?/g;for(;(s=n.exec(l))!==null;)t.push({name:s[1],propsVar:s[2],ssr:false});let r=/ReactComponent\s+name=["']([^"']+)["']/g;for(;(s=r.exec(l))!==null;)t.push({name:s[1],ssr:false});let a=new Set;return t.filter(c=>a.has(c.name)?false:(a.add(c.name),true))}function Pe(l){let e=[],t=l.split(`
|
|
26
|
+
`);for(let o of t){let s=o.match(/^([a-z_]+):/);s&&!s[1].startsWith("_")&&e.push(s[1]);let n=o.match(/^\s+-\s+(\w+)/);n&&e.push(n[1]);}return [...new Set(e)].slice(0,50)}function _e(l){let e=[],t=l.matchAll(/@(\w+)/g);for(let o of t)["import","media","keyframes","charset"].includes(o[1])||e.push(o[1]);return [...new Set(e)]}async function Fe(l,e,t){let o=[];try{await A.access(l);}catch{return o}let s=await glob("**/*_controller.rb",{cwd:l,nodir:true}),n=await Me(t);for(let r of s){let a=x.join(l,r),c=await A.readFile(a,"utf-8"),i=r.replace(/_controller\.rb$/,"").replace(/\//g,"/"),p=Ie(c,i,r,e,n);o.push(...p);}return o}async function Me(l){let e=new Map;try{let t=x.join(l,".repomap","rails-routes.json"),o=await A.readFile(t,"utf-8"),s=JSON.parse(o);for(let n of s){let r=`${n.controller}#${n.action}`;e.set(r,{path:n.path,method:n.method});}}catch{}return e}function Ie(l,e,t,o,s){let n=[],r=l.split(/\n\s*(private|protected)\b/)[0],a=/def\s+(\w+)/g,c;for(;(c=a.exec(r))!==null;){let i=c[1];["initialize","new","create","update","destroy","index","show","edit"].includes(i)||i.startsWith("set_")||i.startsWith("_");let p=c.index,u=ke(r,p),m=Ve(u,t),d=je(u),y=Te(u),f=ze(u),g=o.find(v=>v.controller===e&&v.action===i),h=`${e}#${i}`,b=s.get(h);n.push({route:b?.path||`/${e}/${i}`,method:b?.method||"GET",controller:e,action:i,view:g,apis:m,services:d,grpcCalls:y,modelAccess:f});}return n}function ke(l,e){let t=0,o=false,s="";for(let n=e;n<l.length;n++){let r=l.slice(n,l.indexOf(`
|
|
27
|
+
`,n)+1||l.length);if(r.match(/^\s*(def|class|module|if|unless|case|while|until|for|begin|do)\b/)&&(t++,o=true),r.match(/^\s*end\b/)&&(t--,o&&t===0)||(s+=r,n=l.indexOf(`
|
|
28
|
+
`,n),n===-1))break}return s}function Ve(l,e){let t=[],o=[/HTTPClient\.(get|post|put|patch|delete)\s*\(\s*['"]([^'"]+)['"]/gi,/RestClient\.(get|post|put|patch|delete)\s*\(\s*['"]([^'"]+)['"]/gi,/Faraday\.(get|post|put|patch|delete)\s*\(\s*['"]([^'"]+)['"]/gi,/Net::HTTP\.(get|post)\s*\(/gi];for(let s of o){let n;for(;(n=s.exec(l))!==null;)t.push({type:"http",name:n[2]||"HTTP call",method:n[1]?.toUpperCase(),source:e});}return t}function je(l){let e=[],t=/(\w+(?:::\w+)*Service)\.(?:call!?|new)/g,o;for(;(o=t.exec(l))!==null;)e.push(o[1]);return [...new Set(e)]}function Te(l){let e=[],t=[/(\w+(?:::\w+)*Grpc(?:::\w+)?)\./g,/Grpc::(\w+(?:::\w+)*)/g,/(\w+GrpcService)\./g];for(let o of t){let s;for(;(s=o.exec(l))!==null;)e.push(s[1]);}return [...new Set(e)]}function ze(l){let e=[],t=/([A-Z][a-zA-Z0-9]+)\.(?:find|where|find_by|first|last|all|create|update|destroy|new)/g,o;for(;(o=t.exec(l))!==null;)["File","Dir","Time","Date","DateTime","JSON","YAML","CSV","Logger"].includes(o[1])||e.push(o[1]);return [...new Set(e)]}var Ee=["app/javascript/packs","app/javascript/entrypoints","app/frontend/entrypoints","app/javascript/application","frontend/assets/javascripts/entries","frontend/entries","app/assets/javascripts/entries","client/entries","src/entries"],De=["app/javascript/components","app/javascript/react","app/javascript/src/components","app/javascript/bundles","app/frontend/components","app/frontend/react","frontend/assets/javascripts/react","frontend/assets/javascripts/components","frontend/src","frontend/src/components","frontend/components","client/components","src/components"],E={dataReactComponent:/react_component:\s*["']([A-Za-z0-9_/]+)["']/g,renderReactComponent:/render_react_component\s*\(?\s*["']([A-Za-z0-9_/]+)["']/g,reactComponent:/<%=?\s*react_component\s*\(\s*["']([A-Za-z0-9_/]+)["']/g,reduxStore:/<%=?\s*redux_store\s*\(\s*["']([A-Za-z0-9_/]+)["']/g,dataComponent:/data-component\s*[=:]\s*["']([A-Za-z0-9_/]+)["']/g,dataReactClass:/data-react-class\s*[=:]\s*["']([A-Za-z0-9_/]+)["']/g};async function Q(l){let e=new Map,t=[],o=await Ge(l);console.log(` \u{1F4C2} Detected paths: ${o.entryDirs.length} entry dirs, ${o.componentDirs.length} component dirs (${o.integrationPattern})`);for(let a of o.entryDirs){let c=x.join(l,a);try{await A.access(c);let i=await glob("**/*.{tsx,ts,jsx,js}",{cwd:c,nodir:!0,ignore:["**/*.d.ts","**/*.test.*","**/*.spec.*"]});for(let p of i){let u=await Ze(x.join(c,p),p,a);if(u&&(t.push(u),u.componentName)){let m=e.get(u.componentName);m?(m.entryFile=x.join(a,p),m.importPath=u.imports[0]):e.set(u.componentName,{name:u.componentName,entryFile:x.join(a,p),importPath:u.imports[0],ssr:!1,usedIn:[]});}}}catch{}}let s=x.join(l,"app/views");try{await A.access(s);let a=await glob("**/*.{haml,erb,html.haml,html.erb,slim}",{cwd:s,nodir:!0});for(let c of a){let i=await Be(x.join(s,c),c);for(let p of i){let u=e.get(p.componentName);u?(u.usedIn.push({viewPath:c,controller:p.controller,action:p.action,propsVar:p.propsVar,line:p.line,pattern:p.pattern}),p.ssr&&(u.ssr=!0)):e.set(p.componentName,{name:p.componentName,ssr:p.ssr,usedIn:[{viewPath:c,controller:p.controller,action:p.action,propsVar:p.propsVar,line:p.line,pattern:p.pattern}]});}}}catch{}await Oe(l,e,o.componentDirs);let n=Array.from(e.values()),r=n.filter(a=>a.ssr).length;return {components:n,entryPoints:t,detectedPaths:o,summary:{totalComponents:n.length,totalEntryPoints:t.length,ssrComponents:r,clientComponents:n.length-r}}}async function Ge(l){let e=[],t=[],o="unknown";for(let s of Ee){let n=x.join(l,s);try{(await A.stat(n)).isDirectory()&&e.push(s);}catch{}}for(let s of De){let n=x.join(l,s);try{(await A.stat(n)).isDirectory()&&t.push(s);}catch{}}if(o=await Le(l),e.length===0){let s=await Ue(l);e.push(...s);}return t.length===0&&e.length>0&&t.push(...e),{entryDirs:e,componentDirs:t,integrationPattern:o}}async function Le(l){try{let e=x.join(l,"Gemfile"),t=await A.readFile(e,"utf-8");if(t.includes("react_on_rails"))return "react_on_rails";if(t.includes("react-rails"))return "react-rails";if(t.includes("vite_rails")||t.includes("vite_ruby"))return "vite";if(t.includes("webpacker"))return "webpacker";try{return await A.access(x.join(l,"vite.config.ts")),"vite"}catch{}try{return await A.access(x.join(l,"vite.config.js")),"vite"}catch{}return "custom"}catch{return "unknown"}}async function Ue(l){let e=[],t=["app/**/entries","app/**/packs","frontend/**/entries","client/**/entries","src/**/entries"];for(let o of t)try{let s=await glob(o,{cwd:l,nodir:!1});for(let n of s){let r=x.join(l,n);try{(await A.stat(r)).isDirectory()&&e.push(n);}catch{}}}catch{}return e}async function Ze(l,e,t){try{let o=await A.readFile(l,"utf-8"),s=[/\[data-react-component[=:][\s]*["']?([A-Za-z0-9_]+)["']?\]/,/\[data-component[=:][\s]*["']?([A-Za-z0-9_]+)["']?\]/,/\[data-react-class[=:][\s]*["']?([A-Za-z0-9_]+)["']?\]/,/getElementById\s*\(\s*["']([A-Za-z0-9_-]+)["']\s*\)/,/querySelector\s*\(\s*["']#([A-Za-z0-9_-]+)["']\s*\)/],n=null,r;for(let p of s){let u=o.match(p);if(u){n=u[1],r=u[0];break}}n||(n=x.basename(e,x.extname(e)).split(/[-_]/).map(u=>u.charAt(0).toUpperCase()+u.slice(1)).join(""));let a=[],c=o.matchAll(/import\s+(?:\{[^}]+\}|\*\s+as\s+\w+|\w+)\s+from\s+["']([^"']+)["']/g);for(let p of c){let u=p[1];(u.includes("/react/")||u.includes("/components/")||u.includes("/containers/")||u.includes("/bundles/")||u.includes("/pages/")||u.match(/\/[A-Z][a-zA-Z0-9]*/))&&a.push(u);}let i=o.matchAll(/require\s*\(\s*["']([^"']+)["']\s*\)/g);for(let p of i){let u=p[1];(u.includes("/react/")||u.includes("/components/")||u.includes("/containers/"))&&a.push(u);}return !n&&a.length===0?null:{file:e,fullPath:x.join(t,e),componentName:n||"",imports:a,selector:r}}catch{return null}}async function Be(l,e){let t=[];try{let s=(await A.readFile(l,"utf-8")).split(`
|
|
29
|
+
`),n=e.split("/"),r=n.pop()||"",a=n.join("/")||"application",c=r.split(".")[0].replace(/^_/,""),i=0;for(let p of s){i++;let u=p.matchAll(E.dataReactComponent);for(let h of u){let b=p.match(/react_component_props:\s*(@?\w+(?:\.\w+)*)/);t.push({componentName:h[1],controller:a,action:c,propsVar:b?b[1]:void 0,line:i,pattern:"data-react-component",ssr:!1});}let m=p.match(E.renderReactComponent);if(m){let h=p.match(/ssr:\s*(true|false|@\w+)/);t.push({componentName:m[1],controller:a,action:c,line:i,pattern:"render_react_component",ssr:h?h[1]==="true"||h[1].startsWith("@"):!1});}let d=p.match(E.reactComponent);if(d){let h=p.match(/props:\s*(@?\w+(?:\.\w+)*)/),b=p.match(/prerender:\s*(true|false)/);t.push({componentName:d[1],controller:a,action:c,propsVar:h?h[1]:void 0,line:i,pattern:"react_component",ssr:b?b[1]==="true":!1});}let y=p.match(E.reduxStore);y&&t.push({componentName:y[1],controller:a,action:c,line:i,pattern:"redux_store",ssr:!1});let f=p.match(E.dataComponent);f&&t.push({componentName:f[1],controller:a,action:c,line:i,pattern:"data-react-component",ssr:!1});let g=p.match(E.dataReactClass);g&&t.push({componentName:g[1],controller:a,action:c,line:i,pattern:"data-react-component",ssr:!1});}}catch{}return t}async function Oe(l,e,t){for(let[o,s]of e)if(!(!o||typeof o!="string")){if(s.importPath&&typeof s.importPath=="string"){let n=s.importPath.replace(/\.js$/,"").replace(/\.tsx?$/,"").replace(/^\.\.\//,"").replace(/^\.\//,"");s.sourceFile=n;}else if(!s.sourceFile){let n=[".tsx",".ts",".jsx",".js"],r=[o,We(o),He(o)].filter(Boolean),a=false;for(let c of t){if(a)break;for(let i of r){if(a)break;for(let p of n){let u=[x.join(l,c,i,`index${p}`),x.join(l,c,i,`${i}${p}`),x.join(l,c,`${i}${p}`),x.join(l,c,"components",`${i}${p}`),x.join(l,c,"containers",`${i}${p}`)];for(let m of u)try{await A.access(m),s.sourceFile=x.relative(l,m),a=!0;break}catch{}}}}}}}function We(l){return l?l.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,""):""}function He(l){return l?l.replace(/([A-Z])/g,"-$1").toLowerCase().replace(/^-/,""):""}async function qe(l){console.log(`
|
|
30
|
+
\u{1F4E6} Analyzing Rails application at: ${l}
|
|
31
|
+
`),console.log("\u{1F504} Analyzing routes...");let t=await new k(l).analyze();console.log(` \u2705 Found ${t.routes.length} routes`),console.log("\u{1F504} Analyzing controllers...");let s=await new V(l).analyze();console.log(` \u2705 Found ${s.controllers.length} controllers with ${s.totalActions} actions`),console.log("\u{1F504} Analyzing models...");let r=await new j(l).analyze();console.log(` \u2705 Found ${r.models.length} models with ${r.totalAssociations} associations`),console.log("\u{1F504} Analyzing gRPC services...");let c=await new T(l).analyze();console.log(` \u2705 Found ${c.services.length} gRPC services with ${c.totalRpcs} RPCs`),console.log("\u{1F504} Analyzing views...");let i=await K(l);console.log(` \u2705 Found ${i.summary.totalViews} views and ${i.summary.totalPages} pages`),console.log("\u{1F504} Analyzing React components...");let p=await Q(l);console.log(` \u2705 Found ${p.summary.totalComponents} React components (${p.summary.ssrComponents} SSR, ${p.summary.clientComponents} client)`);let u=[...new Set([...t.namespaces,...s.namespaces,...r.namespaces,...c.namespaces])],m=[...new Set([...s.concerns,...r.concerns])],d={totalRoutes:t.routes.length,totalControllers:s.controllers.length,totalActions:s.totalActions,totalModels:r.models.length,totalAssociations:r.totalAssociations,totalValidations:r.totalValidations,totalGrpcServices:c.services.length,totalRpcs:c.totalRpcs,totalViews:i.summary.totalViews,totalPages:i.summary.totalPages,totalReactComponents:p.summary.totalComponents,ssrReactComponents:p.summary.ssrComponents,namespaces:u,concerns:m};return {routes:t,controllers:s,models:r,grpc:c,views:i,react:p,summary:d}}async function Je(){let l=process.argv[2]||process.cwd(),e=await qe(l);console.log(`
|
|
32
|
+
`+"=".repeat(60)),console.log("\u{1F4CA} RAILS APPLICATION ANALYSIS SUMMARY"),console.log("=".repeat(60)+`
|
|
33
|
+
`),console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log("\u2502 Routes \u2502"),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Total routes: ${String(e.summary.totalRoutes).padStart(6)} \u2502`),console.log(`\u2502 Resources: ${String(e.routes.resources.length).padStart(6)} \u2502`),console.log(`\u2502 Mounted engines: ${String(e.routes.mountedEngines.length).padStart(6)} \u2502`),console.log(`\u2502 External files: ${String(e.routes.drawnFiles.length).padStart(6)} \u2502`),console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log("\u2502 Controllers \u2502"),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Total controllers: ${String(e.summary.totalControllers).padStart(6)} \u2502`),console.log(`\u2502 Total actions: ${String(e.summary.totalActions).padStart(6)} \u2502`),console.log(`\u2502 Namespaces: ${String(e.controllers.namespaces.length).padStart(6)} \u2502`),console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log("\u2502 Models \u2502"),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Total models: ${String(e.summary.totalModels).padStart(6)} \u2502`),console.log(`\u2502 Associations: ${String(e.summary.totalAssociations).padStart(6)} \u2502`),console.log(`\u2502 Validations: ${String(e.summary.totalValidations).padStart(6)} \u2502`),console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log("\u2502 gRPC Services \u2502"),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Total services: ${String(e.summary.totalGrpcServices).padStart(6)} \u2502`),console.log(`\u2502 Total RPCs: ${String(e.summary.totalRpcs).padStart(6)} \u2502`),console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"),console.log("\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"),console.log("\u2502 Shared \u2502"),console.log("\u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524"),console.log(`\u2502 Total namespaces: ${String(e.summary.namespaces.length).padStart(6)} \u2502`),console.log(`\u2502 Total concerns: ${String(e.summary.concerns.length).padStart(6)} \u2502`),console.log("\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518");let t=e.routes.errors.length+e.controllers.errors.length+e.models.errors.length+e.grpc.errors.length;t>0?console.log(`
|
|
34
|
+
\u26A0\uFE0F Total errors: ${t}`):console.log(`
|
|
35
|
+
\u2705 Analysis completed without errors!`);}var Ke=import.meta.url===`file://${process.argv[1]}`;Ke&&Je().catch(console.error);
|
|
36
|
+
export{se as a,ne as b,N as c,R as d,k as e,V as f,j as g,T as h,K as i,Q as j,qe as k};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as a from'fs/promises';import*as c from'path';async function d(s){let t=[],i=await f(s);i.detected&&t.push(i);let p=await l(s);p.detected&&t.push(p);let e=t.some(o=>o.type==="nextjs"),n=t.some(o=>o.type==="react"||o.type==="nextjs"),u=t.some(o=>o.type==="rails"),r="generic";return e?r="nextjs":n?r="react":u&&(r="rails"),{environments:t,hasNextjs:e,hasReact:n,hasRails:u,primary:r}}async function f(s){let t={type:"rails",detected:false,path:s,features:[]};try{let i=c.join(s,"Gemfile"),p=c.join(s,"config","routes.rb");await a.access(i),await a.access(p);let e=await a.readFile(i,"utf-8");if(!(e.includes("gem 'rails'")||e.includes('gem "rails"')))return t;t.detected=!0;let u=e.match(/gem ['"]rails['"],\s*['"]([^'"]+)['"]/);u&&(t.version=u[1]);let r=[];try{await a.access(c.join(s,"app","grpc_services")),r.push("grpc");}catch{}try{(await a.readFile(c.join(s,"config","application.rb"),"utf-8")).includes("config.api_only = true")&&r.push("api-only");}catch{}(e.includes("gem 'graphql'")||e.includes('gem "graphql"'))&&r.push("graphql"),(e.includes("gem 'devise'")||e.includes('gem "devise"'))&&r.push("devise"),t.features=r;}catch{}return t}async function l(s){let t={type:"react",detected:false,path:s,features:[]};try{let i=c.join(s,"package.json"),p=JSON.parse(await a.readFile(i,"utf-8")),e={...p.dependencies,...p.devDependencies};if(!e.react)return t;t.detected=!0,t.version=e.react;let n=[];if(e.next){t.type="nextjs",t.version=e.next;try{await a.access(c.join(s,"app")),n.push("app-router");}catch{}try{await a.access(c.join(s,"pages")),n.push("pages-router");}catch{}try{await a.access(c.join(s,"src","pages")),n.push("pages-router");}catch{}try{await a.access(c.join(s,"src","app")),n.push("app-router");}catch{}}(e["@apollo/client"]||e.graphql||e["graphql-request"]||e.urql)&&n.push("graphql"),e.typescript&&n.push("typescript"),(e.redux||e["@reduxjs/toolkit"])&&n.push("redux"),e.zustand&&n.push("zustand"),(e.jotai||e.recoil)&&n.push("atomic-state"),t.features=n;}catch{}return t}function h(s){let t=[],i=[];return (s.hasNextjs||s.hasReact)&&t.push("pages","graphql","dataflow","rest-api"),s.hasRails&&i.push("routes","controllers","models","grpc"),{frontend:t,backend:i}}export{d as a,h as b};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var F=class{generateAll(t,e){let n=[];for(let a of t)n.push(this.generateNavigationDiagram(a)),n.push(this.generateDataFlowDiagram(a)),n.push(this.generateComponentDiagram(a)),n.push(this.generateGraphQLDiagram(a));return t.length>1&&n.push(this.generateCrossRepoDiagram(t,e)),n}generateNavigationDiagram(t){let e=["flowchart TB"," %% Page Navigation Flow - Grouped by Category"],n=new Map,a=0,r=new Map;for(let i of t.pages){let c=i.path.split("/").filter(Boolean)[0]||"root",h=r.get(c)||[];h.push(i),r.set(c,h);}for(let[i,p]of r){let c=i.replace(/[^a-zA-Z0-9]/g,"_"),h=i==="root"?"Root Pages":`/${i}`;e.push(""),e.push(` subgraph ${c}["${h}"]`),e.push(" direction TB");for(let l of p){let m=`P${a++}`;n.set(l.path,m);let u=l.path.split("/").filter(Boolean),g=u.length>1?u.slice(1).join("/"):l.path,f=l.authentication.required?" AUTH":"";e.push(` ${m}["${g}${f}"]`);}e.push(" end");}let s=0,o=30;e.push(""),e.push(" %% Navigation Links");for(let i of t.pages){if(s>=o)break;let p=n.get(i.path);for(let c of i.linkedPages.slice(0,2)){if(s>=o)break;let h=n.get(c);p&&h&&p!==h&&(e.push(` ${p} --> ${h}`),s++);}}e.push(""),e.push(" %% Styling"),e.push(" classDef authRequired fill:#fee2e2,stroke:#ef4444,color:#991b1b"),e.push(" classDef public fill:#dcfce7,stroke:#22c55e,color:#166534");for(let i of t.pages){let p=n.get(i.path);p&&(i.authentication.required?e.push(` class ${p} authRequired`):e.push(` class ${p} public`));}return {type:"flowchart",title:`${t.repository} - Page Navigation`,content:e.join(`
|
|
2
|
+
`),relatedFiles:t.pages.map(i=>i.filePath)}}generateDataFlowDiagram(t){let e=["flowchart LR"," %% Data Flow Diagram"],n=new Map,a=0,r=h=>{let l=`${h.type}:${h.name}`;if(!n.has(l)){let m=h.type.charAt(0).toUpperCase();n.set(l,`${m}${a++}`);}return n.get(l)??`N${a++}`},o=h=>h.replace(/[\u{1F4E1}\u{270F}\u{FE0F}\u{1F504}\u{1F4E6}]/gu,"").trim().substring(0,40),i=t.dataFlows.filter(h=>h.name.includes("\u{1F4E1}")||h.operations.some(l=>l.includes("Query"))),p=t.dataFlows.filter(h=>h.name.includes("\u270F\uFE0F")||h.operations.some(l=>l.includes("Mutation"))),c=t.dataFlows.filter(h=>h.name.includes("\u{1F504}")||h.source.type==="context"||h.operations.some(l=>l.includes("Context")));if(i.length>0){e.push(""),e.push(" subgraph Queries[\u{1F4E1} Queries]"),e.push(" direction TB");for(let h of i.slice(0,20)){let l=r(h.source),m=r(h.target),u=o(h.source.name),g=o(h.target.name);e.push(` ${l}(("${u}"))`),e.push(` ${m}["${g}"]`),e.push(` ${l} --> ${m}`);}e.push(" end");}if(p.length>0){e.push(""),e.push(" subgraph Mutations[\u270F\uFE0F Mutations]"),e.push(" direction TB");for(let h of p.slice(0,20)){let l=r(h.source),m=r(h.target),u=o(h.source.name),g=o(h.target.name);e.push(` ${l}["${u}"]`),e.push(` ${m}(("${g}"))`),e.push(` ${l} --> ${m}`);}e.push(" end");}if(c.length>0){e.push(""),e.push(" subgraph Context[\u{1F504} Context]"),e.push(" direction TB");for(let h of c.slice(0,15)){let l=r(h.source),m=r(h.target),u=o(h.source.name),g=o(h.target.name);e.push(` ${l}{{"${u}"}}`),e.push(` ${m}["${g}"]`),e.push(` ${l} -.-> ${m}`);}e.push(" end");}return e.push(""),e.push(" %% Styling"),e.push(" classDef query fill:#dbeafe,stroke:#3b82f6,color:#1e40af"),e.push(" classDef mutation fill:#fce7f3,stroke:#ec4899,color:#9d174d"),e.push(" classDef context fill:#d1fae5,stroke:#10b981,color:#065f46"),{type:"flowchart",title:`${t.repository} - Data Flow`,content:e.join(`
|
|
3
|
+
`),relatedFiles:t.dataFlows.map(h=>h.source.name)}}generateComponentDiagram(t){let e=["flowchart TB"," %% Component Hierarchy"],n=new Map;for(let s of t.components){let o=n.get(s.type)||[];o.push(s),n.set(s.type,o);}for(let[s,o]of n){e.push(` subgraph ${s.charAt(0).toUpperCase()+s.slice(1)}s`);for(let i of o.slice(0,20)){let p=i.name.replace(/[^a-zA-Z0-9]/g,"_");e.push(` ${p}["${i.name}"]`);}e.push(" end");}let a=0,r=50;for(let s of t.components){if(a>=r)break;let o=s.name.replace(/[^a-zA-Z0-9]/g,"_");for(let i of s.dependencies.slice(0,3)){if(a>=r)break;let p=i.replace(/[^a-zA-Z0-9]/g,"_");e.push(` ${o} --> ${p}`),a++;}}return {type:"flowchart",title:`${t.repository} - Component Hierarchy`,content:e.join(`
|
|
4
|
+
`),relatedFiles:t.components.map(s=>s.filePath)}}generateGraphQLDiagram(t){let e=["flowchart LR"," %% GraphQL Operations"],n=t.graphqlOperations.filter(s=>s.type==="query"),a=t.graphqlOperations.filter(s=>s.type==="mutation"),r=t.graphqlOperations.filter(s=>s.type==="fragment");if(e.push(' API[("GraphQL API")]'),n.length>0){e.push(" subgraph Queries");for(let s of n.slice(0,15)){let o=`Q_${s.name.replace(/[^a-zA-Z0-9]/g,"_")}`;e.push(` ${o}["${s.name}"]`),e.push(` ${o} --> API`);}e.push(" end");}if(a.length>0){e.push(" subgraph Mutations");for(let s of a.slice(0,15)){let o=`M_${s.name.replace(/[^a-zA-Z0-9]/g,"_")}`;e.push(` ${o}["${s.name}"]`),e.push(` ${o} --> API`);}e.push(" end");}if(r.length>0){e.push(" subgraph Fragments");for(let s of r.slice(0,10)){let o=`F_${s.name.replace(/[^a-zA-Z0-9]/g,"_")}`;e.push(` ${o}[/"${s.name}"/]`);}e.push(" end");}return {type:"flowchart",title:`${t.repository} - GraphQL Operations`,content:e.join(`
|
|
5
|
+
`),relatedFiles:t.graphqlOperations.map(s=>s.filePath)}}generateCrossRepoDiagram(t,e){let n=["flowchart TB"," %% Cross-Repository Architecture"];for(let a of t){let r=a.repository.replace(/[^a-zA-Z0-9]/g,"_");n.push(` subgraph ${r}["${a.repository}"]`),n.push(` ${r}_pages["\u{1F4C4} ${a.pages.length} Pages"]`),n.push(` ${r}_gql["\u{1F537} ${a.graphqlOperations.length} GraphQL Ops"]`),n.push(` ${r}_comp["\u{1F9E9} ${a.components.length} Components"]`),n.push(" end");}for(let a of e){let r=a.sourceRepo.replace(/[^a-zA-Z0-9]/g,"_"),s=a.targetRepo.replace(/[^a-zA-Z0-9]/g,"_"),o="-->";a.linkType==="api-call"?o="==>":a.linkType==="graphql-operation"&&(o="-..->"),n.push(` ${r}_gql ${o}|"${a.linkType}"| ${s}_gql`);}return {type:"flowchart",title:"Cross-Repository Architecture",content:n.join(`
|
|
6
|
+
`),relatedFiles:t.map(a=>a.repository)}}generateSequenceDiagram(t){let e=["sequenceDiagram",` %% ${t.name}`],n=[t.source,...t.via,t.target];for(let s of n)e.push(` participant ${s.name}`);let a=t.source;for(let s=0;s<t.via.length;s++){let o=t.via[s],i=t.operations[s]||"data";e.push(` ${a.name}->>+${o.name}: ${i}`),a=o;}let r=t.operations[t.operations.length-1]||"data";return e.push(` ${a.name}->>+${t.target.name}: ${r}`),e.push(` ${t.target.name}-->>-${t.source.name}: response`),{type:"sequence",title:t.name,content:e.join(`
|
|
7
|
+
`),relatedFiles:[]}}};var q=class{generateDocumentation(t){let e=new Map;e.set("index.md",this.generateIndex(t));for(let n of t.repositories)e.set(`repos/${n.name}/index.md`,this.generateRepoIndex(n)),e.set(`repos/${n.name}/pages.md`,this.generatePagesDoc(n)),e.set(`repos/${n.name}/components.md`,this.generateComponentsDoc(n)),e.set(`repos/${n.name}/graphql.md`,this.generateGraphQLDoc(n)),e.set(`repos/${n.name}/dataflow.md`,this.generateDataFlowDoc(n));return e.set("cross-repo.md",this.generateCrossRepoDoc(t)),e.set("diagrams.md",this.generateDiagramsDoc(t.diagrams)),e}generateIndex(t){let n=[`# ${t.repositories.length===1?`${t.repositories[0].displayName} Documentation`:"Project Documentation"}`,"",`Generated: ${t.generatedAt}`,"",t.repositories.length>1?"## Repositories":"## Overview",""];for(let a of t.repositories)n.push(`### [${a.displayName}](/docs/repos/${a.name}/index)`),n.push(""),n.push(`- **Version**: ${a.version}`),n.push(`- **Commit**: \`${a.commitHash.substring(0,7)}\``),n.push(`- **Pages**: ${a.summary.totalPages}`),n.push(`- **Components**: ${a.summary.totalComponents}`),n.push(`- **GraphQL Ops**: ${a.summary.totalGraphQLOperations}`),n.push("");return n.push("## Quick Links"),n.push(""),n.push("- [Cross Repository](/docs/cross-repo)"),n.push("- [Diagrams](/docs/diagrams)"),n.push("- [Page Map (Interactive)](/page-map)"),n.push(""),n.join(`
|
|
8
|
+
`)}generateRepoIndex(t){return [`# ${t.displayName}`,"",`Version: ${t.version} | Commit: \`${t.commitHash.substring(0,7)}\``,"","## Overview","","| Metric | Count |","|--------|-------|",`| Pages | ${t.summary.totalPages} |`,`| Components | ${t.summary.totalComponents} |`,`| GraphQL Operations | ${t.summary.totalGraphQLOperations} |`,`| Data Flows | ${t.summary.totalDataFlows} |`,`| Auth Required | ${t.summary.authRequiredPages} |`,`| Public | ${t.summary.publicPages} |`,"","## Documentation","",`- [Pages](/docs/repos/${t.name}/pages)`,`- [Components](/docs/repos/${t.name}/components)`,`- [GraphQL](/docs/repos/${t.name}/graphql)`,`- [Data Flow](/docs/repos/${t.name}/dataflow)`,"","## Quick Access","","- [Page Map](/page-map)","- [Diagrams](/docs/diagrams)",""].join(`
|
|
9
|
+
`)}generatePagesDoc(t){let e=[`# ${t.displayName} - Pages`,""],n=t.analysis.pages.filter(o=>o.authentication.required).length,a=t.analysis.pages.filter(o=>o.dataFetching.some(i=>!i.type.includes("Mutation"))).length,r=t.analysis.pages.filter(o=>o.dataFetching.some(i=>i.type.includes("Mutation"))).length;e.push("| Metric | Value |"),e.push("|--------|-------|"),e.push(`| Total | **${t.analysis.pages.length}** |`),e.push(`| Auth Required | ${n} |`),e.push(`| With Queries | ${a} |`),e.push(`| With Mutations | ${r} |`),e.push("");let s=new Map;for(let o of t.analysis.pages){let i=o.path.split("/")[1]||"root",p=s.get(i)||[];p.push(o),s.set(i,p);}for(let[o,i]of s){e.push(`## /${o}`),e.push(""),e.push("| Page | Auth | Layout | Data |"),e.push("|------|------|--------|------|");for(let p of i){let c=p.path.replace(`/${o}`,"")||"/",h=p.authentication.required?"Required":"Public",l=p.layout||"-",m=[],u=p.dataFetching.filter(C=>!C.type.includes("Mutation")),g=p.dataFetching.filter(C=>C.type.includes("Mutation"));for(let C of u.slice(0,2)){let $=C.operationName||"";if(!$||$.trim().length<2)continue;let D=$.startsWith("\u2192")||$.startsWith("->"),y=$.replace(/^[→\->\s]+/,"");y&&y.trim().length>0&&(D?m.push(`<span class="gql-ref" data-ref="${y}" title="Component">${y}</span>`):m.push(`<span class="gql-op" data-op="${y}">${y}</span>`));}for(let C of g.slice(0,2)){let $=C.operationName||"";if(!$||$.trim().length<2)continue;let D=$.startsWith("\u2192")||$.startsWith("->"),y=$.replace(/^[→\->\s]+/,"");y&&y.trim().length>0&&(D?m.push(`<span class="gql-ref mutation" data-ref="${y}" title="Component">${y}</span>`):m.push(`<span class="gql-op mutation" data-op="${y}">${y}</span>`));}let f=u.length+g.length-Math.min(u.length,2)-Math.min(g.length,2);f>0&&m.push(`<span class="gql-more" data-type="all" data-page="${p.path}">+${f} more</span>`);let d=m.length>0?m.join(" "):"-";e.push(`| \`${c}\` | ${h} | ${l} | ${d} |`);}e.push("");for(let p of i){let c=p.dataFetching.filter(l=>!l.type.includes("Mutation")),h=p.dataFetching.filter(l=>l.type.includes("Mutation"));if(c.length>0||h.length>0){e.push(`### ${p.path}`),e.push(""),e.push(`> ${p.filePath}`),e.push("");let l=c.filter(u=>u.operationName&&u.operationName.trim().length>=2);if(l.length>0){e.push(`**Queries (${l.length})**`),e.push(""),e.push('<div class="gql-ops-list">');for(let u of l){let g=u.operationName||"",f=g.startsWith("\u2192")||g.startsWith("->"),d=g.replace(/^[→\->\s]+/,"");f?e.push(`<span class="gql-ref" data-ref="${d}" title="Component">${d}</span>`):e.push(`<span class="gql-op" data-op="${d}">${d}</span>`);}e.push("</div>"),e.push("");}let m=h.filter(u=>u.operationName&&u.operationName.trim().length>=2);if(m.length>0){e.push(`**Mutations (${m.length})**`),e.push(""),e.push('<div class="gql-ops-list">');for(let u of m){let g=u.operationName||"",f=g.startsWith("\u2192")||g.startsWith("->"),d=g.replace(/^[→\->\s]+/,"");f?e.push(`<span class="gql-ref mutation" data-ref="${d}" title="Component">${d}</span>`):e.push(`<span class="gql-op mutation" data-op="${d}">${d}</span>`);}e.push("</div>"),e.push("");}e.push("");}}}return e.join(`
|
|
10
|
+
`)}generateComponentsDoc(t){let e=[`# ${t.displayName} - Components`,""],n=new Map;for(let r of t.analysis.components){let s=n.get(r.type)||[];s.push(r),n.set(r.type,s);}e.push("| Type | Count |"),e.push("|------|-------|"),e.push(`| Container | ${n.get("container")?.length||0} |`),e.push(`| Presentational | ${n.get("presentational")?.length||0} |`),e.push(`| Layout | ${n.get("layout")?.length||0} |`),e.push(`| Hook | ${n.get("hook")?.length||0} |`),e.push(`| **Total** | **${t.analysis.components.length}** |`),e.push("");let a=new Map;for(let r of t.analysis.pages)a.set(r.path,[]);for(let r of t.analysis.components)for(let s of t.analysis.pages){let o=this.extractFeatureFromPage(s.filePath),i=this.extractFeatureFromComponent(r.filePath);o&&i&&o===i&&a.get(s.path)?.push(r);}e.push("## By Page"),e.push("");for(let[r,s]of a){if(s.length===0)continue;let o=s.filter(c=>c.type==="container"),i=s.filter(c=>c.type==="presentational"),p=s.filter(c=>c.type==="hook");e.push(`### ${r}`),e.push(""),e.push("| Component | Type | Data |"),e.push("|-----------|------|------|");for(let c of o){let h=this.formatComponentDataOps(c);e.push(`| ${c.name} | Container | ${h||"-"} |`);}for(let c of i.slice(0,10))e.push(`| ${c.name} | UI | - |`);i.length>10&&e.push(`| *+${i.length-10} more* | UI | - |`);for(let c of p)e.push(`| ${c.name} | Hook | - |`);e.push("");}e.push("## By Type"),e.push("");for(let[r,s]of n){e.push(`### ${r.charAt(0).toUpperCase()+r.slice(1)} (${s.length})`),e.push(""),e.push("| Name | File |"),e.push("|------|------|");for(let o of s.slice(0,25)){let i=o.filePath.replace("src/features/","").replace("src/","");e.push(`| ${o.name} | ${i} |`);}s.length>25&&e.push(`| *+${s.length-25} more* | |`),e.push("");}return e.join(`
|
|
11
|
+
`)}extractFeatureFromPage(t){let e=t.split("/");return e.length>1?e[0]:null}extractFeatureFromComponent(t){let e=t.match(/src\/features\/([^/]+)/);return e?e[1]:null}formatComponentDataOps(t){let e=[],n=[];for(let u of t.hooks){let g=u.match(/(?:useQuery|Query):\s*(\w+)/),f=u.match(/(?:useMutation|Mutation):\s*(\w+)/);g&&g[1]&&g[1].trim().length>=2?e.push(g[1]):f&&f[1]&&f[1].trim().length>=2&&n.push(f[1]);}let a=e.filter(u=>u&&u.trim().length>=2),r=n.filter(u=>u&&u.trim().length>=2);if(a.length===0&&r.length===0)return "";let s=[],o=2,i=2,p=a.slice(0,o);for(let u of p)s.push(`<span class="gql-op" data-op="${u}">${u}</span>`);let c=r.slice(0,i);for(let u of c)s.push(`<span class="gql-op mutation" data-op="${u}">${u}</span>`);let h=a.slice(o),l=r.slice(i),m=h.length+l.length;if(m>0){let u=JSON.stringify(a).replace(/"/g,"""),g=JSON.stringify(r).replace(/"/g,""");s.push(`<span class="gql-ref" data-ref="${t.name}" data-queries="${u}" data-mutations="${g}" title="View all ${a.length} queries and ${r.length} mutations">+${m} more</span>`);}return `<div class="gql-ops-inline">${s.join(" ")}</div>`}generateGraphQLDoc(t){let e=[`# ${t.displayName} - GraphQL`,""],n=t.analysis.graphqlOperations.filter(s=>s.type==="query"),a=t.analysis.graphqlOperations.filter(s=>s.type==="mutation"),r=t.analysis.graphqlOperations.filter(s=>s.type==="fragment");if(e.push("| Type | Count |"),e.push("|------|-------|"),e.push(`| Query | ${n.length} |`),e.push(`| Mutation | ${a.length} |`),e.push(`| Fragment | ${r.length} |`),e.push(`| **Total** | **${t.analysis.graphqlOperations.length}** |`),e.push(""),n.length>0){e.push("## Queries"),e.push("");for(let s of n.slice(0,80)){e.push(`### ${s.name}`),e.push("");let o=s.returnType||"unknown",i=s.variables.length,p=s.usedIn.length;if(e.push(`> Return: \`${o}\` | Variables: ${i} | Used: ${p} files`),e.push(""),s.variables.length>0){e.push("| Variable | Type |"),e.push("|----------|------|");for(let c of s.variables)e.push(`| ${c.name} | \`${c.type}\` |`);e.push("");}s.fields&&s.fields.length>0&&(e.push("```graphql"),e.push(this.formatGraphQLFields(s.fields,0)),e.push("```"),e.push(""));}n.length>80&&e.push(`*+${n.length-80} more queries*
|
|
12
|
+
`);}if(a.length>0){e.push("## Mutations"),e.push("");for(let s of a.slice(0,80)){e.push(`### ${s.name}`),e.push("");let o=s.variables.length,i=s.usedIn.length;if(e.push(`> Variables: ${o} | Used: ${i} files`),e.push(""),s.variables.length>0){e.push("| Variable | Type |"),e.push("|----------|------|");for(let p of s.variables)e.push(`| ${p.name} | \`${p.type}\` |`);e.push("");}s.fields&&s.fields.length>0&&(e.push("```graphql"),e.push(this.formatGraphQLFields(s.fields,0)),e.push("```"),e.push(""));}a.length>80&&e.push(`*+${a.length-80} more mutations*
|
|
13
|
+
`);}if(r.length>0){e.push("## Fragments"),e.push(""),e.push("| Name | Type | Fields |"),e.push("|------|------|--------|");for(let s of r.slice(0,50)){let o=s.fields?.length||0;e.push(`| ${s.name} | ${s.returnType||"-"} | ${o} |`);}r.length>50&&e.push(`| *+${r.length-50} more* | | |`),e.push("");}return e.join(`
|
|
14
|
+
`)}formatGraphQLFields(t,e){if(!t||t.length===0)return "";let n=[];for(let a of t){let r=" ".repeat(e);a.fields&&a.fields.length>0?(n.push(`${r}${a.name} {`),n.push(this.formatGraphQLFields(a.fields,e+1)),n.push(`${r}}`)):n.push(`${r}${a.name}`);}return n.join(`
|
|
15
|
+
`)}generateDataFlowDoc(t){let e=[`# ${t.displayName} - Data Flow`,""],n=t.analysis.dataFlows.filter(o=>o.name.includes("\u{1F4E1}")||o.operations.some(i=>i.includes("Query"))),a=t.analysis.dataFlows.filter(o=>o.name.includes("\u270F\uFE0F")||o.operations.some(i=>i.includes("Mutation"))),r=t.analysis.dataFlows.filter(o=>o.source.type==="context");e.push("## Overview"),e.push(""),e.push("| Type | Count | Direction |"),e.push("|------|-------|-----------|"),e.push(`| \`QUERY\` | ${n.length} | Server \u2192 Component |`),e.push(`| \`MUTATION\` | ${a.length} | Component \u2192 Server |`),e.push(`| \`CONTEXT\` | ${r.length} | Provider \u2192 Consumer |`),e.push(`| **Total** | **${t.analysis.dataFlows.length}** | |`),e.push(""),e.push("## Architecture"),e.push(""),e.push("```mermaid"),e.push("flowchart LR"),e.push(' subgraph Server["GraphQL Server"]'),e.push(" API[(API)]"),e.push(" end"),e.push(' subgraph Client["React Application"]'),e.push(" Apollo[Apollo Client]"),e.push(" Container[Container Component]"),e.push(" View[View Component]"),e.push(" end"),e.push(" API -->|Query Response| Apollo"),e.push(" Apollo -->|Cache/Data| Container"),e.push(" Container -->|Props| View"),e.push(" View -->|User Action| Container"),e.push(" Container -->|Mutation| Apollo"),e.push(" Apollo -->|GraphQL Request| API"),e.push("```"),e.push(""),e.push("## Page Data Flows"),e.push("");for(let o of t.analysis.pages){let i=this.extractFeatureFromPage(o.filePath),p=t.analysis.components.filter(u=>this.extractFeatureFromComponent(u.filePath)===i);if(!(o.dataFetching.length>0||p.some(u=>u.stateManagement.some(g=>g.includes("Apollo")||g.includes("Context")))))continue;e.push(`### ${o.path}`),e.push(""),e.push(`\`FILE: ${o.filePath}\``),e.push("");let h=this.getPageOperations(o,p,t.analysis.graphqlOperations),l=h.queries.filter(u=>u&&u.trim().length>0),m=h.mutations.filter(u=>u&&u.trim().length>0);if(l.length>0||m.length>0){e.push("```mermaid"),e.push("flowchart LR");let u=o.path.replace(/[^a-zA-Z0-9]/g,"_"),g=o.path.replace(/"/g,"'");e.push(` Page${u}["${g}"]`),l.slice(0,5).forEach((f,d)=>{let C=`Q${u}_${d}`,$=f.replace(/"/g,"'").replace(/[<>]/g,"");e.push(` ${C}["${$}"]:::query --> Page${u}`);}),m.slice(0,5).forEach((f,d)=>{let C=`M${u}_${d}`,$=f.replace(/"/g,"'").replace(/[<>]/g,"");e.push(` Page${u} --> ${C}["${$}"]:::mutation`);}),e.push(" classDef query fill:#dbeafe,stroke:#1d4ed8,color:#1e40af"),e.push(" classDef mutation fill:#fce7f3,stroke:#be185d,color:#9d174d"),e.push("```"),e.push("");}if(h.queries.length>0||h.mutations.length>0){if(l.length>0){e.push(`**Queries (${l.length})**`),e.push(""),e.push('<div class="gql-ops-list">');for(let u of l){let g=u.startsWith("\u2192")||u.startsWith("->"),f=u.replace(/^[→\->\s]+/,"");f&&f.trim().length>0&&(g?e.push(`<span class="gql-ref" data-ref="${f}" title="Component: ${f}">${f}</span>`):e.push(`<span class="gql-op" data-op="${f}">${f}</span>`));}e.push("</div>"),e.push("");}if(m.length>0){e.push(`**Mutations (${m.length})**`),e.push(""),e.push('<div class="gql-ops-list">');for(let u of m){let g=u.startsWith("\u2192")||u.startsWith("->"),f=u.replace(/^[→\->\s]+/,"");f&&f.trim().length>0&&(g?e.push(`<span class="gql-ref mutation" data-ref="${f}" title="Component: ${f}">${f}</span>`):e.push(`<span class="gql-op mutation" data-op="${f}">${f}</span>`));}e.push("</div>"),e.push("");}}e.push("---"),e.push("");}let s=new Set;for(let o of r)s.add(o.source.name);if(s.size>0){e.push("## Context Providers"),e.push(""),e.push("| Provider | Description |"),e.push("|----------|-------------|");for(let o of s)e.push(`| \`${o}\` | Provides shared state |`);e.push("");}return e.join(`
|
|
16
|
+
`)}getPageOperations(t,e,n){let a=new Set,r=new Set,s=o=>{if(!o)return false;let i=o.trim();return i.length>=2&&/[a-zA-Z]/.test(i)};for(let o of t.dataFetching){let p=(o.operationName?.replace(/^[→\->\s]+/,"")||"").replace(/Document$/g,"");s(p)&&(o.type?.includes("Mutation")?r.add(p):a.add(p));}for(let o of e)for(let i of o.hooks){if(i.includes("Query")){let p=i.match(/:\s*(.+)$/);p&&s(p[1])&&a.add(p[1].trim());}if(i.includes("Mutation")){let p=i.match(/:\s*(.+)$/);p&&s(p[1])&&r.add(p[1].trim());}}return {queries:Array.from(a).filter(s),mutations:Array.from(r).filter(s)}}generateCrossRepoDoc(t){let e=["# \u30AF\u30ED\u30B9\u30EA\u30DD\u30B8\u30C8\u30EA\u5206\u6790","","## \u30A2\u30FC\u30AD\u30C6\u30AF\u30C1\u30E3\u6982\u8981","","```mermaid","flowchart TB"];for(let n of t.repositories){let a=n.name.replace(/[^a-zA-Z0-9]/g,"_");e.push(` subgraph ${a}["${n.displayName}"]`),e.push(` ${a}_core["Core"]`),e.push(" end");}e.push("```"),e.push(""),e.push("## API\u63A5\u7D9A"),e.push("");for(let n of t.crossRepoAnalysis.apiConnections)e.push(`- **${n.frontend}** \u2192 **${n.backend}**: \`${n.endpoint}\``);e.push(""),e.push("## \u5171\u6709\u578B"),e.push("");for(let n of t.crossRepoAnalysis.sharedTypes)e.push(`- \`${n}\``);return e.push(""),e.join(`
|
|
17
|
+
`)}createPageDataFlowDiagram(t,e,n){let a=[],r=[],s=[],o=[];for(let i of e){i.type==="container"&&o.push(i.name);for(let p of i.hooks){if(p.includes("Query")||p.includes("\u{1F4E1}")){let c=p.includes(":")?p.split(":")[1].trim():p;r.includes(c)||r.push(c);}if(p.includes("Mutation")||p.includes("\u270F\uFE0F")){let c=p.includes(":")?p.split(":")[1].trim():p;s.includes(c)||s.push(c);}}}for(let i of t.dataFetching){let p=i.operationName.replace(/^→\s*/,"");i.type.includes("Query")&&!r.includes(p)?r.push(p):i.type.includes("Mutation")&&!s.includes(p)&&s.push(p);}if(a.push(`[Page: ${t.path}]`),a.push("\u2502"),r.length>0||s.length>0){a.push("\u251C\u2500 \u{1F4E1} \u30C7\u30FC\u30BF\u53D6\u5F97 (Query)");for(let i of r.slice(0,5))a.push(`\u2502 \u251C\u2500 ${i.substring(0,40)}`),a.push("\u2502 \u2502 \u2514\u2500 GraphQL Server \u2192 Apollo Cache \u2192 Component");if(r.length>5&&a.push(`\u2502 \u2514\u2500 ... \u4ED6 ${r.length-5} \u4EF6`),s.length>0){a.push("\u2502"),a.push("\u251C\u2500 \u270F\uFE0F \u30C7\u30FC\u30BF\u66F4\u65B0 (Mutation)");for(let i of s.slice(0,5))a.push(`\u2502 \u251C\u2500 ${i.substring(0,40)}`),a.push("\u2502 \u2502 \u2514\u2500 Component \u2192 GraphQL Server \u2192 Apollo Cache");s.length>5&&a.push(`\u2502 \u2514\u2500 ... \u4ED6 ${s.length-5} \u4EF6`);}}if(o.length>0){a.push("\u2502"),a.push("\u251C\u2500 \u{1F4E6} Container Components");for(let i of o.slice(0,5))a.push(`\u2502 \u2514\u2500 ${i}`);o.length>5&&a.push(`\u2502 \u2514\u2500 ... \u4ED6 ${o.length-5} \u4EF6`);}return a.push("\u2502"),a.push("\u2514\u2500 [Render]"),a.join(`
|
|
18
|
+
`)}generateDiagramsDoc(t){let e=["# Diagrams",""];e.push("## Overview"),e.push(""),e.push("| Diagram | Type | Description |"),e.push("|---------|------|-------------|");for(let n of t)e.push(`| ${n.title} | \`${n.type.toUpperCase()}\` | Auto-generated |`);e.push("");for(let n of t)e.push(`## ${n.title}`),e.push(""),e.push(`\`TYPE: ${n.type.toUpperCase()}\``),e.push(""),e.push("```mermaid"),e.push(n.content),e.push("```"),e.push("");return e.join(`
|
|
19
|
+
`)}};export{F as a,q as b};
|