@lunora/cli
Version:
The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands
2 lines (1 loc) • 928 B
JavaScript
import{spawn as s}from"node:child_process";import{platform as a}from"node:os";import{LunoraError as n}from"@lunora/errors";const i=()=>{const e=a();return e==="darwin"?{args:[],command:"open"}:e==="win32"?{args:["/c","start",""],command:"cmd"}:{args:[],command:"xdg-open"}},d=e=>e.replaceAll("%","%25").replaceAll("&","%26").replaceAll("|","%7C").replaceAll("^","%5E").replaceAll("<","%3C").replaceAll(">","%3E").replaceAll("(","%28").replaceAll(")","%29").replaceAll('"',"%22").replaceAll("!","%21"),w=e=>new Promise((o,r)=>{const{args:t,command:c}=i(),p=a()==="win32"?d(e):e,l=s(c,[...t,p],{detached:!0,stdio:"ignore"});l.once("error",m=>{r(m)}),l.once("spawn",()=>{l.unref(),o()})}),h=async(e,o={})=>{let r;try{r=new URL(e)}catch{throw new n("INTERNAL",`Invalid URL: ${e}`)}if(r.protocol!=="http:"&&r.protocol!=="https:")throw new n("INTERNAL",`Refusing to open non-http(s) URL: ${e}`);await(o.opener??w)(e)};export{h as f};