better-commits 1.18.0 → 1.18.1
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.js +12 -12
- package/package.json +1 -1
- package/readme.md +0 -2
- package/src/index.ts +4 -0
package/dist/index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import{a as A,c as T,e as g,g as x,h as b,j as R,k as v,l as P,m as j,n as G,o as N,p as D,r as I,s as W,t as M,u as V,v as C,w as H,x as k,y}from"./chunk-ELYOZGPM.js";import*as s from"@clack/prompts";import
|
|
3
|
-
`),o=[],
|
|
4
|
-
`+n),r.length){let
|
|
5
|
-
`+
|
|
2
|
+
import{a as A,c as T,e as g,g as x,h as b,j as R,k as v,l as P,m as j,n as G,o as N,p as D,r as I,s as W,t as M,u as V,v as C,w as H,x as k,y}from"./chunk-ELYOZGPM.js";import*as s from"@clack/prompts";import l from"picocolors";import{execSync as w}from"child_process";import{chdir as q}from"process";import{parse as K}from"valibot";import{execSync as X}from"child_process";import*as $ from"@clack/prompts";import E from"picocolors";var L=["M","T","R","D","A","C"];function S(){let e="";try{e=X(`git ${g.git_args} status --porcelain`,{stdio:"pipe"}).toString()}catch(u){return $.log.error(E.red("Failed to git status"+u)),{index:[],work_tree:[]}}let t=e.split(`
|
|
3
|
+
`),o=[],f=[];return t.forEach(u=>{let a=u.trimEnd();if(!a)return;let p=a.substring(2).trim(),h=a.charAt(0).trim(),i=a.charAt(1).trim();(h==="?"||i==="?")&&o.push(p),L.includes(h)&&f.push(p),L.includes(i)&&o.push(p)}),{index:f,work_tree:o}}function F(e){let t=e.join(" ");if(t)try{X(`git ${g.git_args} add ${t}`,{stdio:"pipe"}).toString(),$.log.success(E.green("Changes successfully staged"))}catch{$.log.error(E.red("Failed to stage changes"))}}import Y from"configstore";J(W());async function J(e){let t=K(T,{});q(V());let o=e.cache_last_value?new Y("better-commits"):I;if(e.check_status){let{index:i,work_tree:r}=S();s.log.step(l.black(l.bgGreen(" Checking Git Status ")));let n=i.reduce((c,m,d)=>l.green(c+m+C(i,d)),"");if(s.log.success(`Changes to be committed:
|
|
4
|
+
`+n),r.length){let c=r.reduce((d,U,B)=>l.red(d+U+C(r,B)),"");s.log.error(`Changes not staged for commit:
|
|
5
|
+
`+c);let m=await s.multiselect({message:`Some files have not been staged, would you like to add them now? ${x}`,options:[{value:".",label:"."},...r.map(d=>({value:d,label:d}))],required:!1});s.isCancel(m)&&process.exit(0),F(m)}S().index.length||(s.log.error(l.red('no changes added to commit (use "git add" and/or "git commit -a")')),process.exit(0))}let f=e.commit_type.options.reduce((i,r)=>({...i,[r.value]:{emoji:r.emoji??"",trailer:r.trailer??""}}),{});if(e.commit_type.enable){let i="Select a commit type",r=e.commit_type.initial_value;if(e.commit_type.infer_type_from_branch){let _=e.commit_type.options.map(m=>m.value),c=M(_);c&&(i=`Commit type inferred from branch ${l.dim("(confirm / edit)")}`,r=c)}let n=await s.select({message:i,initialValue:k(o,"commit_type")||r,maxItems:e.commit_type.max_items,options:e.commit_type.options});s.isCancel(n)&&process.exit(0),y(o,"commit_type",n),t.trailer=f[n].trailer,t.type=e.commit_type.append_emoji_to_commit&&e.commit_type.emoji_commit_position==="Start"?`${f[n].emoji} ${n}`.trim():n}if(e.commit_scope.enable){let i=await s.select({message:"Select a commit scope",initialValue:k(o,"commit_scope")||e.commit_scope.initial_value,maxItems:e.commit_scope.max_items,options:e.commit_scope.options});s.isCancel(i)&&process.exit(0),y(o,"commit_scope",i),i===A&&e.commit_scope.custom_scope&&(i=await s.text({message:"Write a custom scope",placeholder:""}),s.isCancel(i)&&process.exit(0)),t.scope=i}if(e.check_ticket.infer_ticket)try{let i=w(`git ${g.git_args} branch --show-current`,{stdio:"pipe"}).toString(),r=[i.match(P),i.match(j),i.match(R),i.match(G),i.match(v),i.match(N)].filter(n=>n!=null).map(n=>n&&n.length>=2?n[1]:"");r.length&&r[0]&&(t.ticket=e.check_ticket.append_hashtag||e.check_ticket.prepend_hashtag==="Prompt"?"#"+r[0]:r[0])}catch{}if(e.check_ticket.confirm_ticket){let i=await s.text({message:t.ticket?`Ticket / issue inferred from branch ${l.dim("(confirm / edit)")}`:`Add ticket / issue ${b}`,placeholder:"",initialValue:k(o,"commit_ticket")||t.ticket});s.isCancel(i)&&process.exit(0),y(o,"commit_ticket",i),t.ticket=i??""}e.check_ticket.prepend_hashtag==="Always"&&t.ticket&&!t.ticket.startsWith("#")&&(t.ticket="#"+t.ticket);let u=await s.text({message:"Write a brief title describing the commit",initialValue:k(o,"commit_title")||"",placeholder:"",validate:i=>{if(!i)return"Please enter a title";let r=t.scope?t.scope.length+2:0,n=t.type.length,_=e.check_ticket.add_to_title?t.ticket.length:0;if(r+n+_+i.length>e.commit_title.max_size)return`Exceeded max length. Title max [${e.commit_title.max_size}]`}});s.isCancel(u)&&process.exit(0),y(o,"commit_title",u);let a=u;if(e.commit_type.append_emoji_to_commit&&e.commit_type.emoji_commit_position==="After-Colon"&&(a=`${f[t.type].emoji} ${u}`),t.title=H(a),e.commit_body.enable){let i=await s.text({message:`Write a detailed description of the changes ${b}`,initialValue:k(o,"commit_body")||"",placeholder:"",validate:r=>{if(e.commit_body.required&&!r)return"Please enter a description"}});s.isCancel(i)&&process.exit(0),y(o,"commit_body",i),t.body=i??""}if(e.commit_footer.enable){let i=k(o,"commit_footer").split(","),r=await s.multiselect({message:`Select optional footers ${x}`,initialValues:i||e.commit_footer.initial_value,options:D,required:!1});if(s.isCancel(r)&&process.exit(0),y(o,"commit_footer",r.join(",")),r.includes("breaking-change")){let n=await s.text({message:"Breaking changes: Write a short title / summary",placeholder:"",validate:c=>{if(!c)return"Please enter a title / summary"}});s.isCancel(n)&&process.exit(0);let _=await s.text({message:`Breaking Changes: Write a description & migration instructions ${b}`,placeholder:""});s.isCancel(_)&&process.exit(0),t.breaking_title=n,t.breaking_body=_}if(r.includes("deprecated")){let n=await s.text({message:"Deprecated: Write a short title / summary",placeholder:"",validate:c=>{if(!c)return"Please enter a title / summary"}});s.isCancel(n)&&process.exit(0);let _=await s.text({message:`Deprecated: Write a description ${b}`,placeholder:""});s.isCancel(_)&&process.exit(0),t.deprecates_body=_,t.deprecates_title=n}if(r.includes("closes")&&(t.closes="Closes:"),r.includes("custom")){let n=await s.text({message:"Write a custom footer",placeholder:""});s.isCancel(n)&&process.exit(0),t.custom_footer=n}r.includes("trailer")||(t.trailer="")}if(e.confirm_with_editor){let i=e.overrides.shell?{shell:e.overrides.shell,stdio:"inherit"}:{stdio:"inherit"},r=t.trailer?`--trailer="${t.trailer}"`:"";w(`git ${g.git_args} commit -m "${O(t,e,!1,!0,!1)}" ${r} --edit`,i),process.exit(0)}let p=!0;e.print_commit_output&&s.note(O(t,e,!0,!1,!0),"Commit Preview"),e.confirm_commit&&(p=await s.confirm({message:"Confirm Commit?"}),s.isCancel(p)&&process.exit(0)),p||(s.log.info("Exiting without commit"),process.exit(0));try{s.log.info("Committing changes...");let i=e.overrides.shell?{shell:e.overrides.shell,stdio:"inherit"}:{stdio:"inherit"},r=t.trailer?`--trailer="${t.trailer}"`:"";w(`git ${g.git_args} commit -m "${O(t,e,!1,!0,!1)}" ${r}`,i)}catch(i){s.log.error("Something went wrong when committing: "+i)}s.log.success("Commit Complete");let h=o.get("username");o.clear(),h&&o.set("username",h)}function O(e,t,o=!1,f=!1,u=!1){let a="";if(e.type&&(a+=o?l.blue(e.type):e.type),e.scope){let c=o?l.cyan(e.scope):e.scope;a+=`(${c})`}let p=e.ticket,h=t.check_ticket.surround;if(e.ticket&&h){let c=h.charAt(0),m=h.charAt(1);p=`${c}${e.ticket}${m}`}let i=t.check_ticket.title_position==="beginning";p&&t.check_ticket.add_to_title&&i&&(a=`${o?l.magenta(p):p} ${a}`);let r=t.check_ticket.title_position==="before-colon";if(p&&t.check_ticket.add_to_title&&r){let c=e.scope||e.type&&!t.check_ticket.surround?" ":"";a+=o?l.magenta(c+p):c+p}e.breaking_title&&t.breaking_change.add_exclamation_to_title&&(a+=o?l.red("!"):"!"),(e.scope||e.type||p&&r)&&(a+=": ");let n=t.check_ticket.title_position==="start",_=t.check_ticket.title_position==="end";if(p&&t.check_ticket.add_to_title&&n&&(a+=o?l.magenta(p)+" ":p+" "),e.title&&(a+=o?l.reset(e.title):e.title),p&&t.check_ticket.add_to_title&&_&&(a+=" "+(o?l.magenta(p):p)),e.body){let m=e.body.split("\\n").map(d=>o?l.reset(d.trim()):d.trim()).join(`
|
|
6
6
|
`);a+=o?`
|
|
7
7
|
|
|
8
8
|
${m}`:`
|
|
9
9
|
|
|
10
|
-
${m}`}if(e.breaking_title){let
|
|
10
|
+
${m}`}if(e.breaking_title){let c=o?l.red(`BREAKING CHANGE: ${e.breaking_title}`):`BREAKING CHANGE: ${e.breaking_title}`;a+=`
|
|
11
11
|
|
|
12
|
-
${
|
|
12
|
+
${c}`}if(e.breaking_body){let c=o?l.red(e.breaking_body):e.breaking_body;a+=`
|
|
13
13
|
|
|
14
|
-
${
|
|
14
|
+
${c}`}if(e.deprecates_title){let c=o?l.yellow(`DEPRECATED: ${e.deprecates_title}`):`DEPRECATED: ${e.deprecates_title}`;a+=`
|
|
15
15
|
|
|
16
|
-
${
|
|
16
|
+
${c}`}if(e.deprecates_body){let c=o?l.yellow(e.deprecates_body):e.deprecates_body;a+=`
|
|
17
17
|
|
|
18
|
-
${
|
|
18
|
+
${c}`}if(e.custom_footer){let m=e.custom_footer.split("\\n").map(d=>o?l.reset(d.trim()):d.trim()).join(`
|
|
19
19
|
`);a+=o?`
|
|
20
20
|
|
|
21
21
|
${m}`:`
|
|
22
22
|
|
|
23
23
|
${m}`}return e.closes&&e.ticket&&(a+=o?`
|
|
24
24
|
|
|
25
|
-
${
|
|
25
|
+
${l.reset(e.closes)} ${l.magenta(e.ticket)}`:`
|
|
26
26
|
|
|
27
27
|
${e.closes} ${e.ticket}`),u&&e.trailer&&(a+=o?`
|
|
28
28
|
|
|
29
|
-
${
|
|
29
|
+
${l.dim(e.trailer)}`:`
|
|
30
30
|
|
|
31
|
-
${e.trailer}`),
|
|
31
|
+
${e.trailer}`),f&&(a=a.replaceAll('"','\\"').replaceAll("`","\\`")),a}export{J as main};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-commits",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.18.
|
|
4
|
+
"version": "1.18.1",
|
|
5
5
|
"description": "A CLI for creating better commits following the conventional commits specification",
|
|
6
6
|
"author": "Erik Verduin (https://github.com/everduin94)",
|
|
7
7
|
"type": "module",
|
package/readme.md
CHANGED
|
@@ -72,8 +72,6 @@ To create a **repository-specific config**, navigate to the root of your project
|
|
|
72
72
|
|
|
73
73
|
### Options
|
|
74
74
|
|
|
75
|
-
Better-commits (& better-branch) are highly flexible with sane defaults. These options allow you specify whats best for your workflow.
|
|
76
|
-
|
|
77
75
|
> [!NOTE]<br>
|
|
78
76
|
> All properties are optional and can be removed from the config. It will be replaced by the default at run-time.
|
|
79
77
|
>
|
package/src/index.ts
CHANGED
|
@@ -358,7 +358,11 @@ export async function main(config: Output<typeof Config>) {
|
|
|
358
358
|
p.log.error("Something went wrong when committing: " + err);
|
|
359
359
|
}
|
|
360
360
|
p.log.success("Commit Complete");
|
|
361
|
+
|
|
362
|
+
// Instead of deleting individual keys, just get what we need and clear.
|
|
363
|
+
const user_name = prompt_cache.get("username");
|
|
361
364
|
prompt_cache.clear();
|
|
365
|
+
if (user_name) prompt_cache.set("username", user_name);
|
|
362
366
|
}
|
|
363
367
|
|
|
364
368
|
function build_commit_string(
|