UNPKG

bit-ship

Version:

Bit-Ship CLI is tool that analyses your code and generates a custom environment for your needs You can use if to local development, CI/CD or even production.

2 lines (1 loc) 1.91 kB
import{_ as e,b as t}from"./index.js";import{ofetch as i}from"ofetch";import o from"consola";import n from"chalk";const{apiURL:r}=t(),s=()=>({create:c});function c(){return e(this,arguments,void 0,(function*(t={}){o.box("Image configuration");let s=!1;if(Object.keys(t).length&&(o.info("Dependencies found in your project"),Object.keys(t).forEach((e=>{o.log(`${e} -> ${t[e]}`)})),s=!(yield o.prompt("Are dependencies correct?",{type:"confirm"})),s)){(yield o.prompt("Remove tools",{type:"multiselect",required:!1,options:Object.keys(t).map((e=>({label:e,value:e,hint:t[e].version})))})).forEach((e=>delete t[e]))}const c=yield function(){return e(this,void 0,void 0,(function*(){return yield i(`${r}/public/v1/tools`)}))}();if(!Object.keys(t).length||s){o.info("You can find more at https://www.bit-ship.dev/tools");const e=Object.keys(c).map((e=>({label:c[e].label,value:e,hint:c[e].description}))).filter((e=>!Object.keys(t).includes(e.value))),i=yield o.prompt("Add any more tooling",{type:"multiselect",required:!1,options:e});for(const e of i){const i=yield o.prompt(`Pick ${e}version`,{type:"select",required:!0,options:c[e].versions});t[e]=i}}let l="queued";const u=(e=>{const t=["◐","◓","◑","◒"];let i=0;const o=setInterval((()=>{process.stdout.write(n.magenta(`\r${t[i++]} ${e()}`)),i&=3}),250);return()=>{clearInterval(o)}})((()=>`Please wait while we prepare your image: ${l}`));try{const{name:e}=yield a(t,0,(e=>l=e));return o.start("Generating initial bit-ship.yml config"),u(),{name:e,dependencies:t}}catch(e){u(),o.error(e)}}))}const a=(e,t,n)=>new Promise(((s,c)=>{i(`${r}/public/v1/image`,{method:"POST",body:{dependencies:e}}).then((i=>"finished"===i.status?(o.success("Image is ready"),s(i)):("queued"===i.status||"running"===i.status)&&t<800?(n("running"===i.status?"building":"queued"),setTimeout((()=>{a(e,t++,n).then(s).catch(c)}),2e3)):void c(i))).catch(c)}));export{s as u};