UNPKG

commitsmile

Version:
7 lines (6 loc) 11.2 kB
import {createRequire}from'node:module';import T from'node:process';import H from'node:os';import j from'node:tty';createRequire(import.meta.url); var I=(t,e,o)=>e?o:t;var M=(t=0)=>e=>`\x1B[${e+t}m`,P=(t=0)=>e=>`\x1B[${38+t};5;${e}m`,S=(t=0)=>(e,o,r)=>`\x1B[${38+t};2;${e};${o};${r}m`,l={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(l.modifier);var W=Object.keys(l.color),Y=Object.keys(l.bgColor);[...W,...Y];function V(){let t=new Map;for(let[e,o]of Object.entries(l)){for(let[r,n]of Object.entries(o))l[r]={open:`\x1B[${n[0]}m`,close:`\x1B[${n[1]}m`},o[r]=l[r],t.set(n[0],n[1]);Object.defineProperty(l,e,{value:o,enumerable:!1});}return Object.defineProperty(l,"codes",{value:t,enumerable:!1}),l.color.close="\x1B[39m",l.bgColor.close="\x1B[49m",l.color.ansi=M(),l.color.ansi256=P(),l.color.ansi16m=S(),l.bgColor.ansi=M(10),l.bgColor.ansi256=P(10),l.bgColor.ansi16m=S(10),Object.defineProperties(l,{rgbToAnsi256:{value(e,o,r){return e===o&&o===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(o/255*5)+Math.round(r/255*5)},enumerable:!1},hexToRgb:{value(e){let o=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!o)return [0,0,0];let[r]=o;r.length===3&&(r=[...r].map(i=>i+i).join(""));let n=Number.parseInt(r,16);return [n>>16&255,n>>8&255,n&255]},enumerable:!1},hexToAnsi256:{value:e=>l.rgbToAnsi256(...l.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let o,r,n;if(e>=232)o=((e-232)*10+8)/255,r=o,n=o;else {e-=16;let N=e%36;o=Math.floor(e/36)/5,r=Math.floor(N/6)/5,n=N%6/5;}let i=Math.max(o,r,n)*2;if(i===0)return 30;let a=30+(Math.round(n)<<2|Math.round(r)<<1|Math.round(o));return i===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,o,r)=>l.ansi256ToAnsi(l.rgbToAnsi256(e,o,r)),enumerable:!1},hexToAnsi:{value:e=>l.ansi256ToAnsi(l.hexToAnsi256(e)),enumerable:!1}}),l}var K=V(),c=K;function u(t,e=globalThis.Deno?globalThis.Deno.args:T.argv){let o=t.startsWith("-")?"":t.length===1?"-":"--",r=e.indexOf(o+t),n=e.indexOf("--");return r!==-1&&(n===-1||r<n)}var{env:s}=T,y;u("no-color")||u("no-colors")||u("color=false")||u("color=never")?y=0:(u("color")||u("colors")||u("color=true")||u("color=always"))&&(y=1);function z(){if("FORCE_COLOR"in s)return s.FORCE_COLOR==="true"?1:s.FORCE_COLOR==="false"?0:s.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(s.FORCE_COLOR,10),3)}function J(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function Q(t,{streamIsTTY:e,sniffFlags:o=!0}={}){let r=z();r!==void 0&&(y=r);let n=o?y:r;if(n===0)return 0;if(o){if(u("color=16m")||u("color=full")||u("color=truecolor"))return 3;if(u("color=256"))return 2}if("TF_BUILD"in s&&"AGENT_NAME"in s)return 1;if(t&&!e&&n===void 0)return 0;let i=n||0;if(s.TERM==="dumb")return i;if(T.platform==="win32"){let a=H.release().split(".");return Number(a[0])>=10&&Number(a[2])>=10586?Number(a[2])>=14931?3:2:1}if("CI"in s)return "GITHUB_ACTIONS"in s||"GITEA_ACTIONS"in s?3:["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(a=>a in s)||s.CI_NAME==="codeship"?1:i;if("TEAMCITY_VERSION"in s)return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(s.TEAMCITY_VERSION)?1:0;if(s.COLORTERM==="truecolor"||s.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in s){let a=Number.parseInt((s.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(s.TERM_PROGRAM){case"iTerm.app":return a>=3?3:2;case"Apple_Terminal":return 2}}return /-256(color)?$/i.test(s.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(s.TERM)||"COLORTERM"in s?1:i}function B(t,e={}){let o=Q(t,{streamIsTTY:t&&t.isTTY,...e});return J(o)}var X={stdout:B({isTTY:j.isatty(1)}),stderr:B({isTTY:j.isatty(2)})},F=X;function w(t,e,o){let r=t.indexOf(e);if(r===-1)return t;let n=e.length,i=0,a="";do a+=t.slice(i,r)+e+o,i=r+n,r=t.indexOf(e,i);while(r!==-1);return a+=t.slice(i),a}function $(t,e,o,r){let n=0,i="";do{let a=t[r-1]==="\r";i+=t.slice(n,a?r-1:r)+e+(a?`\r `:` `)+o,n=r+1,r=t.indexOf(` `,n);}while(r!==-1);return i+=t.slice(n),i}var{stdout:k,stderr:G}=F,R=Symbol("GENERATOR"),d=Symbol("STYLER"),h=Symbol("IS_EMPTY"),L=["ansi","ansi","ansi256","ansi16m"],p=Object.create(null),Z=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let o=k?k.level:0;t.level=e.level===void 0?o:e.level;};var ee=t=>{let e=(...o)=>o.join(" ");return Z(e,t),Object.setPrototypeOf(e,b.prototype),e};function b(t){return ee(t)}Object.setPrototypeOf(b.prototype,Function.prototype);for(let[t,e]of Object.entries(c))p[t]={get(){let o=C(this,E(e.open,e.close,this[d]),this[h]);return Object.defineProperty(this,t,{value:o}),o}};p.visible={get(){let t=C(this,this[d],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var x=(t,e,o,...r)=>t==="rgb"?e==="ansi16m"?c[o].ansi16m(...r):e==="ansi256"?c[o].ansi256(c.rgbToAnsi256(...r)):c[o].ansi(c.rgbToAnsi(...r)):t==="hex"?x("rgb",e,o,...c.hexToRgb(...r)):c[o][t](...r),oe=["rgb","hex","ansi256"];for(let t of oe){p[t]={get(){let{level:o}=this;return function(...r){let n=E(x(t,L[o],"color",...r),c.color.close,this[d]);return C(this,n,this[h])}}};let e="bg"+t[0].toUpperCase()+t.slice(1);p[e]={get(){let{level:o}=this;return function(...r){let n=E(x(t,L[o],"bgColor",...r),c.bgColor.close,this[d]);return C(this,n,this[h])}}};}var te=Object.defineProperties(()=>{},{...p,level:{enumerable:!0,get(){return this[R].level},set(t){this[R].level=t;}}}),E=(t,e,o)=>{let r,n;return o===void 0?(r=t,n=e):(r=o.openAll+t,n=e+o.closeAll),{open:t,close:e,openAll:r,closeAll:n,parent:o}},C=(t,e,o)=>{let r=(...n)=>re(r,n.length===1?""+n[0]:n.join(" "));return Object.setPrototypeOf(r,te),r[R]=t,r[d]=e,r[h]=o,r},re=(t,e)=>{if(t.level<=0||!e)return t[h]?"":e;let o=t[d];if(o===void 0)return e;let{openAll:r,closeAll:n}=o;if(e.includes("\x1B"))for(;o!==void 0;)e=w(e,o.close,o.open),o=o.parent;let i=e.indexOf(` `);return i!==-1&&(e=$(e,n,r,i)),r+e+n};Object.defineProperties(b.prototype,p);var ne=b();b({level:G?G.level:0});var g=ne;var D={log(...t){console.log(...t);},error(...t){console.error(g.bgRed(" ERROR "),...t);},debug(...t){process.env.DEBUG==="TRUE"&&console.debug(g.bgGray(" DEBUG "),...t);},success(...t){console.log(g.bgGreen(" SUCCESS "),...t);},info(...t){console.info(g.bgBlue(" INFO "),...t);},warn(...t){console.warn(g.bgYellow(" WARN "),...t);}};var v=(t,e)=>{if(t==null)return e;if(e==null||typeof t!="object"||typeof e!="object")return t;let o={...t};for(let r in e){if(!(r in o)){o[r]=e[r];continue}typeof e[r]=="object"&&typeof o[r]=="object"&&!Array.isArray(e[r])&&!Array.isArray(o[r])&&(o[r]=v(o[r],e[r]));}return o};var ie=Object.defineProperty,_=Object.getOwnPropertySymbols,le=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable,U=(t,e,o)=>e in t?ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,ae=(t,e)=>{for(var o in e||(e={}))le.call(e,o)&&U(t,o,e[o]);if(_)for(var o of _(e))se.call(e,o)&&U(t,o,e[o]);return t};var q=(t,e)=>(...o)=>{let r=i=>e?i:[i,!1],n=i=>{if(e)throw typeof e=="function"?e(i):e;return [i,!0]};try{let i=t(...o);return i instanceof Promise?i.then(r).catch(n):r(i)}catch(i){return n(i)}};var O=(t,e)=>{let o=ae({},t);return o};var ue={WRONG_CONFIG:{name:"Wrong Config",code:"WRONG_CONFIG",message:"Configuration is incorrect",hint:"Please check your configuration settings."}},A=class extends Promise{async deepMerge(e){return this.then(o=>v(e,o))}},ce=t=>new A(e=>{let o=fe(t);e(o);});var fe=t=>{D.debug(t);let e=q(me,O(ue.WRONG_CONFIG))(t),o=I.bind(void 0,""),r=n=>{if(n==null)return {};if(typeof e.finalCommands=="boolean")return e.finalCommands?n:{};let i=n;for(let a of e.finalCommands.remove)delete i[a];return i};return {formatter:{format:n=>`${n.type}${n.scopes}${n.isBreaking}: ${n.title}`,type:n=>n??"",scopes:n=>n?.length?`(${n})`:"",title:n=>n??"",isBreaking:n=>n?"!":""},prompts:{type:{multiple:!1,message:"What type of changes are you making?",required:!0,options:[{hint:"A new feature for the user, not a new feature for build script",label:`${o(e.emoji.label,"\u{1F389} ")}Feat`,value:`${o(e.emoji.value,"\u{1F389} ")}Feat`},{hint:"A bug fix",label:`${o(e.emoji.label,"\u{1F41B} ")}Fix`,value:`${o(e.emoji.value,"\u{1F41B} ")}Fix`},{hint:"Documentation only changes",label:`${o(e.emoji.label,"\u{1F4D6} ")}Docs`,value:`${o(e.emoji.value,"\u{1F4D6} ")}Docs`},{hint:"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",label:`${o(e.emoji.label,"\u{1F3A8} ")}Style`,value:`${o(e.emoji.value,"\u{1F3A8} ")}Style`},{hint:"Changes that affect the build system or external dependencies",label:`${o(e.emoji.label,"\u267B\uFE0F ")}Refactor`,value:`${o(e.emoji.value,"\u267B\uFE0F ")}Refactor`},{hint:"A code change that improves performance",label:`${o(e.emoji.label,"\u{1F3CE}\uFE0F ")}Perf`,value:`${o(e.emoji.value,"\u{1F3CE}\uFE0F ")}Perf`},{hint:"Adding missing tests or correcting existing tests",label:`${o(e.emoji.label,"\u{1F9EA} ")}Test`,value:`${o(e.emoji.value,"\u{1F9EA} ")}Test`},{hint:"Changes to the build process or auxiliary tools and libraries such as documentation generation",label:`${o(e.emoji.label,"\u2699\uFE0F ")}Chore`,value:`${o(e.emoji.value,"\u2699\uFE0F ")}Chore`}]},scopes:{workspaces:!1,custom:99,message:"What is the scope of this change (e.g. component or file name)?",multiple:!0,required:!0,options:[{label:`${o(e.emoji.label,"\u{1F30D} ")}Enviroment`,value:"enviroment"},{label:`${o(e.emoji.label,"\u{1F4D6} ")}Docs`,value:"docs"},{label:`${o(e.emoji.label,"\u{1F310} ")}Website`,value:"web"},{label:`${o(e.emoji.label,"\u{1F4F1} ")}Mobile`,value:"mobile"},{label:`${o(e.emoji.label,"\u{1F343} ")}API`,value:"api"}]},isBreaking:{message:"Are there any breaking changes?",active:"Yes",inactive:"No",initialValue:!1},title:{message:"Write short description of commit",validate(n){if(n.length===0)return "Value is required!"}},description:{message:"Write longer description of commit (optional)"}},finalCommands:r({gitAdd:"git add .",commit:n=>n.description=="editor"?`git commit ${o(!!n.description,"-e")} -m "${n.format()}"`:`git commit -m "${n.format()}" ${o(!!n.description,`-m "${n.description}"`)}`,gitPush:"git push"})}},me=t=>{let e={emoji:!0,finalCommands:{remove:["gitPush"]}},o=t?v(t,e):e;return typeof o.emoji=="boolean"&&(o.emoji={label:o.emoji,value:o.emoji}),o};export{ce as defaultConfig};