bostrat-node 1.9.12 → 1.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/bostrat-view CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- var p=process.env.BOSTRAT_AGENT_URL||`http://127.0.0.1:${process.env.BOSTRAT_AGENT_PORT||3362}`;async function r(s,e,i){let t=await fetch(`${p}${e}`,{method:s,headers:i?{"content-type":"application/json"}:void 0,body:i?JSON.stringify(i):void 0}),w=await t.json().catch(()=>({}));if(!t.ok)throw new Error(w.error||`HTTP ${t.status}`);return w}function n(s){console.error(`[bostrat-view] ${s}`),process.exit(1)}var l=process.argv.slice(2),c=l.shift();if(c==="up"){let s=l.indexOf("--");(s===-1||s===l.length-1)&&n('usage: bostrat-view up --name "<name>" [--port N] -- <serve command>');let e=l.slice(0,s),i=l.slice(s+1).join(" "),t=null,w;for(let o=0;o<e.length;o++)e[o]==="--name"?t=e[++o]:e[o]==="--port"&&(w=Number(e[++o]));t||n("--name is required");try{let{view:o}=await r("POST","/api/views",{name:t,cmd:i,port:w,cwd:process.cwd()});o.reused&&console.log(`[bostrat-view] reusing existing view "${o.name}" \u2014 same URL, no new server needed`);let a=o;for(let d=0;d<60&&a.state==="starting";d++)await new Promise(v=>setTimeout(v,2e3)),a=(await r("GET",`/api/views/${o.id}`)).view;a.state==="error"&&n(`server failed to start:
3
- ${a.error||"(no output captured)"}`),console.log(`[bostrat-view] ${a.state}: ${a.url} (view:${a.id})`),a.serveCwd&&console.log(`[bostrat-view] running \`${a.cmd}\` in ${a.serveCwd}`),console.log("Share this URL \u2014 it works from the operator's phone. Do NOT share a localhost URL."),a.state==="starting"&&console.log("(still starting \u2014 the URL shows a holding page until it's up)")}catch(o){n(o.message)}}else if(c==="ls"){let{views:s}=await r("GET","/api/views").catch(e=>n(e.message));s.length||console.log("no views");for(let e of s)console.log(`${e.state.padEnd(9)} ${e.name} \u2014 ${e.url} (view:${e.id}, port ${e.port})`),e.cmd&&console.log(`${" ".repeat(10)}\`${e.cmd}\` in ${e.serveCwd||e.cwd}`)}else if(c==="stop"||c==="rm"){let s=l[0];s||n(`usage: bostrat-view ${c} <name|slug|id>`);let{views:e}=await r("GET","/api/views").catch(t=>n(t.message)),i=e.find(t=>t.id===s||t.slug===s||t.name===s);i||n(`no view matching "${s}"`),c==="stop"?(await r("POST",`/api/views/${i.id}/stop`).catch(t=>n(t.message)),console.log(`[bostrat-view] stopped: ${i.name}`)):(await r("DELETE",`/api/views/${i.id}`).catch(t=>n(t.message)),console.log(`[bostrat-view] removed: ${i.name}`))}else n('usage: bostrat-view <up|ls|stop|rm> \u2026 (up --name "<name>" -- <serve command>)');
2
+ var v=process.env.BOSTRAT_AGENT_URL||`http://127.0.0.1:${process.env.BOSTRAT_AGENT_PORT||3362}`;async function r(s,e,i){let t=await fetch(`${v}${e}`,{method:s,headers:i?{"content-type":"application/json"}:void 0,body:i?JSON.stringify(i):void 0}),w=await t.json().catch(()=>({}));if(!t.ok)throw new Error(w.error||`HTTP ${t.status}`);return w}function n(s){console.error(`[bostrat-view] ${s}`),process.exit(1)}var l=process.argv.slice(2),c=l.shift();if(c==="up"){let s=l.indexOf("--");(s===-1||s===l.length-1)&&n('usage: bostrat-view up --name "<name>" [--port N] -- <serve command>');let e=l.slice(0,s),i=l.slice(s+1).join(" "),t=null,w;for(let o=0;o<e.length;o++)e[o]==="--name"?t=e[++o]:e[o]==="--port"&&(w=Number(e[++o]));t||n("--name is required");try{let{view:o}=await r("POST","/api/views",{name:t,cmd:i,port:w,cwd:process.cwd()});o.reused&&console.log(`[bostrat-view] reusing existing view "${o.name}" \u2014 same URL, no new server needed`);let a=o;for(let d=0;d<60&&a.state==="starting";d++)await new Promise(p=>setTimeout(p,2e3)),a=(await r("GET",`/api/views/${o.id}`)).view;a.state==="error"&&n(`server failed to start:
3
+ ${a.error||"(no output captured)"}`),console.log(`[bostrat-view] ${a.state}: ${a.url} (view:${a.id})`),a.serveCwd&&console.log(`[bostrat-view] running \`${a.cmd}\` in ${a.serveCwd}`),console.log("Share this URL \u2014 it works from the operator's phone. Do NOT share a localhost URL."),a.state==="starting"&&console.log("(still starting \u2014 the URL shows a holding page until it's up)")}catch(o){n(o.message)}}else if(c==="ls"){let{views:s}=await r("GET","/api/views").catch(e=>n(e.message));s.length||console.log("no views");for(let e of s)console.log(`${e.state.padEnd(9)} ${e.name} \u2014 ${e.url||"(no public URL on this node \u2014 see `bostrat-node doctor`)"} (view:${e.id}, port ${e.port})`),e.cmd&&console.log(`${" ".repeat(10)}\`${e.cmd}\` in ${e.serveCwd||e.cwd}`)}else if(c==="stop"||c==="rm"){let s=l[0];s||n(`usage: bostrat-view ${c} <name|slug|id>`);let{views:e}=await r("GET","/api/views").catch(t=>n(t.message)),i=e.find(t=>t.id===s||t.slug===s||t.name===s);i||n(`no view matching "${s}"`),c==="stop"?(await r("POST",`/api/views/${i.id}/stop`).catch(t=>n(t.message)),console.log(`[bostrat-view] stopped: ${i.name}`)):(await r("DELETE",`/api/views/${i.id}`).catch(t=>n(t.message)),console.log(`[bostrat-view] removed: ${i.name}`))}else n('usage: bostrat-view <up|ls|stop|rm> \u2026 (up --name "<name>" -- <serve command>)');