builder.io 0.0.4 → 0.0.5
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/index.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -55,7 +55,7 @@ ${C.default.cyan(O2)}
|
|
|
55
55
|
`)}
|
|
56
56
|
`)},info:t=>{ft.message(t,{symbol:C.default.blue(kl)})},success:t=>{ft.message(t,{symbol:C.default.green(Ml)})},step:t=>{ft.message(t,{symbol:C.default.green(on)})},warn:t=>{ft.message(t,{symbol:C.default.yellow(Ul)})},warning:t=>{ft.warn(t)},error:t=>{ft.message(t,{symbol:C.default.red(Vl)})}},un=()=>{let t=sn?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],e=sn?80:120,a,i,p=!1,r="",n=(u="")=>{p=!0,a=B2(),r=u.replace(/\.+$/,""),process.stdout.write(`${C.default.gray(Ve)}
|
|
57
57
|
`);let l=0,m=0;i=setInterval(()=>{let c=C.default.magenta(t[l]),h=".".repeat(Math.floor(m)).slice(0,3);process.stdout.write(r1.cursor.move(-999,0)),process.stdout.write(r1.erase.down(1)),process.stdout.write(`${c} ${r}${h}`),l=l+1<t.length?l+1:0,m=m<t.length?m+.125:0},e)},s=(u="",l=0)=>{r=u??r,p=!1,clearInterval(i);let m=l===0?C.default.green(on):l===1?C.default.red(x2):C.default.red(I2);process.stdout.write(r1.cursor.move(-999,0)),process.stdout.write(r1.erase.down(1)),process.stdout.write(`${m} ${r}
|
|
58
|
-
`),a()},d=(u="")=>{r=u??r},o=u=>{let l=u>1?"Something went wrong":"Canceled";p&&s(l,u)};return process.on("uncaughtExceptionMonitor",()=>o(2)),process.on("unhandledRejection",()=>o(2)),process.on("SIGINT",()=>o(1)),process.on("SIGTERM",()=>o(1)),process.on("exit",o),{start:n,stop:s,message:d}};var Qu=require("path"),zp=require("fs"),el=Ae(t2()),tl=Ae(require("prettier")),al=Ae(Zu());async function il(t){try{if(t.command==="add"){let a=t.snippetId;if(!a)throw new Error("No snippet id provided");let i=un();i.start(`Fetching snippet ${a}`);let p=await nv(a);if(i.stop(`Fetched snippet ${a}`),!p)throw new Error(`No snippet found for id ${a}`);let{code:r,suggestedName:n}=p;n??(n="./src/components/MyComponent.jsx");let s=t.path;s||(s=await P2({message:"Where should we copy the code?",initialValue:n?.startsWith("./")?n:`./${n}`,validate(o){if(o.length===0)return"Value is required!";if(o[0]!==".")return"Please enter a relative path."}}),ii(s)&&process.exit(0));let d=(0,Qu.resolve)(process.cwd(),s);if((0,zp.existsSync)(d))throw new Error(`File already exists at ${d}`);{let o=rv(r);try{o=tl.default.format(dv(o,d),{parser:d.endsWith("html")?"html":d.endsWith("vue")?"vue":"typescript"})}catch(l){console.warn("Warning: code has formatting errors: ",l.message)}let u=un();u.start(`Writing ${d}`),(0,zp.writeFileSync)(d,o),u.stop("Done!")}}}catch(e){el.captureException(e),ft.error(String(e.message||e))}console.log("")}function nv(t){return(0,al.default)(`https://cdn.builder.io/api/v1/snippet/${t}`).then(e=>e.status===404?null:e.json())}function rv(t){return t.replace(/^```jsx\s?|\s?```$/g,"").trim()}function dv(t,e){return["vue","html"].filter(a=>e.endsWith(`.${a}`)).length?`<!-- This code was generated by Builder.io -->
|
|
58
|
+
`),a()},d=(u="")=>{r=u??r},o=u=>{let l=u>1?"Something went wrong":"Canceled";p&&s(l,u)};return process.on("uncaughtExceptionMonitor",()=>o(2)),process.on("unhandledRejection",()=>o(2)),process.on("SIGINT",()=>o(1)),process.on("SIGTERM",()=>o(1)),process.on("exit",o),{start:n,stop:s,message:d}};var Qu=require("path"),zp=require("fs"),el=Ae(t2()),tl=Ae(require("prettier")),al=Ae(Zu());async function il(t){try{if(t.command==="add"){let a=t.snippetId;if(!a)throw new Error("No snippet id provided");let i=un();i.start(`Fetching snippet ${a}`);let p=await nv(a);if(i.stop(`Fetched snippet ${a}`),!p)throw new Error(`No snippet found for id ${a}`);let{code:r,suggestedName:n}=p;n??(n="./src/components/MyComponent.jsx");let s=t.path;s||(s=await P2({message:"Where should we copy the code?",initialValue:n?.startsWith("./")?n:`./${n}`,validate(o){if(o.length===0)return"Value is required!";if(o[0]!==".")return"Please enter a relative path."}}),ii(s)&&process.exit(0));let d=(0,Qu.resolve)(process.cwd(),s);if((0,zp.existsSync)(d))throw new Error(`File already exists at ${d}`);{let o=rv(r);try{o=tl.default.format(dv(o,d),{parser:d.endsWith("html")?"html":d.endsWith("vue")?"vue":"typescript"})}catch(l){console.warn("Warning: code has formatting errors: ",l.message)}let u=un();u.start(`Writing ${d}`),(0,zp.writeFileSync)(d,o),u.stop("Done!")}}}catch(e){el.captureException(e),ft.error(String(e.message||e))}console.log("")}function nv(t){return(0,al.default)(`https://cdn.builder.io/api/v1/snippet/${t}`).then(e=>e.status===404?null:e.json())}function rv(t){return t.replace(/^```jsx\s?|\s?```$/g,"").trim()}function dv(t,e){return["vue","html","svelte"].filter(a=>e.endsWith(`.${a}`)).length?`<!-- This code was generated by Builder.io -->
|
|
59
59
|
${t}`:`/**
|
|
60
60
|
* This code was generated by Builder.io.
|
|
61
61
|
*/
|