create-bunny-launcher
Version:
Configure your static sites with bunny.net in a single cli command 🐰
3 lines (2 loc) • 3.17 kB
JavaScript
import { createRequire } from 'module';const require = createRequire(import.meta.url);
import{option as v}from"pastel";import{z as a}from"zod";import{resolveNs as A}from"node:dns/promises";import{getDomain as z}from"tldts";async function d(r){let e=z(r),n=new URL(r);if(!e)throw new Error(`Cannot resolve domain for "${n.hostname}"`);try{let t=await A(e),o=!0;return t[0]?.toLowerCase()!=="kiki.bunny.net"&&(o=!1),t[1]?.toLowerCase()!=="coco.bunny.net"&&(o=!1),t.length>2&&(o=!1),{isChecked:o,records:t,type:"nameserver"}}catch(t){throw new Error(`Cannot resolve NS records for "${e}"`,{cause:t})}}import{sanitizeUrl as U}from"@braintree/sanitize-url";import{argument as X,option as F}from"pastel";import{z as k}from"zod";var J=/^[a-z]/i;function f(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(J.test(e))return`https://${e}`}return r}var y=k.preprocess(r=>process.env.BUNNY_DOMAIN_NAME&&!r?f(process.env.BUNNY_DOMAIN_NAME):typeof r=="string"?f(r):r,k.string().url().startsWith("https://").transform(U)),or=y.optional().describe(F({alias:"d",description:"Domain name",valueDescription:"string"})),x=y.describe(X({name:"domain-name"}));import P from"react";import R from"react";function E(){let[r,e]=R.useState(null);return R.useEffect(()=>{r&&(process.exitCode=1,process.env.CI&&(console.error(r),console.error()))},[r]),[r,e]}function L(r){return typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"}function _(r){if(L(r))return r;try{return new Error(JSON.stringify(r))}catch{return new Error(String(r))}}function N(r){return _(r).message}import T from"figures";import{Text as s}from"ink";import{jsx as C,jsxs as i}from"react/jsx-runtime";function w({isChecked:r,type:e}){return r?i(s,{children:[C(s,{color:"green",children:T.tick}),i(s,{color:"white",children:[" ",e," configured correctly"]})]}):i(s,{children:[C(s,{color:"red",children:T.cross}),i(s,{color:"white",children:[" ",e," configured incorrectly"]})]})}import $ from"figures";import{Text as l}from"ink";import{jsx as I,jsxs as b}from"react/jsx-runtime";function S({error:r}){return b(l,{children:[I(l,{color:"red",children:$.cross}),b(l,{color:"white",children:[" ",r]})]})}import{Newline as O,Text as c}from"ink";import{jsx as p,jsxs as B}from"react/jsx-runtime";function D({records:r}){return p(c,{children:r.map((e,n)=>n===0?p(c,{children:e},e):B(c,{children:[p(O,{}),p(c,{children:e})]},e))})}import{jsx as u}from"react/jsx-runtime";function M({check:r,shouldCheck:e,type:n,url:t}){let[o,W]=P.useState(),[h,g]=E();return P.useEffect(()=>{r(t).then(m=>{W(m)}).catch(m=>{g(N(m))})},[t,g,r]),h?u(S,{error:h}):o&&!e?u(D,{records:o.records}):o&&e?u(w,{isChecked:o.isChecked,type:n}):null}import{jsx as H}from"react/jsx-runtime";var Y=a.tuple([x]),q=a.object({check:a.boolean().default(!1).describe(v({alias:"c",description:"Check NS records point to bunny.net"})),verify:a.boolean().default(!1).describe(v({description:"Alias of --check"}))});function G({args:r,options:e}){return H(M,{check:d,shouldCheck:e.check||e.verify,type:"Nameserver",url:r[0]})}export{Y as args,G as default,q as options};