better-commits 1.16.0 → 1.16.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.
Files changed (3) hide show
  1. package/dist/index.js +13 -13
  2. package/package.json +1 -1
  3. package/src/index.ts +15 -14
package/dist/index.js CHANGED
@@ -1,30 +1,30 @@
1
1
  #! /usr/bin/env node
2
- import{a as S,c as A,e as g,g as y,h as k,j as T,k as O,l as R,m as v,n as P,o as G,p as j,r as N,s as D,t as I,u as $,v as W}from"./chunk-KYIWYSZF.js";import*as s from"@clack/prompts";import c from"picocolors";import{execSync as E}from"child_process";import{chdir as X}from"process";import{parse as F}from"valibot";import{execSync as L}from"child_process";import*as b from"@clack/prompts";import x from"picocolors";var M=["M","T","R","D","A","C"];function C(){let e="";try{e=L(`git ${g.git_args} status --porcelain`,{stdio:"pipe"}).toString()}catch(_){return b.log.error(x.red("Failed to git status"+_)),{index:[],work_tree:[]}}let i=e.split(`
3
- `),a=[],d=[];return i.forEach(_=>{let o=_.trimEnd();if(!o)return;let t=o.substring(2).trim(),r=o.charAt(0).trim(),n=o.charAt(1).trim();(r==="?"||n==="?")&&a.push(t),M.includes(r)&&d.push(t),M.includes(n)&&a.push(t)}),{index:d,work_tree:a}}function V(e){let i=e.join(" ");if(i)try{L(`git ${g.git_args} add ${i}`,{stdio:"pipe"}).toString(),b.log.success(x.green("Changes successfully staged"))}catch{b.log.error(x.red("Failed to stage changes"))}}H(N());async function H(e){let i=F(A,{});if(X(I()),e.check_status){let{index:t,work_tree:r}=C();s.log.step(c.black(c.bgGreen(" Checking Git Status ")));let n=t.reduce((u,h,l)=>c.green(u+h+$(t,l)),"");if(s.log.success(`Changes to be committed:
4
- `+n),r.length){let u=r.reduce((l,m,f)=>c.red(l+m+$(r,f)),"");s.log.error(`Changes not staged for commit:
5
- `+u);let h=await s.multiselect({message:`Some files have not been staged, would you like to add them now? ${y}`,options:[{value:".",label:"."},...r.map(l=>({value:l,label:l}))],required:!1});s.isCancel(h)&&process.exit(0),V(h)}C().index.length||(s.log.error(c.red('no changes added to commit (use "git add" and/or "git commit -a")')),process.exit(0))}let a=e.commit_type.options.reduce((t,r)=>({...t,[r.value]:{emoji:r.emoji??"",trailer:r.trailer??""}}),{});if(e.commit_type.enable){let t="Select a commit type",r=e.commit_type.initial_value;if(e.commit_type.infer_type_from_branch){let p=e.commit_type.options.map(h=>h.value),u=D(p);u&&(t=`Commit type inferred from branch ${c.dim("(confirm / edit)")}`,r=u)}let n=await s.select({message:t,initialValue:r,maxItems:e.commit_type.max_items,options:e.commit_type.options});s.isCancel(n)&&process.exit(0),i.trailer=a[n].trailer,i.type=e.commit_type.append_emoji_to_commit&&e.commit_type.emoji_commit_position==="Start"?`${a[n].emoji} ${n}`.trim():n}if(e.commit_scope.enable){let t=await s.select({message:"Select a commit scope",initialValue:e.commit_scope.initial_value,maxItems:e.commit_scope.max_items,options:e.commit_scope.options});s.isCancel(t)&&process.exit(0),t===S&&e.commit_scope.custom_scope&&(t=await s.text({message:"Write a custom scope",placeholder:""}),s.isCancel(t)&&process.exit(0)),i.scope=t}if(e.check_ticket.infer_ticket)try{let t=E(`git ${g.git_args} branch --show-current`,{stdio:"pipe"}).toString(),r=[t.match(R),t.match(v),t.match(T),t.match(P),t.match(O),t.match(G)].filter(n=>n!=null).map(n=>n&&n.length>=2?n[1]:"");r.length&&r[0]&&(i.ticket=e.check_ticket.append_hashtag||e.check_ticket.prepend_hashtag==="Prompt"?"#"+r[0]:r[0])}catch{}if(e.check_ticket.confirm_ticket){let t=await s.text({message:i.ticket?`Ticket / issue inferred from branch ${c.dim("(confirm / edit)")}`:`Add ticket / issue ${k}`,placeholder:"",initialValue:i.ticket});s.isCancel(t)&&process.exit(0),i.ticket=t??""}e.check_ticket.prepend_hashtag==="Always"&&i.ticket&&!i.ticket.startsWith("#")&&(i.ticket="#"+i.ticket);let d=await s.text({message:"Write a brief title describing the commit",placeholder:"",validate:t=>{if(!t)return"Please enter a title";let r=i.scope?i.scope.length+2:0,n=i.type.length,p=e.check_ticket.add_to_title?i.ticket.length:0;if(r+n+p+t.length>e.commit_title.max_size)return`Exceeded max length. Title max [${e.commit_title.max_size}]`}});s.isCancel(d)&&process.exit(0);let _=d;if(e.commit_type.append_emoji_to_commit&&e.commit_type.emoji_commit_position==="After-Colon"&&(_=`${a[i.type].emoji} ${d}`),i.title=W(_),e.commit_body.enable){let t=await s.text({message:`Write a detailed description of the changes ${k}`,placeholder:"",validate:r=>{if(e.commit_body.required&&!r)return"Please enter a description"}});s.isCancel(t)&&process.exit(0),i.body=t??""}if(e.commit_footer.enable){let t=await s.multiselect({message:`Select optional footers ${y}`,initialValues:e.commit_footer.initial_value,options:j,required:!1});if(s.isCancel(t)&&process.exit(0),t.includes("breaking-change")){let r=await s.text({message:"Breaking changes: Write a short title / summary",placeholder:"",validate:p=>{if(!p)return"Please enter a title / summary"}});s.isCancel(r)&&process.exit(0);let n=await s.text({message:`Breaking Changes: Write a description & migration instructions ${k}`,placeholder:""});s.isCancel(n)&&process.exit(0),i.breaking_title=r,i.breaking_body=n}if(t.includes("deprecated")){let r=await s.text({message:"Deprecated: Write a short title / summary",placeholder:"",validate:p=>{if(!p)return"Please enter a title / summary"}});s.isCancel(r)&&process.exit(0);let n=await s.text({message:`Deprecated: Write a description ${k}`,placeholder:""});s.isCancel(n)&&process.exit(0),i.deprecates_body=n,i.deprecates_title=r}if(t.includes("closes")&&(i.closes="Closes:"),t.includes("custom")){let r=await s.text({message:"Write a custom footer",placeholder:""});s.isCancel(r)&&process.exit(0),i.custom_footer=r}t.includes("trailer")||(i.trailer="")}if(e.confirm_with_editor){let t=e.overrides.shell?{shell:e.overrides.shell,stdio:"inherit"}:{stdio:"inherit"},r=i.trailer?`--trailer="${i.trailer}"`:"";E(`git ${g.git_args} commit -m "${w(i,e,!1,!0,!1)}" ${r} --edit`,t),process.exit(0)}let o=!0;s.note(w(i,e,!0,!1,!0),"Commit Preview"),e.confirm_commit&&(o=await s.confirm({message:"Confirm Commit?"}),s.isCancel(o)&&process.exit(0)),o||(s.log.info("Exiting without commit"),process.exit(0));try{let t=e.overrides.shell?{shell:e.overrides.shell}:{},r=i.trailer?`--trailer="${i.trailer}"`:"",n=E(`git ${g.git_args} commit -m "${w(i,e,!1,!0,!1)}" ${r}`,t).toString().trim();e.print_commit_output&&s.log.info(n)}catch(t){s.log.error("Something went wrong when committing: "+t)}}function w(e,i,a=!1,d=!1,_=!1){let o="";if(e.type&&(o+=a?c.blue(e.type):e.type),e.scope){let l=a?c.cyan(e.scope):e.scope;o+=`(${l})`}let t=e.ticket,r=i.check_ticket.surround;if(e.ticket&&r){let l=r.charAt(0),m=r.charAt(1);t=`${l}${e.ticket}${m}`}let n=i.check_ticket.title_position==="beginning";t&&i.check_ticket.add_to_title&&n&&(o=`${a?c.magenta(t):t} ${o}`);let p=i.check_ticket.title_position==="before-colon";if(t&&i.check_ticket.add_to_title&&p){let l=e.scope||e.type&&!i.check_ticket.surround?" ":"";o+=a?c.magenta(l+t):l+t}e.breaking_title&&i.breaking_change.add_exclamation_to_title&&(o+=a?c.red("!"):"!"),(e.scope||e.type||t&&p)&&(o+=": ");let u=i.check_ticket.title_position==="start",h=i.check_ticket.title_position==="end";if(t&&i.check_ticket.add_to_title&&u&&(o+=a?c.magenta(t)+" ":t+" "),e.title&&(o+=a?c.reset(e.title):e.title),t&&i.check_ticket.add_to_title&&h&&(o+=" "+(a?c.magenta(t):t)),e.body){let m=e.body.split("\\n").map(f=>a?c.reset(f.trim()):f.trim()).join(`
6
- `);o+=a?`
2
+ import{a as w,c as O,e as g,g as y,h as k,j as A,k as T,l as R,m as v,n as P,o as G,p as j,r as N,s as D,t as I,u as $,v as W}from"./chunk-KYIWYSZF.js";import*as s from"@clack/prompts";import c from"picocolors";import{execSync as S}from"child_process";import{chdir as X}from"process";import{parse as F}from"valibot";import{execSync as L}from"child_process";import*as b from"@clack/prompts";import x from"picocolors";var M=["M","T","R","D","A","C"];function C(){let e="";try{e=L(`git ${g.git_args} status --porcelain`,{stdio:"pipe"}).toString()}catch(_){return b.log.error(x.red("Failed to git status"+_)),{index:[],work_tree:[]}}let i=e.split(`
3
+ `),n=[],d=[];return i.forEach(_=>{let o=_.trimEnd();if(!o)return;let t=o.substring(2).trim(),r=o.charAt(0).trim(),a=o.charAt(1).trim();(r==="?"||a==="?")&&n.push(t),M.includes(r)&&d.push(t),M.includes(a)&&n.push(t)}),{index:d,work_tree:n}}function V(e){let i=e.join(" ");if(i)try{L(`git ${g.git_args} add ${i}`,{stdio:"pipe"}).toString(),b.log.success(x.green("Changes successfully staged"))}catch{b.log.error(x.red("Failed to stage changes"))}}H(N());async function H(e){let i=F(O,{});if(X(I()),e.check_status){let{index:t,work_tree:r}=C();s.log.step(c.black(c.bgGreen(" Checking Git Status ")));let a=t.reduce((u,h,l)=>c.green(u+h+$(t,l)),"");if(s.log.success(`Changes to be committed:
4
+ `+a),r.length){let u=r.reduce((l,m,f)=>c.red(l+m+$(r,f)),"");s.log.error(`Changes not staged for commit:
5
+ `+u);let h=await s.multiselect({message:`Some files have not been staged, would you like to add them now? ${y}`,options:[{value:".",label:"."},...r.map(l=>({value:l,label:l}))],required:!1});s.isCancel(h)&&process.exit(0),V(h)}C().index.length||(s.log.error(c.red('no changes added to commit (use "git add" and/or "git commit -a")')),process.exit(0))}let n=e.commit_type.options.reduce((t,r)=>({...t,[r.value]:{emoji:r.emoji??"",trailer:r.trailer??""}}),{});if(e.commit_type.enable){let t="Select a commit type",r=e.commit_type.initial_value;if(e.commit_type.infer_type_from_branch){let p=e.commit_type.options.map(h=>h.value),u=D(p);u&&(t=`Commit type inferred from branch ${c.dim("(confirm / edit)")}`,r=u)}let a=await s.select({message:t,initialValue:r,maxItems:e.commit_type.max_items,options:e.commit_type.options});s.isCancel(a)&&process.exit(0),i.trailer=n[a].trailer,i.type=e.commit_type.append_emoji_to_commit&&e.commit_type.emoji_commit_position==="Start"?`${n[a].emoji} ${a}`.trim():a}if(e.commit_scope.enable){let t=await s.select({message:"Select a commit scope",initialValue:e.commit_scope.initial_value,maxItems:e.commit_scope.max_items,options:e.commit_scope.options});s.isCancel(t)&&process.exit(0),t===w&&e.commit_scope.custom_scope&&(t=await s.text({message:"Write a custom scope",placeholder:""}),s.isCancel(t)&&process.exit(0)),i.scope=t}if(e.check_ticket.infer_ticket)try{let t=S(`git ${g.git_args} branch --show-current`,{stdio:"pipe"}).toString(),r=[t.match(R),t.match(v),t.match(A),t.match(P),t.match(T),t.match(G)].filter(a=>a!=null).map(a=>a&&a.length>=2?a[1]:"");r.length&&r[0]&&(i.ticket=e.check_ticket.append_hashtag||e.check_ticket.prepend_hashtag==="Prompt"?"#"+r[0]:r[0])}catch{}if(e.check_ticket.confirm_ticket){let t=await s.text({message:i.ticket?`Ticket / issue inferred from branch ${c.dim("(confirm / edit)")}`:`Add ticket / issue ${k}`,placeholder:"",initialValue:i.ticket});s.isCancel(t)&&process.exit(0),i.ticket=t??""}e.check_ticket.prepend_hashtag==="Always"&&i.ticket&&!i.ticket.startsWith("#")&&(i.ticket="#"+i.ticket);let d=await s.text({message:"Write a brief title describing the commit",placeholder:"",validate:t=>{if(!t)return"Please enter a title";let r=i.scope?i.scope.length+2:0,a=i.type.length,p=e.check_ticket.add_to_title?i.ticket.length:0;if(r+a+p+t.length>e.commit_title.max_size)return`Exceeded max length. Title max [${e.commit_title.max_size}]`}});s.isCancel(d)&&process.exit(0);let _=d;if(e.commit_type.append_emoji_to_commit&&e.commit_type.emoji_commit_position==="After-Colon"&&(_=`${n[i.type].emoji} ${d}`),i.title=W(_),e.commit_body.enable){let t=await s.text({message:`Write a detailed description of the changes ${k}`,placeholder:"",validate:r=>{if(e.commit_body.required&&!r)return"Please enter a description"}});s.isCancel(t)&&process.exit(0),i.body=t??""}if(e.commit_footer.enable){let t=await s.multiselect({message:`Select optional footers ${y}`,initialValues:e.commit_footer.initial_value,options:j,required:!1});if(s.isCancel(t)&&process.exit(0),t.includes("breaking-change")){let r=await s.text({message:"Breaking changes: Write a short title / summary",placeholder:"",validate:p=>{if(!p)return"Please enter a title / summary"}});s.isCancel(r)&&process.exit(0);let a=await s.text({message:`Breaking Changes: Write a description & migration instructions ${k}`,placeholder:""});s.isCancel(a)&&process.exit(0),i.breaking_title=r,i.breaking_body=a}if(t.includes("deprecated")){let r=await s.text({message:"Deprecated: Write a short title / summary",placeholder:"",validate:p=>{if(!p)return"Please enter a title / summary"}});s.isCancel(r)&&process.exit(0);let a=await s.text({message:`Deprecated: Write a description ${k}`,placeholder:""});s.isCancel(a)&&process.exit(0),i.deprecates_body=a,i.deprecates_title=r}if(t.includes("closes")&&(i.closes="Closes:"),t.includes("custom")){let r=await s.text({message:"Write a custom footer",placeholder:""});s.isCancel(r)&&process.exit(0),i.custom_footer=r}t.includes("trailer")||(i.trailer="")}if(e.confirm_with_editor){let t=e.overrides.shell?{shell:e.overrides.shell,stdio:"inherit"}:{stdio:"inherit"},r=i.trailer?`--trailer="${i.trailer}"`:"";S(`git ${g.git_args} commit -m "${E(i,e,!1,!0,!1)}" ${r} --edit`,t),process.exit(0)}let o=!0;e.print_commit_output&&s.note(E(i,e,!0,!1,!0),"Commit Preview"),e.confirm_commit&&(o=await s.confirm({message:"Confirm Commit?"}),s.isCancel(o)&&process.exit(0)),o||(s.log.info("Exiting without commit"),process.exit(0));try{s.log.info("Committing changes...");let t=e.overrides.shell?{shell:e.overrides.shell,stdio:"inherit"}:{stdio:"inherit"},r=i.trailer?`--trailer="${i.trailer}"`:"";S(`git ${g.git_args} commit -m "${E(i,e,!1,!0,!1)}" ${r}`,t)}catch(t){s.log.error("Something went wrong when committing: "+t)}s.log.success("Commit Complete")}function E(e,i,n=!1,d=!1,_=!1){let o="";if(e.type&&(o+=n?c.blue(e.type):e.type),e.scope){let l=n?c.cyan(e.scope):e.scope;o+=`(${l})`}let t=e.ticket,r=i.check_ticket.surround;if(e.ticket&&r){let l=r.charAt(0),m=r.charAt(1);t=`${l}${e.ticket}${m}`}let a=i.check_ticket.title_position==="beginning";t&&i.check_ticket.add_to_title&&a&&(o=`${n?c.magenta(t):t} ${o}`);let p=i.check_ticket.title_position==="before-colon";if(t&&i.check_ticket.add_to_title&&p){let l=e.scope||e.type&&!i.check_ticket.surround?" ":"";o+=n?c.magenta(l+t):l+t}e.breaking_title&&i.breaking_change.add_exclamation_to_title&&(o+=n?c.red("!"):"!"),(e.scope||e.type||t&&p)&&(o+=": ");let u=i.check_ticket.title_position==="start",h=i.check_ticket.title_position==="end";if(t&&i.check_ticket.add_to_title&&u&&(o+=n?c.magenta(t)+" ":t+" "),e.title&&(o+=n?c.reset(e.title):e.title),t&&i.check_ticket.add_to_title&&h&&(o+=" "+(n?c.magenta(t):t)),e.body){let m=e.body.split("\\n").map(f=>n?c.reset(f.trim()):f.trim()).join(`
6
+ `);o+=n?`
7
7
 
8
8
  ${m}`:`
9
9
 
10
- ${m}`}if(e.breaking_title){let l=a?c.red(`BREAKING CHANGE: ${e.breaking_title}`):`BREAKING CHANGE: ${e.breaking_title}`;o+=`
10
+ ${m}`}if(e.breaking_title){let l=n?c.red(`BREAKING CHANGE: ${e.breaking_title}`):`BREAKING CHANGE: ${e.breaking_title}`;o+=`
11
11
 
12
- ${l}`}if(e.breaking_body){let l=a?c.red(e.breaking_body):e.breaking_body;o+=`
12
+ ${l}`}if(e.breaking_body){let l=n?c.red(e.breaking_body):e.breaking_body;o+=`
13
13
 
14
- ${l}`}if(e.deprecates_title){let l=a?c.yellow(`DEPRECATED: ${e.deprecates_title}`):`DEPRECATED: ${e.deprecates_title}`;o+=`
14
+ ${l}`}if(e.deprecates_title){let l=n?c.yellow(`DEPRECATED: ${e.deprecates_title}`):`DEPRECATED: ${e.deprecates_title}`;o+=`
15
15
 
16
- ${l}`}if(e.deprecates_body){let l=a?c.yellow(e.deprecates_body):e.deprecates_body;o+=`
16
+ ${l}`}if(e.deprecates_body){let l=n?c.yellow(e.deprecates_body):e.deprecates_body;o+=`
17
17
 
18
- ${l}`}if(e.custom_footer){let m=e.custom_footer.split("\\n").map(f=>a?c.reset(f.trim()):f.trim()).join(`
19
- `);o+=a?`
18
+ ${l}`}if(e.custom_footer){let m=e.custom_footer.split("\\n").map(f=>n?c.reset(f.trim()):f.trim()).join(`
19
+ `);o+=n?`
20
20
 
21
21
  ${m}`:`
22
22
 
23
- ${m}`}return e.closes&&e.ticket&&(o+=a?`
23
+ ${m}`}return e.closes&&e.ticket&&(o+=n?`
24
24
 
25
25
  ${c.reset(e.closes)} ${c.magenta(e.ticket)}`:`
26
26
 
27
- ${e.closes} ${e.ticket}`),_&&e.trailer&&(o+=a?`
27
+ ${e.closes} ${e.ticket}`),_&&e.trailer&&(o+=n?`
28
28
 
29
29
  ${c.dim(e.trailer)}`:`
30
30
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "better-commits",
3
3
  "private": false,
4
- "version": "1.16.0",
4
+ "version": "1.16.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/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as p from "@clack/prompts";
4
4
  import color from "picocolors";
5
- import { execSync } from "child_process";
5
+ import { StdioOptions, execSync } from "child_process";
6
6
  import { chdir } from "process";
7
7
  import { Output, parse } from "valibot";
8
8
  import { CommitState, Config } from "./valibot-state";
@@ -285,8 +285,8 @@ export async function main(config: Output<typeof Config>) {
285
285
 
286
286
  if (config.confirm_with_editor) {
287
287
  const options = config.overrides.shell
288
- ? { shell: config.overrides.shell, stdio: "inherit" }
289
- : { stdio: "inherit" };
288
+ ? { shell: config.overrides.shell, stdio: "inherit" as StdioOptions }
289
+ : { stdio: "inherit" as StdioOptions };
290
290
  const trailer = commit_state.trailer
291
291
  ? `--trailer="${commit_state.trailer}"`
292
292
  : "";
@@ -298,10 +298,12 @@ export async function main(config: Output<typeof Config>) {
298
298
  }
299
299
 
300
300
  let continue_commit = true;
301
- p.note(
302
- build_commit_string(commit_state, config, true, false, true),
303
- "Commit Preview",
304
- );
301
+ if (config.print_commit_output) {
302
+ p.note(
303
+ build_commit_string(commit_state, config, true, false, true),
304
+ "Commit Preview",
305
+ );
306
+ }
305
307
  if (config.confirm_commit) {
306
308
  continue_commit = (await p.confirm({
307
309
  message: "Confirm Commit?",
@@ -315,22 +317,21 @@ export async function main(config: Output<typeof Config>) {
315
317
  }
316
318
 
317
319
  try {
320
+ p.log.info("Committing changes...");
318
321
  const options = config.overrides.shell
319
- ? { shell: config.overrides.shell }
320
- : {};
322
+ ? { shell: config.overrides.shell, stdio: "inherit" as StdioOptions }
323
+ : { stdio: "inherit" as StdioOptions };
321
324
  const trailer = commit_state.trailer
322
325
  ? `--trailer="${commit_state.trailer}"`
323
326
  : "";
324
- const output = execSync(
327
+ execSync(
325
328
  `git ${flags.git_args} commit -m "${build_commit_string(commit_state, config, false, true, false)}" ${trailer}`,
326
329
  options,
327
- )
328
- .toString()
329
- .trim();
330
- if (config.print_commit_output) p.log.info(output);
330
+ );
331
331
  } catch (err) {
332
332
  p.log.error("Something went wrong when committing: " + err);
333
333
  }
334
+ p.log.success("Commit Complete");
334
335
  }
335
336
 
336
337
  function build_commit_string(