sdin
Version:
JavaScript package builder.
2 lines • 2.08 kB
JavaScript
import{isNil as r}from"lodash";import{ellipsis as v}from"./string";import{filterNotNone as g}from"./array";import{RuntimeError as s}from"./errors";function c(o){return r(o)?"":"[31m"+o+"[0m"}function n(o){return r(o)?"":"[32m"+o+"[0m"}function t(o){return r(o)?"":"[33m"+o+"[0m"}function i(o){return r(o)?"":"[34m"+o+"[0m"}function o(o){return r(o)?"":"[35m"+o+"[0m"}function e(o){return r(o)?"":"[36m"+o+"[0m"}function f(o,r){var n,t,o=Array.isArray(o)?o:[o],i=2<o.length?"\n ":"\n ",e=2<o.length?"\n - ":"\n ",s=[];for(n of o)n&&(t="string"==typeof n?n:n instanceof Error?n.message:JSON.stringify(n))&&s.push(t.replaceAll("\n",i));if(0<s.length)return(r?r+" ":"")+s.join(e)}function a(o,r,n){o=o?f(o,r):void 0;o&&console.log(o),Number.isInteger(n)&&(console.log(),process.exit(n))}function l(o,r){void 0!==r?a(o,i("i"),r):a(o,i("i"))}function u(o,r){void 0!==r?a(o,t("!"),r):a(o,t("!"))}function p(o,r){void 0!==r?a(o,n("√"),r):a(o,n("√"))}function h(o,r,n){let t=void 0,i=void 0,e=void 0;o instanceof Error?i=o:e=r instanceof Error?(t=o,i=r,n):(t=o,r),i instanceof s?a(i.message,c("x"),i.code):(t&&a(t,c("x")),i&&console.error(i),void 0!==e&&a(void 0,void 0,e))}function y(){process.stdout.write("\r[K")}function x(o,r){y(),process.stdout.write((r?r+" ":"")+o)}let E=[o("⠙"),c("⠸"),t("⠴"),n("⠦"),i("⠇"),e("⠋")];async function m(r){let{exitCode:n,loading:t,resolve:o,reject:i,task:e}=r,s,c=[],f=-1,a=-1,l=setInterval(()=>{var o=1<c.length?c.shift():c[0],o=g([void 0===s?void 0:"".concat(s," / ",100),void 0===o?void 0:v(o,80)]).join(" ");o&&(0===(a=(a+1)%3)&&(f=(f+1)%E.length),x(o,E[f]))},200);r=()=>{clearInterval(l),y(),s=void 0,c=[]};try{var u=o=>{c=t(o).split("\n").filter(Boolean)},m=(u(),await e({progress:o=>{s=o},loading:u})),d=(r(),o(m));return d&&p(d),m}catch(o){r();u=i(o);if(void 0===n)throw h(u),o;o instanceof Error?h(u,o,n):h(u,n)}}export{c as red,n as green,t as yellow,i as blue,o as magenta,e as cyan,a as print,l as printInfo,u as printWarn,p as printSuccess,h as printError,m as printTask};
//# sourceMappingURL=print.js.map