@lomray/react-mobx-manager
Version:
This package provides Mobx stores manager for react.
3 lines (2 loc) • 1.56 kB
JavaScript
import s from"node:fs";import e from"node:path";import{fileURLToPath as t}from"node:url";const r=t(import.meta.url),o=`${e.dirname(r).split("node_modules")[0]}node_modules/.cache/@lomray/react-mobx-manager`,n=`${o}/store-ids.json`,a=(e=!1)=>{if(e&&s.existsSync(n)){const e=JSON.parse(s.readFileSync(n,{encoding:"utf-8"}));return new Map(e)}return new Map},i=e=>{s.existsSync(o)||s.mkdirSync(o,{recursive:!0}),s.writeFileSync(n,JSON.stringify([...e.entries()],null,2),{encoding:"utf-8"})},c=(s="")=>{const e=s.split(""),t=e.pop()??"`";if("z"===t)return[...e,"A"].join("");if("Z"===t){const s=e.pop();return s?[c([...e,s].join("")),"a"].join(""):"aa"}return[...e,String.fromCharCode(t.charCodeAt(0)+1)].join("")};class l{cache;root;lastId;constructor(s,e=!1){this.root=s,this.cache=a(e)}injectId=(s,e)=>{const{classname:t,storeId:r}=this.cache.get(e),o=new RegExp(`(class\\s${t}\\s+?{)`);return s.replace(o,`$1static id = '${r}';`)};getDevId=(s,e)=>`${s.replace(this.root,"").replace(/\/index.(js|ts|tsx)/,"").split("/").filter(Boolean).join("-")}-${e}`;getProdId=()=>{const s=c(this.lastId),e=`S${s}`;return this.lastId=s,e};matchMobxStore=s=>{const{classname:e}=s.match(/class\s(?<classname>\w+)\s+?{(?!.*static\sid\s*=.*).+(makeObservable|makeAutoObservable)(?!.*persistStore\(\1.*)/s)?.groups??{};if(e)return e;const{classname:t}=s.match(/(@mobx-store).+class\s(?<classname>\w+)\s+?{(?!.*static\sid\s*=.*).+}(?!.*persistStore.*)/s)?.groups??{};return t}}export{l as Generator,c as getNextLetter,a as loadCache,i as saveCache};
//# sourceMappingURL=helpers.js.map