better-commits 1.18.1 → 1.19.0

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.
@@ -3,13 +3,16 @@
3
3
  "append_emoji_to_label": true,
4
4
  "append_emoji_to_commit": false
5
5
  },
6
+ "commit_body": {
7
+ "split_by_period": true
8
+ },
6
9
  "commit_scope": {
7
10
  "enable": true,
8
- "initial_value": "main",
11
+ "initial_value": "commit",
9
12
  "options": [
10
13
  {
11
- "value": "main",
12
- "label": "main"
14
+ "value": "commit",
15
+ "label": "commit"
13
16
  },
14
17
  {
15
18
  "value": "branch",
@@ -9,15 +9,21 @@ jobs:
9
9
  publish:
10
10
  name: Publish
11
11
  runs-on: ubuntu-latest
12
+ permissions:
13
+ contents: write
14
+ issues: write
15
+ pull-requests: write
16
+ id-token: write
12
17
  steps:
13
18
  - name: Checkout
14
- uses: actions/checkout@v3
19
+ uses: actions/checkout@v4
15
20
  with:
16
21
  fetch-depth: 0
17
22
  - name: Setup Node.js
18
- uses: actions/setup-node@v3
23
+ uses: actions/setup-node@v4
19
24
  with:
20
25
  node-version: "lts/*"
26
+ registry-url: "https://registry.npmjs.org"
21
27
  - name: Install dependencies
22
28
  run: npm ci
23
29
  - name: Build package
@@ -25,5 +31,4 @@ jobs:
25
31
  - name: Release
26
32
  env:
27
33
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
29
34
  run: npx semantic-release
package/dist/branch.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #! /usr/bin/env node
2
- import{d as f,e as g,h as _,i as b,q as w,s as y,u as h}from"./chunk-ELYOZGPM.js";import*as r from"@clack/prompts";import{execSync as l}from"child_process";import C from"configstore";import s from"picocolors";import{chdir as k}from"process";import{parse as $}from"valibot";O(y(" better-branch "));async function O(e){let o=$(f,{});k(h());let a="branch";if(e.worktrees.enable){let t=await r.select({message:"Checkout a branch or create a worktree?",initialValue:e.branch_action_default,options:w});r.isCancel(t)&&process.exit(),a=t}if(e.branch_user.enable){let t=N(),n=e.branch_user.required,p=await r.text({message:`Type your git username ${n?"":_} ${b}`.trim(),placeholder:"",initialValue:t,validate:x=>{if(n&&!x)return"Please enter a username"}});r.isCancel(p)&&process.exit(0),o.user=p?.replace(/\s+/g,"-")?.toLowerCase()??"",T(o.user)}if(e.branch_type.enable){let t=e.commit_type.initial_value,n=await r.select({message:"Select a branch type",initialValue:t,options:e.commit_type.options});r.isCancel(n)&&process.exit(0),o.type=n}if(e.branch_ticket.enable){let t=e.branch_ticket.required,n=await r.text({message:`Type ticket / issue number ${t?"":_}`.trim(),placeholder:"",validate:p=>{if(t&&!p)return"Please enter a ticket / issue"}});r.isCancel(n)&&process.exit(0),o.ticket=n}if(e.branch_version.enable){let t=e.branch_version.required,n=await r.text({message:`Type version number ${t?"":_}`.trim(),placeholder:"",validate:p=>{if(t&&!p)return"Please enter a version"}});r.isCancel(n)&&process.exit(0),o.version=n}let c=e.branch_description.max_length,i=await r.text({message:"Type a short description",placeholder:"",validate:t=>{if(!t)return"Please enter a description";if(t.length>c)return`Exceeded max length. Description max [${c}]`}});r.isCancel(i)&&process.exit(0),o.description=i?.replace(/\s+/g,"-")?.toLowerCase()??"",(a==="worktree"?e.worktree_pre_commands:e.branch_pre_commands).forEach(t=>{try{l(t,{stdio:"inherit"})}catch(n){r.log.error("Something went wrong when executing pre-commands: "+n),process.exit(0)}});let m=v(o,e),d=A(m);if(a==="branch")try{l(`git ${g.git_args} checkout ${d} ${m}`,{stdio:"inherit"}),r.log.info(`Switched to a new branch '${s.bgGreen(" "+s.black(m)+" ")}'`)}catch{process.exit(0)}else try{let t=S(o,e);l(`git worktree add ${t} ${d} ${m}`,{stdio:"inherit"}),r.log.info(`Created a new worktree ${s.bgGreen(+" "+s.black(t)+" ")}, checked out branch ${s.bgGreen(" "+s.black(m)+" ")}`),r.log.info(s.bgMagenta(s.black(` cd ${t} `))+" to navigate to your new worktree"),k(t)}catch{process.exit(0)}(a==="worktree"?e.worktree_post_commands:e.branch_post_commands).forEach(t=>{try{l(t,{stdio:"inherit"})}catch(n){r.log.error("Something went wrong when executing post-commands: "+n),process.exit(0)}})}function v(e,o){let a="";return o.branch_order.forEach(c=>{let i=`branch_${c}`;e[c]&&(a+=e[c]+o[i].separator)}),a.endsWith("-")||a.endsWith("/")||a.endsWith("_")?a.slice(0,-1).trim():a.trim()}function S(e,o){let c=h().split("/").pop()||"repo",i=o.worktrees.folder_template;i=i.replace("{{repo_name}}",c).replace("{{branch_description}}",e.description).replace("{{user}}",e.user||"").replace("{{type}}",e.type||"").replace("{{ticket}}",e.ticket||"").replace("{{version}}",e.version||""),i=i.replace(/\s/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"");let u=o.worktrees.base_path;return`${u}${u.endsWith("/")?"":"/"}${i}`}function N(){try{return new C("better-commits").get("username")??""}catch{r.log.warn('There was an issue accessing username from cache. Check that the folder "~/.config" exists')}return""}function A(e){let o="";try{l(`git show-ref ${e}`,{encoding:"utf-8"}),r.log.warning(s.yellow(`${e} already exists! Checking out existing branch.`))}catch{o="-b"}return o}function T(e){try{new C("better-commits").set("username",e)}catch{}}
2
+ import{d as f,e as g,h as _,i as b,q as w,s as y,u as h}from"./chunk-K2RPF2JY.js";import*as r from"@clack/prompts";import{execSync as l}from"child_process";import C from"configstore";import s from"picocolors";import{chdir as k}from"process";import{parse as $}from"valibot";O(y(" better-branch "));async function O(e){let o=$(f,{});k(h());let a="branch";if(e.worktrees.enable){let t=await r.select({message:"Checkout a branch or create a worktree?",initialValue:e.branch_action_default,options:w});r.isCancel(t)&&process.exit(),a=t}if(e.branch_user.enable){let t=N(),n=e.branch_user.required,p=await r.text({message:`Type your git username ${n?"":_} ${b}`.trim(),placeholder:"",initialValue:t,validate:x=>{if(n&&!x)return"Please enter a username"}});r.isCancel(p)&&process.exit(0),o.user=p?.replace(/\s+/g,"-")?.toLowerCase()??"",T(o.user)}if(e.branch_type.enable){let t=e.commit_type.initial_value,n=await r.select({message:"Select a branch type",initialValue:t,options:e.commit_type.options});r.isCancel(n)&&process.exit(0),o.type=n}if(e.branch_ticket.enable){let t=e.branch_ticket.required,n=await r.text({message:`Type ticket / issue number ${t?"":_}`.trim(),placeholder:"",validate:p=>{if(t&&!p)return"Please enter a ticket / issue"}});r.isCancel(n)&&process.exit(0),o.ticket=n}if(e.branch_version.enable){let t=e.branch_version.required,n=await r.text({message:`Type version number ${t?"":_}`.trim(),placeholder:"",validate:p=>{if(t&&!p)return"Please enter a version"}});r.isCancel(n)&&process.exit(0),o.version=n}let c=e.branch_description.max_length,i=await r.text({message:"Type a short description",placeholder:"",validate:t=>{if(!t)return"Please enter a description";if(t.length>c)return`Exceeded max length. Description max [${c}]`}});r.isCancel(i)&&process.exit(0),o.description=i?.replace(/\s+/g,"-")?.toLowerCase()??"",(a==="worktree"?e.worktree_pre_commands:e.branch_pre_commands).forEach(t=>{try{l(t,{stdio:"inherit"})}catch(n){r.log.error("Something went wrong when executing pre-commands: "+n),process.exit(0)}});let m=v(o,e),d=A(m);if(a==="branch")try{l(`git ${g.git_args} checkout ${d} ${m}`,{stdio:"inherit"}),r.log.info(`Switched to a new branch '${s.bgGreen(" "+s.black(m)+" ")}'`)}catch{process.exit(0)}else try{let t=S(o,e);l(`git worktree add ${t} ${d} ${m}`,{stdio:"inherit"}),r.log.info(`Created a new worktree ${s.bgGreen(+" "+s.black(t)+" ")}, checked out branch ${s.bgGreen(" "+s.black(m)+" ")}`),r.log.info(s.bgMagenta(s.black(` cd ${t} `))+" to navigate to your new worktree"),k(t)}catch{process.exit(0)}(a==="worktree"?e.worktree_post_commands:e.branch_post_commands).forEach(t=>{try{l(t,{stdio:"inherit"})}catch(n){r.log.error("Something went wrong when executing post-commands: "+n),process.exit(0)}})}function v(e,o){let a="";return o.branch_order.forEach(c=>{let i=`branch_${c}`;e[c]&&(a+=e[c]+o[i].separator)}),a.endsWith("-")||a.endsWith("/")||a.endsWith("_")?a.slice(0,-1).trim():a.trim()}function S(e,o){let c=h().split("/").pop()||"repo",i=o.worktrees.folder_template;i=i.replace("{{repo_name}}",c).replace("{{branch_description}}",e.description).replace("{{user}}",e.user||"").replace("{{type}}",e.type||"").replace("{{ticket}}",e.ticket||"").replace("{{version}}",e.version||""),i=i.replace(/\s/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"");let u=o.worktrees.base_path;return`${u}${u.endsWith("/")?"":"/"}${i}`}function N(){try{return new C("better-commits").get("username")??""}catch{r.log.warn('There was an issue accessing username from cache. Check that the folder "~/.config" exists')}return""}function A(e){let o="";try{l(`git show-ref ${e}`,{encoding:"utf-8"}),r.log.warning(s.yellow(`${e} already exists! Checking out existing branch.`))}catch{o="-b"}return o}function T(e){try{new C("better-commits").set("username",e)}catch{}}
@@ -1,4 +1,4 @@
1
- import*as p from"valibot";var c="custom",f=["closes","trailer","breaking-change","deprecated","custom"],h=p.picklist(["branch","worktree"]),g=p.picklist(["closes","trailer","breaking-change","deprecated","custom"]),d=p.picklist(["user","version","type","ticket","description"]),$=p.picklist(["branch_user","branch_version","branch_type","branch_ticket","branch_description"]),O=["user","version","type","ticket","description"],x=[{value:"app",label:"app"},{value:"shared",label:"shared"},{value:"server",label:"server"},{value:"tools",label:"tools"},{value:"",label:"none"}],C=[{value:"feat",label:"feat",hint:"A new feature",emoji:"\u{1F31F}",trailer:"Changelog: feature"},{value:"fix",label:"fix",hint:"A bug fix",emoji:"\u{1F41B}",trailer:"Changelog: fix"},{value:"docs",label:"docs",hint:"Documentation only changes",emoji:"\u{1F4DA}",trailer:"Changelog: documentation"},{value:"refactor",label:"refactor",hint:"A code change that neither fixes a bug nor adds a feature",emoji:"\u{1F528}",trailer:"Changelog: refactor"},{value:"perf",label:"perf",hint:"A code change that improves performance",emoji:"\u{1F680}",trailer:"Changelog: performance"},{value:"test",label:"test",hint:"Adding missing tests or correcting existing tests",emoji:"\u{1F6A8}",trailer:"Changelog: test"},{value:"build",label:"build",hint:"Changes that affect the build system or external dependencies",emoji:"\u{1F6A7}",trailer:"Changelog: build"},{value:"ci",label:"ci",hint:"Changes to our CI configuration files and scripts",emoji:"\u{1F916}",trailer:"Changelog: ci"},{value:"chore",label:"chore",hint:"Other changes that do not modify src or test files",emoji:"\u{1F9F9}",trailer:"Changelog: chore"},{value:"",label:"none"}];import*as t from"valibot";var m=t.object({check_status:t.optional(t.boolean(),!0),commit_type:t.transform(t.optional(t.object({enable:t.optional(t.boolean(),!0),initial_value:t.optional(t.string(),"feat"),max_items:t.optional(t.number([t.minValue(1)]),20),infer_type_from_branch:t.optional(t.boolean(),!0),append_emoji_to_label:t.optional(t.boolean(),!1),append_emoji_to_commit:t.optional(t.boolean(),!1),emoji_commit_position:t.optional(t.picklist(["Start","After-Colon"]),"Start"),options:t.optional(t.array(t.object({value:t.string(),label:t.optional(t.string()),hint:t.optional(t.string()),emoji:t.optional(t.string([t.emoji()]),void 0),trailer:t.optional(t.string())})),C)},[t.custom(e=>e.options.map(o=>o.value).includes(e.initial_value),e=>`Type: initial_value "${e.input.initial_value}" must exist in options`)]),{}),e=>{let o=e.options.map(n=>({...n,label:n.emoji&&e.append_emoji_to_label?`${n.emoji} ${n.label}`:n.label}))??[];return{...e,options:o}}),commit_scope:t.transform(t.optional(t.object({enable:t.optional(t.boolean(),!0),custom_scope:t.optional(t.boolean(),!1),max_items:t.optional(t.number([t.minValue(1)]),20),initial_value:t.optional(t.string(),"app"),options:t.optional(t.array(t.object({value:t.string(),label:t.optional(t.string()),hint:t.optional(t.string())})),x)},[t.custom(e=>{let o=e.options.map(n=>n.value);return e.custom_scope&&o.push(c),o.includes(e.initial_value)},e=>`Scope: initial_value "${e.input.initial_value}" must exist in options`)]),{}),e=>{let o=e.options.map(n=>n.value);return e.custom_scope&&!o.includes(c)?{...e,options:[...e.options,{label:c,value:c,hint:"Write a custom scope"}]}:e}),check_ticket:t.optional(t.object({infer_ticket:t.optional(t.boolean(),!0),confirm_ticket:t.optional(t.boolean(),!0),add_to_title:t.optional(t.boolean(),!0),append_hashtag:t.optional(t.boolean(),!1),prepend_hashtag:t.optional(t.picklist(["Never","Always","Prompt"]),"Never"),surround:t.optional(t.picklist(["","()","[]","{}"]),""),title_position:t.optional(t.picklist(["start","end","before-colon","beginning"]),"start")}),{}),commit_title:t.optional(t.object({max_size:t.optional(t.number([t.minValue(1)]),70)}),{}),commit_body:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1)}),{}),commit_footer:t.optional(t.object({enable:t.optional(t.boolean(),!0),initial_value:t.optional(t.array(g),[]),options:t.optional(t.array(g),f)}),{}),breaking_change:t.optional(t.object({add_exclamation_to_title:t.optional(t.boolean(),!1)}),{}),cache_last_value:t.optional(t.boolean(),!0),confirm_with_editor:t.optional(t.boolean(),!1),confirm_commit:t.optional(t.boolean(),!0),print_commit_output:t.optional(t.boolean(),!0),branch_pre_commands:t.optional(t.array(t.string()),[]),branch_post_commands:t.optional(t.array(t.string()),[]),worktree_pre_commands:t.optional(t.array(t.string()),[]),worktree_post_commands:t.optional(t.array(t.string()),[]),branch_user:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_type:t.optional(t.object({enable:t.optional(t.boolean(),!0),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_version:t.optional(t.object({enable:t.optional(t.boolean(),!1),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_ticket:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"-")}),{}),branch_description:t.optional(t.object({max_length:t.optional(t.number([t.minValue(1)]),70),separator:t.optional(t.picklist(["","/","-","_"]),"")}),{}),branch_action_default:t.optional(h,"branch"),branch_order:t.optional(t.array(d),O),enable_worktrees:t.optional(t.boolean(),!0),worktrees:t.optional(t.object({enable:t.optional(t.boolean(),!0),base_path:t.optional(t.string(),".."),folder_template:t.optional(t.string(),"{{repo_name}}-{{ticket}}-{{branch_description}}")}),{}),overrides:t.optional(t.object({shell:t.optional(t.string())}),{})}),H=t.optional(t.object({type:t.optional(t.string(),""),scope:t.optional(t.string(),""),title:t.optional(t.string(),""),body:t.optional(t.string(),""),closes:t.optional(t.string(),""),ticket:t.optional(t.string(),""),breaking_title:t.optional(t.string(),""),breaking_body:t.optional(t.string(),""),deprecates:t.optional(t.string(),""),deprecates_title:t.optional(t.string(),""),deprecates_body:t.optional(t.string(),""),custom_footer:t.optional(t.string(),""),trailer:t.optional(t.string(),"")}),{}),D=t.optional(t.object({user:t.optional(t.string(),""),type:t.optional(t.string(),""),ticket:t.optional(t.string(),""),description:t.optional(t.string(),""),version:t.optional(t.string(),"")}),{});var b=class{#t="";constructor(){}get git_args(){return this.#t}set git_args(o){this.#t=o}},_=new b;import*as i from"@clack/prompts";import{execSync as S}from"child_process";import u from"fs";import{homedir as R}from"os";import a from"picocolors";import{ValiError as N,parse as y}from"valibot";import{argv as E}from"process";var T=".better-commits.json",K=`${a.dim("(<space> to select)")}`,Q=`${a.dim("(<space> to select, <a> to select all)")}`,tt=`${a.dim("(optional)")}`,ot=`${a.dim("(value will be saved)")}`,et=new RegExp(/\/(\w+-\d+)/),nt=new RegExp(/^(\w+-\d+)/),it=new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/),rt=new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/),at=new RegExp(/\/(\d+)/),lt=new RegExp(/^(\d+)/),st=[{value:"closes",label:"closes <issue/ticket>",hint:"Attempts to infer ticket from branch"},{value:"trailer",label:"trailer",hint:"Appends trailer based on commit type"},{value:"breaking-change",label:"breaking change",hint:"Add breaking change"},{value:"deprecated",label:"deprecated",hint:"Add deprecated change"},{value:"custom",label:"custom",hint:"Add a custom footer"}],pt=[{value:"branch",label:"Branch"},{value:"worktree",label:"Worktree"}],ct={get:()=>"",set:(e,o)=>{},clear:()=>{}};function vt(e=" better-commits "){console.clear(),i.intro(`${a.bgCyan(a.black(e))}`),P();let o=null,n=I();u.existsSync(n)&&(i.log.step("Found global config"),o=A(n));let l=`${w()}/${T}`;if(u.existsSync(l)){i.log.step("Found repository config");let s=A(l);return o?{...s,overrides:o.overrides.shell?o.overrides:s.overrides,confirm_with_editor:o.confirm_with_editor,cache_last_value:o.cache_last_value}:s}if(o)return o;let v=y(m,{});return i.log.step("Config not found. Generating default .better-commit.json at $HOME"),u.writeFileSync(n,JSON.stringify(v,null,4)),v}function A(e){let o=null;try{o=JSON.parse(u.readFileSync(e,"utf8"))}catch(n){i.log.error(`Invalid JSON file. Exiting.
1
+ import*as p from"valibot";var c="custom",f=["closes","trailer","breaking-change","deprecated","custom"],h=p.picklist(["branch","worktree"]),g=p.picklist(["closes","trailer","breaking-change","deprecated","custom"]),d=p.picklist(["user","version","type","ticket","description"]),$=p.picklist(["branch_user","branch_version","branch_type","branch_ticket","branch_description"]),O=["user","version","type","ticket","description"],x=[{value:"app",label:"app"},{value:"shared",label:"shared"},{value:"server",label:"server"},{value:"tools",label:"tools"},{value:"",label:"none"}],C=[{value:"feat",label:"feat",hint:"A new feature",emoji:"\u{1F31F}",trailer:"Changelog: feature"},{value:"fix",label:"fix",hint:"A bug fix",emoji:"\u{1F41B}",trailer:"Changelog: fix"},{value:"docs",label:"docs",hint:"Documentation only changes",emoji:"\u{1F4DA}",trailer:"Changelog: documentation"},{value:"refactor",label:"refactor",hint:"A code change that neither fixes a bug nor adds a feature",emoji:"\u{1F528}",trailer:"Changelog: refactor"},{value:"perf",label:"perf",hint:"A code change that improves performance",emoji:"\u{1F680}",trailer:"Changelog: performance"},{value:"test",label:"test",hint:"Adding missing tests or correcting existing tests",emoji:"\u{1F6A8}",trailer:"Changelog: test"},{value:"build",label:"build",hint:"Changes that affect the build system or external dependencies",emoji:"\u{1F6A7}",trailer:"Changelog: build"},{value:"ci",label:"ci",hint:"Changes to our CI configuration files and scripts",emoji:"\u{1F916}",trailer:"Changelog: ci"},{value:"chore",label:"chore",hint:"Other changes that do not modify src or test files",emoji:"\u{1F9F9}",trailer:"Changelog: chore"},{value:"",label:"none"}];import*as t from"valibot";var m=t.object({check_status:t.optional(t.boolean(),!0),commit_type:t.transform(t.optional(t.object({enable:t.optional(t.boolean(),!0),initial_value:t.optional(t.string(),"feat"),max_items:t.optional(t.number([t.minValue(1)]),20),infer_type_from_branch:t.optional(t.boolean(),!0),append_emoji_to_label:t.optional(t.boolean(),!1),append_emoji_to_commit:t.optional(t.boolean(),!1),emoji_commit_position:t.optional(t.picklist(["Start","After-Colon"]),"Start"),options:t.optional(t.array(t.object({value:t.string(),label:t.optional(t.string()),hint:t.optional(t.string()),emoji:t.optional(t.string([t.emoji()]),void 0),trailer:t.optional(t.string())})),C)},[t.custom(e=>e.options.map(o=>o.value).includes(e.initial_value),e=>`Type: initial_value "${e.input.initial_value}" must exist in options`)]),{}),e=>{let o=e.options.map(n=>({...n,label:n.emoji&&e.append_emoji_to_label?`${n.emoji} ${n.label}`:n.label}))??[];return{...e,options:o}}),commit_scope:t.transform(t.optional(t.object({enable:t.optional(t.boolean(),!0),custom_scope:t.optional(t.boolean(),!1),max_items:t.optional(t.number([t.minValue(1)]),20),initial_value:t.optional(t.string(),"app"),options:t.optional(t.array(t.object({value:t.string(),label:t.optional(t.string()),hint:t.optional(t.string())})),x)},[t.custom(e=>{let o=e.options.map(n=>n.value);return e.custom_scope&&o.push(c),o.includes(e.initial_value)},e=>`Scope: initial_value "${e.input.initial_value}" must exist in options`)]),{}),e=>{let o=e.options.map(n=>n.value);return e.custom_scope&&!o.includes(c)?{...e,options:[...e.options,{label:c,value:c,hint:"Write a custom scope"}]}:e}),check_ticket:t.optional(t.object({infer_ticket:t.optional(t.boolean(),!0),confirm_ticket:t.optional(t.boolean(),!0),add_to_title:t.optional(t.boolean(),!0),append_hashtag:t.optional(t.boolean(),!1),prepend_hashtag:t.optional(t.picklist(["Never","Always","Prompt"]),"Never"),surround:t.optional(t.picklist(["","()","[]","{}"]),""),title_position:t.optional(t.picklist(["start","end","before-colon","beginning"]),"start")}),{}),commit_title:t.optional(t.object({max_size:t.optional(t.number([t.minValue(1)]),70)}),{}),commit_body:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1),split_by_period:t.optional(t.boolean(),!1)}),{}),commit_footer:t.optional(t.object({enable:t.optional(t.boolean(),!0),initial_value:t.optional(t.array(g),[]),options:t.optional(t.array(g),f)}),{}),breaking_change:t.optional(t.object({add_exclamation_to_title:t.optional(t.boolean(),!0)}),{}),cache_last_value:t.optional(t.boolean(),!0),confirm_with_editor:t.optional(t.boolean(),!1),confirm_commit:t.optional(t.boolean(),!0),print_commit_output:t.optional(t.boolean(),!0),branch_pre_commands:t.optional(t.array(t.string()),[]),branch_post_commands:t.optional(t.array(t.string()),[]),worktree_pre_commands:t.optional(t.array(t.string()),[]),worktree_post_commands:t.optional(t.array(t.string()),[]),branch_user:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_type:t.optional(t.object({enable:t.optional(t.boolean(),!0),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_version:t.optional(t.object({enable:t.optional(t.boolean(),!1),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"/")}),{}),branch_ticket:t.optional(t.object({enable:t.optional(t.boolean(),!0),required:t.optional(t.boolean(),!1),separator:t.optional(t.picklist(["/","-","_"]),"-")}),{}),branch_description:t.optional(t.object({max_length:t.optional(t.number([t.minValue(1)]),70),separator:t.optional(t.picklist(["","/","-","_"]),"")}),{}),branch_action_default:t.optional(h,"branch"),branch_order:t.optional(t.array(d),O),enable_worktrees:t.optional(t.boolean(),!0),worktrees:t.optional(t.object({enable:t.optional(t.boolean(),!0),base_path:t.optional(t.string(),".."),folder_template:t.optional(t.string(),"{{repo_name}}-{{ticket}}-{{branch_description}}")}),{}),overrides:t.optional(t.object({shell:t.optional(t.string())}),{})}),H=t.optional(t.object({type:t.optional(t.string(),""),scope:t.optional(t.string(),""),title:t.optional(t.string(),""),body:t.optional(t.string(),""),closes:t.optional(t.string(),""),ticket:t.optional(t.string(),""),breaking_title:t.optional(t.string(),""),breaking_body:t.optional(t.string(),""),deprecates:t.optional(t.string(),""),deprecates_title:t.optional(t.string(),""),deprecates_body:t.optional(t.string(),""),custom_footer:t.optional(t.string(),""),trailer:t.optional(t.string(),"")}),{}),D=t.optional(t.object({user:t.optional(t.string(),""),type:t.optional(t.string(),""),ticket:t.optional(t.string(),""),description:t.optional(t.string(),""),version:t.optional(t.string(),"")}),{});var b=class{#t="";constructor(){}get git_args(){return this.#t}set git_args(o){this.#t=o}},_=new b;import*as i from"@clack/prompts";import{execSync as S}from"child_process";import u from"fs";import{homedir as R}from"os";import a from"picocolors";import{ValiError as N,parse as y}from"valibot";import{argv as E}from"process";var T=".better-commits.json",K=`${a.dim("(<space> to select)")}`,Q=`${a.dim("(<space> to select, <a> to select all)")}`,tt=`${a.dim("(optional)")}`,ot=`${a.dim("(value will be saved)")}`,et=new RegExp(/\/(\w+-\d+)/),nt=new RegExp(/^(\w+-\d+)/),it=new RegExp(/^([A-Z]+-[\[a-zA-Z\]\d]+)_/),rt=new RegExp(/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/),at=new RegExp(/\/(\d+)/),lt=new RegExp(/^(\d+)/),st=[{value:"closes",label:"closes <issue/ticket>",hint:"Attempts to infer ticket from branch"},{value:"trailer",label:"trailer",hint:"Appends trailer based on commit type"},{value:"breaking-change",label:"breaking change",hint:"Add breaking change"},{value:"deprecated",label:"deprecated",hint:"Add deprecated change"},{value:"custom",label:"custom",hint:"Add a custom footer"}],pt=[{value:"branch",label:"Branch"},{value:"worktree",label:"Worktree"}],ct={get:()=>"",set:(e,o)=>{},clear:()=>{}};function vt(e=" better-commits "){console.clear(),i.intro(`${a.bgCyan(a.black(e))}`),P();let o=null,n=I();u.existsSync(n)&&(i.log.step("Found global config"),o=A(n));let l=`${w()}/${T}`;if(u.existsSync(l)){i.log.step("Found repository config");let s=A(l);return o?{...s,overrides:o.overrides.shell?o.overrides:s.overrides,confirm_with_editor:o.confirm_with_editor,cache_last_value:o.cache_last_value}:s}if(o)return o;let v=y(m,{});return i.log.step("Config not found. Generating default .better-commit.json at $HOME"),u.writeFileSync(n,JSON.stringify(v,null,4)),v}function A(e){let o=null;try{o=JSON.parse(u.readFileSync(e,"utf8"))}catch(n){i.log.error(`Invalid JSON file. Exiting.
2
2
  `+n),process.exit(0)}return j(o)}function j(e){try{return y(m,e)}catch(o){if(o instanceof N){let r=(o.issues[0].path??[]).map(l=>l.key).join(".");i.log.error(`Invalid Configuration: ${a.red(r)}
3
3
  `+o.message)}process.exit(0)}}function _t(e){let o="";try{o=S(`git ${_.git_args} branch --show-current`,{stdio:"pipe"}).toString()}catch{return""}return e.find(r=>{let l=new RegExp(`^${r}-`),v=new RegExp(`-${r}-`),s=new RegExp(`${r}/`);return[o.match(l),o.match(v),o.match(s)].filter(k=>k!=null)?.length})??""}function w(){let e=".";try{e=S(`git ${_.git_args} rev-parse --show-toplevel`).toString().trim()}catch{i.log.warn("Could not find git root. If in a --bare repository, ignore this warning.")}return e}function I(){return R()+"/"+T}function ut(e,o){return o===e.length-1?"":`
4
4
  `}function gt(e){let o=e.trim();return o.endsWith(".")?o.substring(0,o.length-1).trim():e.trim()}function P(){_.git_args=`${E[2]??""} ${E[3]??""}`.trim()}function mt(e,o){try{return e.get(o)??""}catch{i.log.warn(`Could not access ${o} from cache. Check that "~/.config" exists. Set "cache_last_value" to false to disable.`)}return""}function bt(e,o,n){try{e.set(o,n)}catch{i.log.warn(`Could not access ${o} from cache. Check that "~/.config" exists. Set "cache_last_value" to false to disable.`)}}export{c as a,m as b,H as c,D as d,_ as e,T as f,K as g,tt as h,ot as i,et as j,nt as k,it as l,rt as m,at as n,lt as o,st as p,pt as q,ct as r,vt as s,_t as t,w as u,ut as v,gt as w,mt as x,bt as y};
package/dist/index.js CHANGED
@@ -1,8 +1,9 @@
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 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(`
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-K2RPF2JY.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
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
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(`
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"}});if(s.isCancel(i)&&process.exit(0),t.body=i??"",e.commit_body.split_by_period){let r=i.split(".").map(n=>n.trim());t.body=r.join(`.
6
+ `)}y(o,"commit_body",t.body)}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
7
  `);a+=o?`
7
8
 
8
9
  ${m}`:`
package/dist/init.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #! /usr/bin/env node
2
- import{b as r,f as e,u as i}from"./chunk-ELYOZGPM.js";import*as t from"@clack/prompts";import c from"fs";import o from"picocolors";import{parse as l}from"valibot";try{console.clear(),t.intro(`${o.bgCyan(o.black(" better-commits-init "))}`);let s=`${i()}/${e}`,m=l(r,{});c.writeFileSync(s,JSON.stringify(m,null,4)),t.log.success(`${o.green("Successfully created .better-commits.json")}`),t.outro(`Run ${o.bgBlack(o.white("better-commits"))} to start the CLI`)}catch{t.log.error(`${o.red("Could not determine git root folder. better-commits-init must be used in a git repository")}`)}
2
+ import{b as r,f as e,u as i}from"./chunk-K2RPF2JY.js";import*as t from"@clack/prompts";import c from"fs";import o from"picocolors";import{parse as l}from"valibot";try{console.clear(),t.intro(`${o.bgCyan(o.black(" better-commits-init "))}`);let s=`${i()}/${e}`,m=l(r,{});c.writeFileSync(s,JSON.stringify(m,null,4)),t.log.success(`${o.green("Successfully created .better-commits.json")}`),t.outro(`Run ${o.bgBlack(o.white("better-commits"))} to start the CLI`)}catch{t.log.error(`${o.red("Could not determine git root folder. better-commits-init must be used in a git repository")}`)}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "better-commits",
3
3
  "private": false,
4
- "version": "1.18.1",
4
+ "version": "1.19.0",
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",
@@ -21,6 +21,10 @@
21
21
  "git-bc": "./dist/index.js"
22
22
  },
23
23
  "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/Everduin94/better-commits"
27
+ },
24
28
  "dependencies": {
25
29
  "@clack/core": "^0.3.1",
26
30
  "@clack/prompts": "^0.7.0",
@@ -37,11 +41,12 @@
37
41
  },
38
42
  "devDependencies": {
39
43
  "@semantic-release/git": "^10.0.1",
44
+ "@semantic-release/npm": "^13.1.3",
40
45
  "@types/configstore": "^6.0.0",
41
46
  "@types/node": "^18.14.5",
42
47
  "jiti": "^1.17.0",
43
48
  "prettier": "3.2.5",
44
- "semantic-release": "^21.0.1",
49
+ "semantic-release": "^25.0.2",
45
50
  "tsup": "^8.0.2",
46
51
  "tsx": "^3.12.3",
47
52
  "typescript": "^5.4.5"
package/readme.md CHANGED
@@ -205,7 +205,8 @@ To create a **repository-specific config**, navigate to the root of your project
205
205
  },
206
206
  "commit_body": {
207
207
  "enable": true,
208
- "required": false
208
+ "required": false,
209
+ "split_by_period": false
209
210
  },
210
211
  "commit_footer": {
211
212
  "enable": true,
@@ -312,6 +313,7 @@ Expand to see explanations and possible values
312
313
  | `commit_title.max_size` | Max size of title including scope, type, etc... |
313
314
  | `commit_body.enable` | If true include body |
314
315
  | `commit_body.required` | If true body is required |
316
+ | `commit_body.split_by_period` | Automatically split sentences into new lines |
315
317
  | `commit_footer.enable` | If true include footer |
316
318
  | `commit_footer.initial_value` | Initial values selected in footer |
317
319
  | `commit_footer.options` | Footer options |
@@ -343,7 +345,7 @@ Branch configuration (same config file, split for readability)
343
345
  | `branch_version.enable` | If enabled include version |
344
346
  | `branch_version.required` | If enabled require version |
345
347
  | `branch_version.separator` | Branch delimeter - "", "/" (default), "-", "\_" |
346
- | `branch_order` | Order of branch name values (doesn't effect prompt order) |
348
+ | `branch_order` | Order of branch name values (doesn't affect prompt order) |
347
349
  | `branch_action_default` | "branch" or "worktree" |
348
350
  | `enable_worktrees` | `Deprecated` see `worktrees.enable` |
349
351
  | `worktrees.enable` | If false, always default to branch action |
package/src/index.ts CHANGED
@@ -233,8 +233,14 @@ export async function main(config: Output<typeof Config>) {
233
233
  },
234
234
  });
235
235
  if (p.isCancel(commit_body)) process.exit(0);
236
- set_value_cache(prompt_cache, "commit_body", commit_body);
236
+
237
237
  commit_state.body = commit_body ?? "";
238
+ if (config.commit_body.split_by_period) {
239
+ const sentences = commit_body.split(".").map((s) => s.trim());
240
+ commit_state.body = sentences.join(".\n");
241
+ }
242
+
243
+ set_value_cache(prompt_cache, "commit_body", commit_state.body);
238
244
  }
239
245
 
240
246
  if (config.commit_footer.enable) {
@@ -145,6 +145,7 @@ export const Config = v.object({
145
145
  v.object({
146
146
  enable: v.optional(v.boolean(), true),
147
147
  required: v.optional(v.boolean(), false),
148
+ split_by_period: v.optional(v.boolean(), false),
148
149
  }),
149
150
  {},
150
151
  ),
@@ -158,7 +159,7 @@ export const Config = v.object({
158
159
  ),
159
160
  breaking_change: v.optional(
160
161
  v.object({
161
- add_exclamation_to_title: v.optional(v.boolean(), false),
162
+ add_exclamation_to_title: v.optional(v.boolean(), true),
162
163
  }),
163
164
  {},
164
165
  ),