githublogen 0.3.0 → 0.3.2
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/cli.cjs +12 -1
- package/dist/cli.mjs +12 -6
- package/package.json +2 -2
- package/dist/cli.d.ts +0 -2
package/dist/cli.cjs
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";const l=require("cac"),kolorist=require("kolorist"),changelog=require("@soybeanjs/changelog"),ofetch=require("ofetch");function _interopDefaultCompat(o){return o&&typeof o=="object"&&"default"in o?o.default:o}const l__default=_interopDefaultCompat(l),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=".",r){if(!isObject(t))return _defu(o,{},e,r);const s=Object.assign({},t);for(const i in o){if(i==="__proto__"||i==="constructor")continue;const n=o[i];n!=null&&(r&&r(s,i,n,e)||(Array.isArray(n)&&Array.isArray(s[i])?s[i]=[...n,...s[i]]:isObject(n)&&isObject(s[i])?s[i]=_defu(n,s[i],(e?`${e}.`:"")+i.toString(),r):s[i]=n))}return s}function createDefu(o){return(...t)=>t.reduce((e,r)=>_defu(e,r,"",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 r in e){const s={type:r,...this.options.defaults,...e[r]};this[r]=this._wrapLogFn(s),this[r].raw=this._wrapLogFn(s,!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=r=>{this[e].raw(String(r).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 r in this.options.types)this[r]=e(r,this.options.types[r])||this[r],this[r].raw=this[r]}_wrapLogFn(t,e){return(...r)=>{if(paused){queue.push([this,t,r,e]);return}return this._logFn(t,r,e)}}_logFn(t,e,r){if((t.level||0)>this.level)return!1;const s={date:new Date,args:[],...t,level:_normalizeLogLevel(t.level,this.options.types)};!r&&e.length===1&&isLogObj(e[0])?Object.assign(s,e[0]):s.args=[...e],s.message&&(s.args.unshift(s.message),delete s.message),s.additional&&(Array.isArray(s.additional)||(s.additional=s.additional.split(`
|
|
2
|
+
`)),s.args.push(`
|
|
3
|
+
`+s.additional.join(`
|
|
4
|
+
`)),delete s.additional),s.type=typeof s.type=="string"?s.type.toLowerCase():"log",s.tag=typeof s.tag=="string"?s.tag:"";const i=(c=!1)=>{const a=(this._lastLog.count||0)-this.options.throttleMin;if(this._lastLog.object&&a>0){const p=[...this._lastLog.object.args];a>1&&p.push(`(repeated ${a} times)`),this._log({...this._lastLog.object,args:p}),this._lastLog.count=1}c&&(this._lastLog.object=s,this._log(s))};clearTimeout(this._lastLog.timeout);const n=this._lastLog.time&&s.date?s.date.getTime()-this._lastLog.time.getTime():0;if(this._lastLog.time=s.date,n<this.options.throttle)try{const c=JSON.stringify([s.type,s.tag,s.args]),a=this._lastLog.serialized===c;if(this._lastLog.serialized=c,a&&(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),r=t.type==="log"?"":t.type,s=t.tag||"",n=`
|
|
5
|
+
background: ${this.typeColorMap[t.type]||this.levelColorMap[t.level]||this.defaultColor};
|
|
6
|
+
border-radius: 0.5em;
|
|
7
|
+
color: white;
|
|
8
|
+
font-weight: bold;
|
|
9
|
+
padding: 2px 0.5em;
|
|
10
|
+
`,c=`%c${[s,r].filter(Boolean).join(":")}`;typeof t.args[0]=="string"?e(`${c}%c ${t.args[0]}`,n,"",...t.args.slice(1)):e(c,n,...t.args)}}function createConsola(o={}){return createConsola$1({reporters:o.reporters||[new BrowserReporter({})],prompt(e,r={}){return r.type==="confirm"?Promise.resolve(confirm(e)):Promise.resolve(prompt(e))},...o})}const consola=createConsola(),version="0.3.2";function g(o){return{accept:"application/vnd.github.v3+json",authorization:`token ${o}`}}async function hasTagOnGitHub(o,t,e){try{return await ofetch.ofetch(`https://api.github.com/repos/${t}/git/ref/tags/${o}`,{headers:g(e)}),!0}catch{return!1}}async function sendRelease(o,t){const e=g(o.github.token),r=o.github.repo;let s=`https://api.github.com/repos/${r}/releases`,i="POST";try{const a=await ofetch.ofetch(`https://api.github.com/repos/${r}/releases/tags/${o.to}`,{headers:e});a.url&&(s=a.url,i="PATCH")}catch{}const n={body:t,draft:!1,name:o.to,prerelease:o.prerelease,tag_name:o.to},c=`https://github.com/${r}/releases/new?title=${encodeURIComponent(String(n.name))}&body=${encodeURIComponent(String(n.body))}&tag=${encodeURIComponent(String(o.to))}&prerelease=${o.prerelease}`;try{consola.log(kolorist.cyan(i==="POST"?"Creating release notes...":"Updating release notes..."));const a=await ofetch.ofetch(s,{method:i,body:JSON.stringify(n),headers:e});consola.log(kolorist.green(`Released on ${a.html_url}`))}catch(a){throw consola.error(kolorist.red("Failed to create the release. Using the following link to create it manually:")),consola.error(kolorist.yellow(c)),a}}async function y(o,t){const{execa:e}=await import("execa");return(await e(o,t)).stdout.trim()}async function isRepoShallow(){return(await y("git",["rev-parse","--is-shallow-repository"])).trim()==="true"}function k(){const o=l__default("githublogen");o.version(version).option("-t, --token <path>","GitHub Token").help(),o.command("").action(async t=>{try{const e=process.cwd(),{options:r,commits:s,markdown:i}=await changelog.getChangelogMarkdown({cwd:e,...t},!1);if(consola.log(kolorist.cyan(r.from)+kolorist.dim(" -> ")+kolorist.blue(r.to)+kolorist.dim(` (${s.length} commits)`)),await hasTagOnGitHub(r.to,r.github.repo,r.github.token)||(consola.error(kolorist.yellow(`Current ref "${kolorist.bold(r.to)}" is not available as tags on GitHub. Release skipped.`)),process.exitCode&&(process.exitCode=1)),!s.length&&await isRepoShallow()){consola.error(kolorist.yellow("The repo seems to be clone shallowly, which make changelog failed to generate. You might want to specify `fetch-depth: 0` in your CI config.")),process.exitCode&&(process.exitCode=1);return}await sendRelease(r,i)}catch(e){consola.error(kolorist.red(String(e))),e?.stack&&consola.error(kolorist.dim(e.stack?.split(`
|
|
11
|
+
`).slice(1).join(`
|
|
12
|
+
`))),process.exit(1)}}),o.parse()}k();
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import S from"cac";import{cyan as v,green as T,red as b,yellow as u,dim as f,blue as $,bold as F}from"kolorist";import{getChangelogMarkdown as I}from"@soybeanjs/changelog";import{ofetch as g}from"ofetch";const a={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},L={silent:{level:-1},fatal:{level:a.fatal},error:{level:a.error},warn:{level:a.warn},log:{level:a.log},info:{level:a.info},success:{level:a.success},fail:{level:a.fail},ready:{level:a.info},start:{level:a.info},box:{level:a.info},debug:{level:a.debug},trace:{level:a.trace},verbose:{level:a.verbose}};function d(s){return s!==null&&typeof s=="object"}function y(s,t,e=".",r){if(!d(t))return y(s,{},e,r);const o=Object.assign({},t);for(const i in s){if(i==="__proto__"||i==="constructor")continue;const n=s[i];n!=null&&(r&&r(o,i,n,e)||(Array.isArray(n)&&Array.isArray(o[i])?o[i]=[...n,...o[i]]:d(n)&&d(o[i])?o[i]=y(n,o[i],(e?`${e}.`:"")+i.toString(),r):o[i]=n))}return o}function R(s){return(...t)=>t.reduce((e,r)=>y(e,r,"",s),{})}const A=R();function x(s){return Object.prototype.toString.call(s)==="[object Object]"}function N(s){return!(!x(s)||!s.message&&!s.args||s.stack)}let m=!1;const k=[];class l{constructor(t={}){const e=t.types||L;this.options=A({...t,defaults:{...t.defaults},level:_(t.level,e),reporters:[...t.reporters||[]]},{types:L,throttle:1e3,throttleMin:5,formatOptions:{date:!0,colors:!1,compact:!0}});for(const r in e){const o={type:r,...this.options.defaults,...e[r]};this[r]=this._wrapLogFn(o),this[r].raw=this._wrapLogFn(o,!0)}this.options.mockFn&&this.mockTypes(),this._lastLog={}}get level(){return this.options.level}set level(t){this.options.level=_(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 l({...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=r=>{this[e].raw(String(r).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(){m=!0}resumeLogs(){m=!1;const t=k.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 r in this.options.types)this[r]=e(r,this.options.types[r])||this[r],this[r].raw=this[r]}_wrapLogFn(t,e){return(...r)=>{if(m){k.push([this,t,r,e]);return}return this._logFn(t,r,e)}}_logFn(t,e,r){if((t.level||0)>this.level)return!1;const o={date:new Date,args:[],...t,level:_(t.level,this.options.types)};!r&&e.length===1&&N(e[0])?Object.assign(o,e[0]):o.args=[...e],o.message&&(o.args.unshift(o.message),delete o.message),o.additional&&(Array.isArray(o.additional)||(o.additional=o.additional.split(`
|
|
2
|
+
`)),o.args.push(`
|
|
3
|
+
`+o.additional.join(`
|
|
4
|
+
`)),delete o.additional),o.type=typeof o.type=="string"?o.type.toLowerCase():"log",o.tag=typeof o.tag=="string"?o.tag:"";const i=(p=!1)=>{const c=(this._lastLog.count||0)-this.options.throttleMin;if(this._lastLog.object&&c>0){const w=[...this._lastLog.object.args];c>1&&w.push(`(repeated ${c} times)`),this._log({...this._lastLog.object,args:w}),this._lastLog.count=1}p&&(this._lastLog.object=o,this._log(o))};clearTimeout(this._lastLog.timeout);const n=this._lastLog.time&&o.date?o.date.getTime()-this._lastLog.time.getTime():0;if(this._lastLog.time=o.date,n<this.options.throttle)try{const p=JSON.stringify([o.type,o.tag,o.args]),c=this._lastLog.serialized===p;if(this._lastLog.serialized=p,c&&(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 _(s,t={},e=3){return s===void 0?e:typeof s=="number"?s:t[s]&&t[s].level!==void 0?t[s].level:e}l.prototype.add=l.prototype.addReporter,l.prototype.remove=l.prototype.removeReporter,l.prototype.clear=l.prototype.removeReporter,l.prototype.withScope=l.prototype.withTag,l.prototype.mock=l.prototype.mockTypes,l.prototype.pause=l.prototype.pauseLogs,l.prototype.resume=l.prototype.resumeLogs;function j(s={}){return new l(s)}class M{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),r=t.type==="log"?"":t.type,o=t.tag||"",n=`
|
|
5
|
+
background: ${this.typeColorMap[t.type]||this.levelColorMap[t.level]||this.defaultColor};
|
|
6
|
+
border-radius: 0.5em;
|
|
7
|
+
color: white;
|
|
8
|
+
font-weight: bold;
|
|
9
|
+
padding: 2px 0.5em;
|
|
10
|
+
`,p=`%c${[o,r].filter(Boolean).join(":")}`;typeof t.args[0]=="string"?e(`${p}%c ${t.args[0]}`,n,"",...t.args.slice(1)):e(p,n,...t.args)}}function P(s={}){return j({reporters:s.reporters||[new M({})],prompt(e,r={}){return r.type==="confirm"?Promise.resolve(confirm(e)):Promise.resolve(prompt(e))},...s})}const h=P(),z="0.3.2";function C(s){return{accept:"application/vnd.github.v3+json",authorization:`token ${s}`}}async function D(s,t,e){try{return await g(`https://api.github.com/repos/${t}/git/ref/tags/${s}`,{headers:C(e)}),!0}catch{return!1}}async function O(s,t){const e=C(s.github.token),r=s.github.repo;let o=`https://api.github.com/repos/${r}/releases`,i="POST";try{const c=await g(`https://api.github.com/repos/${r}/releases/tags/${s.to}`,{headers:e});c.url&&(o=c.url,i="PATCH")}catch{}const n={body:t,draft:!1,name:s.to,prerelease:s.prerelease,tag_name:s.to},p=`https://github.com/${r}/releases/new?title=${encodeURIComponent(String(n.name))}&body=${encodeURIComponent(String(n.body))}&tag=${encodeURIComponent(String(s.to))}&prerelease=${s.prerelease}`;try{h.log(v(i==="POST"?"Creating release notes...":"Updating release notes..."));const c=await g(o,{method:i,body:JSON.stringify(n),headers:e});h.log(T(`Released on ${c.html_url}`))}catch(c){throw h.error(b("Failed to create the release. Using the following link to create it manually:")),h.error(u(p)),c}}async function U(s,t){const{execa:e}=await import("execa");return(await e(s,t)).stdout.trim()}async function E(){return(await U("git",["rev-parse","--is-shallow-repository"])).trim()==="true"}function G(){const s=S("githublogen");s.version(z).option("-t, --token <path>","GitHub Token").help(),s.command("").action(async t=>{try{const e=process.cwd(),{options:r,commits:o,markdown:i}=await I({cwd:e,...t},!1);if(h.log(v(r.from)+f(" -> ")+$(r.to)+f(` (${o.length} commits)`)),await D(r.to,r.github.repo,r.github.token)||(h.error(u(`Current ref "${F(r.to)}" is not available as tags on GitHub. Release skipped.`)),process.exitCode&&(process.exitCode=1)),!o.length&&await E()){h.error(u("The repo seems to be clone shallowly, which make changelog failed to generate. You might want to specify `fetch-depth: 0` in your CI config.")),process.exitCode&&(process.exitCode=1);return}await O(r,i)}catch(e){h.error(b(String(e))),e?.stack&&h.error(f(e.stack?.split(`
|
|
11
|
+
`).slice(1).join(`
|
|
12
|
+
`))),process.exit(1)}}),s.parse()}G();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "githublogen",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Soybean",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"execa": "8.0.1",
|
|
36
36
|
"kolorist": "1.8.0",
|
|
37
37
|
"ofetch": "1.2.0",
|
|
38
|
-
"@soybeanjs/changelog": "0.3.
|
|
38
|
+
"@soybeanjs/changelog": "0.3.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@soybeanjs/cli": "0.6.7",
|
package/dist/cli.d.ts
DELETED