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) 1.58 kB
import{readFileSync as l,existsSync as u}from"node:fs";import{join as a}from"node:path";import{parse as d}from"jsonc-parser";import{d as m}from"../packem_shared/command-DwC11Cwe.mjs";import{o as p}from"../packem_shared/open-url-EnKy--w-.mjs";const c=8787,s="/_lunora/studio",g=r=>{for(const t of["wrangler.jsonc","wrangler.json"]){const e=a(r,t);if(u(e))return e}},v=r=>{const t=g(r);if(t)try{const e=d(l(t,"utf8"));return e!==null&&typeof e=="object"?e:void 0}catch{return}},y=r=>{if(!r)return c;const{dev:t}=r;if(t!==null&&typeof t=="object"){const{port:e}=t;if(typeof e=="number"&&Number.isFinite(e))return e}return c},h=r=>{if(!r)return;const{routes:t}=r;if(Array.isArray(t)&&t.length>0){const n=t[0];if(typeof n=="string")return`https://${n.split("/")[0]??n}${s}`;if(n!==null&&typeof n=="object"){const{pattern:o}=n;if(typeof o=="string"&&o.length>0)return`https://${o.split("/")[0]??o}${s}`}}const{name:e}=r;if(typeof e=="string"&&e.length>0)return`https://${e}.workers.dev${s}`},$=async r=>{const t=r.cwd??process.cwd(),e=v(t),{logger:n}=r;let o;if(r.remote){if(o=h(e),!o)return n.error("view --remote: could not determine the remote URL from wrangler config (set `routes` or `name`)."),{code:1,url:void 0}}else o=`http://localhost:${String(y(e))}${s}`;n.info(`opening ${o}`);try{await p(o,{opener:r.opener})}catch(i){const f=i instanceof Error?i.message:String(i);return n.error(`view: failed to open URL: ${f}`),{code:1,url:o}}return{code:0,url:o}},A=m(({cwd:r,logger:t,options:e})=>$({cwd:r,logger:t,remote:e.remote===!0}));export{A as execute,$ as runViewCommand};