bostrat-node 0.2.9 → 0.2.11
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-flow +3 -0
- package/bin/bostrat-mock +2 -2
- package/dist/index.js +159 -136
- package/package.json +1 -1
package/bin/bostrat-flow
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import p from"node:fs/promises";var $=process.env.BOSTRAT_AGENT_URL||`http://127.0.0.1:${process.env.BOSTRAT_AGENT_PORT||3362}`;async function c(e,o,t){let n=await fetch(`${$}${o}`,{method:e,headers:t?{"content-type":"application/json"}:void 0,body:t?JSON.stringify(t):void 0}),s=await n.json().catch(()=>({}));if(!n.ok)throw new Error(s.error||`HTTP ${n.status}`);return s}function a(e){console.error(`[bostrat-flow] ${e}`),process.exit(1)}async function f(e){let o=await p.readFile(e,"utf8").catch(()=>a(`cannot read ${e}`));try{return JSON.parse(o)}catch(t){a(`${e} is not valid JSON: ${t.message}`)}}async function r(e){let{flows:o}=await c("GET","/api/flows");return o.find(t=>t.id===e||t.name===e)||null}function g(e,o){let t=`${o+1}`.padStart(2),n=e.missing?"\u26A0 mock removed":e.mockState!=="ready"?`\u26A0 ${e.mockState}`:`v${e.servedV}${e.v!=null?" pinned":""}`;return`${t}. ${e.caption}
|
|
3
|
+
\u2014 ${e.missing?`(mock:${e.mockId})`:`"${e.mockName}" (mock:${e.mockId})`} ${n}`}function d(e,o){let t=e.steps.filter(s=>s.missing||s.mockState!=="ready").length,n=e.version>1?` v${e.version}`:"";console.log(`[bostrat-flow] ${o}: "${e.name}"${n} \u2014 ${e.steps.length} steps${t?` (${t} not ready yet)`:""} (flow:${e.id})`),console.log("The operator reads it as a storyboard in the Track chat and the gallery \u2014 no need to screenshot or link it.")}var i=process.argv.slice(2),l=i.shift();if(l==="add"){let e=null,o=null;for(let t=0;t<i.length;t++)i[t]==="--name"?e=i[++t]:i[t].startsWith("--")||(o=i[t]);o||a('usage: bostrat-flow add --name "<journey>" <flow.json>');try{let t=await f(o),n=(await c("POST","/api/flows",{name:e||t.name,steps:t.steps,cwd:process.cwd()})).flow;d((await c("GET",`/api/flows/${n.id}`)).flow,"created")}catch(t){a(t.message)}}else if(l==="update"){let e=null,o=[];for(let s=0;s<i.length;s++)i[s]==="--note"?e=i[++s]:i[s].startsWith("--")||o.push(i[s]);let[t,n]=o;(!t||!n)&&a('usage: bostrat-flow update <name|id> [--note "<what changed>"] <flow.json>');try{let s=await r(t);s||a(`no flow matching "${t}" \u2014 use \`bostrat-flow ls\`, or \`add\` for a new journey`);let w=await f(n),m=(await c("POST",`/api/flows/${s.id}/update`,{steps:w.steps,note:e})).flow;d((await c("GET",`/api/flows/${m.id}`)).flow,"updated")}catch(s){a(s.message)}}else if(l==="ls"){let{flows:e}=await c("GET","/api/flows").catch(o=>a(o.message));e.length||console.log("no flows");for(let o of e){let t=o.version>1?` v${o.version}`:"";console.log(`${o.name}${t} \xB7 ${o.steps.length} steps (flow:${o.id})`)}}else if(l==="show"){let e=i[0];e||a("usage: bostrat-flow show <name|id>");try{let o=await r(e);o||a(`no flow matching "${e}"`);let t=(await c("GET",`/api/flows/${o.id}`)).flow,n=t.version>1?` v${t.version}`:"";console.log(`"${t.name}"${n} \u2014 ${t.steps.length} steps (flow:${t.id})`);for(let s=0;s<t.steps.length;s++)console.log(g(t.steps[s],s))}catch(o){a(o.message)}}else if(l==="rm"){let e=i[0];e||a("usage: bostrat-flow rm <name|id>");let o=await r(e).catch(t=>a(t.message));o||a(`no flow matching "${e}"`),await c("DELETE",`/api/flows/${o.id}`).catch(t=>a(t.message)),console.log(`[bostrat-flow] deleted: ${o.name} (its mocks are untouched)`)}else a('usage: bostrat-flow <add|update|ls|show|rm> \u2026 (add --name "<journey>" <flow.json>; update <name|id> <flow.json>)');
|
package/bin/bostrat-mock
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
${e.error||"(no detail)"}`),e.state!=="ready"&&i(`render still ${e.state} \u2014 check the gallery later (mock:${e.id})`);let
|
|
2
|
+
import f from"node:fs/promises";import h from"node:path";var k=process.env.BOSTRAT_AGENT_URL||`http://127.0.0.1:${process.env.BOSTRAT_AGENT_PORT||3362}`;async function c(e,a,o,s){let t=await fetch(`${k}${a}`,{method:e,headers:o?{"content-type":s||"application/json"}:void 0,body:o?s?o:JSON.stringify(o):void 0}),r=await t.json().catch(()=>({}));if(!t.ok)throw new Error(r.error||`HTTP ${t.status}`);return r}function i(e){console.error(`[bostrat-mock] ${e}`),process.exit(1)}async function d(e){let a=(await c("GET",`/api/mocks/${e}`)).mock;for(let o=0;o<60&&(a.state==="queued"||a.state==="rendering");o++)await new Promise(s=>setTimeout(s,2e3)),a=(await c("GET",`/api/mocks/${e}`)).mock;return a}function g(e,a){e.state==="error"&&i(`render failed:
|
|
3
|
+
${e.error||"(no detail)"}`),e.state!=="ready"&&i(`render still ${e.state} \u2014 check the gallery later (mock:${e.id})`);let o=e.version>1?` v${e.version}`:"";console.log(`[bostrat-mock] ${a}: "${e.name}"${o} ${e.width}\xD7${e.height}${e.dpr>1?` @${e.dpr}x`:""} (mock:${e.id})`),console.log("The operator sees it as an image in the Track chat and the gallery \u2014 no need to screenshot or link it.")}async function p(e){let a=h.extname(e).toLowerCase()===".png",o=await f.readFile(e).catch(()=>i(`cannot read ${e}`));return a?{image:o}:{html:o.toString("utf8")}}var n=process.argv.slice(2),m=n.shift();if(m==="add"){let e=null,a,o,s=null;for(let t=0;t<n.length;t++)n[t]==="--name"?e=n[++t]:n[t]==="--group"?a=n[++t]:n[t]==="--width"?o=Number(n[++t]):n[t].startsWith("--")||(s=n[t]);(!e||!s)&&i('usage: bostrat-mock add --name "<name>" [--group <id>] [--width N] <file.html|file.png>');try{let t=await p(s),r=t.image?(await c("POST",`/api/mocks?${new URLSearchParams({name:e,cwd:process.cwd(),...a?{group:a}:{}})}`,t.image,"image/png")).mock:(await c("POST","/api/mocks",{name:e,html:t.html,group:a,width:o,cwd:process.cwd()})).mock;g(await d(r.id),"ready")}catch(t){i(t.message)}}else if(m==="update"){let[e,a]=n.filter(o=>!o.startsWith("--"));(!e||!a)&&i("usage: bostrat-mock update <name|id> <file.html|file.png>");try{let{mocks:o}=await c("GET","/api/mocks"),s=o.find(l=>l.id===e||l.name===e);s||i(`no mock matching "${e}" \u2014 use \`bostrat-mock ls\`, or \`add\` for a new comp`);let t=await p(a),r=t.image?(await c("POST",`/api/mocks/${s.id}/update`,t.image,"image/png")).mock:(await c("POST",`/api/mocks/${s.id}/update`,{html:t.html})).mock;g(await d(r.id),"updated")}catch(o){i(o.message)}}else if(m==="ls"){let{mocks:e}=await c("GET","/api/mocks").catch(a=>i(a.message));e.length||console.log("no mocks");for(let a of e){let o=a.readyVersion?` ${a.width}\xD7${a.height}`:"",s=a.version>1?` v${a.version}`:"";console.log(`${a.state.padEnd(9)} ${a.name}${s}${a.group?` [${a.group}]`:""}${o} (mock:${a.id})`)}}else if(m==="rm"){let e=n[0];e||i("usage: bostrat-mock rm <name|id>");let{mocks:a}=await c("GET","/api/mocks").catch(t=>i(t.message)),o=a.find(t=>t.id===e||t.name===e);o||i(`no mock matching "${e}"`);let s=await c("DELETE",`/api/mocks/${o.id}`).catch(t=>i(t.message));console.log(`[bostrat-mock] deleted: ${o.name}`),s.danglingFlows?.length&&console.log(`\u26A0 flows now missing this step \u2014 revise them with \`bostrat-flow update\`: ${s.danglingFlows.map(t=>`"${t.name}" (flow:${t.id})`).join(", ")}`)}else i('usage: bostrat-mock <add|update|ls|rm> \u2026 (add --name "<name>" <file>; update <name|id> <file>)');
|