UNPKG

@lunora/cli

Version:

The Lunora CLI: init, dev, deploy, codegen, migrate, seed, doctor, insights, logs, registry, and the rest of the project commands

2 lines (1 loc) 795 B
import{spawn as i}from"node:child_process";import{platform as a}from"node:os";import{LunoraError as e}from"@lunora/errors";const d=()=>{const o=a();return o==="darwin"?{args:[],command:"open"}:o==="win32"?{args:["/c","start",""],command:"cmd"}:{args:[],command:"xdg-open"}},w=o=>o.replaceAll(/[!"%&()<>^|]/gu,r=>`%${(r.codePointAt(0)??0).toString(16).toUpperCase()}`),g=o=>new Promise((r,t)=>{const{args:p,command:c}=d(),m=a()==="win32"?w(o):o,n=i(c,[...p,m],{detached:!0,stdio:"ignore"});n.once("error",s=>{t(s)}),n.once("spawn",()=>{n.unref(),r()})}),u=async(o,r={})=>{let t;try{t=new URL(o)}catch{throw new e("INTERNAL",`Invalid URL: ${o}`)}if(t.protocol!=="http:"&&t.protocol!=="https:")throw new e("INTERNAL",`Refusing to open non-http(s) URL: ${o}`);await(r.opener??g)(o)};export{u as f};