@frontfriend/tailwind 2.6.0 → 3.0.0

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.
@@ -80,11 +80,15 @@ class CacheManager {
80
80
  // Use Function constructor to evaluate in isolated scope
81
81
  const evalFunc = new Function('module', 'exports', content);
82
82
  evalFunc(fakeModule, moduleExports);
83
-
83
+
84
84
  data[key] = fakeModule.exports;
85
85
  }
86
86
  } catch (e) {
87
- // Skip files that can't be parsed
87
+ // Log parsing errors to help debug Windows/encoding issues
88
+ console.warn(`[Frontfriend] Failed to load ${file}: ${e.message}`);
89
+ if (e.message.includes('Unexpected token') || e.message.includes('Invalid character')) {
90
+ console.warn('[Frontfriend] This might be a BOM or encoding issue. Try deleting node_modules/.cache/frontfriend and running `npx frontfriend init` again.');
91
+ }
88
92
  }
89
93
  }
90
94
  }
@@ -1,3 +1,3 @@
1
- var y=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var v=y((ue,T)=>{var W="https://app.frontfriend.dev",z="https://tokens-studio-donux.up.railway.app/api",K=".cache/frontfriend",Q={JS:["tokens.js","variables.js","semanticVariables.js","semanticDarkVariables.js","safelist.js","custom.js"],JSON:["fonts.json","icons.json","components-config.json","version.json","metadata.json"]},X={FF_ID:"FF_ID",FF_API_URL:"FF_API_URL",FF_USE_LOCAL:"FF_USE_LOCAL"};T.exports={DEFAULT_API_URL:W,LEGACY_API_URL:z,CACHE_DIR_NAME:K,CACHE_TTL_DAYS:7,CACHE_TTL_MS:6048e5,CACHE_FILES:Q,ENV_VARS:X}});var L=y((pe,A)=>{var F=class extends Error{constructor(e,t,s){super(e),this.name="APIError",this.statusCode=t,this.url=s,this.code=`API_${t}`}},C=class extends Error{constructor(e,t){super(e),this.name="CacheError",this.operation=t,this.code=`CACHE_${t.toUpperCase()}`}},$=class extends Error{constructor(e,t){super(e),this.name="ConfigError",this.field=t,this.code=`CONFIG_${t.toUpperCase()}`}},E=class extends Error{constructor(e,t){super(e),this.name="ProcessingError",this.token=t,this.code="PROCESSING_ERROR"}};A.exports={APIError:F,CacheError:C,ConfigError:$,ProcessingError:E}});var k=y((me,I)=>{var u=require("fs");function Z(i){try{let e=u.readFileSync(i,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}function ee(i){try{return u.readFileSync(i,"utf8")}catch(e){if(e.code==="ENOENT")return null;throw e}}function te(i,e,t=2){let s=JSON.stringify(e,null,t);u.writeFileSync(i,s,"utf8")}function se(i,e){if(e==null||typeof e=="object"&&Object.keys(e).length===0||Array.isArray(e)&&e.length===0){let s=`module.exports = ${Array.isArray(e)?"[]":"{}"};`;u.writeFileSync(i,s,"utf8")}else{let t=`module.exports = ${JSON.stringify(e,null,2)};`;u.writeFileSync(i,t,"utf8")}}function oe(i){return u.existsSync(i)}function ne(i){u.mkdirSync(i,{recursive:!0})}function re(i){u.rmSync(i,{recursive:!0,force:!0})}I.exports={readJsonFileSafe:Z,readFileSafe:ee,writeJsonFile:te,writeModuleExportsFile:se,fileExists:oe,ensureDirectoryExists:ne,removeDirectory:re}});var M=y((we,b)=>{var d=require("path"),{fileExists:P}=k();function ae(i,e=process.cwd()){let t=e;for(;t!==d.parse(t).root;){let s=d.join(t,i);if(P(s))return s;t=d.dirname(t)}return null}function ie(i,e=process.cwd(),t=null){let s=[],n=e,o=10;for(let r=0;r<o;r++){s.push(d.join(n,i)),r<3&&s.push(d.join(n,"../".repeat(r+1)+i));let a=d.dirname(n);if(a===n)break;n=a}s.push(d.join(__dirname,"../../../",i));for(let r of s)if(P(r)&&(!t||t(r)))return r;return null}function ce(i,e=process.cwd()){let t=i.map(s=>d.isAbsolute(s)?s:d.join(e,s));for(let s of t)if(P(s))return s;return null}b.exports={findFileUpward:ae,findDirectoryUpward:ie,findDirectoryWithPaths:ce}});var O=y((ge,G)=>{var c=require("path"),{findDirectoryUpward:J}=M(),{readJsonFileSafe:p,readFileSafe:x,fileExists:_}=k(),D=class{constructor(e,t={}){if(this.ffId=e,this.tokensBasePath=t.tokensBasePath||this.findTokensPath(),this.folderMap=this.loadFolderMap(),this.projectFolder=this.folderMap[e],!this.projectFolder)throw new Error(`No folder mapping found for ff-id: ${e}`);this.projectPath=c.join(this.tokensBasePath,this.projectFolder)}findTokensPath(){let e=J("apps/tokens",process.cwd(),t=>_(c.join(t,"folderMap.json")));if(e||(e=J("tokens",process.cwd(),t=>_(c.join(t,"folderMap.json")))),!e)throw new Error("Could not find tokens directory with folderMap.json");return e}loadFolderMap(){let e=c.join(this.tokensBasePath,"folderMap.json"),t=p(e);if(!t)throw new Error("Failed to load folderMap.json: File not found");return t}async fetchTokens(){let e=c.join(this.projectPath,"figma"),t={global:[c.join(e,"Global Tokens","Default.json"),c.join(e,"global.json")],colors:[c.join(e,"Global Colors","Default.json"),c.join(e,"Global Colors","Light.json")],semantic:[c.join(e,"Semantic","Light.json"),c.join(e,"Semantic","Default.json")],semanticDark:[c.join(e,"Semantic","Dark.json")]},s={};for(let[n,o]of Object.entries(t)){for(let r of o){let a=p(r);if(a!==null){s[n]=a;break}}s[n]||(s[n]=null)}return s}async fetchProcessedTokens(){let e=c.join(this.projectPath,"cache");if(!_(e))return null;let t={"tokens.js":"hashedTokens.js","variables.js":"hashedVariables.js","semanticVariables.js":"hashedSemanticVariables.js","semanticDarkVariables.js":"hashedSemanticDarkVariables.js","safelist.js":"safelist.js","custom.js":"custom.js","fonts.json":"fonts.json","icons.json":"icons.json","components-config.json":"encoded-config.json","version.json":"version.json"},s={};for(let[o,r]of Object.entries(t)){let a=c.join(e,r);o.endsWith(".js")?s[o]=x(a):s[o]=p(a)}return Object.values(s).some(o=>o!==null)?s:null}async fetchComponentsConfig(){return p(c.join(this.projectPath,"components-config.json"))}async fetchFonts(){return p(c.join(this.projectPath,"font.json"))}async fetchIcons(){return p(c.join(this.projectPath,"icons.json"))}async fetchVersion(){return p(c.join(this.projectPath,"version.json"))}async fetchCustomCss(){return x(c.join(this.projectPath,"custom.css"))}async fetchPlanMetadata(){return p(c.join(this.projectPath,"metadata.json"))||{planType:"full",allowedComponents:null}}fetchJson(){throw new Error("fetchJson is not implemented in LocalTokenReader. Use specific fetch methods.")}fetchRaw(){throw new Error("fetchRaw is not implemented in LocalTokenReader. Use specific fetch methods.")}};G.exports={LocalTokenReader:D}});var H=y((je,V)=>{var B=require("https"),q=require("http"),{URL:ye}=require("url"),{DEFAULT_API_URL:le,LEGACY_API_URL:w,ENV_VARS:N}=v(),{APIError:h}=L(),{LocalTokenReader:fe}=O(),R=class{constructor(e,t={}){this.ffId=e,this.baseURL=t.baseURL||process.env[N.FF_API_URL]||le,process.env[N.FF_USE_LOCAL]==="true"&&(console.log(" \u{1F3E0} Using local token reader"),this.localReader=new fe(e,t))}fetchJson(e){return new Promise((t,s)=>{(e.startsWith("https")?B:q).get(e,o=>{let r="";if(o.statusCode>=400){s(new h(`HTTP ${o.statusCode}: ${o.statusMessage}`,o.statusCode,e));return}o.on("data",a=>{r+=a}),o.on("end",()=>{try{let a=JSON.parse(r);t(a)}catch(a){s(new h(`Invalid JSON response: ${a.message}`,o.statusCode,e))}}),o.on("error",a=>{s(new h(`Response error: ${a.message}`,o.statusCode,e))})}).on("error",o=>{s(new h(`Network error: ${o.message}`,0,e))})})}fetchRaw(e){return new Promise((t,s)=>{(e.startsWith("https")?B:q).get(e,o=>{let r="";if(o.statusCode>=400){s(new h(`HTTP ${o.statusCode}: ${o.statusMessage}`,o.statusCode,e));return}o.on("data",a=>{r+=a}),o.on("end",()=>{t(r)}),o.on("error",a=>{s(new h(`Response error: ${a.message}`,o.statusCode,e))})}).on("error",o=>{s(new h(`Network error: ${o.message}`,0,e))})})}async fetchTokens(){if(this.localReader)return this.localReader.fetchTokens();try{let n=`${this.baseURL}/api/design-systems/${this.ffId}/tokens`,o=await this.fetchJson(n);if(o&&o.tokens){let r=o.tokens;return{global:r["Global Tokens/Default"]||r.global||null,colors:r["Global Colors/Default"]||r.colors||null,semantic:r["Semantic/Light"]||r["semantic/light"]||null,semanticDark:r["Semantic/Dark"]||r["semantic/dark"]||null}}}catch(n){if(n.statusCode===400)throw new h("Design system not synced with Figma. Please sync tokens from Figma before using this design system.",400,`${this.baseURL}/api/design-systems/${this.ffId}/tokens`)}let e=w,t={global:`${e}/${this.ffId}/global-tokens/default.json`,colors:`${e}/${this.ffId}/global-colors/default.json`,semantic:`${e}/${this.ffId}/semantic/light.json`,semanticDark:`${e}/${this.ffId}/semantic/dark.json`},s=await Promise.all([this.fetchJson(t.global).catch(n=>n.statusCode===404?null:Promise.reject(n)),this.fetchJson(t.colors).catch(n=>n.statusCode===404?null:Promise.reject(n)),this.fetchJson(t.semantic).catch(n=>n.statusCode===404?null:Promise.reject(n)),this.fetchJson(t.semanticDark).catch(n=>n.statusCode===404?null:Promise.reject(n))]);return{global:s[0],colors:s[1],semantic:s[2],semanticDark:s[3]}}async fetchProcessedTokens(){if(this.localReader)return this.localReader.fetchProcessedTokens();let e=`${this.baseURL}/api/design-systems/${this.ffId}/processed-tokens`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t.statusCode===400?new h("Design system not synced with Figma. Please sync tokens from Figma before using this design system.",400,e):t}}async fetchComponentsConfig(){if(this.localReader)return this.localReader.fetchComponentsConfig();let e=`${w}/${this.ffId}/components-config.json`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchFonts(){if(this.localReader)return this.localReader.fetchFonts();let e=`${w}/${this.ffId}/font.json`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchIcons(){if(this.localReader)return this.localReader.fetchIcons();let e=`${w}/${this.ffId}/icons.json`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchVersion(){if(this.localReader)return this.localReader.fetchVersion();let e=`${w}/${this.ffId}/version.json`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchCustomCss(){if(this.localReader)return this.localReader.fetchCustomCss();let e=`${w}/${this.ffId}/custom.css`;try{return await this.fetchRaw(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchPlanMetadata(){if(this.localReader)return process.env.FF_DEBUG&&console.log(" \u2192 Using local reader for plan metadata"),this.localReader.fetchPlanMetadata();let e=`${this.baseURL}/api/design-systems/${this.ffId}/processed-tokens`;try{process.env.FF_DEBUG&&console.log(` \u2192 Fetching plan metadata from saas app: ${e}`);let t=await this.fetchJson(e);if(t&&t.metadata){let s={planType:t.metadata.planType||"full",allowedComponents:t.metadata.allowedComponents||null};return process.env.FF_DEBUG&&console.log(` \u2192 Found plan metadata in saas app: ${s.planType}, allowed: ${s.allowedComponents?s.allowedComponents.length+" components":"all"}`),s}}catch(t){if(t.statusCode===404){process.env.FF_DEBUG&&console.log(" \u2192 ff-id not found in saas app, trying legacy server");let s=`${w}/${this.ffId}/metadata`;try{process.env.FF_DEBUG&&console.log(` \u2192 Fetching from legacy server: ${s}`);let n=await this.fetchJson(s),o={planType:n.planType||"full",allowedComponents:n.allowedComponents||null};return process.env.FF_DEBUG&&console.log(` \u2192 Found in legacy server: ${o.planType}, allowed: ${o.allowedComponents?o.allowedComponents.length+" components":"all"}`),o}catch(n){if(n.statusCode===404)return process.env.FF_DEBUG&&console.log(" \u2192 ff-id not found in any server - access denied"),{planType:"denied",allowedComponents:[],error:"Design system not found. Please ensure your ff-id is valid."};throw n}}throw t}}};V.exports={APIClient:R}});var de=require("https"),m=require("fs"),f=require("path"),{URL:Fe}=require("url"),Y=require("os"),j=process.env.FF_REGISTRY_URL||"https://ff-registry.up.railway.app",S=class{constructor(e={}){this.appRoot=e.appRoot||process.cwd(),this.framework=e.framework||this.detectFramework(),this.config=e.config||{},this.outputPath=e.outputPath||this.getDefaultOutputPath(),this.overwrite=e.overwrite||!1,this.downloadedComponents=new Set,this.ffId=this.config.ffId||this.config["ff-id"]||null,this.planMetadata=null}detectFramework(){let e=f.join(this.appRoot,"package.json");if(m.existsSync(e)){let t=JSON.parse(m.readFileSync(e,"utf8")),s={...t.dependencies,...t.devDependencies};if(s.vue)return"vue";if(s.react)return"react"}return"react"}getDefaultOutputPath(){if(this.config.aliases&&this.config.aliases.ui){let t=this.config.aliases.ui.replace(/^@\//,"");return f.join(this.appRoot,t)}return this.framework==="vue"?f.join(this.appRoot,"src/components/ui"):f.join(this.appRoot,"components/ui")}fetchJson(e){let t=process.env.FF_USE_LOCAL==="true",s=process.env.FF_USE_LOCAL_REGISTRY==="true",n=e.includes(j);if(t||s&&n){process.env.FF_DEBUG&&s&&!t&&console.log(" \u2192 Using local registry for components");let o=["../../packages/registry","../../../packages/registry","../../../../packages/registry",f.join(__dirname,"../../../registry"),"packages/registry"],r;for(let l of o){let U=f.isAbsolute(l)?l:f.join(process.cwd(),l);if(m.existsSync(U)){r=U;break}}if(!r)return Promise.reject(new Error(`Local registry not found. Tried paths: ${o.join(", ")}`));let a=e.replace(j,"").replace(/^\//,""),g=f.join(r,...a.split("/"));try{let l=m.readFileSync(g,"utf8");return Promise.resolve(JSON.parse(l))}catch(l){return l.code==="ENOENT"?Promise.reject(new Error("HTTP 404: Not Found")):Promise.reject(l)}}return new Promise((o,r)=>{de.get(e,a=>{let g="";if(a.statusCode>=400){r(new Error(`HTTP ${a.statusCode}: ${a.statusMessage}`));return}a.on("data",l=>{g+=l}),a.on("end",()=>{try{o(JSON.parse(g))}catch(l){r(new Error(`Invalid JSON response: ${l.message}`))}})}).on("error",a=>{r(a)})})}async getAllComponents(){try{let e=`${j}/components/${this.framework}/index.json`,s=(await this.fetchJson(e)).components||[];if(this.ffId){try{await this.isComponentAllowed("dummy")}catch{if(this.planMetadata&&this.planMetadata.planType==="denied")throw new Error(this.planMetadata.error||"Access denied. Your ff-id was not found in any server.")}this.planMetadata&&this.planMetadata.planType==="trial"&&this.planMetadata.allowedComponents&&(s=s.filter(n=>this.planMetadata.allowedComponents.includes(n)),process.env.FF_DEBUG&&console.log(` \u2192 Trial plan: filtering to ${s.length} allowed components`))}return s}catch(e){return console.error("Failed to fetch component index:",e.message),[]}}async getCustomComponents(){if(!this.ffId)return process.env.FF_DEBUG&&console.log(" \u2192 No ff-id found, skipping custom components"),[];try{let e=`${j}/custom/${this.ffId}/${this.framework}/index.json`;process.env.FF_DEBUG&&console.log(` \u2192 Fetching custom components from: ${e}`);let t=await this.fetchJson(e);return process.env.FF_DEBUG&&console.log(` \u2192 Found custom components: ${JSON.stringify(t.components)}`),t.components||[]}catch(e){return process.env.FF_DEBUG&&console.log(` \u2192 No custom components found: ${e.message}`),[]}}async downloadComponents(e){process.env.FF_DEBUG&&console.log(` \u2192 ComponentDownloader initialized with ff-id: ${this.ffId}`);let t={successful:[],failed:[],dependencies:new Set};for(let s of e)try{let n=await this.downloadComponent(s);t.successful.push(s),n.forEach(o=>t.dependencies.add(o))}catch(n){t.failed.push({component:s,error:n.message})}return{successful:t.successful,failed:t.failed,dependencies:Array.from(t.dependencies)}}async isComponentAllowed(e){if(!this.planMetadata&&this.ffId){let{APIClient:t}=H(),s=new t(this.ffId,{baseURL:this.config["api-url"]||this.config.apiUrl});try{this.planMetadata=await s.fetchPlanMetadata(),process.env.FF_DEBUG&&console.log(` \u2192 Fetched plan metadata: ${this.planMetadata.planType}, allowed: ${this.planMetadata.allowedComponents?this.planMetadata.allowedComponents.length+" components":"all"}`)}catch(n){console.warn("Failed to fetch plan metadata:",n.message),this.planMetadata={planType:"full",allowedComponents:null}}}if(this.planMetadata&&this.planMetadata.planType==="denied")throw new Error(this.planMetadata.error||"Access denied. Your ff-id was not found in any server.");return!this.planMetadata||this.planMetadata.planType==="full"?!0:this.planMetadata.planType==="trial"&&this.planMetadata.allowedComponents?this.planMetadata.allowedComponents.includes(e):!1}async downloadComponent(e){if(this.downloadedComponents.has(e))return[];if(process.env.FF_DEBUG&&(console.log(` \u2192 Checking if component "${e}" is allowed...`),console.log(` \u2192 FF-ID: ${this.ffId}`)),!await this.isComponentAllowed(e)){let r=`Component "${e}" is not available in your trial plan. Please upgrade to access all components.`;throw console.error(`\u274C ${r}`),new Error(r)}console.log(`\u{1F4E5} Downloading ${e}...`);let s,n=!1;if(this.ffId){let r=`${j}/custom/${this.ffId}/${this.framework}/${e}.json`;try{s=await this.fetchJson(r),n=!0,process.env.FF_DEBUG&&console.log(` \u2192 Found custom component for ${e}`)}catch{process.env.FF_DEBUG&&console.log(` \u2192 No custom component found for ${e}, trying standard`)}}if(!s){let r=`${j}/components/${this.framework}/${e}.json`;try{s=await this.fetchJson(r)}catch(a){throw a.message.includes("404")?new Error(`Component "${e}" not found`):new Error(`Failed to fetch ${e}: ${a.message}`)}}if(!s.files||!Array.isArray(s.files))throw new Error(`Invalid component data for ${e}`);for(let r of s.files)await this.writeComponentFile(r);this.downloadedComponents.add(e),console.log(` \u2713 ${e} downloaded${n&&process.env.FF_DEBUG?" (custom)":""}`);let o=[...s.dependencies||[]];if(s.registryDependencies&&s.registryDependencies.length>0){console.log(` \u{1F4E6} Installing registry dependencies: ${s.registryDependencies.join(", ")}`);for(let r of s.registryDependencies)try{(await this.downloadComponent(r)).forEach(g=>o.push(g))}catch(a){console.warn(` \u26A0\uFE0F Failed to download dependency ${r}: ${a.message}`)}}return o}async writeComponentFile(e){let t=e.name.split("/").join(f.sep),s=f.join(this.outputPath,t),n=f.dirname(s);if(m.existsSync(n)||m.mkdirSync(n,{recursive:!0}),m.existsSync(s)&&!this.overwrite){console.log(` \u26A0\uFE0F Skipping ${e.name} (already exists)`);return}let o=e.content;Y.EOL!==`
2
- `&&(o=e.content.replace(/\n/g,Y.EOL)),m.writeFileSync(s,o,"utf8")}};module.exports={ComponentDownloader:S};
1
+ var y=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports);var T=y((pe,v)=>{var W="https://app.frontfriend.dev",z="https://tokens-studio-donux.up.railway.app/api",K=".cache/frontfriend",Q={JS:["tokens.js","variables.js","semanticVariables.js","semanticDarkVariables.js","safelist.js","custom.js"],JSON:["fonts.json","icons.json","components-config.json","version.json","metadata.json"]},X={FF_ID:"FF_ID",FF_API_URL:"FF_API_URL",FF_USE_LOCAL:"FF_USE_LOCAL"};v.exports={DEFAULT_API_URL:W,LEGACY_API_URL:z,CACHE_DIR_NAME:K,CACHE_TTL_DAYS:7,CACHE_TTL_MS:6048e5,CACHE_FILES:Q,ENV_VARS:X}});var L=y((me,A)=>{var j=class extends Error{constructor(e,t,s){super(e),this.name="APIError",this.statusCode=t,this.url=s,this.code=`API_${t}`}},C=class extends Error{constructor(e,t){super(e),this.name="CacheError",this.operation=t,this.code=`CACHE_${t.toUpperCase()}`}},$=class extends Error{constructor(e,t){super(e),this.name="ConfigError",this.field=t,this.code=`CONFIG_${t.toUpperCase()}`}},E=class extends Error{constructor(e,t){super(e),this.name="ProcessingError",this.token=t,this.code="PROCESSING_ERROR"}};A.exports={APIError:j,CacheError:C,ConfigError:$,ProcessingError:E}});var k=y((we,I)=>{var p=require("fs");function Z(i){try{let e=p.readFileSync(i,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}function ee(i){try{return p.readFileSync(i,"utf8").replace(/^\uFEFF/,"")}catch(e){if(e.code==="ENOENT")return null;throw e}}function te(i,e,t=2){let s=JSON.stringify(e,null,t);p.writeFileSync(i,s,"utf8")}function se(i,e){if(e==null||typeof e=="object"&&Object.keys(e).length===0||Array.isArray(e)&&e.length===0){let s=`module.exports = ${Array.isArray(e)?"[]":"{}"};`;p.writeFileSync(i,s,"utf8")}else{let t=`module.exports = ${JSON.stringify(e,null,2)};`;p.writeFileSync(i,t,"utf8")}}function oe(i){return p.existsSync(i)}function ne(i){p.mkdirSync(i,{recursive:!0})}function re(i){p.rmSync(i,{recursive:!0,force:!0})}I.exports={readJsonFileSafe:Z,readFileSafe:ee,writeJsonFile:te,writeModuleExportsFile:se,fileExists:oe,ensureDirectoryExists:ne,removeDirectory:re}});var b=y((ge,M)=>{var h=require("path"),{fileExists:P}=k();function ae(i,e=process.cwd()){let t=e;for(;t!==h.parse(t).root;){let s=h.join(t,i);if(P(s))return s;t=h.dirname(t)}return null}function ie(i,e=process.cwd(),t=null){let s=[],o=e,r=10;for(let n=0;n<r;n++){s.push(h.join(o,i)),n<3&&s.push(h.join(o,"../".repeat(n+1)+i));let a=h.dirname(o);if(a===o)break;o=a}s.push(h.join(__dirname,"../../../",i));for(let n of s)if(P(n)&&(!t||t(n)))return n;return null}function ce(i,e=process.cwd()){let t=i.map(s=>h.isAbsolute(s)?s:h.join(e,s));for(let s of t)if(P(s))return s;return null}M.exports={findFileUpward:ae,findDirectoryUpward:ie,findDirectoryWithPaths:ce}});var O=y((ye,G)=>{var c=require("path"),{findDirectoryUpward:J}=b(),{readJsonFileSafe:m,readFileSafe:x,fileExists:_}=k(),D=class{constructor(e,t={}){if(this.ffId=e,this.tokensBasePath=t.tokensBasePath||this.findTokensPath(),this.folderMap=this.loadFolderMap(),this.projectFolder=this.folderMap[e],!this.projectFolder)throw new Error(`No folder mapping found for ff-id: ${e}`);this.projectPath=c.join(this.tokensBasePath,this.projectFolder)}findTokensPath(){let e=J("apps/tokens",process.cwd(),t=>_(c.join(t,"folderMap.json")));if(e||(e=J("tokens",process.cwd(),t=>_(c.join(t,"folderMap.json")))),!e)throw new Error("Could not find tokens directory with folderMap.json");return e}loadFolderMap(){let e=c.join(this.tokensBasePath,"folderMap.json"),t=m(e);if(!t)throw new Error("Failed to load folderMap.json: File not found");return t}async fetchTokens(){let e=c.join(this.projectPath,"figma"),t={global:[c.join(e,"Global Tokens","Default.json"),c.join(e,"global.json")],colors:[c.join(e,"Global Colors","Default.json"),c.join(e,"Global Colors","Light.json")],semantic:[c.join(e,"Semantic","Light.json"),c.join(e,"Semantic","Default.json")],semanticDark:[c.join(e,"Semantic","Dark.json")]},s={};for(let[o,r]of Object.entries(t)){for(let n of r){let a=m(n);if(a!==null){s[o]=a;break}}s[o]||(s[o]=null)}return s}async fetchProcessedTokens(){let e=c.join(this.projectPath,"cache");if(!_(e))return null;let t={"tokens.js":"hashedTokens.js","variables.js":"hashedVariables.js","semanticVariables.js":"hashedSemanticVariables.js","semanticDarkVariables.js":"hashedSemanticDarkVariables.js","safelist.js":"safelist.js","custom.js":"custom.js","fonts.json":"fonts.json","icons.json":"icons.json","components-config.json":"encoded-config.json","version.json":"version.json"},s={};for(let[r,n]of Object.entries(t)){let a=c.join(e,n);r.endsWith(".js")?s[r]=x(a):s[r]=m(a)}return Object.values(s).some(r=>r!==null)?s:null}async fetchComponentsConfig(){return m(c.join(this.projectPath,"components-config.json"))}async fetchFonts(){return m(c.join(this.projectPath,"font.json"))}async fetchIcons(){return m(c.join(this.projectPath,"icons.json"))}async fetchVersion(){return m(c.join(this.projectPath,"version.json"))}async fetchCustomCss(){return x(c.join(this.projectPath,"custom.css"))}async fetchPlanMetadata(){return m(c.join(this.projectPath,"metadata.json"))||{planType:"full",allowedComponents:null}}fetchJson(){throw new Error("fetchJson is not implemented in LocalTokenReader. Use specific fetch methods.")}fetchRaw(){throw new Error("fetchRaw is not implemented in LocalTokenReader. Use specific fetch methods.")}};G.exports={LocalTokenReader:D}});var V=y((Fe,H)=>{var B=require("https"),q=require("http"),{URL:le}=require("url"),{DEFAULT_API_URL:de,LEGACY_API_URL:g,ENV_VARS:N}=T(),{APIError:u}=L(),{LocalTokenReader:fe}=O(),R=class{constructor(e,t={}){this.ffId=e,this.baseURL=t.baseURL||process.env[N.FF_API_URL]||de,process.env[N.FF_USE_LOCAL]==="true"&&(console.log(" \u{1F3E0} Using local token reader"),this.localReader=new fe(e,t))}fetchJson(e,t={}){return new Promise((s,o)=>{(e.startsWith("https")?B:q).get(e,n=>{let a="";if(n.statusCode>=400){o(new u(`HTTP ${n.statusCode}: ${n.statusMessage}`,n.statusCode,e));return}n.on("data",l=>{a+=l}),n.on("end",()=>{try{let l=JSON.parse(a);t.returnHeaders?s({data:l,headers:n.headers}):s(l)}catch(l){o(new u(`Invalid JSON response: ${l.message}`,n.statusCode,e))}}),n.on("error",l=>{o(new u(`Response error: ${l.message}`,n.statusCode,e))})}).on("error",n=>{o(new u(`Network error: ${n.message}`,0,e))})})}fetchRaw(e){return new Promise((t,s)=>{(e.startsWith("https")?B:q).get(e,r=>{let n="";if(r.statusCode>=400){s(new u(`HTTP ${r.statusCode}: ${r.statusMessage}`,r.statusCode,e));return}r.on("data",a=>{n+=a}),r.on("end",()=>{t(n)}),r.on("error",a=>{s(new u(`Response error: ${a.message}`,r.statusCode,e))})}).on("error",r=>{s(new u(`Network error: ${r.message}`,0,e))})})}async fetchTokens(){if(this.localReader)return this.localReader.fetchTokens();try{let o=`${this.baseURL}/api/design-systems/${this.ffId}/tokens`,r=await this.fetchJson(o);if(r&&r.tokens){let n=r.tokens;return{global:n["Global Tokens/Default"]||n.global||null,colors:n["Global Colors/Default"]||n.colors||null,semantic:n["Semantic/Light"]||n["semantic/light"]||null,semanticDark:n["Semantic/Dark"]||n["semantic/dark"]||null}}}catch(o){if(o.statusCode===400)throw new u("Design system not synced with Figma. Please sync tokens from Figma before using this design system.",400,`${this.baseURL}/api/design-systems/${this.ffId}/tokens`)}let e=g,t={global:`${e}/${this.ffId}/global-tokens/default.json`,colors:`${e}/${this.ffId}/global-colors/default.json`,semantic:`${e}/${this.ffId}/semantic/light.json`,semanticDark:`${e}/${this.ffId}/semantic/dark.json`},s=await Promise.all([this.fetchJson(t.global).catch(o=>o.statusCode===404?null:Promise.reject(o)),this.fetchJson(t.colors).catch(o=>o.statusCode===404?null:Promise.reject(o)),this.fetchJson(t.semantic).catch(o=>o.statusCode===404?null:Promise.reject(o)),this.fetchJson(t.semanticDark).catch(o=>o.statusCode===404?null:Promise.reject(o))]);return{global:s[0],colors:s[1],semantic:s[2],semanticDark:s[3]}}async fetchProcessedTokens(e={}){if(this.localReader)return this.localReader.fetchProcessedTokens();let t=new le(`${this.baseURL}/api/design-systems/${this.ffId}/processed-tokens`);e.tag&&t.searchParams.append("tag",e.tag),e.version&&t.searchParams.append("version",e.version);let s=t.toString();try{let o=await this.fetchJson(s,{returnHeaders:!0});return o.headers&&(o.data.versionMetadata={version:o.headers["x-frontfriend-version"],tag:o.headers["x-frontfriend-tag"],cached:o.headers["x-frontfriend-cached"]==="true"}),o.data}catch(o){if(o.statusCode===404)return null;throw o.statusCode===400?new u("Design system not synced with Figma. Please sync tokens from Figma before using this design system.",400,s):o}}async fetchComponentsConfig(){if(this.localReader)return this.localReader.fetchComponentsConfig();let e=`${g}/${this.ffId}/components-config.json`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchFonts(){if(this.localReader)return this.localReader.fetchFonts();let e=`${g}/${this.ffId}/font.json`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchIcons(){if(this.localReader)return this.localReader.fetchIcons();let e=`${g}/${this.ffId}/icons.json`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchVersion(){if(this.localReader)return this.localReader.fetchVersion();let e=`${g}/${this.ffId}/version.json`;try{return await this.fetchJson(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchCustomCss(){if(this.localReader)return this.localReader.fetchCustomCss();let e=`${g}/${this.ffId}/custom.css`;try{return await this.fetchRaw(e)}catch(t){if(t.statusCode===404)return null;throw t}}async fetchPlanMetadata(){if(this.localReader)return process.env.FF_DEBUG&&console.log(" \u2192 Using local reader for plan metadata"),this.localReader.fetchPlanMetadata();let e=`${this.baseURL}/api/design-systems/${this.ffId}/processed-tokens`;try{process.env.FF_DEBUG&&console.log(` \u2192 Fetching plan metadata from saas app: ${e}`);let t=await this.fetchJson(e);if(t&&t.metadata){let s={planType:t.metadata.planType||"full",allowedComponents:t.metadata.allowedComponents||null};return process.env.FF_DEBUG&&console.log(` \u2192 Found plan metadata in saas app: ${s.planType}, allowed: ${s.allowedComponents?s.allowedComponents.length+" components":"all"}`),s}}catch(t){if(t.statusCode===404){process.env.FF_DEBUG&&console.log(" \u2192 ff-id not found in saas app, trying legacy server");let s=`${g}/${this.ffId}/metadata`;try{process.env.FF_DEBUG&&console.log(` \u2192 Fetching from legacy server: ${s}`);let o=await this.fetchJson(s),r={planType:o.planType||"full",allowedComponents:o.allowedComponents||null};return process.env.FF_DEBUG&&console.log(` \u2192 Found in legacy server: ${r.planType}, allowed: ${r.allowedComponents?r.allowedComponents.length+" components":"all"}`),r}catch(o){if(o.statusCode===404)return process.env.FF_DEBUG&&console.log(" \u2192 ff-id not found in any server - access denied"),{planType:"denied",allowedComponents:[],error:"Design system not found. Please ensure your ff-id is valid."};throw o}}throw t}}};H.exports={APIClient:R}});var he=require("https"),w=require("fs"),f=require("path"),{URL:je}=require("url"),Y=require("os"),F=process.env.FF_REGISTRY_URL||"https://ff-registry.up.railway.app",S=class{constructor(e={}){this.appRoot=e.appRoot||process.cwd(),this.framework=e.framework||this.detectFramework(),this.config=e.config||{},this.outputPath=e.outputPath||this.getDefaultOutputPath(),this.overwrite=e.overwrite||!1,this.downloadedComponents=new Set,this.ffId=this.config.ffId||this.config["ff-id"]||null,this.planMetadata=null}detectFramework(){let e=f.join(this.appRoot,"package.json");if(w.existsSync(e)){let t=JSON.parse(w.readFileSync(e,"utf8")),s={...t.dependencies,...t.devDependencies};if(s.vue)return"vue";if(s.react)return"react"}return"react"}getDefaultOutputPath(){if(this.config.aliases&&this.config.aliases.ui){let t=this.config.aliases.ui.replace(/^@\//,"");return f.join(this.appRoot,t)}return this.framework==="vue"?f.join(this.appRoot,"src/components/ui"):f.join(this.appRoot,"components/ui")}fetchJson(e){let t=process.env.FF_USE_LOCAL==="true",s=process.env.FF_USE_LOCAL_REGISTRY==="true",o=e.includes(F);if(t||s&&o){process.env.FF_DEBUG&&s&&!t&&console.log(" \u2192 Using local registry for components");let r=["../../packages/registry","../../../packages/registry","../../../../packages/registry",f.join(__dirname,"../../../registry"),"packages/registry"],n;for(let d of r){let U=f.isAbsolute(d)?d:f.join(process.cwd(),d);if(w.existsSync(U)){n=U;break}}if(!n)return Promise.reject(new Error(`Local registry not found. Tried paths: ${r.join(", ")}`));let a=e.replace(F,"").replace(/^\//,""),l=f.join(n,...a.split("/"));try{let d=w.readFileSync(l,"utf8");return Promise.resolve(JSON.parse(d))}catch(d){return d.code==="ENOENT"?Promise.reject(new Error("HTTP 404: Not Found")):Promise.reject(d)}}return new Promise((r,n)=>{he.get(e,a=>{let l="";if(a.statusCode>=400){n(new Error(`HTTP ${a.statusCode}: ${a.statusMessage}`));return}a.on("data",d=>{l+=d}),a.on("end",()=>{try{r(JSON.parse(l))}catch(d){n(new Error(`Invalid JSON response: ${d.message}`))}})}).on("error",a=>{n(a)})})}async getAllComponents(){try{let e=`${F}/components/${this.framework}/index.json`,s=(await this.fetchJson(e)).components||[];if(this.ffId){try{await this.isComponentAllowed("dummy")}catch{if(this.planMetadata&&this.planMetadata.planType==="denied")throw new Error(this.planMetadata.error||"Access denied. Your ff-id was not found in any server.")}this.planMetadata&&this.planMetadata.planType==="trial"&&this.planMetadata.allowedComponents&&(s=s.filter(o=>this.planMetadata.allowedComponents.includes(o)),process.env.FF_DEBUG&&console.log(` \u2192 Trial plan: filtering to ${s.length} allowed components`))}return s}catch(e){return console.error("Failed to fetch component index:",e.message),[]}}async getCustomComponents(){if(!this.ffId)return process.env.FF_DEBUG&&console.log(" \u2192 No ff-id found, skipping custom components"),[];try{let e=`${F}/custom/${this.ffId}/${this.framework}/index.json`;process.env.FF_DEBUG&&console.log(` \u2192 Fetching custom components from: ${e}`);let t=await this.fetchJson(e);return process.env.FF_DEBUG&&console.log(` \u2192 Found custom components: ${JSON.stringify(t.components)}`),t.components||[]}catch(e){return process.env.FF_DEBUG&&console.log(` \u2192 No custom components found: ${e.message}`),[]}}async downloadComponents(e){process.env.FF_DEBUG&&console.log(` \u2192 ComponentDownloader initialized with ff-id: ${this.ffId}`);let t={successful:[],failed:[],dependencies:new Set};for(let s of e)try{let o=await this.downloadComponent(s);t.successful.push(s),o.forEach(r=>t.dependencies.add(r))}catch(o){t.failed.push({component:s,error:o.message})}return{successful:t.successful,failed:t.failed,dependencies:Array.from(t.dependencies)}}async isComponentAllowed(e){if(!this.planMetadata&&this.ffId){let{APIClient:t}=V(),s=new t(this.ffId,{baseURL:this.config["api-url"]||this.config.apiUrl});try{this.planMetadata=await s.fetchPlanMetadata(),process.env.FF_DEBUG&&console.log(` \u2192 Fetched plan metadata: ${this.planMetadata.planType}, allowed: ${this.planMetadata.allowedComponents?this.planMetadata.allowedComponents.length+" components":"all"}`)}catch(o){console.warn("Failed to fetch plan metadata:",o.message),this.planMetadata={planType:"full",allowedComponents:null}}}if(this.planMetadata&&this.planMetadata.planType==="denied")throw new Error(this.planMetadata.error||"Access denied. Your ff-id was not found in any server.");return!this.planMetadata||this.planMetadata.planType==="full"?!0:this.planMetadata.planType==="trial"&&this.planMetadata.allowedComponents?this.planMetadata.allowedComponents.includes(e):!1}async downloadComponent(e){if(this.downloadedComponents.has(e))return[];if(process.env.FF_DEBUG&&(console.log(` \u2192 Checking if component "${e}" is allowed...`),console.log(` \u2192 FF-ID: ${this.ffId}`)),!await this.isComponentAllowed(e)){let n=`Component "${e}" is not available in your trial plan. Please upgrade to access all components.`;throw console.error(`\u274C ${n}`),new Error(n)}console.log(`\u{1F4E5} Downloading ${e}...`);let s,o=!1;if(this.ffId){let n=`${F}/custom/${this.ffId}/${this.framework}/${e}.json`;try{s=await this.fetchJson(n),o=!0,process.env.FF_DEBUG&&console.log(` \u2192 Found custom component for ${e}`)}catch{process.env.FF_DEBUG&&console.log(` \u2192 No custom component found for ${e}, trying standard`)}}if(!s){let n=`${F}/components/${this.framework}/${e}.json`;try{s=await this.fetchJson(n)}catch(a){throw a.message.includes("404")?new Error(`Component "${e}" not found`):new Error(`Failed to fetch ${e}: ${a.message}`)}}if(!s.files||!Array.isArray(s.files))throw new Error(`Invalid component data for ${e}`);for(let n of s.files)await this.writeComponentFile(n);this.downloadedComponents.add(e),console.log(` \u2713 ${e} downloaded${o&&process.env.FF_DEBUG?" (custom)":""}`);let r=[...s.dependencies||[]];if(s.registryDependencies&&s.registryDependencies.length>0){console.log(` \u{1F4E6} Installing registry dependencies: ${s.registryDependencies.join(", ")}`);for(let n of s.registryDependencies)try{(await this.downloadComponent(n)).forEach(l=>r.push(l))}catch(a){console.warn(` \u26A0\uFE0F Failed to download dependency ${n}: ${a.message}`)}}return r}async writeComponentFile(e){let t=e.name.split("/").join(f.sep),s=f.join(this.outputPath,t),o=f.dirname(s);if(w.existsSync(o)||w.mkdirSync(o,{recursive:!0}),w.existsSync(s)&&!this.overwrite){console.log(` \u26A0\uFE0F Skipping ${e.name} (already exists)`);return}let r=e.content;Y.EOL!==`
2
+ `&&(r=e.content.replace(/\n/g,Y.EOL)),w.writeFileSync(s,r,"utf8")}};module.exports={ComponentDownloader:S};
3
3
  //# sourceMappingURL=component-downloader.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../lib/core/constants.js", "../../../lib/core/errors.js", "../../../lib/core/file-utils.js", "../../../lib/core/path-utils.js", "../../../lib/core/local-token-reader.js", "../../../lib/core/api-client.js", "../../../lib/core/component-downloader.js"],
4
- "sourcesContent": ["/**\n * Configuration constants for FrontFriend Tailwind v2\n */\n\n// API Configuration\nconst DEFAULT_API_URL = 'https://app.frontfriend.dev';\nconst LEGACY_API_URL = 'https://tokens-studio-donux.up.railway.app/api';\n\n// Cache Configuration\nconst CACHE_DIR_NAME = '.cache/frontfriend';\nconst CACHE_TTL_DAYS = 7;\nconst CACHE_TTL_MS = CACHE_TTL_DAYS * 24 * 60 * 60 * 1000;\n\n// File names\nconst CACHE_FILES = {\n JS: [\n 'tokens.js',\n 'variables.js',\n 'semanticVariables.js',\n 'semanticDarkVariables.js',\n 'safelist.js',\n 'custom.js'\n ],\n JSON: [\n 'fonts.json',\n 'icons.json',\n 'components-config.json',\n 'version.json',\n 'metadata.json'\n ]\n};\n\n// Environment variables\nconst ENV_VARS = {\n FF_ID: 'FF_ID',\n FF_API_URL: 'FF_API_URL',\n FF_USE_LOCAL: 'FF_USE_LOCAL'\n};\n\nmodule.exports = {\n DEFAULT_API_URL,\n LEGACY_API_URL,\n CACHE_DIR_NAME,\n CACHE_TTL_DAYS,\n CACHE_TTL_MS,\n CACHE_FILES,\n ENV_VARS\n};", "class APIError extends Error {\n constructor(message, statusCode, url) {\n super(message);\n this.name = 'APIError';\n this.statusCode = statusCode;\n this.url = url;\n this.code = `API_${statusCode}`;\n }\n}\n\nclass CacheError extends Error {\n constructor(message, operation) {\n super(message);\n this.name = 'CacheError';\n this.operation = operation;\n this.code = `CACHE_${operation.toUpperCase()}`;\n }\n}\n\nclass ConfigError extends Error {\n constructor(message, field) {\n super(message);\n this.name = 'ConfigError';\n this.field = field;\n this.code = `CONFIG_${field.toUpperCase()}`;\n }\n}\n\nclass ProcessingError extends Error {\n constructor(message, token) {\n super(message);\n this.name = 'ProcessingError';\n this.token = token;\n this.code = 'PROCESSING_ERROR';\n }\n}\n\nmodule.exports = {\n APIError,\n CacheError,\n ConfigError,\n ProcessingError\n};", "const fs = require('fs');\n\n/**\n * Read a JSON file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the JSON file\n * @returns {Object|null} Parsed JSON or null if file not found\n * @throws {Error} If JSON is invalid\n */\nfunction readJsonFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n return JSON.parse(content);\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found, return null like API would return 404\n }\n throw error;\n }\n}\n\n/**\n * Read a file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the file\n * @returns {string|null} File content or null if file not found\n * @throws {Error} For other file system errors\n */\nfunction readFileSafe(filepath) {\n try {\n return fs.readFileSync(filepath, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found\n }\n throw error;\n }\n}\n\n/**\n * Write JSON data to a file with proper formatting\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to write\n * @param {number} indent - Indentation level (default: 2)\n */\nfunction writeJsonFile(filepath, data, indent = 2) {\n const content = JSON.stringify(data, null, indent);\n fs.writeFileSync(filepath, content, 'utf8');\n}\n\n/**\n * Write module.exports file with JSON data\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to export\n */\nfunction writeModuleExportsFile(filepath, data) {\n // Handle empty data cases\n if (data === null || data === undefined || \n (typeof data === 'object' && Object.keys(data).length === 0) ||\n (Array.isArray(data) && data.length === 0)) {\n const emptyContent = Array.isArray(data) ? '[]' : '{}';\n const content = `module.exports = ${emptyContent};`;\n fs.writeFileSync(filepath, content, 'utf8');\n } else {\n const content = `module.exports = ${JSON.stringify(data, null, 2)};`;\n fs.writeFileSync(filepath, content, 'utf8');\n }\n}\n\n/**\n * Check if a file exists\n * @param {string} filepath - Path to check\n * @returns {boolean} True if file exists\n */\nfunction fileExists(filepath) {\n return fs.existsSync(filepath);\n}\n\n/**\n * Create directory recursively\n * @param {string} dirpath - Directory path to create\n */\nfunction ensureDirectoryExists(dirpath) {\n fs.mkdirSync(dirpath, { recursive: true });\n}\n\n/**\n * Remove directory recursively\n * @param {string} dirpath - Directory path to remove\n */\nfunction removeDirectory(dirpath) {\n fs.rmSync(dirpath, { recursive: true, force: true });\n}\n\nmodule.exports = {\n readJsonFileSafe,\n readFileSafe,\n writeJsonFile,\n writeModuleExportsFile,\n fileExists,\n ensureDirectoryExists,\n removeDirectory\n};", "const path = require('path');\nconst { fileExists } = require('./file-utils');\n\n/**\n * Find a file by traversing up the directory tree\n * @param {string} filename - Name of the file to find\n * @param {string} startDir - Starting directory (defaults to cwd)\n * @returns {string|null} Full path to the file or null if not found\n */\nfunction findFileUpward(filename, startDir = process.cwd()) {\n let currentDir = startDir;\n \n while (currentDir !== path.parse(currentDir).root) {\n const filePath = path.join(currentDir, filename);\n \n if (fileExists(filePath)) {\n return filePath;\n }\n \n currentDir = path.dirname(currentDir);\n }\n \n return null;\n}\n\n/**\n * Find a directory by traversing up and checking multiple possible paths\n * @param {string} dirname - Name of the directory to find\n * @param {string} startDir - Starting directory (defaults to cwd)\n * @param {Function} validator - Optional function to validate the directory\n * @returns {string|null} Full path to the directory or null if not found\n */\nfunction findDirectoryUpward(dirname, startDir = process.cwd(), validator = null) {\n const possiblePaths = [];\n let currentDir = startDir;\n const maxLevels = 10; // Prevent infinite loop\n \n // Build list of possible paths\n for (let i = 0; i < maxLevels; i++) {\n // Direct path\n possiblePaths.push(path.join(currentDir, dirname));\n \n // Relative paths up to 3 levels\n if (i < 3) {\n possiblePaths.push(path.join(currentDir, '../'.repeat(i + 1) + dirname));\n }\n \n const parentDir = path.dirname(currentDir);\n if (parentDir === currentDir) break; // Reached root\n currentDir = parentDir;\n }\n \n // Also check from module directory (for when running from node_modules)\n possiblePaths.push(path.join(__dirname, '../../../', dirname));\n \n // Find first existing directory that passes validation\n for (const dirPath of possiblePaths) {\n if (fileExists(dirPath)) {\n if (!validator || validator(dirPath)) {\n return dirPath;\n }\n }\n }\n \n return null;\n}\n\n/**\n * Find a directory with multiple possible relative paths\n * @param {string[]} possiblePaths - Array of possible paths to check\n * @param {string} startDir - Starting directory (defaults to cwd)\n * @returns {string|null} Full path to the directory or null if not found\n */\nfunction findDirectoryWithPaths(possiblePaths, startDir = process.cwd()) {\n // Build absolute paths from the start directory\n const absolutePaths = possiblePaths.map(p => {\n if (path.isAbsolute(p)) {\n return p;\n }\n return path.join(startDir, p);\n });\n \n // Find first existing path\n for (const dirPath of absolutePaths) {\n if (fileExists(dirPath)) {\n return dirPath;\n }\n }\n \n return null;\n}\n\nmodule.exports = {\n findFileUpward,\n findDirectoryUpward,\n findDirectoryWithPaths\n};", "const path = require('path');\nconst { findDirectoryUpward } = require('./path-utils');\nconst { readJsonFileSafe, readFileSafe, fileExists } = require('./file-utils');\n\n/**\n * LocalTokenReader - Reads tokens directly from the local file system\n * Mimics the APIClient interface but reads from apps/tokens directory\n */\nclass LocalTokenReader {\n constructor(ffId, options = {}) {\n this.ffId = ffId;\n this.tokensBasePath = options.tokensBasePath || this.findTokensPath();\n this.folderMap = this.loadFolderMap();\n this.projectFolder = this.folderMap[ffId];\n \n if (!this.projectFolder) {\n throw new Error(`No folder mapping found for ff-id: ${ffId}`);\n }\n \n this.projectPath = path.join(this.tokensBasePath, this.projectFolder);\n }\n\n /**\n * Find the tokens directory by looking for apps/tokens in parent directories\n */\n findTokensPath() {\n // Try to find apps/tokens first\n let tokensPath = findDirectoryUpward('apps/tokens', process.cwd(), (dir) => {\n return fileExists(path.join(dir, 'folderMap.json'));\n });\n \n // If not found, try just 'tokens'\n if (!tokensPath) {\n tokensPath = findDirectoryUpward('tokens', process.cwd(), (dir) => {\n return fileExists(path.join(dir, 'folderMap.json'));\n });\n }\n \n if (!tokensPath) {\n throw new Error('Could not find tokens directory with folderMap.json');\n }\n \n return tokensPath;\n }\n\n /**\n * Load the folder mapping from folderMap.json\n */\n loadFolderMap() {\n const folderMapPath = path.join(this.tokensBasePath, 'folderMap.json');\n const folderMap = readJsonFileSafe(folderMapPath);\n \n if (!folderMap) {\n throw new Error(`Failed to load folderMap.json: File not found`);\n }\n \n return folderMap;\n }\n\n /**\n * Fetch all token files (global, colors, semantic)\n * Mimics the APIClient.fetchTokens() method\n */\n async fetchTokens() {\n const figmaPath = path.join(this.projectPath, 'figma');\n \n // Try different possible paths for tokens\n const tokenPaths = {\n global: [\n path.join(figmaPath, 'Global Tokens', 'Default.json'),\n path.join(figmaPath, 'global.json')\n ],\n colors: [\n path.join(figmaPath, 'Global Colors', 'Default.json'),\n path.join(figmaPath, 'Global Colors', 'Light.json')\n ],\n semantic: [\n path.join(figmaPath, 'Semantic', 'Light.json'),\n path.join(figmaPath, 'Semantic', 'Default.json')\n ],\n semanticDark: [\n path.join(figmaPath, 'Semantic', 'Dark.json')\n ]\n };\n\n const results = {};\n \n // Try each possible path for each token type\n for (const [key, paths] of Object.entries(tokenPaths)) {\n for (const tokenPath of paths) {\n const content = readJsonFileSafe(tokenPath);\n if (content !== null) {\n results[key] = content;\n break; // Found it, no need to try other paths\n }\n }\n // If not found in any path, set to null\n if (!results[key]) {\n results[key] = null;\n }\n }\n\n return results;\n }\n\n /**\n * Fetch pre-processed tokens (if available in cache folder)\n */\n async fetchProcessedTokens() {\n const cachePath = path.join(this.projectPath, 'cache');\n \n if (!fileExists(cachePath)) {\n return null;\n }\n\n // Read all the cache files that would be in processed tokens\n const cacheFiles = {\n 'tokens.js': 'hashedTokens.js',\n 'variables.js': 'hashedVariables.js', \n 'semanticVariables.js': 'hashedSemanticVariables.js',\n 'semanticDarkVariables.js': 'hashedSemanticDarkVariables.js',\n 'safelist.js': 'safelist.js',\n 'custom.js': 'custom.js',\n 'fonts.json': 'fonts.json',\n 'icons.json': 'icons.json',\n 'components-config.json': 'encoded-config.json',\n 'version.json': 'version.json'\n };\n\n const processedData = {};\n \n for (const [key, fileName] of Object.entries(cacheFiles)) {\n const filePath = path.join(cachePath, fileName);\n if (key.endsWith('.js')) {\n processedData[key] = readFileSafe(filePath);\n } else {\n processedData[key] = readJsonFileSafe(filePath);\n }\n }\n\n // Only return if we have at least some data\n const hasData = Object.values(processedData).some(val => val !== null);\n return hasData ? processedData : null;\n }\n\n /**\n * Fetch components configuration\n */\n async fetchComponentsConfig() {\n return readJsonFileSafe(path.join(this.projectPath, 'components-config.json'));\n }\n\n /**\n * Fetch fonts configuration\n */\n async fetchFonts() {\n return readJsonFileSafe(path.join(this.projectPath, 'font.json'));\n }\n\n /**\n * Fetch icons configuration\n */\n async fetchIcons() {\n return readJsonFileSafe(path.join(this.projectPath, 'icons.json'));\n }\n\n /**\n * Fetch version information\n */\n async fetchVersion() {\n return readJsonFileSafe(path.join(this.projectPath, 'version.json'));\n }\n\n /**\n * Fetch custom CSS\n */\n async fetchCustomCss() {\n return readFileSafe(path.join(this.projectPath, 'custom.css'));\n }\n\n /**\n * Fetch plan metadata\n */\n async fetchPlanMetadata() {\n const metadata = readJsonFileSafe(path.join(this.projectPath, 'metadata.json'));\n \n // Default to full plan if no metadata exists\n return metadata || {\n planType: 'full',\n allowedComponents: null\n };\n }\n\n // Compatibility methods to match APIClient interface\n fetchJson() {\n throw new Error('fetchJson is not implemented in LocalTokenReader. Use specific fetch methods.');\n }\n\n fetchRaw() {\n throw new Error('fetchRaw is not implemented in LocalTokenReader. Use specific fetch methods.');\n }\n}\n\nmodule.exports = { LocalTokenReader };", "const https = require('https');\nconst http = require('http');\nconst { URL } = require('url');\nconst { DEFAULT_API_URL, LEGACY_API_URL, ENV_VARS } = require('./constants');\nconst { APIError } = require('./errors');\nconst { LocalTokenReader } = require('./local-token-reader');\n\nclass APIClient {\n constructor(ffId, options = {}) {\n this.ffId = ffId;\n this.baseURL = options.baseURL || process.env[ENV_VARS.FF_API_URL] || DEFAULT_API_URL;\n \n // Check if we should use local token reader\n if (process.env[ENV_VARS.FF_USE_LOCAL] === 'true') {\n console.log(' \uD83C\uDFE0 Using local token reader');\n this.localReader = new LocalTokenReader(ffId, options);\n }\n }\n\n /**\n * Fetch JSON data from a URL using native https module\n * @param {string} url - The URL to fetch\n * @returns {Promise<any>} Parsed JSON data\n */\n fetchJson(url) {\n return new Promise((resolve, reject) => {\n // Determine if we should use http or https\n const protocol = url.startsWith('https') ? https : http;\n \n protocol.get(url, (response) => {\n let data = '';\n \n // Check for HTTP errors\n if (response.statusCode >= 400) {\n reject(new APIError(\n `HTTP ${response.statusCode}: ${response.statusMessage}`,\n response.statusCode,\n url\n ));\n return;\n }\n\n // Collect response chunks\n response.on('data', (chunk) => {\n data += chunk;\n });\n\n // Parse JSON when complete\n response.on('end', () => {\n try {\n const parsed = JSON.parse(data);\n resolve(parsed);\n } catch (error) {\n reject(new APIError(\n `Invalid JSON response: ${error.message}`,\n response.statusCode,\n url\n ));\n }\n });\n\n // Handle response errors\n response.on('error', (error) => {\n reject(new APIError(\n `Response error: ${error.message}`,\n response.statusCode,\n url\n ));\n });\n }).on('error', (error) => {\n // Handle network errors\n reject(new APIError(\n `Network error: ${error.message}`,\n 0,\n url\n ));\n });\n });\n }\n\n /**\n * Fetch raw content from a URL\n * @param {string} url - The URL to fetch\n * @returns {Promise<string>} Raw text content\n */\n fetchRaw(url) {\n return new Promise((resolve, reject) => {\n // Determine if we should use http or https\n const protocol = url.startsWith('https') ? https : http;\n \n protocol.get(url, (response) => {\n let data = '';\n \n // Check for HTTP errors\n if (response.statusCode >= 400) {\n reject(new APIError(\n `HTTP ${response.statusCode}: ${response.statusMessage}`,\n response.statusCode,\n url\n ));\n return;\n }\n\n // Collect response chunks\n response.on('data', (chunk) => {\n data += chunk;\n });\n\n // Return raw data when complete\n response.on('end', () => {\n resolve(data);\n });\n\n // Handle response errors\n response.on('error', (error) => {\n reject(new APIError(\n `Response error: ${error.message}`,\n response.statusCode,\n url\n ));\n });\n }).on('error', (error) => {\n // Handle network errors\n reject(new APIError(\n `Network error: ${error.message}`,\n 0,\n url\n ));\n });\n });\n }\n\n /**\n * Fetch all token files (global, colors, semantic)\n * @returns {Promise<Object>} Object with all token data\n */\n async fetchTokens() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchTokens();\n }\n \n // First try the new design system endpoint\n try {\n const designSystemUrl = `${this.baseURL}/api/design-systems/${this.ffId}/tokens`;\n const tokensData = await this.fetchJson(designSystemUrl);\n \n // If we have the new format, parse it\n if (tokensData && tokensData.tokens) {\n const tokens = tokensData.tokens;\n \n // Extract specific token sets from the new format\n return {\n global: tokens['Global Tokens/Default'] || tokens['global'] || null,\n colors: tokens['Global Colors/Default'] || tokens['colors'] || null,\n semantic: tokens['Semantic/Light'] || tokens['semantic/light'] || null,\n semanticDark: tokens['Semantic/Dark'] || tokens['semantic/dark'] || null\n };\n }\n } catch (err) {\n // If design system is not synced (400 error), throw with clear message\n if (err.statusCode === 400) {\n throw new APIError(\n 'Design system not synced with Figma. Please sync tokens from Figma before using this design system.',\n 400,\n `${this.baseURL}/api/design-systems/${this.ffId}/tokens`\n );\n }\n // Failed to fetch from design system endpoint, falling back to legacy URLs\n }\n \n // Fall back to legacy token URLs\n // Use legacy API URL for backward compatibility\n const legacyBaseURL = LEGACY_API_URL;\n const urls = {\n global: `${legacyBaseURL}/${this.ffId}/global-tokens/default.json`,\n colors: `${legacyBaseURL}/${this.ffId}/global-colors/default.json`,\n semantic: `${legacyBaseURL}/${this.ffId}/semantic/light.json`,\n semanticDark: `${legacyBaseURL}/${this.ffId}/semantic/dark.json`\n };\n\n const results = await Promise.all([\n this.fetchJson(urls.global).catch(err => err.statusCode === 404 ? null : Promise.reject(err)),\n this.fetchJson(urls.colors).catch(err => err.statusCode === 404 ? null : Promise.reject(err)),\n this.fetchJson(urls.semantic).catch(err => err.statusCode === 404 ? null : Promise.reject(err)),\n this.fetchJson(urls.semanticDark).catch(err => err.statusCode === 404 ? null : Promise.reject(err))\n ]);\n\n return {\n global: results[0],\n colors: results[1],\n semantic: results[2],\n semanticDark: results[3]\n };\n }\n\n /**\n * Fetch pre-processed tokens from the design system endpoint\n * @returns {Promise<Object|null>} Processed tokens ready for caching or null if not found\n */\n async fetchProcessedTokens() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchProcessedTokens();\n }\n \n const processedUrl = `${this.baseURL}/api/design-systems/${this.ffId}/processed-tokens`;\n try {\n return await this.fetchJson(processedUrl);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n // If design system is not synced (400 error), throw with clear message\n if (error.statusCode === 400) {\n throw new APIError(\n 'Design system not synced with Figma. Please sync tokens from Figma before using this design system.',\n 400,\n processedUrl\n );\n }\n throw error;\n }\n }\n\n /**\n * Fetch components configuration\n * @returns {Promise<Object|null>} Components config or null if not found\n */\n async fetchComponentsConfig() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchComponentsConfig();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/components-config.json`;\n try {\n return await this.fetchJson(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch fonts configuration\n * @returns {Promise<Object|null>} Fonts object with font1, font2, etc. URLs or null\n */\n async fetchFonts() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchFonts();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/font.json`;\n try {\n return await this.fetchJson(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch icons configuration\n * @returns {Promise<Object|null>} Icons data or null if not found\n */\n async fetchIcons() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchIcons();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/icons.json`;\n try {\n return await this.fetchJson(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch version information\n * @returns {Promise<Object|null>} Version data or null if not found\n */\n async fetchVersion() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchVersion();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/version.json`;\n try {\n return await this.fetchJson(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch custom CSS\n * @returns {Promise<string|null>} Custom CSS string or null if not found\n */\n async fetchCustomCss() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchCustomCss();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/custom.css`;\n try {\n return await this.fetchRaw(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch plan metadata (plan type and allowed components)\n * @returns {Promise<Object|null>} Plan metadata or null if not found\n */\n async fetchPlanMetadata() {\n // Use local reader if available\n if (this.localReader) {\n if (process.env.FF_DEBUG) {\n console.log(' \u2192 Using local reader for plan metadata');\n }\n return this.localReader.fetchPlanMetadata();\n }\n \n // First try the saas app (processed-tokens endpoint) - this is the authoritative source\n const processedUrl = `${this.baseURL}/api/design-systems/${this.ffId}/processed-tokens`;\n try {\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Fetching plan metadata from saas app: ${processedUrl}`);\n }\n \n const processedData = await this.fetchJson(processedUrl);\n \n // Extract metadata from processed tokens response\n if (processedData && processedData.metadata) {\n const metadata = {\n planType: processedData.metadata.planType || 'full',\n allowedComponents: processedData.metadata.allowedComponents || null\n };\n \n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Found plan metadata in saas app: ${metadata.planType}, allowed: ${metadata.allowedComponents ? metadata.allowedComponents.length + ' components' : 'all'}`);\n }\n \n return metadata;\n }\n } catch (saasError) {\n // If not found in saas app, try legacy server\n if (saasError.statusCode === 404) {\n if (process.env.FF_DEBUG) {\n console.log(' \u2192 ff-id not found in saas app, trying legacy server');\n }\n \n // Try legacy tokens server (these are always full plan - no trial concept)\n const tokensUrl = `${LEGACY_API_URL}/${this.ffId}/metadata`;\n try {\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Fetching from legacy server: ${tokensUrl}`);\n }\n const legacyMetadata = await this.fetchJson(tokensUrl);\n \n // Use the plan metadata from legacy server if available\n const metadata = {\n planType: legacyMetadata.planType || 'full',\n allowedComponents: legacyMetadata.allowedComponents || null\n };\n \n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Found in legacy server: ${metadata.planType}, allowed: ${metadata.allowedComponents ? metadata.allowedComponents.length + ' components' : 'all'}`);\n }\n \n return metadata;\n } catch (legacyError) {\n if (legacyError.statusCode === 404) {\n // Not found in either place - DENY access\n if (process.env.FF_DEBUG) {\n console.log(' \u2192 ff-id not found in any server - access denied');\n }\n \n // Return a denied plan type instead of defaulting to full\n return {\n planType: 'denied',\n allowedComponents: [],\n error: 'Design system not found. Please ensure your ff-id is valid.'\n };\n }\n throw legacyError;\n }\n }\n throw saasError;\n }\n }\n}\n\nmodule.exports = { APIClient };", "const https = require('https');\nconst fs = require('fs');\nconst path = require('path');\nconst { URL } = require('url');\nconst os = require('os');\n\nconst REGISTRY_URL = process.env.FF_REGISTRY_URL || 'https://ff-registry.up.railway.app';\n\nclass ComponentDownloader {\n constructor(options = {}) {\n this.appRoot = options.appRoot || process.cwd();\n this.framework = options.framework || this.detectFramework();\n this.config = options.config || {};\n this.outputPath = options.outputPath || this.getDefaultOutputPath();\n this.overwrite = options.overwrite || false;\n this.downloadedComponents = new Set();\n this.ffId = this.config.ffId || this.config['ff-id'] || null;\n this.planMetadata = null; // Will be populated when needed\n }\n\n /**\n * Detect framework from package.json\n */\n detectFramework() {\n const packageJsonPath = path.join(this.appRoot, 'package.json');\n \n if (fs.existsSync(packageJsonPath)) {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));\n const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };\n \n if (deps.vue) {\n return 'vue';\n } else if (deps.react) {\n return 'react';\n }\n }\n \n // Default to React if can't detect\n return 'react';\n }\n\n /**\n * Get default output path based on framework and config\n */\n getDefaultOutputPath() {\n // Check if config has ui alias\n if (this.config.aliases && this.config.aliases.ui) {\n const uiAlias = this.config.aliases.ui;\n // Convert alias to actual path (e.g., @/components/ui -> components/ui)\n const cleanPath = uiAlias.replace(/^@\\//, '');\n return path.join(this.appRoot, cleanPath);\n }\n \n // Fallback to default paths\n if (this.framework === 'vue') {\n return path.join(this.appRoot, 'src/components/ui');\n }\n return path.join(this.appRoot, 'components/ui');\n }\n\n /**\n * Fetch JSON from URL or local file\n */\n fetchJson(url) {\n // Check if using local mode at runtime\n // FF_USE_LOCAL: affects both tokens and components\n // FF_USE_LOCAL_REGISTRY: affects only components (for registry URLs)\n const USE_LOCAL = process.env.FF_USE_LOCAL === 'true';\n const USE_LOCAL_REGISTRY = process.env.FF_USE_LOCAL_REGISTRY === 'true';\n \n // Check if this is a registry URL\n const isRegistryUrl = url.includes(REGISTRY_URL);\n \n // Use local file system if:\n // 1. FF_USE_LOCAL is set (affects everything), OR\n // 2. FF_USE_LOCAL_REGISTRY is set AND this is a registry URL\n if (USE_LOCAL || (USE_LOCAL_REGISTRY && isRegistryUrl)) {\n if (process.env.FF_DEBUG && USE_LOCAL_REGISTRY && !USE_LOCAL) {\n console.log(' \u2192 Using local registry for components');\n }\n \n // Try multiple paths to find the registry\n const possiblePaths = [\n '../../packages/registry',\n '../../../packages/registry',\n '../../../../packages/registry',\n path.join(__dirname, '../../../registry'),\n 'packages/registry'\n ];\n \n let registryPath;\n for (const p of possiblePaths) {\n const fullPath = path.isAbsolute(p) ? p : path.join(process.cwd(), p);\n if (fs.existsSync(fullPath)) {\n registryPath = fullPath;\n break;\n }\n }\n \n if (!registryPath) {\n return Promise.reject(new Error(`Local registry not found. Tried paths: ${possiblePaths.join(', ')}`));\n }\n \n // Extract the path from the URL and construct proper local path\n const urlPath = url.replace(REGISTRY_URL, '').replace(/^\\//, '');\n const localPath = path.join(registryPath, ...urlPath.split('/'));\n \n try {\n const content = fs.readFileSync(localPath, 'utf8');\n return Promise.resolve(JSON.parse(content));\n } catch (error) {\n if (error.code === 'ENOENT') {\n return Promise.reject(new Error('HTTP 404: Not Found'));\n }\n return Promise.reject(error);\n }\n }\n\n return new Promise((resolve, reject) => {\n https.get(url, (response) => {\n let data = '';\n \n if (response.statusCode >= 400) {\n reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));\n return;\n }\n\n response.on('data', (chunk) => {\n data += chunk;\n });\n\n response.on('end', () => {\n try {\n resolve(JSON.parse(data));\n } catch (error) {\n reject(new Error(`Invalid JSON response: ${error.message}`));\n }\n });\n\n }).on('error', (error) => {\n reject(error);\n });\n });\n }\n\n /**\n * Get all available components from registry\n */\n async getAllComponents() {\n try {\n const url = `${REGISTRY_URL}/components/${this.framework}/index.json`;\n const index = await this.fetchJson(url);\n let components = index.components || [];\n \n // Filter components based on plan\n if (this.ffId) {\n // Ensure plan metadata is loaded\n try {\n await this.isComponentAllowed('dummy'); // This will load metadata\n } catch (error) {\n // If access is denied, throw error\n if (this.planMetadata && this.planMetadata.planType === 'denied') {\n throw new Error(this.planMetadata.error || 'Access denied. Your ff-id was not found in any server.');\n }\n }\n \n if (this.planMetadata && this.planMetadata.planType === 'trial' && this.planMetadata.allowedComponents) {\n components = components.filter(comp => this.planMetadata.allowedComponents.includes(comp));\n \n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Trial plan: filtering to ${components.length} allowed components`);\n }\n }\n }\n \n return components;\n } catch (error) {\n console.error('Failed to fetch component index:', error.message);\n return [];\n }\n }\n\n /**\n * Get all custom components for this ff-id\n */\n async getCustomComponents() {\n if (!this.ffId) {\n if (process.env.FF_DEBUG) {\n console.log(' \u2192 No ff-id found, skipping custom components');\n }\n return [];\n }\n \n try {\n const url = `${REGISTRY_URL}/custom/${this.ffId}/${this.framework}/index.json`;\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Fetching custom components from: ${url}`);\n }\n const index = await this.fetchJson(url);\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Found custom components: ${JSON.stringify(index.components)}`);\n }\n return index.components || [];\n } catch (error) {\n // Custom components might not exist, that's ok\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 No custom components found: ${error.message}`);\n }\n return [];\n }\n }\n\n /**\n * Download multiple components\n */\n async downloadComponents(components) {\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 ComponentDownloader initialized with ff-id: ${this.ffId}`);\n }\n \n const results = {\n successful: [],\n failed: [],\n dependencies: new Set()\n };\n\n for (const component of components) {\n try {\n const deps = await this.downloadComponent(component);\n results.successful.push(component);\n \n // Add dependencies\n deps.forEach(dep => results.dependencies.add(dep));\n } catch (error) {\n results.failed.push({\n component,\n error: error.message\n });\n }\n }\n\n return {\n successful: results.successful,\n failed: results.failed,\n dependencies: Array.from(results.dependencies)\n };\n }\n\n /**\n * Check if component is allowed based on plan\n */\n async isComponentAllowed(componentName) {\n // Fetch plan metadata if not already loaded\n if (!this.planMetadata && this.ffId) {\n const { APIClient } = require('./api-client');\n const apiClient = new APIClient(this.ffId, {\n baseURL: this.config['api-url'] || this.config.apiUrl\n });\n try {\n this.planMetadata = await apiClient.fetchPlanMetadata();\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Fetched plan metadata: ${this.planMetadata.planType}, allowed: ${this.planMetadata.allowedComponents ? this.planMetadata.allowedComponents.length + ' components' : 'all'}`);\n }\n } catch (error) {\n console.warn('Failed to fetch plan metadata:', error.message);\n // Default to full plan if we can't fetch metadata\n this.planMetadata = { planType: 'full', allowedComponents: null };\n }\n }\n\n // Handle denied plan (ff-id not found anywhere)\n if (this.planMetadata && this.planMetadata.planType === 'denied') {\n throw new Error(this.planMetadata.error || 'Access denied. Your ff-id was not found in any server.');\n }\n \n // If full plan or no metadata, allow all components\n if (!this.planMetadata || this.planMetadata.planType === 'full') {\n return true;\n }\n\n // For trial plan, check if component is in allowed list\n if (this.planMetadata.planType === 'trial' && this.planMetadata.allowedComponents) {\n return this.planMetadata.allowedComponents.includes(componentName);\n }\n\n // Default to denying if we can't determine (safer)\n return false;\n }\n\n /**\n * Download a single component and its registry dependencies\n */\n async downloadComponent(componentName) {\n // Avoid downloading the same component twice\n if (this.downloadedComponents.has(componentName)) {\n return [];\n }\n\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Checking if component \"${componentName}\" is allowed...`);\n console.log(` \u2192 FF-ID: ${this.ffId}`);\n }\n\n // Check if component is allowed based on plan\n const isAllowed = await this.isComponentAllowed(componentName);\n if (!isAllowed) {\n const errorMsg = `Component \"${componentName}\" is not available in your trial plan. Please upgrade to access all components.`;\n console.error(`\u274C ${errorMsg}`);\n throw new Error(errorMsg);\n }\n\n console.log(`\uD83D\uDCE5 Downloading ${componentName}...`);\n\n // Try to fetch from custom components first if ff-id is available\n let componentData;\n let isCustom = false;\n \n if (this.ffId) {\n const customUrl = `${REGISTRY_URL}/custom/${this.ffId}/${this.framework}/${componentName}.json`;\n try {\n componentData = await this.fetchJson(customUrl);\n isCustom = true;\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Found custom component for ${componentName}`);\n }\n } catch (error) {\n // Custom component not found, try standard registry\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 No custom component found for ${componentName}, trying standard`);\n }\n }\n }\n \n // If not found in custom, try standard registry\n if (!componentData) {\n const url = `${REGISTRY_URL}/components/${this.framework}/${componentName}.json`;\n \n try {\n componentData = await this.fetchJson(url);\n } catch (error) {\n // Check if it's a 404 (component not found)\n if (error.message.includes('404')) {\n throw new Error(`Component \"${componentName}\" not found`);\n }\n throw new Error(`Failed to fetch ${componentName}: ${error.message}`);\n }\n }\n\n // Validate component data\n if (!componentData.files || !Array.isArray(componentData.files)) {\n throw new Error(`Invalid component data for ${componentName}`);\n }\n\n // Write component files\n for (const file of componentData.files) {\n await this.writeComponentFile(file);\n }\n\n this.downloadedComponents.add(componentName);\n console.log(` \u2713 ${componentName} downloaded${isCustom && process.env.FF_DEBUG ? ' (custom)' : ''}`);\n\n // Download registry dependencies\n const allDependencies = [...(componentData.dependencies || [])];\n \n if (componentData.registryDependencies && componentData.registryDependencies.length > 0) {\n console.log(` \uD83D\uDCE6 Installing registry dependencies: ${componentData.registryDependencies.join(', ')}`);\n \n for (const dep of componentData.registryDependencies) {\n try {\n const depDeps = await this.downloadComponent(dep);\n depDeps.forEach(d => allDependencies.push(d));\n } catch (error) {\n console.warn(` \u26A0\uFE0F Failed to download dependency ${dep}: ${error.message}`);\n }\n }\n }\n\n return allDependencies;\n }\n\n /**\n * Write component file to disk\n */\n async writeComponentFile(file) {\n // Normalize the file path for the current platform\n // Convert forward slashes to the platform-specific separator\n const normalizedFileName = file.name.split('/').join(path.sep);\n const filePath = path.join(this.outputPath, normalizedFileName);\n const dir = path.dirname(filePath);\n\n // Create directory if it doesn't exist\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n\n // Check if file exists and overwrite setting\n if (fs.existsSync(filePath) && !this.overwrite) {\n console.log(` \u26A0\uFE0F Skipping ${file.name} (already exists)`);\n return;\n }\n\n // Normalize line endings to match the platform\n // This prevents git from showing every line as changed\n let normalizedContent = file.content;\n if (os.EOL !== '\\n') {\n // On Windows, replace LF with CRLF\n normalizedContent = file.content.replace(/\\n/g, os.EOL);\n }\n\n // Write file\n fs.writeFileSync(fileP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L,KAAOK,EAAc,qBAC9B,GAAI,EACc,MAAM,KAAK,kBAAkBL,CAAG,GACxC,QAAQU,GAAKD,EAAgB,KAAKC,CAAC,CAAC,CAC9C,OAASrB,EAAO,CACd,QAAQ,KAAK,kDAAwCW,CAAG,KAAKX,EAAM,OAAO,EAAE,CAC9E,CAEJ,CAEA,OAAOoB,CACT,CAKA,MAAM,mBAAmBD,EAAM,CAG7B,IAAMG,EAAqBH,EAAK,KAAK,MAAM,GAAG,EAAE,KAAKxC,EAAK,GAAG,EACvD4C,EAAW5C,EAAK,KAAK,KAAK,WAAY2C,CAAkB,EACxDE,EAAM7C,EAAK,QAAQ4C,CAAQ,EAQjC,GALK7C,EAAG,WAAW8C,CAAG,GACpB9C,EAAG,UAAU8C,EAAK,CAAE,UAAW,EAAK,CAAC,EAInC9C,EAAG,WAAW6C,CAAQ,GAAK,CAAC,KAAK,UAAW,CAC9C,QAAQ,IAAI,6BAAmBJ,EAAK,IAAI,mBAAmB,EAC3D,MACF,CAIA,IAAIM,EAAoBN,EAAK,QACzBtC,EAAG,MAAQ;AAAA,IAEb4C,EAAoBN,EAAK,QAAQ,QAAQ,MAAOtC,EAAG,GAAG,GAIxDH,EAAG,cAAc6C,EAAUE,EAAmB,MAAM,CACtD,CACF,EAEA,OAAO,QAAU,CAAE,oBAAA1C,CAAoB",
6
- "names": ["require_constants", "__commonJSMin", "exports", "module", "DEFAULT_API_URL", "LEGACY_API_URL", "CACHE_DIR_NAME", "CACHE_FILES", "ENV_VARS", "require_errors", "__commonJSMin", "exports", "module", "APIError", "message", "statusCode", "url", "CacheError", "operation", "ConfigError", "field", "ProcessingError", "token", "require_file_utils", "__commonJSMin", "exports", "module", "fs", "readJsonFileSafe", "filepath", "content", "error", "readFileSafe", "writeJsonFile", "data", "indent", "writeModuleExportsFile", "fileExists", "ensureDirectoryExists", "dirpath", "removeDirectory", "require_path_utils", "__commonJSMin", "exports", "module", "path", "fileExists", "findFileUpward", "filename", "startDir", "currentDir", "filePath", "findDirectoryUpward", "dirname", "validator", "possiblePaths", "maxLevels", "i", "parentDir", "dirPath", "findDirectoryWithPaths", "absolutePaths", "p", "require_local_token_reader", "__commonJSMin", "exports", "module", "path", "findDirectoryUpward", "readJsonFileSafe", "readFileSafe", "fileExists", "LocalTokenReader", "ffId", "options", "tokensPath", "dir", "folderMapPath", "folderMap", "figmaPath", "tokenPaths", "results", "key", "paths", "tokenPath", "content", "cachePath", "cacheFiles", "processedData", "fileName", "filePath", "val", "require_api_client", "__commonJSMin", "exports", "module", "https", "http", "URL", "DEFAULT_API_URL", "LEGACY_API_URL", "ENV_VARS", "APIError", "LocalTokenReader", "APIClient", "ffId", "options", "url", "resolve", "reject", "response", "data", "chunk", "parsed", "error", "designSystemUrl", "tokensData", "tokens", "err", "legacyBaseURL", "urls", "results", "processedUrl", "processedData", "metadata", "saasError", "tokensUrl", "legacyMetadata", "legacyError", "https", "fs", "path", "URL", "os", "REGISTRY_URL", "ComponentDownloader", "options", "packageJsonPath", "packageJson", "deps", "cleanPath", "url", "USE_LOCAL", "USE_LOCAL_REGISTRY", "isRegistryUrl", "possiblePaths", "registryPath", "p", "fullPath", "urlPath", "localPath", "content", "error", "resolve", "reject", "response", "data", "chunk", "components", "comp", "index", "results", "component", "dep", "componentName", "APIClient", "apiClient", "errorMsg", "componentData", "isCustom", "customUrl", "file", "allDependencies", "d", "normalizedFileName", "filePath", "dir", "normalizedContent"]
4
+ "sourcesContent": ["/**\n * Configuration constants for FrontFriend Tailwind v2\n */\n\n// API Configuration\nconst DEFAULT_API_URL = 'https://app.frontfriend.dev';\nconst LEGACY_API_URL = 'https://tokens-studio-donux.up.railway.app/api';\n\n// Cache Configuration\nconst CACHE_DIR_NAME = '.cache/frontfriend';\nconst CACHE_TTL_DAYS = 7;\nconst CACHE_TTL_MS = CACHE_TTL_DAYS * 24 * 60 * 60 * 1000;\n\n// File names\nconst CACHE_FILES = {\n JS: [\n 'tokens.js',\n 'variables.js',\n 'semanticVariables.js',\n 'semanticDarkVariables.js',\n 'safelist.js',\n 'custom.js'\n ],\n JSON: [\n 'fonts.json',\n 'icons.json',\n 'components-config.json',\n 'version.json',\n 'metadata.json'\n ]\n};\n\n// Environment variables\nconst ENV_VARS = {\n FF_ID: 'FF_ID',\n FF_API_URL: 'FF_API_URL',\n FF_USE_LOCAL: 'FF_USE_LOCAL'\n};\n\nmodule.exports = {\n DEFAULT_API_URL,\n LEGACY_API_URL,\n CACHE_DIR_NAME,\n CACHE_TTL_DAYS,\n CACHE_TTL_MS,\n CACHE_FILES,\n ENV_VARS\n};", "class APIError extends Error {\n constructor(message, statusCode, url) {\n super(message);\n this.name = 'APIError';\n this.statusCode = statusCode;\n this.url = url;\n this.code = `API_${statusCode}`;\n }\n}\n\nclass CacheError extends Error {\n constructor(message, operation) {\n super(message);\n this.name = 'CacheError';\n this.operation = operation;\n this.code = `CACHE_${operation.toUpperCase()}`;\n }\n}\n\nclass ConfigError extends Error {\n constructor(message, field) {\n super(message);\n this.name = 'ConfigError';\n this.field = field;\n this.code = `CONFIG_${field.toUpperCase()}`;\n }\n}\n\nclass ProcessingError extends Error {\n constructor(message, token) {\n super(message);\n this.name = 'ProcessingError';\n this.token = token;\n this.code = 'PROCESSING_ERROR';\n }\n}\n\nmodule.exports = {\n APIError,\n CacheError,\n ConfigError,\n ProcessingError\n};", "const fs = require('fs');\n\n/**\n * Read a JSON file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the JSON file\n * @returns {Object|null} Parsed JSON or null if file not found\n * @throws {Error} If JSON is invalid\n */\nfunction readJsonFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n return JSON.parse(content);\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found, return null like API would return 404\n }\n throw error;\n }\n}\n\n/**\n * Read a file safely, returning null if file doesn't exist\n * Strips UTF-8 BOM if present (fixes Windows compatibility)\n * @param {string} filepath - Path to the file\n * @returns {string|null} File content or null if file not found\n * @throws {Error} For other file system errors\n */\nfunction readFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n // Strip UTF-8 BOM if present (Windows compatibility)\n return content.replace(/^\\uFEFF/, '');\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found\n }\n throw error;\n }\n}\n\n/**\n * Write JSON data to a file with proper formatting\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to write\n * @param {number} indent - Indentation level (default: 2)\n */\nfunction writeJsonFile(filepath, data, indent = 2) {\n const content = JSON.stringify(data, null, indent);\n fs.writeFileSync(filepath, content, 'utf8');\n}\n\n/**\n * Write module.exports file with JSON data\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to export\n */\nfunction writeModuleExportsFile(filepath, data) {\n // Handle empty data cases\n if (data === null || data === undefined || \n (typeof data === 'object' && Object.keys(data).length === 0) ||\n (Array.isArray(data) && data.length === 0)) {\n const emptyContent = Array.isArray(data) ? '[]' : '{}';\n const content = `module.exports = ${emptyContent};`;\n fs.writeFileSync(filepath, content, 'utf8');\n } else {\n const content = `module.exports = ${JSON.stringify(data, null, 2)};`;\n fs.writeFileSync(filepath, content, 'utf8');\n }\n}\n\n/**\n * Check if a file exists\n * @param {string} filepath - Path to check\n * @returns {boolean} True if file exists\n */\nfunction fileExists(filepath) {\n return fs.existsSync(filepath);\n}\n\n/**\n * Create directory recursively\n * @param {string} dirpath - Directory path to create\n */\nfunction ensureDirectoryExists(dirpath) {\n fs.mkdirSync(dirpath, { recursive: true });\n}\n\n/**\n * Remove directory recursively\n * @param {string} dirpath - Directory path to remove\n */\nfunction removeDirectory(dirpath) {\n fs.rmSync(dirpath, { recursive: true, force: true });\n}\n\nmodule.exports = {\n readJsonFileSafe,\n readFileSafe,\n writeJsonFile,\n writeModuleExportsFile,\n fileExists,\n ensureDirectoryExists,\n removeDirectory\n};", "const path = require('path');\nconst { fileExists } = require('./file-utils');\n\n/**\n * Find a file by traversing up the directory tree\n * @param {string} filename - Name of the file to find\n * @param {string} startDir - Starting directory (defaults to cwd)\n * @returns {string|null} Full path to the file or null if not found\n */\nfunction findFileUpward(filename, startDir = process.cwd()) {\n let currentDir = startDir;\n \n while (currentDir !== path.parse(currentDir).root) {\n const filePath = path.join(currentDir, filename);\n \n if (fileExists(filePath)) {\n return filePath;\n }\n \n currentDir = path.dirname(currentDir);\n }\n \n return null;\n}\n\n/**\n * Find a directory by traversing up and checking multiple possible paths\n * @param {string} dirname - Name of the directory to find\n * @param {string} startDir - Starting directory (defaults to cwd)\n * @param {Function} validator - Optional function to validate the directory\n * @returns {string|null} Full path to the directory or null if not found\n */\nfunction findDirectoryUpward(dirname, startDir = process.cwd(), validator = null) {\n const possiblePaths = [];\n let currentDir = startDir;\n const maxLevels = 10; // Prevent infinite loop\n \n // Build list of possible paths\n for (let i = 0; i < maxLevels; i++) {\n // Direct path\n possiblePaths.push(path.join(currentDir, dirname));\n \n // Relative paths up to 3 levels\n if (i < 3) {\n possiblePaths.push(path.join(currentDir, '../'.repeat(i + 1) + dirname));\n }\n \n const parentDir = path.dirname(currentDir);\n if (parentDir === currentDir) break; // Reached root\n currentDir = parentDir;\n }\n \n // Also check from module directory (for when running from node_modules)\n possiblePaths.push(path.join(__dirname, '../../../', dirname));\n \n // Find first existing directory that passes validation\n for (const dirPath of possiblePaths) {\n if (fileExists(dirPath)) {\n if (!validator || validator(dirPath)) {\n return dirPath;\n }\n }\n }\n \n return null;\n}\n\n/**\n * Find a directory with multiple possible relative paths\n * @param {string[]} possiblePaths - Array of possible paths to check\n * @param {string} startDir - Starting directory (defaults to cwd)\n * @returns {string|null} Full path to the directory or null if not found\n */\nfunction findDirectoryWithPaths(possiblePaths, startDir = process.cwd()) {\n // Build absolute paths from the start directory\n const absolutePaths = possiblePaths.map(p => {\n if (path.isAbsolute(p)) {\n return p;\n }\n return path.join(startDir, p);\n });\n \n // Find first existing path\n for (const dirPath of absolutePaths) {\n if (fileExists(dirPath)) {\n return dirPath;\n }\n }\n \n return null;\n}\n\nmodule.exports = {\n findFileUpward,\n findDirectoryUpward,\n findDirectoryWithPaths\n};", "const path = require('path');\nconst { findDirectoryUpward } = require('./path-utils');\nconst { readJsonFileSafe, readFileSafe, fileExists } = require('./file-utils');\n\n/**\n * LocalTokenReader - Reads tokens directly from the local file system\n * Mimics the APIClient interface but reads from apps/tokens directory\n */\nclass LocalTokenReader {\n constructor(ffId, options = {}) {\n this.ffId = ffId;\n this.tokensBasePath = options.tokensBasePath || this.findTokensPath();\n this.folderMap = this.loadFolderMap();\n this.projectFolder = this.folderMap[ffId];\n \n if (!this.projectFolder) {\n throw new Error(`No folder mapping found for ff-id: ${ffId}`);\n }\n \n this.projectPath = path.join(this.tokensBasePath, this.projectFolder);\n }\n\n /**\n * Find the tokens directory by looking for apps/tokens in parent directories\n */\n findTokensPath() {\n // Try to find apps/tokens first\n let tokensPath = findDirectoryUpward('apps/tokens', process.cwd(), (dir) => {\n return fileExists(path.join(dir, 'folderMap.json'));\n });\n \n // If not found, try just 'tokens'\n if (!tokensPath) {\n tokensPath = findDirectoryUpward('tokens', process.cwd(), (dir) => {\n return fileExists(path.join(dir, 'folderMap.json'));\n });\n }\n \n if (!tokensPath) {\n throw new Error('Could not find tokens directory with folderMap.json');\n }\n \n return tokensPath;\n }\n\n /**\n * Load the folder mapping from folderMap.json\n */\n loadFolderMap() {\n const folderMapPath = path.join(this.tokensBasePath, 'folderMap.json');\n const folderMap = readJsonFileSafe(folderMapPath);\n \n if (!folderMap) {\n throw new Error(`Failed to load folderMap.json: File not found`);\n }\n \n return folderMap;\n }\n\n /**\n * Fetch all token files (global, colors, semantic)\n * Mimics the APIClient.fetchTokens() method\n */\n async fetchTokens() {\n const figmaPath = path.join(this.projectPath, 'figma');\n \n // Try different possible paths for tokens\n const tokenPaths = {\n global: [\n path.join(figmaPath, 'Global Tokens', 'Default.json'),\n path.join(figmaPath, 'global.json')\n ],\n colors: [\n path.join(figmaPath, 'Global Colors', 'Default.json'),\n path.join(figmaPath, 'Global Colors', 'Light.json')\n ],\n semantic: [\n path.join(figmaPath, 'Semantic', 'Light.json'),\n path.join(figmaPath, 'Semantic', 'Default.json')\n ],\n semanticDark: [\n path.join(figmaPath, 'Semantic', 'Dark.json')\n ]\n };\n\n const results = {};\n \n // Try each possible path for each token type\n for (const [key, paths] of Object.entries(tokenPaths)) {\n for (const tokenPath of paths) {\n const content = readJsonFileSafe(tokenPath);\n if (content !== null) {\n results[key] = content;\n break; // Found it, no need to try other paths\n }\n }\n // If not found in any path, set to null\n if (!results[key]) {\n results[key] = null;\n }\n }\n\n return results;\n }\n\n /**\n * Fetch pre-processed tokens (if available in cache folder)\n */\n async fetchProcessedTokens() {\n const cachePath = path.join(this.projectPath, 'cache');\n \n if (!fileExists(cachePath)) {\n return null;\n }\n\n // Read all the cache files that would be in processed tokens\n const cacheFiles = {\n 'tokens.js': 'hashedTokens.js',\n 'variables.js': 'hashedVariables.js', \n 'semanticVariables.js': 'hashedSemanticVariables.js',\n 'semanticDarkVariables.js': 'hashedSemanticDarkVariables.js',\n 'safelist.js': 'safelist.js',\n 'custom.js': 'custom.js',\n 'fonts.json': 'fonts.json',\n 'icons.json': 'icons.json',\n 'components-config.json': 'encoded-config.json',\n 'version.json': 'version.json'\n };\n\n const processedData = {};\n \n for (const [key, fileName] of Object.entries(cacheFiles)) {\n const filePath = path.join(cachePath, fileName);\n if (key.endsWith('.js')) {\n processedData[key] = readFileSafe(filePath);\n } else {\n processedData[key] = readJsonFileSafe(filePath);\n }\n }\n\n // Only return if we have at least some data\n const hasData = Object.values(processedData).some(val => val !== null);\n return hasData ? processedData : null;\n }\n\n /**\n * Fetch components configuration\n */\n async fetchComponentsConfig() {\n return readJsonFileSafe(path.join(this.projectPath, 'components-config.json'));\n }\n\n /**\n * Fetch fonts configuration\n */\n async fetchFonts() {\n return readJsonFileSafe(path.join(this.projectPath, 'font.json'));\n }\n\n /**\n * Fetch icons configuration\n */\n async fetchIcons() {\n return readJsonFileSafe(path.join(this.projectPath, 'icons.json'));\n }\n\n /**\n * Fetch version information\n */\n async fetchVersion() {\n return readJsonFileSafe(path.join(this.projectPath, 'version.json'));\n }\n\n /**\n * Fetch custom CSS\n */\n async fetchCustomCss() {\n return readFileSafe(path.join(this.projectPath, 'custom.css'));\n }\n\n /**\n * Fetch plan metadata\n */\n async fetchPlanMetadata() {\n const metadata = readJsonFileSafe(path.join(this.projectPath, 'metadata.json'));\n \n // Default to full plan if no metadata exists\n return metadata || {\n planType: 'full',\n allowedComponents: null\n };\n }\n\n // Compatibility methods to match APIClient interface\n fetchJson() {\n throw new Error('fetchJson is not implemented in LocalTokenReader. Use specific fetch methods.');\n }\n\n fetchRaw() {\n throw new Error('fetchRaw is not implemented in LocalTokenReader. Use specific fetch methods.');\n }\n}\n\nmodule.exports = { LocalTokenReader };", "const https = require('https');\nconst http = require('http');\nconst { URL } = require('url');\nconst { DEFAULT_API_URL, LEGACY_API_URL, ENV_VARS } = require('./constants');\nconst { APIError } = require('./errors');\nconst { LocalTokenReader } = require('./local-token-reader');\n\nclass APIClient {\n constructor(ffId, options = {}) {\n this.ffId = ffId;\n this.baseURL = options.baseURL || process.env[ENV_VARS.FF_API_URL] || DEFAULT_API_URL;\n \n // Check if we should use local token reader\n if (process.env[ENV_VARS.FF_USE_LOCAL] === 'true') {\n console.log(' \uD83C\uDFE0 Using local token reader');\n this.localReader = new LocalTokenReader(ffId, options);\n }\n }\n\n /**\n * Fetch JSON data from a URL using native https module\n * @param {string} url - The URL to fetch\n * @param {Object} options - Fetch options\n * @param {boolean} options.returnHeaders - If true, return {data, headers} object\n * @returns {Promise<any>} Parsed JSON data or {data, headers} if returnHeaders is true\n */\n fetchJson(url, options = {}) {\n return new Promise((resolve, reject) => {\n // Determine if we should use http or https\n const protocol = url.startsWith('https') ? https : http;\n\n protocol.get(url, (response) => {\n let data = '';\n\n // Check for HTTP errors\n if (response.statusCode >= 400) {\n reject(new APIError(\n `HTTP ${response.statusCode}: ${response.statusMessage}`,\n response.statusCode,\n url\n ));\n return;\n }\n\n // Collect response chunks\n response.on('data', (chunk) => {\n data += chunk;\n });\n\n // Parse JSON when complete\n response.on('end', () => {\n try {\n const parsed = JSON.parse(data);\n\n // Return headers if requested\n if (options.returnHeaders) {\n resolve({\n data: parsed,\n headers: response.headers\n });\n } else {\n resolve(parsed);\n }\n } catch (error) {\n reject(new APIError(\n `Invalid JSON response: ${error.message}`,\n response.statusCode,\n url\n ));\n }\n });\n\n // Handle response errors\n response.on('error', (error) => {\n reject(new APIError(\n `Response error: ${error.message}`,\n response.statusCode,\n url\n ));\n });\n }).on('error', (error) => {\n // Handle network errors\n reject(new APIError(\n `Network error: ${error.message}`,\n 0,\n url\n ));\n });\n });\n }\n\n /**\n * Fetch raw content from a URL\n * @param {string} url - The URL to fetch\n * @returns {Promise<string>} Raw text content\n */\n fetchRaw(url) {\n return new Promise((resolve, reject) => {\n // Determine if we should use http or https\n const protocol = url.startsWith('https') ? https : http;\n \n protocol.get(url, (response) => {\n let data = '';\n \n // Check for HTTP errors\n if (response.statusCode >= 400) {\n reject(new APIError(\n `HTTP ${response.statusCode}: ${response.statusMessage}`,\n response.statusCode,\n url\n ));\n return;\n }\n\n // Collect response chunks\n response.on('data', (chunk) => {\n data += chunk;\n });\n\n // Return raw data when complete\n response.on('end', () => {\n resolve(data);\n });\n\n // Handle response errors\n response.on('error', (error) => {\n reject(new APIError(\n `Response error: ${error.message}`,\n response.statusCode,\n url\n ));\n });\n }).on('error', (error) => {\n // Handle network errors\n reject(new APIError(\n `Network error: ${error.message}`,\n 0,\n url\n ));\n });\n });\n }\n\n /**\n * Fetch all token files (global, colors, semantic)\n * @returns {Promise<Object>} Object with all token data\n */\n async fetchTokens() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchTokens();\n }\n \n // First try the new design system endpoint\n try {\n const designSystemUrl = `${this.baseURL}/api/design-systems/${this.ffId}/tokens`;\n const tokensData = await this.fetchJson(designSystemUrl);\n \n // If we have the new format, parse it\n if (tokensData && tokensData.tokens) {\n const tokens = tokensData.tokens;\n \n // Extract specific token sets from the new format\n return {\n global: tokens['Global Tokens/Default'] || tokens['global'] || null,\n colors: tokens['Global Colors/Default'] || tokens['colors'] || null,\n semantic: tokens['Semantic/Light'] || tokens['semantic/light'] || null,\n semanticDark: tokens['Semantic/Dark'] || tokens['semantic/dark'] || null\n };\n }\n } catch (err) {\n // If design system is not synced (400 error), throw with clear message\n if (err.statusCode === 400) {\n throw new APIError(\n 'Design system not synced with Figma. Please sync tokens from Figma before using this design system.',\n 400,\n `${this.baseURL}/api/design-systems/${this.ffId}/tokens`\n );\n }\n // Failed to fetch from design system endpoint, falling back to legacy URLs\n }\n \n // Fall back to legacy token URLs\n // Use legacy API URL for backward compatibility\n const legacyBaseURL = LEGACY_API_URL;\n const urls = {\n global: `${legacyBaseURL}/${this.ffId}/global-tokens/default.json`,\n colors: `${legacyBaseURL}/${this.ffId}/global-colors/default.json`,\n semantic: `${legacyBaseURL}/${this.ffId}/semantic/light.json`,\n semanticDark: `${legacyBaseURL}/${this.ffId}/semantic/dark.json`\n };\n\n const results = await Promise.all([\n this.fetchJson(urls.global).catch(err => err.statusCode === 404 ? null : Promise.reject(err)),\n this.fetchJson(urls.colors).catch(err => err.statusCode === 404 ? null : Promise.reject(err)),\n this.fetchJson(urls.semantic).catch(err => err.statusCode === 404 ? null : Promise.reject(err)),\n this.fetchJson(urls.semanticDark).catch(err => err.statusCode === 404 ? null : Promise.reject(err))\n ]);\n\n return {\n global: results[0],\n colors: results[1],\n semantic: results[2],\n semanticDark: results[3]\n };\n }\n\n /**\n * Fetch pre-processed tokens from the design system endpoint\n * @param {Object} options - Fetch options\n * @param {string} options.tag - Tag name (e.g., 'dev', 'next', 'latest')\n * @param {string} options.version - Version label (e.g., 'v1.0.0')\n * @returns {Promise<Object|null>} Processed tokens ready for caching with metadata or null if not found\n */\n async fetchProcessedTokens(options = {}) {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchProcessedTokens();\n }\n\n // Build URL with optional query parameters\n const url = new URL(`${this.baseURL}/api/design-systems/${this.ffId}/processed-tokens`);\n if (options.tag) {\n url.searchParams.append('tag', options.tag);\n }\n if (options.version) {\n url.searchParams.append('version', options.version);\n }\n\n const processedUrl = url.toString();\n\n try {\n const result = await this.fetchJson(processedUrl, { returnHeaders: true });\n\n // Attach version metadata from response headers\n if (result.headers) {\n result.data.versionMetadata = {\n version: result.headers['x-frontfriend-version'],\n tag: result.headers['x-frontfriend-tag'],\n cached: result.headers['x-frontfriend-cached'] === 'true'\n };\n }\n\n return result.data;\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n // If design system is not synced (400 error), throw with clear message\n if (error.statusCode === 400) {\n throw new APIError(\n 'Design system not synced with Figma. Please sync tokens from Figma before using this design system.',\n 400,\n processedUrl\n );\n }\n throw error;\n }\n }\n\n /**\n * Fetch components configuration\n * @returns {Promise<Object|null>} Components config or null if not found\n */\n async fetchComponentsConfig() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchComponentsConfig();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/components-config.json`;\n try {\n return await this.fetchJson(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch fonts configuration\n * @returns {Promise<Object|null>} Fonts object with font1, font2, etc. URLs or null\n */\n async fetchFonts() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchFonts();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/font.json`;\n try {\n return await this.fetchJson(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch icons configuration\n * @returns {Promise<Object|null>} Icons data or null if not found\n */\n async fetchIcons() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchIcons();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/icons.json`;\n try {\n return await this.fetchJson(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch version information\n * @returns {Promise<Object|null>} Version data or null if not found\n */\n async fetchVersion() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchVersion();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/version.json`;\n try {\n return await this.fetchJson(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch custom CSS\n * @returns {Promise<string|null>} Custom CSS string or null if not found\n */\n async fetchCustomCss() {\n // Use local reader if available\n if (this.localReader) {\n return this.localReader.fetchCustomCss();\n }\n \n // Always use legacy URL for these endpoints\n const url = `${LEGACY_API_URL}/${this.ffId}/custom.css`;\n try {\n return await this.fetchRaw(url);\n } catch (error) {\n if (error.statusCode === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Fetch plan metadata (plan type and allowed components)\n * @returns {Promise<Object|null>} Plan metadata or null if not found\n */\n async fetchPlanMetadata() {\n // Use local reader if available\n if (this.localReader) {\n if (process.env.FF_DEBUG) {\n console.log(' \u2192 Using local reader for plan metadata');\n }\n return this.localReader.fetchPlanMetadata();\n }\n \n // First try the saas app (processed-tokens endpoint) - this is the authoritative source\n const processedUrl = `${this.baseURL}/api/design-systems/${this.ffId}/processed-tokens`;\n try {\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Fetching plan metadata from saas app: ${processedUrl}`);\n }\n \n const processedData = await this.fetchJson(processedUrl);\n \n // Extract metadata from processed tokens response\n if (processedData && processedData.metadata) {\n const metadata = {\n planType: processedData.metadata.planType || 'full',\n allowedComponents: processedData.metadata.allowedComponents || null\n };\n \n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Found plan metadata in saas app: ${metadata.planType}, allowed: ${metadata.allowedComponents ? metadata.allowedComponents.length + ' components' : 'all'}`);\n }\n \n return metadata;\n }\n } catch (saasError) {\n // If not found in saas app, try legacy server\n if (saasError.statusCode === 404) {\n if (process.env.FF_DEBUG) {\n console.log(' \u2192 ff-id not found in saas app, trying legacy server');\n }\n \n // Try legacy tokens server (these are always full plan - no trial concept)\n const tokensUrl = `${LEGACY_API_URL}/${this.ffId}/metadata`;\n try {\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Fetching from legacy server: ${tokensUrl}`);\n }\n const legacyMetadata = await this.fetchJson(tokensUrl);\n \n // Use the plan metadata from legacy server if available\n const metadata = {\n planType: legacyMetadata.planType || 'full',\n allowedComponents: legacyMetadata.allowedComponents || null\n };\n \n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Found in legacy server: ${metadata.planType}, allowed: ${metadata.allowedComponents ? metadata.allowedComponents.length + ' components' : 'all'}`);\n }\n \n return metadata;\n } catch (legacyError) {\n if (legacyError.statusCode === 404) {\n // Not found in either place - DENY access\n if (process.env.FF_DEBUG) {\n console.log(' \u2192 ff-id not found in any server - access denied');\n }\n \n // Return a denied plan type instead of defaulting to full\n return {\n planType: 'denied',\n allowedComponents: [],\n error: 'Design system not found. Please ensure your ff-id is valid.'\n };\n }\n throw legacyError;\n }\n }\n throw saasError;\n }\n }\n}\n\nmodule.exports = { APIClient };", "const https = require('https');\nconst fs = require('fs');\nconst path = require('path');\nconst { URL } = require('url');\nconst os = require('os');\n\nconst REGISTRY_URL = process.env.FF_REGISTRY_URL || 'https://ff-registry.up.railway.app';\n\nclass ComponentDownloader {\n constructor(options = {}) {\n this.appRoot = options.appRoot || process.cwd();\n this.framework = options.framework || this.detectFramework();\n this.config = options.config || {};\n this.outputPath = options.outputPath || this.getDefaultOutputPath();\n this.overwrite = options.overwrite || false;\n this.downloadedComponents = new Set();\n this.ffId = this.config.ffId || this.config['ff-id'] || null;\n this.planMetadata = null; // Will be populated when needed\n }\n\n /**\n * Detect framework from package.json\n */\n detectFramework() {\n const packageJsonPath = path.join(this.appRoot, 'package.json');\n \n if (fs.existsSync(packageJsonPath)) {\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));\n const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };\n \n if (deps.vue) {\n return 'vue';\n } else if (deps.react) {\n return 'react';\n }\n }\n \n // Default to React if can't detect\n return 'react';\n }\n\n /**\n * Get default output path based on framework and config\n */\n getDefaultOutputPath() {\n // Check if config has ui alias\n if (this.config.aliases && this.config.aliases.ui) {\n const uiAlias = this.config.aliases.ui;\n // Convert alias to actual path (e.g., @/components/ui -> components/ui)\n const cleanPath = uiAlias.replace(/^@\\//, '');\n return path.join(this.appRoot, cleanPath);\n }\n \n // Fallback to default paths\n if (this.framework === 'vue') {\n return path.join(this.appRoot, 'src/components/ui');\n }\n return path.join(this.appRoot, 'components/ui');\n }\n\n /**\n * Fetch JSON from URL or local file\n */\n fetchJson(url) {\n // Check if using local mode at runtime\n // FF_USE_LOCAL: affects both tokens and components\n // FF_USE_LOCAL_REGISTRY: affects only components (for registry URLs)\n const USE_LOCAL = process.env.FF_USE_LOCAL === 'true';\n const USE_LOCAL_REGISTRY = process.env.FF_USE_LOCAL_REGISTRY === 'true';\n \n // Check if this is a registry URL\n const isRegistryUrl = url.includes(REGISTRY_URL);\n \n // Use local file system if:\n // 1. FF_USE_LOCAL is set (affects everything), OR\n // 2. FF_USE_LOCAL_REGISTRY is set AND this is a registry URL\n if (USE_LOCAL || (USE_LOCAL_REGISTRY && isRegistryUrl)) {\n if (process.env.FF_DEBUG && USE_LOCAL_REGISTRY && !USE_LOCAL) {\n console.log(' \u2192 Using local registry for components');\n }\n \n // Try multiple paths to find the registry\n const possiblePaths = [\n '../../packages/registry',\n '../../../packages/registry',\n '../../../../packages/registry',\n path.join(__dirname, '../../../registry'),\n 'packages/registry'\n ];\n \n let registryPath;\n for (const p of possiblePaths) {\n const fullPath = path.isAbsolute(p) ? p : path.join(process.cwd(), p);\n if (fs.existsSync(fullPath)) {\n registryPath = fullPath;\n break;\n }\n }\n \n if (!registryPath) {\n return Promise.reject(new Error(`Local registry not found. Tried paths: ${possiblePaths.join(', ')}`));\n }\n \n // Extract the path from the URL and construct proper local path\n const urlPath = url.replace(REGISTRY_URL, '').replace(/^\\//, '');\n const localPath = path.join(registryPath, ...urlPath.split('/'));\n \n try {\n const content = fs.readFileSync(localPath, 'utf8');\n return Promise.resolve(JSON.parse(content));\n } catch (error) {\n if (error.code === 'ENOENT') {\n return Promise.reject(new Error('HTTP 404: Not Found'));\n }\n return Promise.reject(error);\n }\n }\n\n return new Promise((resolve, reject) => {\n https.get(url, (response) => {\n let data = '';\n \n if (response.statusCode >= 400) {\n reject(new Error(`HTTP ${response.statusCode}: ${response.statusMessage}`));\n return;\n }\n\n response.on('data', (chunk) => {\n data += chunk;\n });\n\n response.on('end', () => {\n try {\n resolve(JSON.parse(data));\n } catch (error) {\n reject(new Error(`Invalid JSON response: ${error.message}`));\n }\n });\n\n }).on('error', (error) => {\n reject(error);\n });\n });\n }\n\n /**\n * Get all available components from registry\n */\n async getAllComponents() {\n try {\n const url = `${REGISTRY_URL}/components/${this.framework}/index.json`;\n const index = await this.fetchJson(url);\n let components = index.components || [];\n \n // Filter components based on plan\n if (this.ffId) {\n // Ensure plan metadata is loaded\n try {\n await this.isComponentAllowed('dummy'); // This will load metadata\n } catch (error) {\n // If access is denied, throw error\n if (this.planMetadata && this.planMetadata.planType === 'denied') {\n throw new Error(this.planMetadata.error || 'Access denied. Your ff-id was not found in any server.');\n }\n }\n \n if (this.planMetadata && this.planMetadata.planType === 'trial' && this.planMetadata.allowedComponents) {\n components = components.filter(comp => this.planMetadata.allowedComponents.includes(comp));\n \n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Trial plan: filtering to ${components.length} allowed components`);\n }\n }\n }\n \n return components;\n } catch (error) {\n console.error('Failed to fetch component index:', error.message);\n return [];\n }\n }\n\n /**\n * Get all custom components for this ff-id\n */\n async getCustomComponents() {\n if (!this.ffId) {\n if (process.env.FF_DEBUG) {\n console.log(' \u2192 No ff-id found, skipping custom components');\n }\n return [];\n }\n \n try {\n const url = `${REGISTRY_URL}/custom/${this.ffId}/${this.framework}/index.json`;\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Fetching custom components from: ${url}`);\n }\n const index = await this.fetchJson(url);\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Found custom components: ${JSON.stringify(index.components)}`);\n }\n return index.components || [];\n } catch (error) {\n // Custom components might not exist, that's ok\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 No custom components found: ${error.message}`);\n }\n return [];\n }\n }\n\n /**\n * Download multiple components\n */\n async downloadComponents(components) {\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 ComponentDownloader initialized with ff-id: ${this.ffId}`);\n }\n \n const results = {\n successful: [],\n failed: [],\n dependencies: new Set()\n };\n\n for (const component of components) {\n try {\n const deps = await this.downloadComponent(component);\n results.successful.push(component);\n \n // Add dependencies\n deps.forEach(dep => results.dependencies.add(dep));\n } catch (error) {\n results.failed.push({\n component,\n error: error.message\n });\n }\n }\n\n return {\n successful: results.successful,\n failed: results.failed,\n dependencies: Array.from(results.dependencies)\n };\n }\n\n /**\n * Check if component is allowed based on plan\n */\n async isComponentAllowed(componentName) {\n // Fetch plan metadata if not already loaded\n if (!this.planMetadata && this.ffId) {\n const { APIClient } = require('./api-client');\n const apiClient = new APIClient(this.ffId, {\n baseURL: this.config['api-url'] || this.config.apiUrl\n });\n try {\n this.planMetadata = await apiClient.fetchPlanMetadata();\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Fetched plan metadata: ${this.planMetadata.planType}, allowed: ${this.planMetadata.allowedComponents ? this.planMetadata.allowedComponents.length + ' components' : 'all'}`);\n }\n } catch (error) {\n console.warn('Failed to fetch plan metadata:', error.message);\n // Default to full plan if we can't fetch metadata\n this.planMetadata = { planType: 'full', allowedComponents: null };\n }\n }\n\n // Handle denied plan (ff-id not found anywhere)\n if (this.planMetadata && this.planMetadata.planType === 'denied') {\n throw new Error(this.planMetadata.error || 'Access denied. Your ff-id was not found in any server.');\n }\n \n // If full plan or no metadata, allow all components\n if (!this.planMetadata || this.planMetadata.planType === 'full') {\n return true;\n }\n\n // For trial plan, check if component is in allowed list\n if (this.planMetadata.planType === 'trial' && this.planMetadata.allowedComponents) {\n return this.planMetadata.allowedComponents.includes(componentName);\n }\n\n // Default to denying if we can't determine (safer)\n return false;\n }\n\n /**\n * Download a single component and its registry dependencies\n */\n async downloadComponent(componentName) {\n // Avoid downloading the same component twice\n if (this.downloadedComponents.has(componentName)) {\n return [];\n }\n\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Checking if component \"${componentName}\" is allowed...`);\n console.log(` \u2192 FF-ID: ${this.ffId}`);\n }\n\n // Check if component is allowed based on plan\n const isAllowed = await this.isComponentAllowed(componentName);\n if (!isAllowed) {\n const errorMsg = `Component \"${componentName}\" is not available in your trial plan. Please upgrade to access all components.`;\n console.error(`\u274C ${errorMsg}`);\n throw new Error(errorMsg);\n }\n\n console.log(`\uD83D\uDCE5 Downloading ${componentName}...`);\n\n // Try to fetch from custom components first if ff-id is available\n let componentData;\n let isCustom = false;\n \n if (this.ffId) {\n const customUrl = `${REGISTRY_URL}/custom/${this.ffId}/${this.framework}/${componentName}.json`;\n try {\n componentData = await this.fetchJson(customUrl);\n isCustom = true;\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 Found custom component for ${componentName}`);\n }\n } catch (error) {\n // Custom component not found, try standard registry\n if (process.env.FF_DEBUG) {\n console.log(` \u2192 No custom component found for ${componentName}, trying standard`);\n }\n }\n }\n \n // If not found in custom, try standard registry\n if (!componentData) {\n const url = `${REGISTRY_URL}/components/${this.framework}/${componentName}.json`;\n \n try {\n componentData = await this.fetchJson(url);\n } catch (error) {\n // Check if it's a 404 (component not found)\n if (error.message.includes('404')) {\n throw new Error(`Component \"${componentName}\" not found`);\n }\n throw new Error(`Failed to fetch ${componentName}: ${error.message}`);\n }\n }\n\n // Validate component data\n if (!componentData.files || !Array.isArray(componentData.files)) {\n throw new Error(`Invalid component data for ${componentName}`);\n }\n\n // Write component files\n for (const file of componentData.files) {\n await this.writeComponentFile(file);\n }\n\n this.downloadedComponents.add(componentName);\n console.log(` \u2713 ${componentName} downloaded${isCustom && process.env.FF_DEBUG ? ' (custom)' : ''}`);\n\n // Download registry dependencies\n const allDependencies = [...(componentData.dependencies || [])];\n \n if (componentData.registryDependencies && componentData.registryDependencies.length > 0) {\n console.log(` \uD83D\uDCE6 Installing registry dependencies: ${componentData.registryDependencies.join(', ')}`);\n \n for (const dep of componentData.registryDependencies) {\n try {\n const depDeps = await this.downloadComponent(dep);\n depDeps.forEach(d => allDependencies.push(d));\n } catch (error) {\n console.warn(` \u26A0\uFE0F Failed to download dependency ${dep}: ${error.message}`);\n }\n }\n }\n\n return allDependencies;\n }\n\n /**\n * Write component file to disk\n */\n async writeComponentFile(file) {\n // Normalize the file path for the current platform\n // Convert forward slashes to the platform-specific separator\n const normalizedFileName = file.name.split('/').join(path.sep);\n const filePath = path.join(this.outputPath, normalizedFileName);\n const dir = path.dirname(filePath);\n\n // Create directory if it doesn't exist\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n\n // Check if file exists and overwrite setting\n if (fs.existsSync(filePath) && !this.overwrite) {\n console.log(` \u26A0\uFE0F Skipping ${file.name} (already exists)`);\n return;\n }\n\n // Normalize line endings to match the platform\n // This prevents git from showing every line as changed\n let normalizedContent = file.content;\n if (os.EOL !== '\\n') {\n // On Windows, replace LF with CRLF\n normalizedContent = file.content.replace(/\\n/g, os.EOL);\n }\n\n // Write file\n fs.writeFileSync(filePath, normalizedContent, 'utf8');\n }\n}\n\nmodule.exports = { ComponentDownloader };"],
5
+ "mappings": "8DAAA,IAAAA,EAAAC,EAAA,CAAAC,GAAAC,IAAA,CAKA,IAAMC,EAAkB,8BAClBC,EAAiB,iDAGjBC,EAAiB,qBAKjBC,EAAc,CAClB,GAAI,CACF,YACA,eACA,uBACA,2BACA,cACA,WACF,EACA,KAAM,CACJ,aACA,aACA,yBACA,eACA,eACF,CACF,EAGMC,EAAW,CACf,MAAO,QACP,WAAY,a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,EAAE,EAGpG,IAAMG,EAAkB,CAAC,GAAIJ,EAAc,cAAgB,CAAC,CAAE,EAE9D,GAAIA,EAAc,sBAAwBA,EAAc,qBAAqB,OAAS,EAAG,CACvF,QAAQ,IAAI,kDAA2CA,EAAc,qBAAqB,KAAK,IAAI,CAAC,EAAE,EAEtG,QAAWL,KAAOK,EAAc,qBAC9B,GAAI,EACc,MAAM,KAAK,kBAAkBL,CAAG,GACxC,QAAQU,GAAKD,EAAgB,KAAKC,CAAC,CAAC,CAC9C,OAASrB,EAAO,CACd,QAAQ,KAAK,kDAAwCW,CAAG,KAAKX,EAAM,OAAO,EAAE,CAC9E,CAEJ,CAEA,OAAOoB,CACT,CAKA,MAAM,mBAAmBD,EAAM,CAG7B,IAAMG,EAAqBH,EAAK,KAAK,MAAM,GAAG,EAAE,KAAKxC,EAAK,GAAG,EACvD4C,EAAW5C,EAAK,KAAK,KAAK,WAAY2C,CAAkB,EACxDE,EAAM7C,EAAK,QAAQ4C,CAAQ,EAQjC,GALK7C,EAAG,WAAW8C,CAAG,GACpB9C,EAAG,UAAU8C,EAAK,CAAE,UAAW,EAAK,CAAC,EAInC9C,EAAG,WAAW6C,CAAQ,GAAK,CAAC,KAAK,UAAW,CAC9C,QAAQ,IAAI,6BAAmBJ,EAAK,IAAI,mBAAmB,EAC3D,MACF,CAIA,IAAIM,EAAoBN,EAAK,QACzBtC,EAAG,MAAQ;AAAA,IAEb4C,EAAoBN,EAAK,QAAQ,QAAQ,MAAOtC,EAAG,GAAG,GAIxDH,EAAG,cAAc6C,EAAUE,EAAmB,MAAM,CACtD,CACF,EAEA,OAAO,QAAU,CAAE,oBAAA1C,CAAoB",
6
+ "names": ["require_constants", "__commonJSMin", "exports", "module", "DEFAULT_API_URL", "LEGACY_API_URL", "CACHE_DIR_NAME", "CACHE_FILES", "ENV_VARS", "require_errors", "__commonJSMin", "exports", "module", "APIError", "message", "statusCode", "url", "CacheError", "operation", "ConfigError", "field", "ProcessingError", "token", "require_file_utils", "__commonJSMin", "exports", "module", "fs", "readJsonFileSafe", "filepath", "content", "error", "readFileSafe", "writeJsonFile", "data", "indent", "writeModuleExportsFile", "fileExists", "ensureDirectoryExists", "dirpath", "removeDirectory", "require_path_utils", "__commonJSMin", "exports", "module", "path", "fileExists", "findFileUpward", "filename", "startDir", "currentDir", "filePath", "findDirectoryUpward", "dirname", "validator", "possiblePaths", "maxLevels", "i", "parentDir", "dirPath", "findDirectoryWithPaths", "absolutePaths", "p", "require_local_token_reader", "__commonJSMin", "exports", "module", "path", "findDirectoryUpward", "readJsonFileSafe", "readFileSafe", "fileExists", "LocalTokenReader", "ffId", "options", "tokensPath", "dir", "folderMapPath", "folderMap", "figmaPath", "tokenPaths", "results", "key", "paths", "tokenPath", "content", "cachePath", "cacheFiles", "processedData", "fileName", "filePath", "val", "require_api_client", "__commonJSMin", "exports", "module", "https", "http", "URL", "DEFAULT_API_URL", "LEGACY_API_URL", "ENV_VARS", "APIError", "LocalTokenReader", "APIClient", "ffId", "options", "url", "resolve", "reject", "response", "data", "chunk", "parsed", "error", "designSystemUrl", "tokensData", "tokens", "err", "legacyBaseURL", "urls", "results", "processedUrl", "result", "processedData", "metadata", "saasError", "tokensUrl", "legacyMetadata", "legacyError", "https", "fs", "path", "URL", "os", "REGISTRY_URL", "ComponentDownloader", "options", "packageJsonPath", "packageJson", "deps", "cleanPath", "url", "USE_LOCAL", "USE_LOCAL_REGISTRY", "isRegistryUrl", "possiblePaths", "registryPath", "p", "fullPath", "urlPath", "localPath", "content", "error", "resolve", "reject", "response", "data", "chunk", "components", "comp", "index", "results", "component", "dep", "componentName", "APIClient", "apiClient", "errorMsg", "componentData", "isCustom", "customUrl", "file", "allDependencies", "d", "normalizedFileName", "filePath", "dir", "normalizedContent"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var u=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var i=u((w,c)=>{var r=require("fs");function s(n){try{let e=r.readFileSync(n,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}function l(n){try{return r.readFileSync(n,"utf8")}catch(e){if(e.code==="ENOENT")return null;throw e}}function f(n,e,t=2){let o=JSON.stringify(e,null,t);r.writeFileSync(n,o,"utf8")}function y(n,e){if(e==null||typeof e=="object"&&Object.keys(e).length===0||Array.isArray(e)&&e.length===0){let o=`module.exports = ${Array.isArray(e)?"[]":"{}"};`;r.writeFileSync(n,o,"utf8")}else{let t=`module.exports = ${JSON.stringify(e,null,2)};`;r.writeFileSync(n,t,"utf8")}}function p(n){return r.existsSync(n)}function S(n){r.mkdirSync(n,{recursive:!0})}function d(n){r.rmSync(n,{recursive:!0,force:!0})}c.exports={readJsonFileSafe:s,readFileSafe:l,writeJsonFile:f,writeModuleExportsFile:y,fileExists:p,ensureDirectoryExists:S,removeDirectory:d}});var v=require("path"),{fileExists:E}=i();function a(n=process.cwd()){let e=v.join(n,".env.local");return E(e)?(require("dotenv").config({path:e}),console.log("\u{1F4C4} Loaded .env.local"),!0):!1}function x(n,e=void 0){return process.env[n]||e}function F(n){return process.env[n]==="true"}module.exports={loadEnvLocal:a,getEnvVar:x,isEnvTrue:F};
1
+ var u=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports);var i=u((w,c)=>{var r=require("fs");function s(n){try{let e=r.readFileSync(n,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}function l(n){try{return r.readFileSync(n,"utf8").replace(/^\uFEFF/,"")}catch(e){if(e.code==="ENOENT")return null;throw e}}function f(n,e,t=2){let o=JSON.stringify(e,null,t);r.writeFileSync(n,o,"utf8")}function y(n,e){if(e==null||typeof e=="object"&&Object.keys(e).length===0||Array.isArray(e)&&e.length===0){let o=`module.exports = ${Array.isArray(e)?"[]":"{}"};`;r.writeFileSync(n,o,"utf8")}else{let t=`module.exports = ${JSON.stringify(e,null,2)};`;r.writeFileSync(n,t,"utf8")}}function p(n){return r.existsSync(n)}function S(n){r.mkdirSync(n,{recursive:!0})}function E(n){r.rmSync(n,{recursive:!0,force:!0})}c.exports={readJsonFileSafe:s,readFileSafe:l,writeJsonFile:f,writeModuleExportsFile:y,fileExists:p,ensureDirectoryExists:S,removeDirectory:E}});var F=require("path"),{fileExists:d}=i();function v(n=process.cwd()){let e=F.join(n,".env.local");return d(e)?(require("dotenv").config({path:e}),console.log("\u{1F4C4} Loaded .env.local"),!0):!1}function a(n,e=void 0){return process.env[n]||e}function x(n){return process.env[n]==="true"}module.exports={loadEnvLocal:v,getEnvVar:a,isEnvTrue:x};
2
2
  //# sourceMappingURL=env-utils.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../lib/core/file-utils.js", "../../../lib/core/env-utils.js"],
4
- "sourcesContent": ["const fs = require('fs');\n\n/**\n * Read a JSON file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the JSON file\n * @returns {Object|null} Parsed JSON or null if file not found\n * @throws {Error} If JSON is invalid\n */\nfunction readJsonFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n return JSON.parse(content);\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found, return null like API would return 404\n }\n throw error;\n }\n}\n\n/**\n * Read a file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the file\n * @returns {string|null} File content or null if file not found\n * @throws {Error} For other file system errors\n */\nfunction readFileSafe(filepath) {\n try {\n return fs.readFileSync(filepath, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found\n }\n throw error;\n }\n}\n\n/**\n * Write JSON data to a file with proper formatting\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to write\n * @param {number} indent - Indentation level (default: 2)\n */\nfunction writeJsonFile(filepath, data, indent = 2) {\n const content = JSON.stringify(data, null, indent);\n fs.writeFileSync(filepath, content, 'utf8');\n}\n\n/**\n * Write module.exports file with JSON data\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to export\n */\nfunction writeModuleExportsFile(filepath, data) {\n // Handle empty data cases\n if (data === null || data === undefined || \n (typeof data === 'object' && Object.keys(data).length === 0) ||\n (Array.isArray(data) && data.length === 0)) {\n const emptyContent = Array.isArray(data) ? '[]' : '{}';\n const content = `module.exports = ${emptyContent};`;\n fs.writeFileSync(filepath, content, 'utf8');\n } else {\n const content = `module.exports = ${JSON.stringify(data, null, 2)};`;\n fs.writeFileSync(filepath, content, 'utf8');\n }\n}\n\n/**\n * Check if a file exists\n * @param {string} filepath - Path to check\n * @returns {boolean} True if file exists\n */\nfunction fileExists(filepath) {\n return fs.existsSync(filepath);\n}\n\n/**\n * Create directory recursively\n * @param {string} dirpath - Directory path to create\n */\nfunction ensureDirectoryExists(dirpath) {\n fs.mkdirSync(dirpath, { recursive: true });\n}\n\n/**\n * Remove directory recursively\n * @param {string} dirpath - Directory path to remove\n */\nfunction removeDirectory(dirpath) {\n fs.rmSync(dirpath, { recursive: true, force: true });\n}\n\nmodule.exports = {\n readJsonFileSafe,\n readFileSafe,\n writeJsonFile,\n writeModuleExportsFile,\n fileExists,\n ensureDirectoryExists,\n removeDirectory\n};", "const path = require('path');\nconst { fileExists } = require('./file-utils');\n\n/**\n * Load .env.local file if it exists in the current working directory\n * @param {string} cwd - Current working directory (defaults to process.cwd())\n * @returns {boolean} True if .env.local was loaded\n */\nfunction loadEnvLocal(cwd = process.cwd()) {\n const envLocalPath = path.join(cwd, '.env.local');\n \n if (fileExists(envLocalPath)) {\n require('dotenv').config({ path: envLocalPath });\n console.log('\uD83D\uDCC4 Loaded .env.local');\n return true;\n }\n \n return false;\n}\n\n/**\n * Get an environment variable with optional default value\n * @param {string} name - Environment variable name\n * @param {string} defaultValue - Default value if not set\n * @returns {string|undefined} Environment variable value or default\n */\nfunction getEnvVar(name, defaultValue = undefined) {\n return process.env[name] || defaultValue;\n}\n\n/**\n * Check if an environment variable is set to 'true'\n * @param {string} name - Environment variable name\n * @returns {boolean} True if the env var is set to 'true'\n */\nfunction isEnvTrue(name) {\n return process.env[name] === 'true';\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CAAE,UAAW,GAAM,MAAO,EAAK,CAAC,CACrD,CAEAb,EAAO,QAAU,CACf,iBAAAE,EACA,aAAAI,EACA,cAAAC,EACA,uBAAAG,EACA,WAAAC,EACA,sBAAAC,EACA,gBAAAE,CACF,ICpGA,IAAMC,EAAO,QAAQ,MAAM,EACrB,CAAE,WAAAC,CAAW,EAAI,IAOvB,SAASC,EAAaC,EAAM,QAAQ,IAAI,EAAG,CACzC,IAAMC,EAAeJ,EAAK,KAAKG,EAAK,YAAY,EAEhD,OAAIF,EAAWG,CAAY,GACzB,QAAQ,QAAQ,EAAE,OAAO,CAAE,KAAMA,CAAa,CAAC,EAC/C,QAAQ,IAAI,6BAAsB,EAC3B,IAGF,EACT,CAQA,SAASC,EAAUC,EAAMC,EAAe,OAAW,CACjD,OAAO,QAAQ,IAAID,CAAI,GAAKC,CAC9B,CAOA,SAASC,EAAUF,EAAM,CACvB,OAAO,QAAQ,IAAIA,CAAI,IAAM,MAC/B,CAEA,OAAO,QAAU,CACf,aAAAJ,EACA,UAAAG,EACA,UAAAG,CACF",
4
+ "sourcesContent": ["const fs = require('fs');\n\n/**\n * Read a JSON file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the JSON file\n * @returns {Object|null} Parsed JSON or null if file not found\n * @throws {Error} If JSON is invalid\n */\nfunction readJsonFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n return JSON.parse(content);\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found, return null like API would return 404\n }\n throw error;\n }\n}\n\n/**\n * Read a file safely, returning null if file doesn't exist\n * Strips UTF-8 BOM if present (fixes Windows compatibility)\n * @param {string} filepath - Path to the file\n * @returns {string|null} File content or null if file not found\n * @throws {Error} For other file system errors\n */\nfunction readFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n // Strip UTF-8 BOM if present (Windows compatibility)\n return content.replace(/^\\uFEFF/, '');\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found\n }\n throw error;\n }\n}\n\n/**\n * Write JSON data to a file with proper formatting\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to write\n * @param {number} indent - Indentation level (default: 2)\n */\nfunction writeJsonFile(filepath, data, indent = 2) {\n const content = JSON.stringify(data, null, indent);\n fs.writeFileSync(filepath, content, 'utf8');\n}\n\n/**\n * Write module.exports file with JSON data\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to export\n */\nfunction writeModuleExportsFile(filepath, data) {\n // Handle empty data cases\n if (data === null || data === undefined || \n (typeof data === 'object' && Object.keys(data).length === 0) ||\n (Array.isArray(data) && data.length === 0)) {\n const emptyContent = Array.isArray(data) ? '[]' : '{}';\n const content = `module.exports = ${emptyContent};`;\n fs.writeFileSync(filepath, content, 'utf8');\n } else {\n const content = `module.exports = ${JSON.stringify(data, null, 2)};`;\n fs.writeFileSync(filepath, content, 'utf8');\n }\n}\n\n/**\n * Check if a file exists\n * @param {string} filepath - Path to check\n * @returns {boolean} True if file exists\n */\nfunction fileExists(filepath) {\n return fs.existsSync(filepath);\n}\n\n/**\n * Create directory recursively\n * @param {string} dirpath - Directory path to create\n */\nfunction ensureDirectoryExists(dirpath) {\n fs.mkdirSync(dirpath, { recursive: true });\n}\n\n/**\n * Remove directory recursively\n * @param {string} dirpath - Directory path to remove\n */\nfunction removeDirectory(dirpath) {\n fs.rmSync(dirpath, { recursive: true, force: true });\n}\n\nmodule.exports = {\n readJsonFileSafe,\n readFileSafe,\n writeJsonFile,\n writeModuleExportsFile,\n fileExists,\n ensureDirectoryExists,\n removeDirectory\n};", "const path = require('path');\nconst { fileExists } = require('./file-utils');\n\n/**\n * Load .env.local file if it exists in the current working directory\n * @param {string} cwd - Current working directory (defaults to process.cwd())\n * @returns {boolean} True if .env.local was loaded\n */\nfunction loadEnvLocal(cwd = process.cwd()) {\n const envLocalPath = path.join(cwd, '.env.local');\n \n if (fileExists(envLocalPath)) {\n require('dotenv').config({ path: envLocalPath });\n console.log('\uD83D\uDCC4 Loaded .env.local');\n return true;\n }\n \n return false;\n}\n\n/**\n * Get an environment variable with optional default value\n * @param {string} name - Environment variable name\n * @param {string} defaultValue - Default value if not set\n * @returns {string|undefined} Environment variable value or default\n */\nfunction getEnvVar(name, defaultValue = undefined) {\n return process.env[name] || defaultValue;\n}\n\n/**\n * Check if an environment variable is set to 'true'\n * @param {string} name - Environment variable name\n * @returns {boolean} True if the env var is set to 'true'\n */\nfunction isEnvTrue(name) {\n return process.env[name] === 'true';\n}\n\nmodule.exports = {\n loadEnvLocal,\n getEnvVar,\n isEnvTrue\n};"],
5
+ "mappings": "8DAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,KAAMC,EAAK,QAAQ,IAAI,EAQvB,SAASC,EAAiBC,EAAU,CAClC,GAAI,CACF,IAAMC,EAAUH,EAAG,aAAaE,EAAU,MAAM,EAChD,OAAO,KAAK,MAAMC,CAAO,CAC3B,OAASC,EAAO,CACd,GAAIA,EAAM,OAAS,SACjB,OAAO,KAET,MAAMA,CACR,CACF,CASA,SAASC,EAAaH,EAAU,CAC9B,GAAI,CAGF,OAFgBF,EAAG,aAAaE,EAAU,MAAM,EAEjC,QAAQ,UAAW,EAAE,CACtC,OAASE,EAAO,CACd,GAAIA,EAAM,OAAS,SACjB,OAAO,KAET,MAAMA,CACR,CACF,CAQA,SAASE,EAAcJ,EAAUK,EAAMC,EAAS,EAAG,CACjD,IAAML,EAAU,KAAK,UAAUI,EAAM,KAAMC,CAAM,EACjDR,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,CAOA,SAASM,EAAuBP,EAAUK,EAAM,CAE9C,GAAIA,GAAS,MACR,OAAOA,GAAS,UAAY,OAAO,KAAKA,CAAI,EAAE,SAAW,GACzD,MAAM,QAAQA,CAAI,GAAKA,EAAK,SAAW,EAAI,CAE9C,IAAMJ,EAAU,oBADK,MAAM,QAAQI,CAAI,EAAI,KAAO,IACF,IAChDP,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,KAAO,CACL,IAAMA,EAAU,oBAAoB,KAAK,UAAUI,EAAM,KAAM,CAAC,CAAC,IACjEP,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,CACF,CAOA,SAASO,EAAWR,EAAU,CAC5B,OAAOF,EAAG,WAAWE,CAAQ,CAC/B,CAMA,SAASS,EAAsBC,EAAS,CACtCZ,EAAG,UAAUY,EAAS,CAAE,UAAW,EAAK,CAAC,CAC3C,CAMA,SAASC,EAAgBD,EAAS,CAChCZ,EAAG,OAAOY,EAAS,CAAE,UAAW,GAAM,MAAO,EAAK,CAAC,CACrD,CAEAb,EAAO,QAAU,CACf,iBAAAE,EACA,aAAAI,EACA,cAAAC,EACA,uBAAAG,EACA,WAAAC,EACA,sBAAAC,EACA,gBAAAE,CACF,ICvGA,IAAMC,EAAO,QAAQ,MAAM,EACrB,CAAE,WAAAC,CAAW,EAAI,IAOvB,SAASC,EAAaC,EAAM,QAAQ,IAAI,EAAG,CACzC,IAAMC,EAAeJ,EAAK,KAAKG,EAAK,YAAY,EAEhD,OAAIF,EAAWG,CAAY,GACzB,QAAQ,QAAQ,EAAE,OAAO,CAAE,KAAMA,CAAa,CAAC,EAC/C,QAAQ,IAAI,6BAAsB,EAC3B,IAGF,EACT,CAQA,SAASC,EAAUC,EAAMC,EAAe,OAAW,CACjD,OAAO,QAAQ,IAAID,CAAI,GAAKC,CAC9B,CAOA,SAASC,EAAUF,EAAM,CACvB,OAAO,QAAQ,IAAIA,CAAI,IAAM,MAC/B,CAEA,OAAO,QAAU,CACf,aAAAJ,EACA,UAAAG,EACA,UAAAG,CACF",
6
6
  "names": ["require_file_utils", "__commonJSMin", "exports", "module", "fs", "readJsonFileSafe", "filepath", "content", "error", "readFileSafe", "writeJsonFile", "data", "indent", "writeModuleExportsFile", "fileExists", "ensureDirectoryExists", "dirpath", "removeDirectory", "path", "fileExists", "loadEnvLocal", "cwd", "envLocalPath", "getEnvVar", "name", "defaultValue", "isEnvTrue"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var n=require("fs");function o(r){try{let e=n.readFileSync(r,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}function c(r){try{return n.readFileSync(r,"utf8")}catch(e){if(e.code==="ENOENT")return null;throw e}}function u(r,e,t=2){let i=JSON.stringify(e,null,t);n.writeFileSync(r,i,"utf8")}function s(r,e){if(e==null||typeof e=="object"&&Object.keys(e).length===0||Array.isArray(e)&&e.length===0){let i=`module.exports = ${Array.isArray(e)?"[]":"{}"};`;n.writeFileSync(r,i,"utf8")}else{let t=`module.exports = ${JSON.stringify(e,null,2)};`;n.writeFileSync(r,t,"utf8")}}function l(r){return n.existsSync(r)}function f(r){n.mkdirSync(r,{recursive:!0})}function y(r){n.rmSync(r,{recursive:!0,force:!0})}module.exports={readJsonFileSafe:o,readFileSafe:c,writeJsonFile:u,writeModuleExportsFile:s,fileExists:l,ensureDirectoryExists:f,removeDirectory:y};
1
+ var t=require("fs");function c(n){try{let e=t.readFileSync(n,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}function i(n){try{return t.readFileSync(n,"utf8").replace(/^\uFEFF/,"")}catch(e){if(e.code==="ENOENT")return null;throw e}}function u(n,e,r=2){let o=JSON.stringify(e,null,r);t.writeFileSync(n,o,"utf8")}function s(n,e){if(e==null||typeof e=="object"&&Object.keys(e).length===0||Array.isArray(e)&&e.length===0){let o=`module.exports = ${Array.isArray(e)?"[]":"{}"};`;t.writeFileSync(n,o,"utf8")}else{let r=`module.exports = ${JSON.stringify(e,null,2)};`;t.writeFileSync(n,r,"utf8")}}function l(n){return t.existsSync(n)}function f(n){t.mkdirSync(n,{recursive:!0})}function y(n){t.rmSync(n,{recursive:!0,force:!0})}module.exports={readJsonFileSafe:c,readFileSafe:i,writeJsonFile:u,writeModuleExportsFile:s,fileExists:l,ensureDirectoryExists:f,removeDirectory:y};
2
2
  //# sourceMappingURL=file-utils.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../lib/core/file-utils.js"],
4
- "sourcesContent": ["const fs = require('fs');\n\n/**\n * Read a JSON file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the JSON file\n * @returns {Object|null} Parsed JSON or null if file not found\n * @throws {Error} If JSON is invalid\n */\nfunction readJsonFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n return JSON.parse(content);\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found, return null like API would return 404\n }\n throw error;\n }\n}\n\n/**\n * Read a file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the file\n * @returns {string|null} File content or null if file not found\n * @throws {Error} For other file system errors\n */\nfunction readFileSafe(filepath) {\n try {\n return fs.readFileSync(filepath, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found\n }\n throw error;\n }\n}\n\n/**\n * Write JSON data to a file with proper formatting\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to write\n * @param {number} indent - Indentation level (default: 2)\n */\nfunction writeJsonFile(filepath, data, indent = 2) {\n const content = JSON.stringify(data, null, indent);\n fs.writeFileSync(filepath, content, 'utf8');\n}\n\n/**\n * Write module.exports file with JSON data\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to export\n */\nfunction writeModuleExportsFile(filepath, data) {\n // Handle empty data cases\n if (data === null || data === undefined || \n (typeof data === 'object' && Object.keys(data).length === 0) ||\n (Array.isArray(data) && data.length === 0)) {\n const emptyContent = Array.isArray(data) ? '[]' : '{}';\n const content = `module.exports = ${emptyContent};`;\n fs.writeFileSync(filepath, content, 'utf8');\n } else {\n const content = `module.exports = ${JSON.stringify(data, null, 2)};`;\n fs.writeFileSync(filepath, content, 'utf8');\n }\n}\n\n/**\n * Check if a file exists\n * @param {string} filepath - Path to check\n * @returns {boolean} True if file exists\n */\nfunction fileExists(filepath) {\n return fs.existsSync(filepath);\n}\n\n/**\n * Create directory recursively\n * @param {string} dirpath - Directory path to create\n */\nfunction ensureDirectoryExists(dirpath) {\n fs.mkdirSync(dirpath, { recursive: true });\n}\n\n/**\n * Remove directory recursively\n * @param {string} dirpath - Directory path to remove\n */\nfunction removeDirectory(dirpath) {\n fs.rmSync(dirpath, { recursive: true, force: true });\n}\n\nmodule.exports = {\n readJsonFileSafe,\n readFileSafe,\n writeJsonFile,\n writeModuleExportsFile,\n fileExists,\n ensureDirectoryExists,\n removeDirectory\n};"],
5
- "mappings": "AAAA,IAAMA,EAAK,QAAQ,IAAI,EAQvB,SAASC,EAAiBC,EAAU,CAClC,GAAI,CACF,IAAMC,EAAUH,EAAG,aAAaE,EAAU,MAAM,EAChD,OAAO,KAAK,MAAMC,CAAO,CAC3B,OAASC,EAAO,CACd,GAAIA,EAAM,OAAS,SACjB,OAAO,KAET,MAAMA,CACR,CACF,CAQA,SAASC,EAAaH,EAAU,CAC9B,GAAI,CACF,OAAOF,EAAG,aAAaE,EAAU,MAAM,CACzC,OAASE,EAAO,CACd,GAAIA,EAAM,OAAS,SACjB,OAAO,KAET,MAAMA,CACR,CACF,CAQA,SAASE,EAAcJ,EAAUK,EAAMC,EAAS,EAAG,CACjD,IAAML,EAAU,KAAK,UAAUI,EAAM,KAAMC,CAAM,EACjDR,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,CAOA,SAASM,EAAuBP,EAAUK,EAAM,CAE9C,GAAIA,GAAS,MACR,OAAOA,GAAS,UAAY,OAAO,KAAKA,CAAI,EAAE,SAAW,GACzD,MAAM,QAAQA,CAAI,GAAKA,EAAK,SAAW,EAAI,CAE9C,IAAMJ,EAAU,oBADK,MAAM,QAAQI,CAAI,EAAI,KAAO,IACF,IAChDP,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,KAAO,CACL,IAAMA,EAAU,oBAAoB,KAAK,UAAUI,EAAM,KAAM,CAAC,CAAC,IACjEP,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,CACF,CAOA,SAASO,EAAWR,EAAU,CAC5B,OAAOF,EAAG,WAAWE,CAAQ,CAC/B,CAMA,SAASS,EAAsBC,EAAS,CACtCZ,EAAG,UAAUY,EAAS,CAAE,UAAW,EAAK,CAAC,CAC3C,CAMA,SAASC,EAAgBD,EAAS,CAChCZ,EAAG,OAAOY,EAAS,CAAE,UAAW,GAAM,MAAO,EAAK,CAAC,CACrD,CAEA,OAAO,QAAU,CACf,iBAAAX,EACA,aAAAI,EACA,cAAAC,EACA,uBAAAG,EACA,WAAAC,EACA,sBAAAC,EACA,gBAAAE,CACF",
4
+ "sourcesContent": ["const fs = require('fs');\n\n/**\n * Read a JSON file safely, returning null if file doesn't exist\n * @param {string} filepath - Path to the JSON file\n * @returns {Object|null} Parsed JSON or null if file not found\n * @throws {Error} If JSON is invalid\n */\nfunction readJsonFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n return JSON.parse(content);\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found, return null like API would return 404\n }\n throw error;\n }\n}\n\n/**\n * Read a file safely, returning null if file doesn't exist\n * Strips UTF-8 BOM if present (fixes Windows compatibility)\n * @param {string} filepath - Path to the file\n * @returns {string|null} File content or null if file not found\n * @throws {Error} For other file system errors\n */\nfunction readFileSafe(filepath) {\n try {\n const content = fs.readFileSync(filepath, 'utf8');\n // Strip UTF-8 BOM if present (Windows compatibility)\n return content.replace(/^\\uFEFF/, '');\n } catch (error) {\n if (error.code === 'ENOENT') {\n return null; // File not found\n }\n throw error;\n }\n}\n\n/**\n * Write JSON data to a file with proper formatting\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to write\n * @param {number} indent - Indentation level (default: 2)\n */\nfunction writeJsonFile(filepath, data, indent = 2) {\n const content = JSON.stringify(data, null, indent);\n fs.writeFileSync(filepath, content, 'utf8');\n}\n\n/**\n * Write module.exports file with JSON data\n * @param {string} filepath - Path to write the file\n * @param {Object} data - Data to export\n */\nfunction writeModuleExportsFile(filepath, data) {\n // Handle empty data cases\n if (data === null || data === undefined || \n (typeof data === 'object' && Object.keys(data).length === 0) ||\n (Array.isArray(data) && data.length === 0)) {\n const emptyContent = Array.isArray(data) ? '[]' : '{}';\n const content = `module.exports = ${emptyContent};`;\n fs.writeFileSync(filepath, content, 'utf8');\n } else {\n const content = `module.exports = ${JSON.stringify(data, null, 2)};`;\n fs.writeFileSync(filepath, content, 'utf8');\n }\n}\n\n/**\n * Check if a file exists\n * @param {string} filepath - Path to check\n * @returns {boolean} True if file exists\n */\nfunction fileExists(filepath) {\n return fs.existsSync(filepath);\n}\n\n/**\n * Create directory recursively\n * @param {string} dirpath - Directory path to create\n */\nfunction ensureDirectoryExists(dirpath) {\n fs.mkdirSync(dirpath, { recursive: true });\n}\n\n/**\n * Remove directory recursively\n * @param {string} dirpath - Directory path to remove\n */\nfunction removeDirectory(dirpath) {\n fs.rmSync(dirpath, { recursive: true, force: true });\n}\n\nmodule.exports = {\n readJsonFileSafe,\n readFileSafe,\n writeJsonFile,\n writeModuleExportsFile,\n fileExists,\n ensureDirectoryExists,\n removeDirectory\n};"],
5
+ "mappings": "AAAA,IAAMA,EAAK,QAAQ,IAAI,EAQvB,SAASC,EAAiBC,EAAU,CAClC,GAAI,CACF,IAAMC,EAAUH,EAAG,aAAaE,EAAU,MAAM,EAChD,OAAO,KAAK,MAAMC,CAAO,CAC3B,OAASC,EAAO,CACd,GAAIA,EAAM,OAAS,SACjB,OAAO,KAET,MAAMA,CACR,CACF,CASA,SAASC,EAAaH,EAAU,CAC9B,GAAI,CAGF,OAFgBF,EAAG,aAAaE,EAAU,MAAM,EAEjC,QAAQ,UAAW,EAAE,CACtC,OAASE,EAAO,CACd,GAAIA,EAAM,OAAS,SACjB,OAAO,KAET,MAAMA,CACR,CACF,CAQA,SAASE,EAAcJ,EAAUK,EAAMC,EAAS,EAAG,CACjD,IAAML,EAAU,KAAK,UAAUI,EAAM,KAAMC,CAAM,EACjDR,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,CAOA,SAASM,EAAuBP,EAAUK,EAAM,CAE9C,GAAIA,GAAS,MACR,OAAOA,GAAS,UAAY,OAAO,KAAKA,CAAI,EAAE,SAAW,GACzD,MAAM,QAAQA,CAAI,GAAKA,EAAK,SAAW,EAAI,CAE9C,IAAMJ,EAAU,oBADK,MAAM,QAAQI,CAAI,EAAI,KAAO,IACF,IAChDP,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,KAAO,CACL,IAAMA,EAAU,oBAAoB,KAAK,UAAUI,EAAM,KAAM,CAAC,CAAC,IACjEP,EAAG,cAAcE,EAAUC,EAAS,MAAM,CAC5C,CACF,CAOA,SAASO,EAAWR,EAAU,CAC5B,OAAOF,EAAG,WAAWE,CAAQ,CAC/B,CAMA,SAASS,EAAsBC,EAAS,CACtCZ,EAAG,UAAUY,EAAS,CAAE,UAAW,EAAK,CAAC,CAC3C,CAMA,SAASC,EAAgBD,EAAS,CAChCZ,EAAG,OAAOY,EAAS,CAAE,UAAW,GAAM,MAAO,EAAK,CAAC,CACrD,CAEA,OAAO,QAAU,CACf,iBAAAX,EACA,aAAAI,EACA,cAAAC,EACA,uBAAAG,EACA,WAAAC,EACA,sBAAAC,EACA,gBAAAE,CACF",
6
6
  "names": ["fs", "readJsonFileSafe", "filepath", "content", "error", "readFileSafe", "writeJsonFile", "data", "indent", "writeModuleExportsFile", "fileExists", "ensureDirectoryExists", "dirpath", "removeDirectory"]
7
7
  }
@@ -1,2 +1,2 @@
1
- var m=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var u=m((v,y)=>{var f=require("fs");function F(o){try{let e=f.readFileSync(o,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}function S(o){try{return f.readFileSync(o,"utf8")}catch(e){if(e.code==="ENOENT")return null;throw e}}function D(o,e,t=2){let n=JSON.stringify(e,null,t);f.writeFileSync(o,n,"utf8")}function g(o,e){if(e==null||typeof e=="object"&&Object.keys(e).length===0||Array.isArray(e)&&e.length===0){let n=`module.exports = ${Array.isArray(e)?"[]":"{}"};`;f.writeFileSync(o,n,"utf8")}else{let t=`module.exports = ${JSON.stringify(e,null,2)};`;f.writeFileSync(o,t,"utf8")}}function E(o){return f.existsSync(o)}function M(o){f.mkdirSync(o,{recursive:!0})}function x(o){f.rmSync(o,{recursive:!0,force:!0})}y.exports={readJsonFileSafe:F,readFileSafe:S,writeJsonFile:D,writeModuleExportsFile:g,fileExists:E,ensureDirectoryExists:M,removeDirectory:x}});var P=m((J,w)=>{var a=require("path"),{fileExists:j}=u();function C(o,e=process.cwd()){let t=e;for(;t!==a.parse(t).root;){let n=a.join(t,o);if(j(n))return n;t=a.dirname(t)}return null}function T(o,e=process.cwd(),t=null){let n=[],i=e,c=10;for(let r=0;r<c;r++){n.push(a.join(i,o)),r<3&&n.push(a.join(i,"../".repeat(r+1)+o));let l=a.dirname(i);if(l===i)break;i=l}n.push(a.join(__dirname,"../../../",o));for(let r of n)if(j(r)&&(!t||t(r)))return r;return null}function N(o,e=process.cwd()){let t=o.map(n=>a.isAbsolute(n)?n:a.join(e,n));for(let n of t)if(j(n))return n;return null}w.exports={findFileUpward:C,findDirectoryUpward:T,findDirectoryWithPaths:N}});var s=require("path"),{findDirectoryUpward:k}=P(),{readJsonFileSafe:h,readFileSafe:b,fileExists:d}=u(),p=class{constructor(e,t={}){if(this.ffId=e,this.tokensBasePath=t.tokensBasePath||this.findTokensPath(),this.folderMap=this.loadFolderMap(),this.projectFolder=this.folderMap[e],!this.projectFolder)throw new Error(`No folder mapping found for ff-id: ${e}`);this.projectPath=s.join(this.tokensBasePath,this.projectFolder)}findTokensPath(){let e=k("apps/tokens",process.cwd(),t=>d(s.join(t,"folderMap.json")));if(e||(e=k("tokens",process.cwd(),t=>d(s.join(t,"folderMap.json")))),!e)throw new Error("Could not find tokens directory with folderMap.json");return e}loadFolderMap(){let e=s.join(this.tokensBasePath,"folderMap.json"),t=h(e);if(!t)throw new Error("Failed to load folderMap.json: File not found");return t}async fetchTokens(){let e=s.join(this.projectPath,"figma"),t={global:[s.join(e,"Global Tokens","Default.json"),s.join(e,"global.json")],colors:[s.join(e,"Global Colors","Default.json"),s.join(e,"Global Colors","Light.json")],semantic:[s.join(e,"Semantic","Light.json"),s.join(e,"Semantic","Default.json")],semanticDark:[s.join(e,"Semantic","Dark.json")]},n={};for(let[i,c]of Object.entries(t)){for(let r of c){let l=h(r);if(l!==null){n[i]=l;break}}n[i]||(n[i]=null)}return n}async fetchProcessedTokens(){let e=s.join(this.projectPath,"cache");if(!d(e))return null;let t={"tokens.js":"hashedTokens.js","variables.js":"hashedVariables.js","semanticVariables.js":"hashedSemanticVariables.js","semanticDarkVariables.js":"hashedSemanticDarkVariables.js","safelist.js":"safelist.js","custom.js":"custom.js","fonts.json":"fonts.json","icons.json":"icons.json","components-config.json":"encoded-config.json","version.json":"version.json"},n={};for(let[c,r]of Object.entries(t)){let l=s.join(e,r);c.endsWith(".js")?n[c]=b(l):n[c]=h(l)}return Object.values(n).some(c=>c!==null)?n:null}async fetchComponentsConfig(){return h(s.join(this.projectPath,"components-config.json"))}async fetchFonts(){return h(s.join(this.projectPath,"font.json"))}async fetchIcons(){return h(s.join(this.projectPath,"icons.json"))}async fetchVersion(){return h(s.join(this.projectPath,"version.json"))}async fetchCustomCss(){return b(s.join(this.projectPath,"custom.css"))}async fetchPlanMetadata(){return h(s.join(this.projectPath,"metadata.json"))||{planType:"full",allowedComponents:null}}fetchJson(){throw new Error("fetchJson is not implemented in LocalTokenReader. Use specific fetch methods.")}fetchRaw(){throw new Error("fetchRaw is not implemented in LocalTokenReader. Use specific fetch methods.")}};module.exports={LocalTokenReader:p};
1
+ var m=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports);var u=m((v,y)=>{var f=require("fs");function b(o){try{let e=f.readFileSync(o,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}function S(o){try{return f.readFileSync(o,"utf8").replace(/^\uFEFF/,"")}catch(e){if(e.code==="ENOENT")return null;throw e}}function D(o,e,t=2){let n=JSON.stringify(e,null,t);f.writeFileSync(o,n,"utf8")}function g(o,e){if(e==null||typeof e=="object"&&Object.keys(e).length===0||Array.isArray(e)&&e.length===0){let n=`module.exports = ${Array.isArray(e)?"[]":"{}"};`;f.writeFileSync(o,n,"utf8")}else{let t=`module.exports = ${JSON.stringify(e,null,2)};`;f.writeFileSync(o,t,"utf8")}}function E(o){return f.existsSync(o)}function M(o){f.mkdirSync(o,{recursive:!0})}function x(o){f.rmSync(o,{recursive:!0,force:!0})}y.exports={readJsonFileSafe:b,readFileSafe:S,writeJsonFile:D,writeModuleExportsFile:g,fileExists:E,ensureDirectoryExists:M,removeDirectory:x}});var P=m((J,w)=>{var a=require("path"),{fileExists:j}=u();function C(o,e=process.cwd()){let t=e;for(;t!==a.parse(t).root;){let n=a.join(t,o);if(j(n))return n;t=a.dirname(t)}return null}function T(o,e=process.cwd(),t=null){let n=[],i=e,c=10;for(let r=0;r<c;r++){n.push(a.join(i,o)),r<3&&n.push(a.join(i,"../".repeat(r+1)+o));let l=a.dirname(i);if(l===i)break;i=l}n.push(a.join(__dirname,"../../../",o));for(let r of n)if(j(r)&&(!t||t(r)))return r;return null}function N(o,e=process.cwd()){let t=o.map(n=>a.isAbsolute(n)?n:a.join(e,n));for(let n of t)if(j(n))return n;return null}w.exports={findFileUpward:C,findDirectoryUpward:T,findDirectoryWithPaths:N}});var s=require("path"),{findDirectoryUpward:k}=P(),{readJsonFileSafe:h,readFileSafe:F,fileExists:d}=u(),p=class{constructor(e,t={}){if(this.ffId=e,this.tokensBasePath=t.tokensBasePath||this.findTokensPath(),this.folderMap=this.loadFolderMap(),this.projectFolder=this.folderMap[e],!this.projectFolder)throw new Error(`No folder mapping found for ff-id: ${e}`);this.projectPath=s.join(this.tokensBasePath,this.projectFolder)}findTokensPath(){let e=k("apps/tokens",process.cwd(),t=>d(s.join(t,"folderMap.json")));if(e||(e=k("tokens",process.cwd(),t=>d(s.join(t,"folderMap.json")))),!e)throw new Error("Could not find tokens directory with folderMap.json");return e}loadFolderMap(){let e=s.join(this.tokensBasePath,"folderMap.json"),t=h(e);if(!t)throw new Error("Failed to load folderMap.json: File not found");return t}async fetchTokens(){let e=s.join(this.projectPath,"figma"),t={global:[s.join(e,"Global Tokens","Default.json"),s.join(e,"global.json")],colors:[s.join(e,"Global Colors","Default.json"),s.join(e,"Global Colors","Light.json")],semantic:[s.join(e,"Semantic","Light.json"),s.join(e,"Semantic","Default.json")],semanticDark:[s.join(e,"Semantic","Dark.json")]},n={};for(let[i,c]of Object.entries(t)){for(let r of c){let l=h(r);if(l!==null){n[i]=l;break}}n[i]||(n[i]=null)}return n}async fetchProcessedTokens(){let e=s.join(this.projectPath,"cache");if(!d(e))return null;let t={"tokens.js":"hashedTokens.js","variables.js":"hashedVariables.js","semanticVariables.js":"hashedSemanticVariables.js","semanticDarkVariables.js":"hashedSemanticDarkVariables.js","safelist.js":"safelist.js","custom.js":"custom.js","fonts.json":"fonts.json","icons.json":"icons.json","components-config.json":"encoded-config.json","version.json":"version.json"},n={};for(let[c,r]of Object.entries(t)){let l=s.join(e,r);c.endsWith(".js")?n[c]=F(l):n[c]=h(l)}return Object.values(n).some(c=>c!==null)?n:null}async fetchComponentsConfig(){return h(s.join(this.projectPath,"components-config.json"))}async fetchFonts(){return h(s.join(this.projectPath,"font.json"))}async fetchIcons(){return h(s.join(this.projectPath,"icons.json"))}async fetchVersion(){return h(s.join(this.projectPath,"version.json"))}async fetchCustomCss(){return F(s.join(this.projectPath,"custom.css"))}async fetchPlanMetadata(){return h(s.join(this.projectPath,"metadata.json"))||{planType:"full",allowedComponents:null}}fetchJson(){throw new Error("fetchJson is not implemented in LocalTokenReader. Use specific fetch methods.")}fetchRaw(){throw new Error("fetchRaw is not implemented in LocalTokenReader. Use specific fetch methods.")}};module.exports={LocalTokenReader:p};
2
2
  //# sourceMappingURL=local-token-reader.js.map