@soybeanjs/changelog 0.3.6 → 0.3.8
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/dist/index.cjs +8 -6
- package/dist/index.mjs +13 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";const cliProgress=require("cli-progress"),r=require("node:process"),promises=require("node:fs/promises"),ofetch=require("ofetch"),A=require("dayjs"),node_fs=require("node:fs"),convertGitmoji=require("convert-gitmoji");function _interopDefaultCompat(o){return o&&typeof o=="object"&&"default"in o?o.default:o}const r__default=_interopDefaultCompat(r),A__default=_interopDefaultCompat(A),LogLevels={silent:Number.NEGATIVE_INFINITY,fatal:0,error:0,warn:1,log:2,info:3,success:3,fail:3,ready:3,start:3,box:3,debug:4,trace:5,verbose:Number.POSITIVE_INFINITY},LogTypes={silent:{level:-1},fatal:{level:LogLevels.fatal},error:{level:LogLevels.error},warn:{level:LogLevels.warn},log:{level:LogLevels.log},info:{level:LogLevels.info},success:{level:LogLevels.success},fail:{level:LogLevels.fail},ready:{level:LogLevels.info},start:{level:LogLevels.info},box:{level:LogLevels.info},debug:{level:LogLevels.debug},trace:{level:LogLevels.trace},verbose:{level:LogLevels.verbose}};function isObject(o){return o!==null&&typeof o=="object"}function _defu(o,t,e=".",s){if(!isObject(t))return _defu(o,{},e,s);const n=Object.assign({},t);for(const i in o){if(i==="__proto__"||i==="constructor")continue;const a=o[i];a!=null&&(s&&s(n,i,a,e)||(Array.isArray(a)&&Array.isArray(n[i])?n[i]=[...a,...n[i]]:isObject(a)&&isObject(n[i])?n[i]=_defu(a,n[i],(e?`${e}.`:"")+i.toString(),s):n[i]=a))}return n}function createDefu(o){return(...t)=>t.reduce((e,s)=>_defu(e,s,"",o),{})}const defu=createDefu();function isPlainObject(o){return Object.prototype.toString.call(o)==="[object Object]"}function isLogObj(o){return!(!isPlainObject(o)||!o.message&&!o.args||o.stack)}let paused=!1;const queue=[];class Consola{constructor(t={}){const e=t.types||LogTypes;this.options=defu({...t,defaults:{...t.defaults},level:_normalizeLogLevel(t.level,e),reporters:[...t.reporters||[]]},{types:LogTypes,throttle:1e3,throttleMin:5,formatOptions:{date:!0,colors:!1,compact:!0}});for(const s in e){const n={type:s,...this.options.defaults,...e[s]};this[s]=this._wrapLogFn(n),this[s].raw=this._wrapLogFn(n,!0)}this.options.mockFn&&this.mockTypes(),this._lastLog={}}get level(){return this.options.level}set level(t){this.options.level=_normalizeLogLevel(t,this.options.types,this.options.level)}prompt(t,e){if(!this.options.prompt)throw new Error("prompt is not supported!");return this.options.prompt(t,e)}create(t){const e=new Consola({...this.options,...t});return this._mockFn&&e.mockTypes(this._mockFn),e}withDefaults(t){return this.create({...this.options,defaults:{...this.options.defaults,...t}})}withTag(t){return this.withDefaults({tag:this.options.defaults.tag?this.options.defaults.tag+":"+t:t})}addReporter(t){return this.options.reporters.push(t),this}removeReporter(t){if(t){const e=this.options.reporters.indexOf(t);if(e>=0)return this.options.reporters.splice(e,1)}else this.options.reporters.splice(0);return this}setReporters(t){return this.options.reporters=Array.isArray(t)?t:[t],this}wrapAll(){this.wrapConsole(),this.wrapStd()}restoreAll(){this.restoreConsole(),this.restoreStd()}wrapConsole(){for(const t in this.options.types)console["__"+t]||(console["__"+t]=console[t]),console[t]=this[t].raw}restoreConsole(){for(const t in this.options.types)console["__"+t]&&(console[t]=console["__"+t],delete console["__"+t])}wrapStd(){this._wrapStream(this.options.stdout,"log"),this._wrapStream(this.options.stderr,"log")}_wrapStream(t,e){t&&(t.__write||(t.__write=t.write),t.write=s=>{this[e].raw(String(s).trim())})}restoreStd(){this._restoreStream(this.options.stdout),this._restoreStream(this.options.stderr)}_restoreStream(t){t&&t.__write&&(t.write=t.__write,delete t.__write)}pauseLogs(){paused=!0}resumeLogs(){paused=!1;const t=queue.splice(0);for(const e of t)e[0]._logFn(e[1],e[2])}mockTypes(t){const e=t||this.options.mockFn;if(this._mockFn=e,typeof e=="function")for(const s in this.options.types)this[s]=e(s,this.options.types[s])||this[s],this[s].raw=this[s]}_wrapLogFn(t,e){return(...s)=>{if(paused){queue.push([this,t,s,e]);return}return this._logFn(t,s,e)}}_logFn(t,e,s){if((t.level||0)>this.level)return!1;const n={date:new Date,args:[],...t,level:_normalizeLogLevel(t.level,this.options.types)};!s&&e.length===1&&isLogObj(e[0])?Object.assign(n,e[0]):n.args=[...e],n.message&&(n.args.unshift(n.message),delete n.message),n.additional&&(Array.isArray(n.additional)||(n.additional=n.additional.split(`
|
|
1
|
+
"use strict";const cliProgress=require("cli-progress"),r=require("node:process"),promises=require("node:fs/promises"),ofetch=require("ofetch"),A$1=require("dayjs"),node_fs=require("node:fs"),convertGitmoji=require("convert-gitmoji");function _interopDefaultCompat(o){return o&&typeof o=="object"&&"default"in o?o.default:o}const r__default=_interopDefaultCompat(r),A__default=_interopDefaultCompat(A$1),LogLevels={silent:Number.NEGATIVE_INFINITY,fatal:0,error:0,warn:1,log:2,info:3,success:3,fail:3,ready:3,start:3,box:3,debug:4,trace:5,verbose:Number.POSITIVE_INFINITY},LogTypes={silent:{level:-1},fatal:{level:LogLevels.fatal},error:{level:LogLevels.error},warn:{level:LogLevels.warn},log:{level:LogLevels.log},info:{level:LogLevels.info},success:{level:LogLevels.success},fail:{level:LogLevels.fail},ready:{level:LogLevels.info},start:{level:LogLevels.info},box:{level:LogLevels.info},debug:{level:LogLevels.debug},trace:{level:LogLevels.trace},verbose:{level:LogLevels.verbose}};function isObject(o){return o!==null&&typeof o=="object"}function _defu(o,t,e=".",s){if(!isObject(t))return _defu(o,{},e,s);const n=Object.assign({},t);for(const i in o){if(i==="__proto__"||i==="constructor")continue;const a=o[i];a!=null&&(s&&s(n,i,a,e)||(Array.isArray(a)&&Array.isArray(n[i])?n[i]=[...a,...n[i]]:isObject(a)&&isObject(n[i])?n[i]=_defu(a,n[i],(e?`${e}.`:"")+i.toString(),s):n[i]=a))}return n}function createDefu(o){return(...t)=>t.reduce((e,s)=>_defu(e,s,"",o),{})}const defu=createDefu();function isPlainObject(o){return Object.prototype.toString.call(o)==="[object Object]"}function isLogObj(o){return!(!isPlainObject(o)||!o.message&&!o.args||o.stack)}let paused=!1;const queue=[];class Consola{constructor(t={}){const e=t.types||LogTypes;this.options=defu({...t,defaults:{...t.defaults},level:_normalizeLogLevel(t.level,e),reporters:[...t.reporters||[]]},{types:LogTypes,throttle:1e3,throttleMin:5,formatOptions:{date:!0,colors:!1,compact:!0}});for(const s in e){const n={type:s,...this.options.defaults,...e[s]};this[s]=this._wrapLogFn(n),this[s].raw=this._wrapLogFn(n,!0)}this.options.mockFn&&this.mockTypes(),this._lastLog={}}get level(){return this.options.level}set level(t){this.options.level=_normalizeLogLevel(t,this.options.types,this.options.level)}prompt(t,e){if(!this.options.prompt)throw new Error("prompt is not supported!");return this.options.prompt(t,e)}create(t){const e=new Consola({...this.options,...t});return this._mockFn&&e.mockTypes(this._mockFn),e}withDefaults(t){return this.create({...this.options,defaults:{...this.options.defaults,...t}})}withTag(t){return this.withDefaults({tag:this.options.defaults.tag?this.options.defaults.tag+":"+t:t})}addReporter(t){return this.options.reporters.push(t),this}removeReporter(t){if(t){const e=this.options.reporters.indexOf(t);if(e>=0)return this.options.reporters.splice(e,1)}else this.options.reporters.splice(0);return this}setReporters(t){return this.options.reporters=Array.isArray(t)?t:[t],this}wrapAll(){this.wrapConsole(),this.wrapStd()}restoreAll(){this.restoreConsole(),this.restoreStd()}wrapConsole(){for(const t in this.options.types)console["__"+t]||(console["__"+t]=console[t]),console[t]=this[t].raw}restoreConsole(){for(const t in this.options.types)console["__"+t]&&(console[t]=console["__"+t],delete console["__"+t])}wrapStd(){this._wrapStream(this.options.stdout,"log"),this._wrapStream(this.options.stderr,"log")}_wrapStream(t,e){t&&(t.__write||(t.__write=t.write),t.write=s=>{this[e].raw(String(s).trim())})}restoreStd(){this._restoreStream(this.options.stdout),this._restoreStream(this.options.stderr)}_restoreStream(t){t&&t.__write&&(t.write=t.__write,delete t.__write)}pauseLogs(){paused=!0}resumeLogs(){paused=!1;const t=queue.splice(0);for(const e of t)e[0]._logFn(e[1],e[2])}mockTypes(t){const e=t||this.options.mockFn;if(this._mockFn=e,typeof e=="function")for(const s in this.options.types)this[s]=e(s,this.options.types[s])||this[s],this[s].raw=this[s]}_wrapLogFn(t,e){return(...s)=>{if(paused){queue.push([this,t,s,e]);return}return this._logFn(t,s,e)}}_logFn(t,e,s){if((t.level||0)>this.level)return!1;const n={date:new Date,args:[],...t,level:_normalizeLogLevel(t.level,this.options.types)};!s&&e.length===1&&isLogObj(e[0])?Object.assign(n,e[0]):n.args=[...e],n.message&&(n.args.unshift(n.message),delete n.message),n.additional&&(Array.isArray(n.additional)||(n.additional=n.additional.split(`
|
|
2
2
|
`)),n.args.push(`
|
|
3
3
|
`+n.additional.join(`
|
|
4
4
|
`)),delete n.additional),n.type=typeof n.type=="string"?n.type.toLowerCase():"log",n.tag=typeof n.tag=="string"?n.tag:"";const i=(c=!1)=>{const l=(this._lastLog.count||0)-this.options.throttleMin;if(this._lastLog.object&&l>0){const u=[...this._lastLog.object.args];l>1&&u.push(`(repeated ${l} times)`),this._log({...this._lastLog.object,args:u}),this._lastLog.count=1}c&&(this._lastLog.object=n,this._log(n))};clearTimeout(this._lastLog.timeout);const a=this._lastLog.time&&n.date?n.date.getTime()-this._lastLog.time.getTime():0;if(this._lastLog.time=n.date,a<this.options.throttle)try{const c=JSON.stringify([n.type,n.tag,n.args]),l=this._lastLog.serialized===c;if(this._lastLog.serialized=c,l&&(this._lastLog.count=(this._lastLog.count||0)+1,this._lastLog.count>this.options.throttleMin)){this._lastLog.timeout=setTimeout(i,this.options.throttle);return}}catch{}i(!0)}_log(t){for(const e of this.options.reporters)e.log(t,{options:this.options})}}function _normalizeLogLevel(o,t={},e=3){return o===void 0?e:typeof o=="number"?o:t[o]&&t[o].level!==void 0?t[o].level:e}Consola.prototype.add=Consola.prototype.addReporter,Consola.prototype.remove=Consola.prototype.removeReporter,Consola.prototype.clear=Consola.prototype.removeReporter,Consola.prototype.withScope=Consola.prototype.withTag,Consola.prototype.mock=Consola.prototype.mockTypes,Consola.prototype.pause=Consola.prototype.pauseLogs,Consola.prototype.resume=Consola.prototype.resumeLogs;function createConsola$1(o={}){return new Consola(o)}class BrowserReporter{constructor(t){this.options={...t},this.defaultColor="#7f8c8d",this.levelColorMap={0:"#c0392b",1:"#f39c12",3:"#00BCD4"},this.typeColorMap={success:"#2ecc71"}}_getLogFn(t){return t<1?console.__error||console.error:t===1?console.__warn||console.warn:console.__log||console.log}log(t){const e=this._getLogFn(t.level),s=t.type==="log"?"":t.type,n=t.tag||"",a=`
|
|
@@ -12,15 +12,17 @@
|
|
|
12
12
|
`).filter(s=>s.includes(t)).forEach(s=>{const[n,i]=s.split(t),a=A__default(n).format("YYYY-MM-DD"),c=i.match(VERSION_REG)?.[0];c&&a&&e.set(c.trim(),a)}),e}function getFromToTags(o){const t=[];return o.forEach((e,s)=>{s<o.length-1&&t.push({from:e,to:o[s+1]})}),t}async function getLastGitTag(o=0){const t=await getTotalGitTags();return t[t.length+o-1]}async function v$1(){return await execCommand("git",["rev-parse","--abbrev-ref","HEAD"])}async function getCurrentGitBranch(){const o=await execCommand("git",["tag","--points-at","HEAD"]),t=v$1();return o||t}async function getGitHubRepo(){const o=await execCommand("git",["config","--get","remote.origin.url"]),t=o.match(/github\.com[/:]([\w\d._-]+?)\/([\w\d._-]+?)(\.git)?$/i);if(!t)throw new Error(`Can not parse GitHub repo from url ${o}`);return`${t[1]}/${t[2]}`}function isPrerelease(o){return!/^[^.]*[\d.]+$/.test(o)}function getFirstGitCommit(){return execCommand("git",["rev-list","--max-parents=0","HEAD"])}async function E(o,t="HEAD"){return(await execCommand("git",["--no-pager","log",`${o?`${o}...`:""}${t}`,'--pretty="----%n%s|%h|%an|%ae%n%b"',"--name-status"])).split(`----
|
|
13
13
|
`).splice(1).map(e=>{const[s,...n]=e.split(`
|
|
14
14
|
`),[i,a,c,l]=s.split("|");return{message:i,shortHash:a,author:{name:c,email:l},body:n.join(`
|
|
15
|
-
`)}})}function x$1(o){const t=/(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i,e=/co-authored-by:\s*(?<name>.+)(<(?<email>.+)>)/gim,s=/\([a-z]*(#\d+)\s*\)/gm,n=/(#\d+)/gm,i=o.message.match(t);if(!i?.groups)return null;const a=i.groups.type,c=i.groups.scope||"",l=!!i.groups.breaking;let u=i.groups.description;const p=[];for(const g of u.matchAll(s))p.push({type:"pull-request",value:g[1]});for(const g of u.matchAll(n))p.some(_=>_.value===g[1])||p.push({type:"issue",value:g[1]});p.push({value:o.shortHash,type:"hash"}),u=u.replace(s,"").trim();const m=[o.author],f=o.body.matchAll(e);for(const g of f){const{name:_="",email:b=""}=g.groups||{},F={name:_.trim(),email:b.trim()};m.push(F)}return{...o,authors:m,resolvedAuthors:[],description:u,type:a,scope:c,references:p,isBreaking:l}}async function getGitCommits(o,t="HEAD"){return(await E(o,t)).map(e=>x$1(e)).filter(notNullish)}function C(o){return{accept:"application/vnd.github.v3+json",authorization:`token ${o}`}}async function $(o,t,e){let s="";try{s=(await ofetch.ofetch(`https://ungh.cc/users/find/${e}`))?.user?.username||""}catch(a){consola.log("e: ",a)}if(s)return s;const{repo:n,token:i}=o;if(!i)return s;if(t.length)try{s=(await ofetch.ofetch(`https://api.github.com/repos/${n}/commits/${t[0]}`,{headers:C(i)}))?.author?.login||""}catch(a){consola.log("e: ",a)}if(s)return s;try{s=(await ofetch.ofetch(`https://api.github.com/search/users?q=${encodeURIComponent(e)}`,{headers:C(i)})).items[0].login}catch(a){consola.log("e: ",a)}return s}async function getGitCommitsAndResolvedAuthors(o,t,e){const s=[],n=new Map;for await(const i of o){const a=[];for await(const[l,u]of i.authors.entries()){const{email:p,name:m}=u;if(p&&m){const f=[];l===0&&f.push(i.shortHash);const g={name:m,email:p,commits:f,login:""};if(e?.has(p)){const _=e?.get(p)||"";g.login=_}else{const _=await $(t,f,p);g.login=_,e?.set(p,_)}a.push(g),n.has(p)||n.set(p,g)}}const c={...i,resolvedAuthors:a};s.push(c)}return{commits:s,contributors:Array.from(n.values())}}function w(){return{cwd:r__default.cwd(),types:{feat:"\u{1F680} Features",fix:"\u{1F41E} Bug Fixes",perf:"\u{1F525} Performance",refactor:"\u{1F485} Refactors",docs:"\u{1F4D6} Documentation",build:"\u{1F4E6} Build",types:"\u{1F30A} Types",chore:"\u{1F3E1} Chore",examples:"\u{1F3C0} Examples",test:"\u2705 Tests",style:"\u{1F3A8} Styles",ci:"\u{1F916} CI"},github:{repo:"",token:r__default.env.GITHUB_TOKEN||""},from:"",to:"",tags:[],tagDateMap:new Map,capitalize:!1,emoji:!0,titles:{breakingChanges:"\u{1F6A8} Breaking Changes"},output:"CHANGELOG.md",regenerate:!1,newVersion:""}}async function h(o){let t="";try{const e=await promises.readFile(`${o}/package.json`,"utf-8");t=JSON.parse(e)?.version||""}catch{}return{newVersion:t}}async function createOptions(o){var t;const e=w();Object.assign(e,o);const{newVersion:s}=await h(e.cwd);if((t=e.github).repo||(t.repo=await getGitHubRepo()),e.newVersion||(e.newVersion=`v${s}`),e.from||(e.from=await getLastGitTag()),e.to||(e.to=await getCurrentGitBranch()),e.to===e.from){const n=await getLastGitTag(-1),i=await getFirstGitCommit();e.from=n||i}return e.tags=await getTotalGitTags(),e.tagDateMap=await getTagDateMap(),e.prerelease||(e.prerelease=isPrerelease(e.to)),e}function d(o,t,e){const s=o.filter(i=>e==="issues"?i.type==="issue"||i.type==="pull-request":i.type==="hash").map(i=>t?i.type==="pull-request"||i.type==="issue"?`https://github.com/${t}/issues/${i.value.slice(1)}`:`[<samp>(${i.value.slice(0,5)})</samp>](https://github.com/${t}/commit/${i.value})`:i.value),n=join(s).trim();return e==="issues"?n&&`in ${n}`:n}function
|
|
16
|
-
${e}`}function generateMarkdown(o){const{options:t,showTitle:e,contributors:s}=o,n=o.commits.filter(f=>f.description.match(VERSION_WITH_RELEASE)===null),i=[],a
|
|
17
|
-
`).trim(),!0)}async function isVersionInMarkdown(o,t){let
|
|
15
|
+
`)}})}function x$1(o){const t=/(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i,e=/co-authored-by:\s*(?<name>.+)(<(?<email>.+)>)/gim,s=/\([a-z]*(#\d+)\s*\)/gm,n=/(#\d+)/gm,i=o.message.match(t);if(!i?.groups)return null;const a=i.groups.type,c=i.groups.scope||"",l=!!i.groups.breaking;let u=i.groups.description;const p=[];for(const g of u.matchAll(s))p.push({type:"pull-request",value:g[1]});for(const g of u.matchAll(n))p.some(_=>_.value===g[1])||p.push({type:"issue",value:g[1]});p.push({value:o.shortHash,type:"hash"}),u=u.replace(s,"").trim();const m=[o.author],f=o.body.matchAll(e);for(const g of f){const{name:_="",email:b=""}=g.groups||{},F={name:_.trim(),email:b.trim()};m.push(F)}return{...o,authors:m,resolvedAuthors:[],description:u,type:a,scope:c,references:p,isBreaking:l}}async function getGitCommits(o,t="HEAD"){return(await E(o,t)).map(e=>x$1(e)).filter(notNullish)}function C(o){return{accept:"application/vnd.github.v3+json",authorization:`token ${o}`}}async function $(o,t,e){let s="";try{s=(await ofetch.ofetch(`https://ungh.cc/users/find/${e}`))?.user?.username||""}catch(a){consola.log("e: ",a)}if(s)return s;const{repo:n,token:i}=o;if(!i)return s;if(t.length)try{s=(await ofetch.ofetch(`https://api.github.com/repos/${n}/commits/${t[0]}`,{headers:C(i)}))?.author?.login||""}catch(a){consola.log("e: ",a)}if(s)return s;try{s=(await ofetch.ofetch(`https://api.github.com/search/users?q=${encodeURIComponent(e)}`,{headers:C(i)})).items[0].login}catch(a){consola.log("e: ",a)}return s}async function getGitCommitsAndResolvedAuthors(o,t,e){const s=[],n=new Map;for await(const i of o){const a=[];for await(const[l,u]of i.authors.entries()){const{email:p,name:m}=u;if(p&&m){const f=[];l===0&&f.push(i.shortHash);const g={name:m,email:p,commits:f,login:""};if(e?.has(p)){const _=e?.get(p)||"";g.login=_}else{const _=await $(t,f,p);g.login=_,e?.set(p,_)}a.push(g),n.has(p)||n.set(p,g)}}const c={...i,resolvedAuthors:a};s.push(c)}return{commits:s,contributors:Array.from(n.values())}}function w$1(){return{cwd:r__default.cwd(),types:{feat:"\u{1F680} Features",fix:"\u{1F41E} Bug Fixes",perf:"\u{1F525} Performance",refactor:"\u{1F485} Refactors",docs:"\u{1F4D6} Documentation",build:"\u{1F4E6} Build",types:"\u{1F30A} Types",chore:"\u{1F3E1} Chore",examples:"\u{1F3C0} Examples",test:"\u2705 Tests",style:"\u{1F3A8} Styles",ci:"\u{1F916} CI"},github:{repo:"",token:r__default.env.GITHUB_TOKEN||""},from:"",to:"",tags:[],tagDateMap:new Map,capitalize:!1,emoji:!0,titles:{breakingChanges:"\u{1F6A8} Breaking Changes"},output:"CHANGELOG.md",regenerate:!1,newVersion:""}}async function h(o){let t="";try{const e=await promises.readFile(`${o}/package.json`,"utf-8");t=JSON.parse(e)?.version||""}catch{}return{newVersion:t}}async function createOptions(o){var t;const e=w$1();Object.assign(e,o);const{newVersion:s}=await h(e.cwd);if((t=e.github).repo||(t.repo=await getGitHubRepo()),e.newVersion||(e.newVersion=`v${s}`),e.from||(e.from=await getLastGitTag()),e.to||(e.to=await getCurrentGitBranch()),e.to===e.from){const n=await getLastGitTag(-1),i=await getFirstGitCommit();e.from=n||i}return e.tags=await getTotalGitTags(),e.tagDateMap=await getTagDateMap(),e.prerelease||(e.prerelease=isPrerelease(e.to)),e}function d(o,t,e){const s=o.filter(i=>e==="issues"?i.type==="issue"||i.type==="pull-request":i.type==="hash").map(i=>t?i.type==="pull-request"||i.type==="issue"?`https://github.com/${t}/issues/${i.value.slice(1)}`:`[<samp>(${i.value.slice(0,5)})</samp>](https://github.com/${t}/commit/${i.value})`:i.value),n=join(s).trim();return e==="issues"?n&&`in ${n}`:n}function G(o,t){const e=d(o.references,t.github.repo,"issues"),s=d(o.references,t.github.repo,"hash");let n=join([...new Set(o.resolvedAuthors.map(a=>a.login?`@${a.login}`:`**${a.name}**`))]).trim();n&&(n=`by ${n}`);let i=[n,e,s].filter(a=>a?.trim()).join(" ");return i&&(i=` - ${i}`),[t.capitalize?capitalize(o.description):o.description,i].filter(a=>a?.trim()).join(" ")}function k(o,t){const e=/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g;let s=o.trim();return t.emoji||(s=o.replace(e,"").trim()),`### ${s}`}function v(o,t,e){if(!o.length)return[];const s=["",k(t,e),""],n=groupBy(o,"scope");let i=!0;return Object.entries(n).some(([a,c])=>a&&c.length>1)||(i=!1),Object.keys(n).sort().forEach(a=>{let c="",l="";const u=`**${a}**`;a&&i?(s.push(`- ${u}:`),c=" "):a&&(l=`${u}: `),s.push(...n[a].reverse().map(p=>`${c}- ${l}${G(p,e)}`))}),s}function y(o){return`https://github.com/${o}`}function x(o){return`${y(o)}.png?size=48`}function A(o){let t="",e="";const s=new Map;return o.forEach(n=>{s.set(n.email,n)}),Array.from(s.values()).forEach((n,i)=>{const{name:a,email:c,login:l}=n;if(l){const u=y(l),p=x(l);t+=`[](${u}) `}else{let u=`[${a}](mailto:${c})`;i<o.length-1&&(u+=", "),e+=u}}),`${t}
|
|
16
|
+
${e}`}function generateMarkdown(o){const{options:t,showTitle:e,contributors:s}=o,n=o.commits.filter(f=>f.description.match(VERSION_WITH_RELEASE)===null),i=[],{version:a,isNewVersion:c}=w(t.to,t.newVersion),l=`https://github.com/${t.github.repo}/compare/${t.from}...${a}`;if(e){const f=c?A__default().format("YY-MM-DD"):t.tagDateMap.get(t.to);let g=`## [${a}](${l})`;f&&(g+=` (${f})`),i.push(g)}const[u,p]=partition(n,f=>f.isBreaking),m=groupBy(p,"type");i.push(...v(u,t.titles.breakingChanges,t));for(const f of Object.keys(t.types)){const g=m[f]||[];i.push(...v(g,t.types[f],t))}if(i.length||i.push("*No significant changes*"),e||i.push("",`##### [View changes on GitHub](${l})`),e){i.push("","### \u2764\uFE0F Contributors","");const f=A(s);i.push(f)}return convertGitmoji.convert(i.join(`
|
|
17
|
+
`).trim(),!0)}async function isVersionInMarkdown(o,t,e){let s=!1,n="";try{n=await promises.readFile(e,"utf8")}catch{}if(n){const i=n.match(VERSION_REG_OF_MARKDOWN);if(i?.length){const{version:a}=w(o,t),c=`## [${a}]`;s=i.includes(c)}}return s}function w(o,t){const e=!VERSION_REG.test(o);return{version:e?t:o,isNewVersion:e}}async function writeMarkdown(o,t,e=!1){let s="";const n="# Changelog";node_fs.existsSync(t)||await promises.writeFile(t,`${n}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
`,"utf8"),e||(s=await promises.readFile(t,"utf8")),s.startsWith(n)||(s=`${n}
|
|
20
|
+
|
|
21
|
+
${s}`);const i=s.match(/^###?\s+.*$/m);i?s=`${s.slice(0,i.index)+o}
|
|
20
22
|
|
|
21
23
|
${s.slice(i.index)}`:s+=`
|
|
22
24
|
${o}
|
|
23
25
|
|
|
24
26
|
`,await promises.writeFile(t,s)}async function getChangelogMarkdown(o,t=!0){const e=await createOptions(o),s=await getGitCommits(e.from,e.to),{commits:n,contributors:i}=await getGitCommitsAndResolvedAuthors(s,e.github);return{markdown:generateMarkdown({commits:n,options:e,showTitle:t,contributors:i}),commits:n,options:e}}async function getTotalChangelogMarkdown(o,t=!0){const e=await createOptions(o);let s=null;t&&(s=new cliProgress.SingleBar({format:"generate total changelog: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}"},cliProgress.Presets.shades_classic));const n=getFromToTags(e.tags);if(n.length===0){const{markdown:c}=await getChangelogMarkdown(e);return c}s?.start(n.length,0);let i="";const a=new Map;for await(const[c,l]of n.entries()){const{from:u,to:p}=l,m=await getGitCommits(u,p),{commits:f,contributors:g}=await getGitCommitsAndResolvedAuthors(m,e.github,a);i=`${generateMarkdown({commits:f,options:{...e,from:u,to:p},showTitle:!0,contributors:g})}
|
|
25
27
|
|
|
26
|
-
${i}`,s?.update(c+1)}return s?.stop(),i}async function generateChangelog(o){const t=await createOptions(o),e=await isVersionInMarkdown(t.to,t.output);if(!t.regenerate&&e)return;const{markdown:s}=await getChangelogMarkdown(t);await writeMarkdown(s,t.output,t.regenerate)}async function generateTotalChangelog(o,t=!0){const e=await createOptions(o),s=await getTotalChangelogMarkdown(e,t);await writeMarkdown(s,e.output,!0)}exports.generateChangelog=generateChangelog,exports.generateTotalChangelog=generateTotalChangelog,exports.getChangelogMarkdown=getChangelogMarkdown,exports.getTotalChangelogMarkdown=getTotalChangelogMarkdown;
|
|
28
|
+
${i}`,s?.update(c+1)}return s?.stop(),i}async function generateChangelog(o){const t=await createOptions(o),e=await isVersionInMarkdown(t.to,t.newVersion,t.output);if(!t.regenerate&&e)return;const{markdown:s}=await getChangelogMarkdown(t);await writeMarkdown(s,t.output,t.regenerate)}async function generateTotalChangelog(o,t=!0){const e=await createOptions(o),s=await getTotalChangelogMarkdown(e,t);await writeMarkdown(s,e.output,!0)}exports.generateChangelog=generateChangelog,exports.generateTotalChangelog=generateTotalChangelog,exports.getChangelogMarkdown=getChangelogMarkdown,exports.getTotalChangelogMarkdown=getTotalChangelogMarkdown;
|
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import{SingleBar as
|
|
1
|
+
import{SingleBar as J,Presets as K}from"cli-progress";import k from"node:process";import{readFile as _,writeFile as E}from"node:fs/promises";import{ofetch as b}from"ofetch";import D from"dayjs";import{existsSync as Q}from"node:fs";import{convert as X}from"convert-gitmoji";const g={silent:Number.NEGATIVE_INFINITY,fatal:0,error:0,warn:1,log:2,info:3,success:3,fail:3,ready:3,start:3,box:3,debug:4,trace:5,verbose:Number.POSITIVE_INFINITY},T={silent:{level:-1},fatal:{level:g.fatal},error:{level:g.error},warn:{level:g.warn},log:{level:g.log},info:{level:g.info},success:{level:g.success},fail:{level:g.fail},ready:{level:g.info},start:{level:g.info},box:{level:g.info},debug:{level:g.debug},trace:{level:g.trace},verbose:{level:g.verbose}};function v(o){return o!==null&&typeof o=="object"}function $(o,t,e=".",s){if(!v(t))return $(o,{},e,s);const r=Object.assign({},t);for(const n in o){if(n==="__proto__"||n==="constructor")continue;const i=o[n];i!=null&&(s&&s(r,n,i,e)||(Array.isArray(i)&&Array.isArray(r[n])?r[n]=[...i,...r[n]]:v(i)&&v(r[n])?r[n]=$(i,r[n],(e?`${e}.`:"")+n.toString(),s):r[n]=i))}return r}function Z(o){return(...t)=>t.reduce((e,s)=>$(e,s,"",o),{})}const tt=Z();function et(o){return Object.prototype.toString.call(o)==="[object Object]"}function ot(o){return!(!et(o)||!o.message&&!o.args||o.stack)}let F=!1;const M=[];class f{constructor(t={}){const e=t.types||T;this.options=tt({...t,defaults:{...t.defaults},level:C(t.level,e),reporters:[...t.reporters||[]]},{types:T,throttle:1e3,throttleMin:5,formatOptions:{date:!0,colors:!1,compact:!0}});for(const s in e){const r={type:s,...this.options.defaults,...e[s]};this[s]=this._wrapLogFn(r),this[s].raw=this._wrapLogFn(r,!0)}this.options.mockFn&&this.mockTypes(),this._lastLog={}}get level(){return this.options.level}set level(t){this.options.level=C(t,this.options.types,this.options.level)}prompt(t,e){if(!this.options.prompt)throw new Error("prompt is not supported!");return this.options.prompt(t,e)}create(t){const e=new f({...this.options,...t});return this._mockFn&&e.mockTypes(this._mockFn),e}withDefaults(t){return this.create({...this.options,defaults:{...this.options.defaults,...t}})}withTag(t){return this.withDefaults({tag:this.options.defaults.tag?this.options.defaults.tag+":"+t:t})}addReporter(t){return this.options.reporters.push(t),this}removeReporter(t){if(t){const e=this.options.reporters.indexOf(t);if(e>=0)return this.options.reporters.splice(e,1)}else this.options.reporters.splice(0);return this}setReporters(t){return this.options.reporters=Array.isArray(t)?t:[t],this}wrapAll(){this.wrapConsole(),this.wrapStd()}restoreAll(){this.restoreConsole(),this.restoreStd()}wrapConsole(){for(const t in this.options.types)console["__"+t]||(console["__"+t]=console[t]),console[t]=this[t].raw}restoreConsole(){for(const t in this.options.types)console["__"+t]&&(console[t]=console["__"+t],delete console["__"+t])}wrapStd(){this._wrapStream(this.options.stdout,"log"),this._wrapStream(this.options.stderr,"log")}_wrapStream(t,e){t&&(t.__write||(t.__write=t.write),t.write=s=>{this[e].raw(String(s).trim())})}restoreStd(){this._restoreStream(this.options.stdout),this._restoreStream(this.options.stderr)}_restoreStream(t){t&&t.__write&&(t.write=t.__write,delete t.__write)}pauseLogs(){F=!0}resumeLogs(){F=!1;const t=M.splice(0);for(const e of t)e[0]._logFn(e[1],e[2])}mockTypes(t){const e=t||this.options.mockFn;if(this._mockFn=e,typeof e=="function")for(const s in this.options.types)this[s]=e(s,this.options.types[s])||this[s],this[s].raw=this[s]}_wrapLogFn(t,e){return(...s)=>{if(F){M.push([this,t,s,e]);return}return this._logFn(t,s,e)}}_logFn(t,e,s){if((t.level||0)>this.level)return!1;const r={date:new Date,args:[],...t,level:C(t.level,this.options.types)};!s&&e.length===1&&ot(e[0])?Object.assign(r,e[0]):r.args=[...e],r.message&&(r.args.unshift(r.message),delete r.message),r.additional&&(Array.isArray(r.additional)||(r.additional=r.additional.split(`
|
|
2
2
|
`)),r.args.push(`
|
|
3
3
|
`+r.additional.join(`
|
|
4
|
-
`)),delete r.additional),r.type=typeof r.type=="string"?r.type.toLowerCase():"log",r.tag=typeof r.tag=="string"?r.tag:"";const n=(a=!1)=>{const c=(this._lastLog.count||0)-this.options.throttleMin;if(this._lastLog.object&&c>0){const l=[...this._lastLog.object.args];c>1&&l.push(`(repeated ${c} times)`),this._log({...this._lastLog.object,args:l}),this._lastLog.count=1}a&&(this._lastLog.object=r,this._log(r))};clearTimeout(this._lastLog.timeout);const i=this._lastLog.time&&r.date?r.date.getTime()-this._lastLog.time.getTime():0;if(this._lastLog.time=r.date,i<this.options.throttle)try{const a=JSON.stringify([r.type,r.tag,r.args]),c=this._lastLog.serialized===a;if(this._lastLog.serialized=a,c&&(this._lastLog.count=(this._lastLog.count||0)+1,this._lastLog.count>this.options.throttleMin)){this._lastLog.timeout=setTimeout(n,this.options.throttle);return}}catch{}n(!0)}_log(t){for(const e of this.options.reporters)e.log(t,{options:this.options})}}function C(o,t={},e=3){return o===void 0?e:typeof o=="number"?o:t[o]&&t[o].level!==void 0?t[o].level:e}f.prototype.add=f.prototype.addReporter,f.prototype.remove=f.prototype.removeReporter,f.prototype.clear=f.prototype.removeReporter,f.prototype.withScope=f.prototype.withTag,f.prototype.mock=f.prototype.mockTypes,f.prototype.pause=f.prototype.pauseLogs,f.prototype.resume=f.prototype.resumeLogs;function
|
|
4
|
+
`)),delete r.additional),r.type=typeof r.type=="string"?r.type.toLowerCase():"log",r.tag=typeof r.tag=="string"?r.tag:"";const n=(a=!1)=>{const c=(this._lastLog.count||0)-this.options.throttleMin;if(this._lastLog.object&&c>0){const l=[...this._lastLog.object.args];c>1&&l.push(`(repeated ${c} times)`),this._log({...this._lastLog.object,args:l}),this._lastLog.count=1}a&&(this._lastLog.object=r,this._log(r))};clearTimeout(this._lastLog.timeout);const i=this._lastLog.time&&r.date?r.date.getTime()-this._lastLog.time.getTime():0;if(this._lastLog.time=r.date,i<this.options.throttle)try{const a=JSON.stringify([r.type,r.tag,r.args]),c=this._lastLog.serialized===a;if(this._lastLog.serialized=a,c&&(this._lastLog.count=(this._lastLog.count||0)+1,this._lastLog.count>this.options.throttleMin)){this._lastLog.timeout=setTimeout(n,this.options.throttle);return}}catch{}n(!0)}_log(t){for(const e of this.options.reporters)e.log(t,{options:this.options})}}function C(o,t={},e=3){return o===void 0?e:typeof o=="number"?o:t[o]&&t[o].level!==void 0?t[o].level:e}f.prototype.add=f.prototype.addReporter,f.prototype.remove=f.prototype.removeReporter,f.prototype.clear=f.prototype.removeReporter,f.prototype.withScope=f.prototype.withTag,f.prototype.mock=f.prototype.mockTypes,f.prototype.pause=f.prototype.pauseLogs,f.prototype.resume=f.prototype.resumeLogs;function st(o={}){return new f(o)}class rt{constructor(t){this.options={...t},this.defaultColor="#7f8c8d",this.levelColorMap={0:"#c0392b",1:"#f39c12",3:"#00BCD4"},this.typeColorMap={success:"#2ecc71"}}_getLogFn(t){return t<1?console.__error||console.error:t===1?console.__warn||console.warn:console.__log||console.log}log(t){const e=this._getLogFn(t.level),s=t.type==="log"?"":t.type,r=t.tag||"",i=`
|
|
5
5
|
background: ${this.typeColorMap[t.type]||this.levelColorMap[t.level]||this.defaultColor};
|
|
6
6
|
border-radius: 0.5em;
|
|
7
7
|
color: white;
|
|
8
8
|
font-weight: bold;
|
|
9
9
|
padding: 2px 0.5em;
|
|
10
|
-
`,a=`%c${[r,s].filter(Boolean).join(":")}`;typeof t.args[0]=="string"?e(`${a}%c ${t.args[0]}`,i,"",...t.args.slice(1)):e(a,i,...t.args)}}function
|
|
11
|
-
`)}async function
|
|
12
|
-
`).filter(s=>s.includes(t)).forEach(s=>{const[r,n]=s.split(t),i=D(r).format("YYYY-MM-DD"),a=n.match(
|
|
10
|
+
`,a=`%c${[r,s].filter(Boolean).join(":")}`;typeof t.args[0]=="string"?e(`${a}%c ${t.args[0]}`,i,"",...t.args.slice(1)):e(a,i,...t.args)}}function nt(o={}){return st({reporters:o.reporters||[new rt({})],prompt(e,s={}){return s.type==="confirm"?Promise.resolve(confirm(e)):Promise.resolve(prompt(e))},...o})}const L=nt();async function w(o,t,e){const{execa:s}=await import("execa");return(await s(o,t,e))?.stdout?.trim()||""}function it(o){return o!=null}function at(o,...t){const e=Array.from({length:t.length+1}).fill(null).map(()=>[]);return o.forEach((s,r,n)=>{let i=0;for(const a of t){if(a(s,r,n)){e[i].push(s);return}i+=1}e[i].push(s)}),e}function S(o,t,e={}){for(const s of o){const r=s[t];e[r]||(e[r]=[]),e[r].push(s)}return e}function ct(o){return o.charAt(0).toUpperCase()+o.slice(1)}function j(o,t=", ",e=" and "){return!o||o.length===0?"":o.length===1?o[0]:o.length===2?o.join(e):`${o.slice(0,-1).join(t)}${e}${o.slice(-1)}`}const N=/v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?/,lt=/## \[v\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?]/g,ut=/release\sv\d+\.\d+\.\d+(-(beta|alpha)\.\d+)?/;async function x(){return(await w("git",["--no-pager","tag","-l","--sort=creatordate"])).split(`
|
|
11
|
+
`)}async function pt(){const o=await w("git",["--no-pager","log","--tags","--simplify-by-decoration","--pretty=format:%ci %d"]),t="tag: ",e=new Map;return o.split(`
|
|
12
|
+
`).filter(s=>s.includes(t)).forEach(s=>{const[r,n]=s.split(t),i=D(r).format("YYYY-MM-DD"),a=n.match(N)?.[0];a&&i&&e.set(a.trim(),i)}),e}function ht(o){const t=[];return o.forEach((e,s)=>{s<o.length-1&&t.push({from:e,to:o[s+1]})}),t}async function I(o=0){const t=await x();return t[t.length+o-1]}async function ft(){return await w("git",["rev-parse","--abbrev-ref","HEAD"])}async function gt(){const o=await w("git",["tag","--points-at","HEAD"]),t=ft();return o||t}async function mt(){const o=await w("git",["config","--get","remote.origin.url"]),t=o.match(/github\.com[/:]([\w\d._-]+?)\/([\w\d._-]+?)(\.git)?$/i);if(!t)throw new Error(`Can not parse GitHub repo from url ${o}`);return`${t[1]}/${t[2]}`}function dt(o){return!/^[^.]*[\d.]+$/.test(o)}function wt(){return w("git",["rev-list","--max-parents=0","HEAD"])}async function yt(o,t="HEAD"){return(await w("git",["--no-pager","log",`${o?`${o}...`:""}${t}`,'--pretty="----%n%s|%h|%an|%ae%n%b"',"--name-status"])).split(`----
|
|
13
13
|
`).splice(1).map(e=>{const[s,...r]=e.split(`
|
|
14
14
|
`),[n,i,a,c]=s.split("|");return{message:n,shortHash:i,author:{name:a,email:c},body:r.join(`
|
|
15
|
-
`)}})}function
|
|
16
|
-
${e}`}function z(o){const{options:t,showTitle:e,contributors:s}=o,r=o.commits.filter(p=>p.description.match(
|
|
17
|
-
`).trim(),!0)}async function kt(o,t){let
|
|
15
|
+
`)}})}function _t(o){const t=/(?<type>[a-z]+)(\((?<scope>.+)\))?(?<breaking>!)?: (?<description>.+)/i,e=/co-authored-by:\s*(?<name>.+)(<(?<email>.+)>)/gim,s=/\([a-z]*(#\d+)\s*\)/gm,r=/(#\d+)/gm,n=o.message.match(t);if(!n?.groups)return null;const i=n.groups.type,a=n.groups.scope||"",c=!!n.groups.breaking;let l=n.groups.description;const u=[];for(const h of l.matchAll(s))u.push({type:"pull-request",value:h[1]});for(const h of l.matchAll(r))u.some(d=>d.value===h[1])||u.push({type:"issue",value:h[1]});u.push({value:o.shortHash,type:"hash"}),l=l.replace(s,"").trim();const m=[o.author],p=o.body.matchAll(e);for(const h of p){const{name:d="",email:U=""}=h.groups||{},W={name:d.trim(),email:U.trim()};m.push(W)}return{...o,authors:m,resolvedAuthors:[],description:l,type:i,scope:a,references:u,isBreaking:c}}async function R(o,t="HEAD"){return(await yt(o,t)).map(e=>_t(e)).filter(it)}function G(o){return{accept:"application/vnd.github.v3+json",authorization:`token ${o}`}}async function bt(o,t,e){let s="";try{s=(await b(`https://ungh.cc/users/find/${e}`))?.user?.username||""}catch(i){L.log("e: ",i)}if(s)return s;const{repo:r,token:n}=o;if(!n)return s;if(t.length)try{s=(await b(`https://api.github.com/repos/${r}/commits/${t[0]}`,{headers:G(n)}))?.author?.login||""}catch(i){L.log("e: ",i)}if(s)return s;try{s=(await b(`https://api.github.com/search/users?q=${encodeURIComponent(e)}`,{headers:G(n)})).items[0].login}catch(i){L.log("e: ",i)}return s}async function V(o,t,e){const s=[],r=new Map;for await(const n of o){const i=[];for await(const[c,l]of n.authors.entries()){const{email:u,name:m}=l;if(u&&m){const p=[];c===0&&p.push(n.shortHash);const h={name:m,email:u,commits:p,login:""};if(e?.has(u)){const d=e?.get(u)||"";h.login=d}else{const d=await bt(t,p,u);h.login=d,e?.set(u,d)}i.push(h),r.has(u)||r.set(u,h)}}const a={...n,resolvedAuthors:i};s.push(a)}return{commits:s,contributors:Array.from(r.values())}}function vt(){return{cwd:k.cwd(),types:{feat:"\u{1F680} Features",fix:"\u{1F41E} Bug Fixes",perf:"\u{1F525} Performance",refactor:"\u{1F485} Refactors",docs:"\u{1F4D6} Documentation",build:"\u{1F4E6} Build",types:"\u{1F30A} Types",chore:"\u{1F3E1} Chore",examples:"\u{1F3C0} Examples",test:"\u2705 Tests",style:"\u{1F3A8} Styles",ci:"\u{1F916} CI"},github:{repo:"",token:k.env.GITHUB_TOKEN||""},from:"",to:"",tags:[],tagDateMap:new Map,capitalize:!1,emoji:!0,titles:{breakingChanges:"\u{1F6A8} Breaking Changes"},output:"CHANGELOG.md",regenerate:!1,newVersion:""}}async function $t(o){let t="";try{const e=await _(`${o}/package.json`,"utf-8");t=JSON.parse(e)?.version||""}catch{}return{newVersion:t}}async function y(o){var t;const e=vt();Object.assign(e,o);const{newVersion:s}=await $t(e.cwd);if((t=e.github).repo||(t.repo=await mt()),e.newVersion||(e.newVersion=`v${s}`),e.from||(e.from=await I()),e.to||(e.to=await gt()),e.to===e.from){const r=await I(-1),n=await wt();e.from=r||n}return e.tags=await x(),e.tagDateMap=await pt(),e.prerelease||(e.prerelease=dt(e.to)),e}function H(o,t,e){const s=o.filter(n=>e==="issues"?n.type==="issue"||n.type==="pull-request":n.type==="hash").map(n=>t?n.type==="pull-request"||n.type==="issue"?`https://github.com/${t}/issues/${n.value.slice(1)}`:`[<samp>(${n.value.slice(0,5)})</samp>](https://github.com/${t}/commit/${n.value})`:n.value),r=j(s).trim();return e==="issues"?r&&`in ${r}`:r}function Ft(o,t){const e=H(o.references,t.github.repo,"issues"),s=H(o.references,t.github.repo,"hash");let r=j([...new Set(o.resolvedAuthors.map(i=>i.login?`@${i.login}`:`**${i.name}**`))]).trim();r&&(r=`by ${r}`);let n=[r,e,s].filter(i=>i?.trim()).join(" ");return n&&(n=` - ${n}`),[t.capitalize?ct(o.description):o.description,n].filter(i=>i?.trim()).join(" ")}function Ct(o,t){const e=/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g;let s=o.trim();return t.emoji||(s=o.replace(e,"").trim()),`### ${s}`}function O(o,t,e){if(!o.length)return[];const s=["",Ct(t,e),""],r=S(o,"scope");let n=!0;return Object.entries(r).some(([i,a])=>i&&a.length>1)||(n=!1),Object.keys(r).sort().forEach(i=>{let a="",c="";const l=`**${i}**`;i&&n?(s.push(`- ${l}:`),a=" "):i&&(c=`${l}: `),s.push(...r[i].reverse().map(u=>`${a}- ${c}${Ft(u,e)}`))}),s}function B(o){return`https://github.com/${o}`}function Lt(o){return`${B(o)}.png?size=48`}function At(o){let t="",e="";const s=new Map;return o.forEach(r=>{s.set(r.email,r)}),Array.from(s.values()).forEach((r,n)=>{const{name:i,email:a,login:c}=r;if(c){const l=B(c),u=Lt(c);t+=`[](${l}) `}else{let l=`[${i}](mailto:${a})`;n<o.length-1&&(l+=", "),e+=l}}),`${t}
|
|
16
|
+
${e}`}function z(o){const{options:t,showTitle:e,contributors:s}=o,r=o.commits.filter(p=>p.description.match(ut)===null),n=[],{version:i,isNewVersion:a}=Y(t.to,t.newVersion),c=`https://github.com/${t.github.repo}/compare/${t.from}...${i}`;if(e){const p=a?D().format("YY-MM-DD"):t.tagDateMap.get(t.to);let h=`## [${i}](${c})`;p&&(h+=` (${p})`),n.push(h)}const[l,u]=at(r,p=>p.isBreaking),m=S(u,"type");n.push(...O(l,t.titles.breakingChanges,t));for(const p of Object.keys(t.types)){const h=m[p]||[];n.push(...O(h,t.types[p],t))}if(n.length||n.push("*No significant changes*"),e||n.push("",`##### [View changes on GitHub](${c})`),e){n.push("","### \u2764\uFE0F Contributors","");const p=At(s);n.push(p)}return X(n.join(`
|
|
17
|
+
`).trim(),!0)}async function kt(o,t,e){let s=!1,r="";try{r=await _(e,"utf8")}catch{}if(r){const n=r.match(lt);if(n?.length){const{version:i}=Y(o,t),a=`## [${i}]`;s=n.includes(a)}}return s}function Y(o,t){const e=!N.test(o);return{version:e?t:o,isNewVersion:e}}async function P(o,t,e=!1){let s="";const r="# Changelog";Q(t)||await E(t,`${r}
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
`,"utf8"),e||(s=await _(t,"utf8")),s.startsWith(r)||(s=`${r}
|
|
20
|
+
|
|
21
|
+
${s}`);const n=s.match(/^###?\s+.*$/m);n?s=`${s.slice(0,n.index)+o}
|
|
20
22
|
|
|
21
23
|
${s.slice(n.index)}`:s+=`
|
|
22
24
|
${o}
|
|
23
25
|
|
|
24
|
-
`,await E(t,s)}async function
|
|
26
|
+
`,await E(t,s)}async function A(o,t=!0){const e=await y(o),s=await R(e.from,e.to),{commits:r,contributors:n}=await V(s,e.github);return{markdown:z({commits:r,options:e,showTitle:t,contributors:n}),commits:r,options:e}}async function q(o,t=!0){const e=await y(o);let s=null;t&&(s=new J({format:"generate total changelog: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}"},K.shades_classic));const r=ht(e.tags);if(r.length===0){const{markdown:a}=await A(e);return a}s?.start(r.length,0);let n="";const i=new Map;for await(const[a,c]of r.entries()){const{from:l,to:u}=c,m=await R(l,u),{commits:p,contributors:h}=await V(m,e.github,i);n=`${z({commits:p,options:{...e,from:l,to:u},showTitle:!0,contributors:h})}
|
|
25
27
|
|
|
26
|
-
${n}`,s?.update(a+1)}return s?.stop(),n}async function
|
|
28
|
+
${n}`,s?.update(a+1)}return s?.stop(),n}async function Et(o){const t=await y(o),e=await kt(t.to,t.newVersion,t.output);if(!t.regenerate&&e)return;const{markdown:s}=await A(t);await P(s,t.output,t.regenerate)}async function Dt(o,t=!0){const e=await y(o),s=await q(e,t);await P(s,e.output,!0)}export{Et as generateChangelog,Dt as generateTotalChangelog,A as getChangelogMarkdown,q as getTotalChangelogMarkdown};
|