builder.io 1.1.27-1 → 1.1.27-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/index.cjs CHANGED
@@ -1636,7 +1636,7 @@ Visit https://www.docs.developers.amplitude.com/data/sdks/browser-2/#tracking-de
1636
1636
  </script>
1637
1637
  </body>
1638
1638
  </html>
1639
- `)}async function AO(e,t){let n=await Jx(e),r=e.getFrameworks();return t.replace(/__LOCAL_APP_ID__/g,n).replace(/__DEV_TOOLS_URL__/g,e.devToolsServerUrl).replace(/__CLIENT_ID__/g,e.getClientId()).replace(/__FRAMEWORK__/g,r.length?r[0].name:"")}var NO=require("node:os");async function PO(e,t){let n=new URL("/cli-auth","https://builder.io");n.searchParams.set("client_id",e.getClientId()),n.searchParams.set("host",await e.getDeviceId()),n.searchParams.set("response_type","code"),n.searchParams.set("cli","true");let r=new URL(fi,e.devToolsServerUrl);r.searchParams.set(wc,(0,NO.platform)()),r.searchParams.set(Rc,process.versions.node);let i=e.getFrameworks();return i.length>0&&(n.searchParams.set(Zi,i[0].name),r.searchParams.set(Zi,i[0].name)),n.searchParams.set("redirect_url",r.href),n.searchParams.set("preview_url",t),n.href}async function FO(e,t,n,r){try{if(!e)return bs(n,r,400,"Builder context closed");let i=i5(n);if(i.pathname===dp){if(n.method==="POST"){let s=await r5(n);if(s)try{let o=await wO(e,JSON.parse(s));return OO(n,r,200,o)}catch(o){e.debug("Dev API Error",o.stack||o.message||o);let a={errors:[String(o.message||o)]};return OO(n,r,500,a)}}else if(n.method==="OPTIONS"){let s={"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Cache-Control, X-Builder-Devtools-Version"},o=n.headers.origin;o&&o!=="null"?kO(new URL(o))&&(s["Access-Control-Allow-Origin"]=o):s["Access-Control-Allow-Origin"]="*",r.writeHead(200,s),r.end();return}return bs(n,r,405,`${dp} is an API endpoint used only during development by the Builder.io Devtools client-side script`)}if(i.pathname===pp)return e5(n,r,200,await RO(e));if(i.pathname===RE){let s=i.searchParams.get(lp);return s?n5(r,302,await PO(e,s)):bs(n,r,400,`Missing ${lp} querystring`)}return i.pathname===fi?t5(n,r,200,await IO(e)):i.pathname===mi?(e.debug(`Close Dev Tools Server Requested: ${i.href}`),setTimeout(()=>{try{t.close(s=>{e.debug(`Dev Tools Server Closed Error: ${s}`)})}catch(s){e.debug(`Error closing devtools server: ${s}`)}},20),bs(n,r,200,"Closing Dev Tools Server")):bs(n,r,404,"Not found")}catch(i){return console.error("Dev Server Error",i),bs(n,r,500,`Dev Server Error: ${i}`)}}function OO(e,t,n,r){Zd(e,t,n,"application/json",JSON.stringify(r))}function e5(e,t,n,r){Zd(e,t,n,"application/javascript",r)}function t5(e,t,n,r){Zd(e,t,n,"text/html",r)}function bs(e,t,n,r){Zd(e,t,n,"text/plain",r)}function Zd(e,t,n,r,i){let s={"Content-Type":`${r}; charset=utf-8`,"Cache-Control":"no-cache, no-store, must-revalidate","X-Builder-Devtools-Version":"1.1.26"},o=e.headers.origin;o&&o!=="null"?kO(new URL(o))&&(s["Access-Control-Allow-Origin"]=o):s["Access-Control-Allow-Origin"]="*",t.writeHead(n,s),t.end(i)}function kO(e){return e.hostname==="localhost"||e.origin==="https://builder.io"||e.origin==="https://www.builder.io"||e.origin.endsWith(".builder.io")?!0:e.port===""?!1:e.port!=="80"&&e.port!=="443"}function n5(e,t,n){e.writeHead(t,{Location:n}),e.end()}async function r5(e){let t="";for await(let n of e)t+=n;return t}function i5(e){let t=e.url||"/";return new URL(t,`http://${e.headers.host}`)}async function MO(e){if(globalThis.__builderDevToolsServer)return e.debug("reusing existing devtools server"),globalThis.__builderDevToolsServer.setContext(e),globalThis.__builderDevToolsServer;let t=await o5(e),n=(0,ep.createServer)((i,s)=>{FO(e,n,i,s)}),r=()=>new Promise((i,s)=>{n.listening?(e.debug(`closing devtools server on port ${t}`),n.close(o=>{e=null,o?(e.debug(`error closing devtools server on port ${t}`),s(o)):(e&&e.debug(`closed devtools server on port ${t}`),i())})):(e.debug(`devtools server on port ${t} not listening`),i())});return process.once("SIGTERM",r),process.once("SIGINT",r),process.env.CI!=="true"&&process.stdin.on("end",r),globalThis.__builderDevToolsServer={url:new URL(`http://localhost:${t}`).href,port:t,setContext:i=>{e.debug(`set devtools context on server ${t}`),e=i},close:async()=>{globalThis.__builderDevToolsServer=null,await r()}},new Promise(i=>{n.listen(t,()=>{e.debug(`started devtools server on port ${t}`),i(globalThis.__builderDevToolsServer)})})}function o5(e){return new Promise(t=>{let n=e.port;try{(0,ep.request)({hostname:"localhost",port:n,path:mi,method:"GET"},i=>{i.on("end",()=>{e.debug(`${mi} - Response ended`),t(n)})}).on("error",i=>{e.debug(`${mi} - No response ${i}`),t(n)}).end()}catch(r){e.debug(`${mi} - Error ${r}`),t(n)}})}async function yE(e){let t={getPastSyncInfo:()=>null,resyncSnippet:()=>null,...e,devToolsServerUrl:"",isValid:!1,publicApiKey:"",serverShouldRestart:!1,port:e.port||5273,ignoreMissingConfig:!1},n=e.getFrameworks().map(s=>s.name).join(", ");t.debug(`create devtools ${LO} [${n}]`);let r=await MO(t);return t.devToolsServerUrl=r.url,t.port=r.port,{getUrl:()=>t.devToolsServerUrl}}var LO="1.1.26";var qO=q(require("chokidar"),1),jO=q(require("ignore"),1);function GO(e){let t=e.match(/builder\.io\/content\/([^?]+)\?codeSession=([^&]+)&sid=([^\s]+)/);return t?{contentId:t[1],sessionKey:t[2],snippetId:t[3]}:{}}async function s5(e,t,n){let r=await(0,UO.glob)("**/*",{cwd:e,ignore:["node_modules/**"],nodir:!0}),i=[];for(let s of r){let o=(0,_t.resolve)(e,s);try{let a=(0,wt.readFileSync)(o,"utf-8");if(a.includes("This code was generated by Builder.io")){let c=GO(a);if(t&&n&&(c.contentId!==t||c.sessionKey!==n))continue;i.push({path:s,code:tp(a),name:s.split("/").pop()||"",timestamp:(0,wt.statSync)(o).mtime.getTime(),snippetId:c.snippetId})}}catch(a){console.error(`Error reading file ${o}:`,a)}}return i}function a5(e,t){let n=GO(e);return n.contentId===t.contentId&&n.sessionKey===t.sessionKey}function c5(e){let t=[".git",".DS_Store",".vscode","node_modules",".next","coverage"],n=(0,jO.default)().add(t);try{let r=(0,_t.resolve)(e,".gitignore");if((0,wt.existsSync)(r)){let i=(0,wt.readFileSync)(r,"utf8");n.add(i)}}catch(r){console.debug("No .gitignore found or error reading it:",r)}return r=>{let i=(0,_t.relative)(e,r);if(!i)return!1;let s=i.split(_t.sep).join("/");return n.ignores(s)}}function BO(e,t,n){let r=c5(e),i=qO.default.watch(e,{ignored:r,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:500,pollInterval:600},ignorePermissionErrors:!0,followSymlinks:!1,atomic:600}),s=async a=>{let c=(0,_t.relative)(e,a);try{let u=(0,wt.readFileSync)(a,"utf-8");if(a5(u,t.snippet)){let l=t.writtenFiles.find(d=>d.path===c);l?(l.code=tp(u),l.timestamp=Date.now()):t.writtenFiles.push({path:c,code:tp(u),timestamp:Date.now(),name:c.split("/").pop()||""}),t.timeStamp=Date.now(),n(t)}}catch(u){console.debug(`Error reading file ${a}:`,u)}};i.on("add",async a=>{B.info(`File added: ${a}`),await s(a)}).on("change",async a=>{B.info(`File changed: ${a}`),await s(a)}).on("unlink",a=>{B.info(`File deleted: ${a}`);let c=(0,_t.relative)(e,a);t.writtenFiles=t.writtenFiles.filter(u=>u.path!==c),t.timeStamp=Date.now(),n(t)}).on("unlinkDir",a=>{B.info(`Folder deleted: ${a}`);let c=(0,_t.relative)(e,a);t.writtenFiles=t.writtenFiles.filter(u=>!u.path.startsWith(c)),t.timeStamp=Date.now(),n(t)}).on("ready",()=>{console.debug("Initial scan complete. Ready for changes.")}).on("error",a=>{console.error(`Watcher error: ${a}`)}),i.on("raw",async(a,c,u)=>{if(a==="renamed"){B.info(`File renamed: ${u.oldPath} -> ${c}`);let l=u.oldPath?(0,_t.relative)(e,u.oldPath):void 0,d=c?(0,_t.relative)(e,c):void 0;if(l&&d){let p=t.writtenFiles.find(f=>f.path===l);p&&(p.path=d,t.timeStamp=Date.now(),n(t))}}});let o=async()=>{await i.close()};return process.on("SIGINT",o),process.on("SIGTERM",o),o}async function KO(e,t){e.debug("builder sync server init");let n=await zi(e),r=t,i=()=>Promise.resolve();r&&setTimeout(()=>{i=BO(process.cwd(),r,s=>{r=s})},1e3),await yE({...n,getPastSyncInfo:({sessionKey:s,since:o})=>!r||s!==r.snippet.sessionKey?null:{...r,hasChanged:r.timeStamp>o},resyncSnippet:async s=>{await i();let o=await DE({path:r?.pathInput,snippet:s.snippet,cwd:process.cwd()});return o&&(r=o,i=BO(process.cwd(),r,a=>{r=a})),r},getClientId:()=>"builder-sync-cli",closeAppServer:async()=>{await i()},restartAppServer:async()=>{e.debug("restart server")},enableAppWatch:async s=>s,...e})}async function DE(e){let t=e.snippetId,n=e.snippet||null;if(!n&&t&&(n=await hE(t)),!n)throw new Error(`No snippet found for id ${t}`);let r=await s5(process.cwd(),n.contentId,n.sessionKey),i=r.filter(u=>u.snippetId===n.id);if(B.info(`Found ${i.length} matching files for snippet ${n.id} in existing files ${r.length}`),i.length>0){let u=Math.max(...i.map(l=>l.timestamp||0));return{snippet:n,writtenFiles:i,pathInput:$O(i.map(l=>l.path)),timeStamp:u}}let s=$O(r.map(u=>u.path))||_E(n.framework||"react"),o=e.path||await Lt({message:"Where should we copy the files?",initialValue:s,validate(u){if(u.length===0)return"File path is required!";if(u[0]!==".")return"Please enter a relative path."}});Te(o)&&(ne("Cancelled sync"),process.exit(0));for(let u of r){let l=(0,_t.resolve)(process.cwd(),u.path);try{(0,wt.unlinkSync)(l),B.info(`Deleted old file: ${l}`);let d=(0,_t.dirname)(l);(0,wt.readdirSync)(d).length===0&&((0,wt.rmdirSync)(d),B.info(`Deleted empty folder: ${d}`))}catch(d){B.error(`Error cleaning up file ${l}: ${d}`)}}let a=await Xd(n,n.files,o,!0);B.success("All files have been written successfully.");let c=Math.max(...a.map(u=>u.timestamp||0));return{snippet:n,writtenFiles:a.map(u=>({...u,code:tp(u.code)})),pathInput:o,timeStamp:c||Date.now()}}function tp(e){if(!e)return e;let t=/<!--\s*This code was generated by Builder\.io\s*-->\s*(?:<!--\s*https:\/\/builder\.io\/content\/[a-f0-9]+\?codeSession=[a-f0-9]+&sid=[a-f0-9]+\s*-->\s*)?/,n=/\/\*\*\s*\n\s*\* This code was generated by Builder\.io\s*\n\s*\* https:\/\/builder\.io\/content\/[a-f0-9]+\?codeSession=[a-f0-9]+&sid=[a-f0-9]+\s*\n\s*\*\/\s*/,r=e.replace(t,"").replace(n,"");return r=r.replace(/^\n+/,""),r}function $O(e){if(e.length===0)return"";if(e.length===1)return e[0].slice(0,e[0].lastIndexOf("/")+1);let t=e.map(i=>i.split("/")),n=Math.min(...t.map(i=>i.length)),r=[];for(let i=0;i<n;i++){let s=t[0][i];if(t.every(o=>o[i]===s))r.push(s);else break}return r.join("/")}var HO="1.1.26";function l5(){np.init("ac35e3108919035e7d150a2450a07405",{logLevel:np.Types.LogLevel.None,flushIntervalMillis:500}),Dn.init({dsn:"https://3252dddc08dbb5bf406dc33bf3c13633@o117565.ingest.us.sentry.io/4505630794448896",tracesSampleRate:1,release:HO,integrations:[new Dn.Integrations.Http({tracing:!0}),...Dn.autoDiscoverNodePerformanceMonitoringIntegrations()]})}async function d5(e){e.debug("builder dev tools cli init");let t=await(0,VO.createDevTools)(e);await(0,YO.createDevToolsServer)({...t,getClientId:()=>"builder-dev-tools-cli",closeAppServer:async()=>{},restartAppServer:async()=>{e.debug("restart server")},enableAppWatch:async n=>n,...e})}var JO=()=>process.exit(0);process.on("SIGINT",JO);process.on("SIGTERM",JO);async function p5(){l5();try{let e=await(0,zO.createDevToolsNodeSys)({getRootDir:()=>process.cwd(),ignoreMissingConfig:!0}),t=(0,WO.default)(process.argv.slice(2),{string:["figmaToken","privateKey","spaceId"],boolean:["help","ci","force","printJson"]}),n=t._[0];if(n==="figma"){let r=t._[1];try{await cO(e,r,t)}catch(i){return Dn.captureException(i),console.error(i),await oe(1)}}else if(n==="add"){let r=bE(process.cwd(),process.argv.slice(2));await fO(r)}else if(n==="sync"){let r=bE(process.cwd(),process.argv.slice(2)),i=await DE(r);KO(e,i).then(()=>{console.info("Builder dev tools is running")}).catch(s=>{Dn.captureException(s),console.error("Cannot start builder dev tools",s)})}else{if(n==="publish"||n==="migrate"||n==="generate")return ne("Command not found, do you mean `npx builder.io figma "+n+"`?"),await oe(1);d5(e).then(()=>{console.info("Builder dev tools is running")}).catch(r=>{Dn.captureException(r),console.error("Cannot start builder dev tools",r)})}}catch(e){return Dn.captureException(e),console.error(e),await oe(1)}}p5();
1639
+ `)}async function AO(e,t){let n=await Jx(e),r=e.getFrameworks();return t.replace(/__LOCAL_APP_ID__/g,n).replace(/__DEV_TOOLS_URL__/g,e.devToolsServerUrl).replace(/__CLIENT_ID__/g,e.getClientId()).replace(/__FRAMEWORK__/g,r.length?r[0].name:"")}var NO=require("node:os");async function PO(e,t){let n=new URL("/cli-auth","https://builder.io");n.searchParams.set("client_id",e.getClientId()),n.searchParams.set("host",await e.getDeviceId()),n.searchParams.set("response_type","code"),n.searchParams.set("cli","true");let r=new URL(fi,e.devToolsServerUrl);r.searchParams.set(wc,(0,NO.platform)()),r.searchParams.set(Rc,process.versions.node);let i=e.getFrameworks();return i.length>0&&(n.searchParams.set(Zi,i[0].name),r.searchParams.set(Zi,i[0].name)),n.searchParams.set("redirect_url",r.href),n.searchParams.set("preview_url",t),n.href}async function FO(e,t,n,r){try{if(!e)return bs(n,r,400,"Builder context closed");let i=i5(n);if(i.pathname===dp){if(n.method==="POST"){let s=await r5(n);if(s)try{let o=await wO(e,JSON.parse(s));return OO(n,r,200,o)}catch(o){e.debug("Dev API Error",o.stack||o.message||o);let a={errors:[String(o.message||o)]};return OO(n,r,500,a)}}else if(n.method==="OPTIONS"){let s={"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type, Cache-Control, X-Builder-Devtools-Version"},o=n.headers.origin;o&&o!=="null"?kO(new URL(o))&&(s["Access-Control-Allow-Origin"]=o):s["Access-Control-Allow-Origin"]="*",r.writeHead(200,s),r.end();return}return bs(n,r,405,`${dp} is an API endpoint used only during development by the Builder.io Devtools client-side script`)}if(i.pathname===pp)return e5(n,r,200,await RO(e));if(i.pathname===RE){let s=i.searchParams.get(lp);return s?n5(r,302,await PO(e,s)):bs(n,r,400,`Missing ${lp} querystring`)}return i.pathname===fi?t5(n,r,200,await IO(e)):i.pathname===mi?(e.debug(`Close Dev Tools Server Requested: ${i.href}`),setTimeout(()=>{try{t.close(s=>{e.debug(`Dev Tools Server Closed Error: ${s}`)})}catch(s){e.debug(`Error closing devtools server: ${s}`)}},20),bs(n,r,200,"Closing Dev Tools Server")):bs(n,r,404,"Not found")}catch(i){return console.error("Dev Server Error",i),bs(n,r,500,`Dev Server Error: ${i}`)}}function OO(e,t,n,r){Zd(e,t,n,"application/json",JSON.stringify(r))}function e5(e,t,n,r){Zd(e,t,n,"application/javascript",r)}function t5(e,t,n,r){Zd(e,t,n,"text/html",r)}function bs(e,t,n,r){Zd(e,t,n,"text/plain",r)}function Zd(e,t,n,r,i){let s={"Content-Type":`${r}; charset=utf-8`,"Cache-Control":"no-cache, no-store, must-revalidate","X-Builder-Devtools-Version":"1.1.26"},o=e.headers.origin;o&&o!=="null"?kO(new URL(o))&&(s["Access-Control-Allow-Origin"]=o):s["Access-Control-Allow-Origin"]="*",t.writeHead(n,s),t.end(i)}function kO(e){return e.hostname==="localhost"||e.origin==="https://builder.io"||e.origin==="https://www.builder.io"||e.origin.endsWith(".builder.io")?!0:e.port===""?!1:e.port!=="80"&&e.port!=="443"}function n5(e,t,n){e.writeHead(t,{Location:n}),e.end()}async function r5(e){let t="";for await(let n of e)t+=n;return t}function i5(e){let t=e.url||"/";return new URL(t,`http://${e.headers.host}`)}async function MO(e){if(globalThis.__builderDevToolsServer)return e.debug("reusing existing devtools server"),globalThis.__builderDevToolsServer.setContext(e),globalThis.__builderDevToolsServer;let t=await o5(e),n=(0,ep.createServer)((i,s)=>{FO(e,n,i,s)}),r=()=>new Promise((i,s)=>{n.listening?(e.debug(`closing devtools server on port ${t}`),n.close(o=>{e=null,o?(e.debug(`error closing devtools server on port ${t}`),s(o)):(e&&e.debug(`closed devtools server on port ${t}`),i())})):(e.debug(`devtools server on port ${t} not listening`),i())});return process.once("SIGTERM",r),process.once("SIGINT",r),process.env.CI!=="true"&&process.stdin.on("end",r),globalThis.__builderDevToolsServer={url:new URL(`http://localhost:${t}`).href,port:t,setContext:i=>{e.debug(`set devtools context on server ${t}`),e=i},close:async()=>{globalThis.__builderDevToolsServer=null,await r()}},new Promise(i=>{n.listen(t,()=>{e.debug(`started devtools server on port ${t}`),i(globalThis.__builderDevToolsServer)})})}function o5(e){return new Promise(t=>{let n=e.port;try{(0,ep.request)({hostname:"localhost",port:n,path:mi,method:"GET"},i=>{i.on("end",()=>{e.debug(`${mi} - Response ended`),t(n)})}).on("error",i=>{e.debug(`${mi} - No response ${i}`),t(n)}).end()}catch(r){e.debug(`${mi} - Error ${r}`),t(n)}})}async function yE(e){let t={getPastSyncInfo:()=>null,resyncSnippet:()=>null,...e,devToolsServerUrl:"",isValid:!1,publicApiKey:"",serverShouldRestart:!1,port:e.port||5273,ignoreMissingConfig:!1},n=e.getFrameworks().map(s=>s.name).join(", ");t.debug(`create devtools ${LO} [${n}]`);let r=await MO(t);return t.devToolsServerUrl=r.url,t.port=r.port,{getUrl:()=>t.devToolsServerUrl}}var LO="1.1.26";var qO=q(require("chokidar"),1),jO=q(require("ignore"),1);function GO(e){let t=e.match(/builder\.io\/content\/([^?]+)\?codeSession=([^&]+)&sid=([^\s]+)/);return t?{contentId:t[1],sessionKey:t[2],snippetId:t[3]}:{}}async function s5(e,t,n){let r=await(0,UO.glob)("**/*",{cwd:e,ignore:["node_modules/**"],nodir:!0}),i=[];for(let s of r){let o=(0,_t.resolve)(e,s);try{let a=(0,wt.readFileSync)(o,"utf-8");if(a.includes("This code was generated by Builder.io")){let c=GO(a);if(t&&n&&(c.contentId!==t||c.sessionKey!==n))continue;i.push({path:s,code:tp(a),name:s.split("/").pop()||"",timestamp:(0,wt.statSync)(o).mtime.getTime(),snippetId:c.snippetId})}}catch(a){console.error(`Error reading file ${o}:`,a)}}return i}function a5(e,t){let n=GO(e);return n.contentId===t.contentId&&n.sessionKey===t.sessionKey}function c5(e){let t=[".git",".DS_Store",".vscode","node_modules",".next","coverage"],n=(0,jO.default)().add(t);try{let r=(0,_t.resolve)(e,".gitignore");if((0,wt.existsSync)(r)){let i=(0,wt.readFileSync)(r,"utf8");n.add(i)}}catch(r){console.debug("No .gitignore found or error reading it:",r)}return r=>{let i=(0,_t.relative)(e,r);if(!i)return!1;let s=i.split(_t.sep).join("/");return n.ignores(s)}}function BO(e,t,n){let r=c5(e),i=qO.default.watch(e,{ignored:r,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:500,pollInterval:600},ignorePermissionErrors:!0,followSymlinks:!1,atomic:600}),s=async a=>{let c=(0,_t.relative)(e,a);try{let u=(0,wt.readFileSync)(a,"utf-8");if(a5(u,t.snippet)){let l=t.writtenFiles.find(d=>d.path===c);l?(l.code=tp(u),l.timestamp=Date.now()):t.writtenFiles.push({path:c,code:tp(u),timestamp:Date.now(),name:c.split("/").pop()||""}),t.timeStamp=Date.now(),n(t)}}catch(u){console.debug(`Error reading file ${a}:`,u)}};i.on("add",async a=>{B.info(`File added: ${a}`),await s(a)}).on("change",async a=>{B.info(`File changed: ${a}`),await s(a)}).on("unlink",a=>{B.info(`File deleted: ${a}`);let c=(0,_t.relative)(e,a);t.writtenFiles=t.writtenFiles.filter(u=>u.path!==c),t.timeStamp=Date.now(),n(t)}).on("unlinkDir",a=>{B.info(`Folder deleted: ${a}`);let c=(0,_t.relative)(e,a);t.writtenFiles=t.writtenFiles.filter(u=>!u.path.startsWith(c)),t.timeStamp=Date.now(),n(t)}).on("ready",()=>{console.debug("Initial scan complete. Ready for changes.")}).on("error",a=>{console.error(`Watcher error: ${a}`)}),i.on("raw",async(a,c,u)=>{if(a==="renamed"){B.info(`File renamed: ${u.oldPath} -> ${c}`);let l=u.oldPath?(0,_t.relative)(e,u.oldPath):void 0,d=c?(0,_t.relative)(e,c):void 0;if(l&&d){let p=t.writtenFiles.find(f=>f.path===l);p&&(p.path=d,t.timeStamp=Date.now(),n(t))}}});let o=async()=>{await i.close()};return process.on("SIGINT",o),process.on("SIGTERM",o),o}async function KO(e,t){e.debug("builder sync server init");let n=await zi(e),r=t,i=()=>Promise.resolve();r&&setTimeout(()=>{i=BO(process.cwd(),r,s=>{r=s})},1e3),await yE({...n,getPastSyncInfo:({sessionKey:s,since:o})=>!r||s!==r.snippet.sessionKey?null:{...r,hasChanged:r.timeStamp>o},resyncSnippet:async s=>{await i();let o=await DE({path:r?.pathInput,snippet:s.snippet,cwd:process.cwd()});return o&&(r=o,i=BO(process.cwd(),r,a=>{r=a})),r},getClientId:()=>"builder-sync-cli",closeAppServer:async()=>{await i()},restartAppServer:async()=>{e.debug("restart server")},enableAppWatch:async s=>s,...e})}async function DE(e){let t=e.snippetId,n=e.snippet||null;if(!n&&t&&(n=await hE(t)),!n)throw new Error(`No snippet found for id ${t}`);let r=await s5(process.cwd(),n.contentId,n.sessionKey),i=r.filter(u=>u.snippetId===n.id);if(B.info(`Found ${i.length} matching files for snippet ${n.id} in existing files ${r.length}`),i.length>0){let u=Math.max(...i.map(l=>l.timestamp||0));return{snippet:n,writtenFiles:i,pathInput:$O(i.map(l=>l.path)),timeStamp:u}}let s=_E(n.framework||"react"),o=e.path||$O(r.map(u=>u.path))||await Lt({message:"Where should we copy the files?",initialValue:s,validate(u){if(u.length===0)return"File path is required!";if(u[0]!==".")return"Please enter a relative path."}});Te(o)&&(ne("Cancelled sync"),process.exit(0));for(let u of r){let l=(0,_t.resolve)(process.cwd(),u.path);try{(0,wt.unlinkSync)(l),B.info(`Deleted old file: ${l}`);let d=(0,_t.dirname)(l);(0,wt.readdirSync)(d).length===0&&((0,wt.rmdirSync)(d),B.info(`Deleted empty folder: ${d}`))}catch(d){B.error(`Error cleaning up file ${l}: ${d}`)}}let a=await Xd(n,n.files,o,!0);B.success("All files have been written successfully.");let c=Math.max(...a.map(u=>u.timestamp||0));return{snippet:n,writtenFiles:a.map(u=>({...u,code:tp(u.code)})),pathInput:o,timeStamp:c||Date.now()}}function tp(e){if(!e)return e;let t=/<!--\s*This code was generated by Builder\.io\s*-->\s*(?:<!--\s*https:\/\/builder\.io\/content\/[a-f0-9]+\?codeSession=[a-f0-9]+&sid=[a-f0-9]+\s*-->\s*)?/,n=/\/\*\*\s*\n\s*\* This code was generated by Builder\.io\s*\n\s*\* https:\/\/builder\.io\/content\/[a-f0-9]+\?codeSession=[a-f0-9]+&sid=[a-f0-9]+\s*\n\s*\*\/\s*/,r=e.replace(t,"").replace(n,"");return r=r.replace(/^\n+/,""),r}function $O(e){if(e.length===0)return"";if(e.length===1)return`./${e[0].slice(0,e[0].lastIndexOf("/")+1)}`;let t=e.map(i=>i.split("/")),n=Math.min(...t.map(i=>i.length)),r=[];for(let i=0;i<n;i++){let s=t[0][i];if(t.every(o=>o[i]===s))r.push(s);else break}return`./${r.join("/")}`}var HO="1.1.26";function l5(){np.init("ac35e3108919035e7d150a2450a07405",{logLevel:np.Types.LogLevel.None,flushIntervalMillis:500}),Dn.init({dsn:"https://3252dddc08dbb5bf406dc33bf3c13633@o117565.ingest.us.sentry.io/4505630794448896",tracesSampleRate:1,release:HO,integrations:[new Dn.Integrations.Http({tracing:!0}),...Dn.autoDiscoverNodePerformanceMonitoringIntegrations()]})}async function d5(e){e.debug("builder dev tools cli init");let t=await(0,VO.createDevTools)(e);await(0,YO.createDevToolsServer)({...t,getClientId:()=>"builder-dev-tools-cli",closeAppServer:async()=>{},restartAppServer:async()=>{e.debug("restart server")},enableAppWatch:async n=>n,...e})}var JO=()=>process.exit(0);process.on("SIGINT",JO);process.on("SIGTERM",JO);async function p5(){l5();try{let e=await(0,zO.createDevToolsNodeSys)({getRootDir:()=>process.cwd(),ignoreMissingConfig:!0}),t=(0,WO.default)(process.argv.slice(2),{string:["figmaToken","privateKey","spaceId"],boolean:["help","ci","force","printJson"]}),n=t._[0];if(n==="figma"){let r=t._[1];try{await cO(e,r,t)}catch(i){return Dn.captureException(i),console.error(i),await oe(1)}}else if(n==="add"){let r=bE(process.cwd(),process.argv.slice(2));await fO(r)}else if(n==="sync"){let r=bE(process.cwd(),process.argv.slice(2)),i=await DE(r);KO(e,i).then(()=>{console.info("Builder dev tools is running")}).catch(s=>{Dn.captureException(s),console.error("Cannot start builder dev tools",s)})}else{if(n==="publish"||n==="migrate"||n==="generate")return ne("Command not found, do you mean `npx builder.io figma "+n+"`?"),await oe(1);d5(e).then(()=>{console.info("Builder dev tools is running")}).catch(r=>{Dn.captureException(r),console.error("Cannot start builder dev tools",r)})}}catch(e){return Dn.captureException(e),console.error(e),await oe(1)}}p5();
1640
1640
  /*! Bundled license information:
1641
1641
 
1642
1642
  cookie/index.js: