UNPKG

@bring-it/cli

Version:
1 lines 9.74 kB
import*as e from"globby";import*as r from"node:child_process";import*as t from"node:fs";import*as o from"node:fs/promises";import*as n from"node:path";import{default as s}from"node:process";import{default as i}from"node:os";import{default as l}from"node:tty";export const __webpack_esm_id__=473;export const __webpack_esm_ids__=[473];export const __webpack_esm_modules__={373(r,t,o){var n,s;r.exports=(n={globbySync:()=>e.globbySync},s={},o.d(s,n),s)},564(e,t,o){var n,s;e.exports=(n={execFileSync:()=>r.execFileSync},s={},o.d(s,n),s)},627(e,r,o){var n,s;e.exports=(n={mkdirSync:()=>t.mkdirSync},s={},o.d(s,n),s)},298(e,r,t){var o;e.exports=(o={},t.d(o,{}),o)},663(e,r,t){var o,s;e.exports=(o={resolve:()=>n.resolve},s={},t.d(s,o),s)},826(e,r,t){t.d(r,{Ay:()=>x});const o=(e=0)=>r=>`\x1b[${r+e}m`,n=(e=0)=>r=>`\x1b[${38+e};5;${r}m`,c=(e=0)=>(r,t,o)=>`\x1b[${38+e};2;${r};${t};${o}m`,a={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(a.modifier),Object.keys(a.color),Object.keys(a.bgColor);const u=function(){const e=new Map;for(const[r,t]of Object.entries(a)){for(const[r,o]of Object.entries(t))a[r]={open:`\x1b[${o[0]}m`,close:`\x1b[${o[1]}m`},t[r]=a[r],e.set(o[0],o[1]);Object.defineProperty(a,r,{value:t,enumerable:!1})}return Object.defineProperty(a,"codes",{value:e,enumerable:!1}),a.color.close="\x1b[39m",a.bgColor.close="\x1b[49m",a.color.ansi=o(),a.color.ansi256=n(),a.color.ansi16m=c(),a.bgColor.ansi=o(10),a.bgColor.ansi256=n(10),a.bgColor.ansi16m=c(10),Object.defineProperties(a,{rgbToAnsi256:{value:(e,r,t)=>e===r&&r===t?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(r/255*5)+Math.round(t/255*5),enumerable:!1},hexToRgb:{value(e){const r=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!r)return[0,0,0];let[t]=r;3===t.length&&(t=[...t].map(e=>e+e).join(""));const o=Number.parseInt(t,16);return[o>>16&255,o>>8&255,255&o]},enumerable:!1},hexToAnsi256:{value:e=>a.rgbToAnsi256(...a.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return e-8+90;let r,t,o;if(e>=232)r=(10*(e-232)+8)/255,t=r,o=r;else{const n=(e-=16)%36;r=Math.floor(e/36)/5,t=Math.floor(n/6)/5,o=n%6/5}const n=2*Math.max(r,t,o);if(0===n)return 30;let s=30+(Math.round(o)<<2|Math.round(t)<<1|Math.round(r));return 2===n&&(s+=60),s},enumerable:!1},rgbToAnsi:{value:(e,r,t)=>a.ansi256ToAnsi(a.rgbToAnsi256(e,r,t)),enumerable:!1},hexToAnsi:{value:e=>a.ansi256ToAnsi(a.hexToAnsi256(e)),enumerable:!1}}),a}();function g(e,r=(globalThis.Deno?globalThis.Deno.args:s.argv)){const t=e.startsWith("-")?"":1===e.length?"-":"--",o=r.indexOf(t+e),n=r.indexOf("--");return-1!==o&&(-1===n||o<n)}const{env:d}=s;let f;function h(e,r={}){return 0!==(t=function(e,{streamIsTTY:r,sniffFlags:t=!0}={}){const o=function(){if("FORCE_COLOR"in d)return"true"===d.FORCE_COLOR?1:"false"===d.FORCE_COLOR?0:0===d.FORCE_COLOR.length?1:Math.min(Number.parseInt(d.FORCE_COLOR,10),3)}();void 0!==o&&(f=o);const n=t?f:o;if(0===n)return 0;if(t){if(g("color=16m")||g("color=full")||g("color=truecolor"))return 3;if(g("color=256"))return 2}if("TF_BUILD"in d&&"AGENT_NAME"in d)return 1;if(e&&!r&&void 0===n)return 0;const l=n||0;if("dumb"===d.TERM)return l;if("win32"===s.platform){const e=i.release().split(".");return Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}if("CI"in d)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(e=>e in d)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(e=>e in d)||"codeship"===d.CI_NAME?1:l;if("TEAMCITY_VERSION"in d)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(d.TEAMCITY_VERSION)?1:0;if("truecolor"===d.COLORTERM)return 3;if("xterm-kitty"===d.TERM)return 3;if("xterm-ghostty"===d.TERM)return 3;if("wezterm"===d.TERM)return 3;if("TERM_PROGRAM"in d){const e=Number.parseInt((d.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(d.TERM_PROGRAM){case"iTerm.app":return e>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(d.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(d.TERM)||"COLORTERM"in d?1:l}(e,{streamIsTTY:e&&e.isTTY,...r}))&&{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3};var t}g("no-color")||g("no-colors")||g("color=false")||g("color=never")?f=0:(g("color")||g("colors")||g("color=true")||g("color=always"))&&(f=1);const b={stdout:h({isTTY:l.isatty(1)}),stderr:h({isTTY:l.isatty(2)})};function p(e,r,t){let o=e.indexOf(r);if(-1===o)return e;const n=r.length;let s=0,i="";do{i+=e.slice(s,o)+r+t,s=o+n,o=e.indexOf(r,s)}while(-1!==o);return i+=e.slice(s),i}const{stdout:m,stderr:_}=b,T=Symbol("GENERATOR"),O=Symbol("STYLER"),v=Symbol("IS_EMPTY"),R=["ansi","ansi","ansi256","ansi16m"],y=Object.create(null);function E(e){return(e=>{const r=(...e)=>e.join(" ");return((e,r={})=>{if(r.level&&!(Number.isInteger(r.level)&&r.level>=0&&r.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const t=m?m.level:0;e.level=void 0===r.level?t:r.level})(r,e),Object.setPrototypeOf(r,E.prototype),r})(e)}Object.setPrototypeOf(E.prototype,Function.prototype);for(const[e,r]of Object.entries(u))y[e]={get(){const t=I(this,A(r.open,r.close,this[O]),this[v]);return Object.defineProperty(this,e,{value:t}),t}};y.visible={get(){const e=I(this,this[O],!0);return Object.defineProperty(this,"visible",{value:e}),e}};const C=(e,r,t,...o)=>"rgb"===e?"ansi16m"===r?u[t].ansi16m(...o):"ansi256"===r?u[t].ansi256(u.rgbToAnsi256(...o)):u[t].ansi(u.rgbToAnsi(...o)):"hex"===e?C("rgb",r,t,...u.hexToRgb(...o)):u[t][e](...o),B=["rgb","hex","ansi256"];for(const e of B)y[e]={get(){const{level:r}=this;return function(...t){const o=A(C(e,R[r],"color",...t),u.color.close,this[O]);return I(this,o,this[v])}}},y["bg"+e[0].toUpperCase()+e.slice(1)]={get(){const{level:r}=this;return function(...t){const o=A(C(e,R[r],"bgColor",...t),u.bgColor.close,this[O]);return I(this,o,this[v])}}};const M=Object.defineProperties(()=>{},{...y,level:{enumerable:!0,get(){return this[T].level},set(e){this[T].level=e}}}),A=(e,r,t)=>{let o,n;return void 0===t?(o=e,n=r):(o=t.openAll+e,n=r+t.closeAll),{open:e,close:r,openAll:o,closeAll:n,parent:t}},I=(e,r,t)=>{const o=(...e)=>N(o,1===e.length?""+e[0]:e.join(" "));return Object.setPrototypeOf(o,M),o[T]=e,o[O]=r,o[v]=t,o},N=(e,r)=>{if(e.level<=0||!r)return e[v]?"":r;let t=e[O];if(void 0===t)return r;const{openAll:o,closeAll:n}=t;if(r.includes("\x1b"))for(;void 0!==t;)r=p(r,t.close,t.open),t=t.parent;const s=r.indexOf("\n");return-1!==s&&(r=function(e,r,t,o){let n=0,s="";do{const i="\r"===e[o-1];s+=e.slice(n,i?o-1:o)+r+(i?"\r\n":"\n")+t,n=o+1,o=e.indexOf("\n",n)}while(-1!==o);return s+=e.slice(n),s}(r,n,o,s)),o+r+n};Object.defineProperties(E.prototype,y);const w=E(),x=(E({level:_?_.level:0}),w)},460(e,r,t){t.a(e,async(e,r)=>{try{const{CNB_BUILD_ID:t,CNB_BRANCH:o,CNB_COMMIT:n,CNB_COMMIT_SHORT:s,CNB_BEFORE_SHA:i,CNB_REPO_URL_HTTPS:l,CNB_DOCKER_REGISTRY:c,CNB_PIPELINE_NAME:a,CNB_REPO_SLUG_LOWERCASE:u,CNB_BUILD_WEB_URL:g,CNB_TOKEN:d}=process.env;async function f(){const e=`https://api.cnb.cool/${u}/-/build/logs?sourceRef=${o}&pagesize=1&status=success&event=push`;try{const r=await fetch(e,{headers:{Authorization:`Bearer ${d}`}});if(!r.ok)throw new Error(`Response status: ${r.status}`);const t=await r.json(),{sha:o}=t.data[0]||{};return o||i}catch(e){console.error(e.message)}return i}const{CNB:h,npm_package_version:b="\u672a\u77e5",CUSTOM_ARTIFACT_URL:p,BRANCH_NAME:m=(h?o:void 0),CCI_JOB_NAME:_=(h?a:void 0),CI_BUILD_NUMBER:T,DEPOT_NAME:O=(h?u:void 0),GIT_COMMIT_SHORT:v=(h?s:void 0),GIT_COMMIT:R=(h?n:void 0),GIT_PREVIOUS_COMMIT:y=(h?await f():void 0),GIT_HTTP_URL:E=(h?l:void 0),JOB_ID:C=(h?t:void 0),PROJECT_WEB_URL:B=(h?`https://cnb.cool/${u}`:void 0),DOCKER_REG_HOST:M=(h?c:void 0)}=process.env;function A(e=""){return e.slice(0,7)}A(y),r()}catch(I){r(I)}},1)},119(e,r,t){t.a(e,async(e,o)=>{try{t.d(r,{Xe:()=>d}),t(298);var n=t(826),s=t(460),i=e([s]);s=(i.then?(await i)():i)[0];const{red:l,cyan:c,green:a,yellow:u,magenta:g}=n.Ay;a("[okay]"),l("[fail]"),u("[warn]");const d=["**/.{cache,git,svn,ssh,yarn}/**","**/.{npm,yarn}rc","**/.env.*","**/.env","**/.git{keep,ignore}","**/{node,web}_modules/**","**/*.{pem,ppk}","**/id_{d,r}sa","**/.obsidian/**","**/.docusaurus/**","**/miniprogram_npm/**","**/ssh*config","**/sshd*config"];o()}catch(e){o(e)}})},473(e,r,t){t.a(e,async(e,o)=>{try{t.d(r,{action:()=>d});var n=t(564),s=t(627),i=t(663),l=t(119),c=t(373),a=e([l]),u=a.then?(await a)():a;function g(e,r,t){if(0===e.length)throw new Error("Error: no pattern input");const o=(0,c.globbySync)(e,{dot:!0,ignore:t?l.Xe:[],cwd:r});if(o.length>0)return console.log(o),o;throw new Error("Error: no files targeting")}async function d({pattern:e,name:r,dir:t,cwd:o,ignore:l}){const c=g(e,o,l),a=(0,i.resolve)(process.cwd(),t,r);try{(0,n.execFileSync)("ls",[t])}catch{(0,s.mkdirSync)(t,{recursive:!0})}function u(e,r){(0,n.execFileSync)(e,r,{cwd:o})}u("tar",["-c","-f",`${a}.tar`,...c]),u("tar",["-c","-f",`${a}.tar.gz`,"-z",...c]),u("zip",["-r","-FS","-q",`${a}.zip`,...c])}l=u[0],o()}catch(f){o(f)}})}};