UNPKG

create-bunny-launcher

Version:

Configure your static sites with bunny.net in a single cli command 🐰

3 lines (2 loc) 3.4 kB
import { createRequire } from 'module';const require = createRequire(import.meta.url); import{option as W}from"pastel";import{z as f}from"zod";import{resolveCname as z}from"node:dns/promises";import{getSubdomain as J}from"tldts";async function k(r,e=".b-cdn.net"){e=e.toLowerCase();let o=new URL(r),s=J(r);if(s===null)throw new Error(`Cannot resolve subdomain for "${o.hostname}"`);if(s==="")throw new Error(`CNAME records cannot be used for the root domain "${o.hostname}". Instead, consider switching nameservers, or consider using an ANAME record or CNAME Flattening with Anycast DNS.`);try{let t=await z(o.hostname),i=!0;for(let c of t)if(!c.toLowerCase().endsWith(e)){i=!1;break}return{isChecked:i,records:t,type:"cname"}}catch(t){throw new Error(`Cannot resolve CNAME records for domain "${o.hostname}"`,{cause:t})}}import{sanitizeUrl as F}from"@braintree/sanitize-url";import{argument as U,option as X}from"pastel";import{z as x}from"zod";var v=/^[a-z]/i;function u(r){if(typeof r=="string"){let e=r.trim();if(e.startsWith("http://"))return`https://${e.slice(7)}`;if(e.startsWith("https://"))return e;if(v.test(e))return`https://${e}`}return r}var y=x.preprocess(r=>process.env.BUNNY_DOMAIN_NAME&&!r?u(process.env.BUNNY_DOMAIN_NAME):typeof r=="string"?u(r):r,x.string().url().startsWith("https://").transform(F)),or=y.optional().describe(X({alias:"d",description:"Domain name",valueDescription:"string"})),E=y.describe(U({name:"domain-name"}));import P from"react";import C from"react";function R(){let[r,e]=C.useState(null);return C.useEffect(()=>{r&&(process.exitCode=1,process.env.CI&&(console.error(r),console.error()))},[r]),[r,e]}function $(r){return typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"}function I(r){if($(r))return r;try{return new Error(JSON.stringify(r))}catch{return new Error(String(r))}}function w(r){return I(r).message}import T from"figures";import{Text as n}from"ink";import{jsx as N,jsxs as a}from"react/jsx-runtime";function b({isChecked:r,type:e}){return r?a(n,{children:[N(n,{color:"green",children:T.tick}),a(n,{color:"white",children:[" ",e," configured correctly"]})]}):a(n,{children:[N(n,{color:"red",children:T.cross}),a(n,{color:"white",children:[" ",e," configured incorrectly"]})]})}import L from"figures";import{Text as h}from"ink";import{jsx as _,jsxs as M}from"react/jsx-runtime";function A({error:r}){return M(h,{children:[_(h,{color:"red",children:L.cross}),M(h,{color:"white",children:[" ",r]})]})}import{Newline as O,Text as p}from"ink";import{jsx as m,jsxs as B}from"react/jsx-runtime";function S({records:r}){return m(p,{children:r.map((e,o)=>o===0?m(p,{children:e},e):B(p,{children:[m(O,{}),m(p,{children:e})]},e))})}import{jsx as d}from"react/jsx-runtime";function D({check:r,shouldCheck:e,type:o,url:s}){let[t,i]=P.useState(),[c,g]=R();return P.useEffect(()=>{r(s).then(l=>{i(l)}).catch(l=>{g(w(l))})},[s,g,r]),c?d(A,{error:c}):t&&!e?d(S,{records:t.records}):t&&e?d(b,{isChecked:t.isChecked,type:o}):null}import{jsx as H}from"react/jsx-runtime";var Y=f.tuple([E]),q=f.object({check:f.boolean().default(!1).describe(W({alias:"c",description:"Check CNAME records point to bunny.net"})),verify:f.boolean().default(!1).describe(W({description:"Alias of --check"}))});function G({args:r,options:e}){return H(D,{check:k,shouldCheck:e.check||e.verify,type:"CNAME",url:r[0]})}export{Y as args,G as default,q as options};