better-commits 1.23.2 → 1.24.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.
- package/dist/branch.js +19 -19
- package/dist/index.js +31 -53
- package/dist/init.js +1 -1
- package/dist/messages-ZJeoTfy2.js +1 -0
- package/dist/utils-CeUs4BjU.js +259 -0
- package/package.json +18 -12
- package/readme.md +4 -2
- package/.better-commits.json +0 -52
- package/.github/workflows/publish.yml +0 -34
- package/.github/workflows/test.yml +0 -27
- package/.prettierignore +0 -5
- package/.prettierrc +0 -1
- package/dist/chunk-43H72S6V.js +0 -1
- package/dist/chunk-B7AGSPP3.js +0 -261
- package/src/args.test.ts +0 -128
- package/src/args.ts +0 -125
- package/src/branch-args.test.ts +0 -75
- package/src/branch-args.ts +0 -107
- package/src/branch-help.ts +0 -125
- package/src/branch.ts +0 -97
- package/src/default-config-template.ts +0 -258
- package/src/git.test.ts +0 -64
- package/src/git.ts +0 -72
- package/src/help.ts +0 -138
- package/src/index.test.ts +0 -7
- package/src/index.ts +0 -101
- package/src/init.test.ts +0 -123
- package/src/init.ts +0 -46
- package/src/prompts/autocomplete-multiselect.test.ts +0 -129
- package/src/prompts/autocomplete-multiselect.ts +0 -249
- package/src/prompts/branch-checkout.prompt.ts +0 -36
- package/src/prompts/branch-confirm.prompt.test.ts +0 -89
- package/src/prompts/branch-confirm.prompt.ts +0 -149
- package/src/prompts/branch-description.prompt.ts +0 -37
- package/src/prompts/branch-runnable.ts +0 -13
- package/src/prompts/branch-scope.prompt.ts +0 -59
- package/src/prompts/branch-ticket.prompt.ts +0 -41
- package/src/prompts/branch-type.prompt.ts +0 -46
- package/src/prompts/branch-user.prompt.ts +0 -50
- package/src/prompts/branch-version.prompt.ts +0 -41
- package/src/prompts/commit-body.prompt.ts +0 -51
- package/src/prompts/commit-confirm.prompt.ts +0 -123
- package/src/prompts/commit-footer.prompt.ts +0 -195
- package/src/prompts/commit-scope.prompt.ts +0 -91
- package/src/prompts/commit-status.prompt.ts +0 -66
- package/src/prompts/commit-ticket.prompt.ts +0 -82
- package/src/prompts/commit-title.prompt.ts +0 -98
- package/src/prompts/commit-type.prompt.ts +0 -96
- package/src/prompts/runnable.ts +0 -13
- package/src/utils/build-branch.test.ts +0 -159
- package/src/utils/build-branch.ts +0 -48
- package/src/utils/build-commit-string.test.ts +0 -273
- package/src/utils/build-commit-string.ts +0 -163
- package/src/utils/commit-title-size.ts +0 -24
- package/src/utils/infer.test.ts +0 -174
- package/src/utils/infer.ts +0 -160
- package/src/utils/messages.ts +0 -25
- package/src/utils/no-interactive-branch-validation.test.ts +0 -193
- package/src/utils/no-interactive-validation.test.ts +0 -174
- package/src/utils/no-interactive-validation.ts +0 -213
- package/src/utils.test.ts +0 -164
- package/src/utils.ts +0 -235
- package/src/valibot-consts.ts +0 -117
- package/src/valibot-state.test.ts +0 -57
- package/src/valibot-state.ts +0 -276
- package/tsconfig.json +0 -15
- package/tsup.config.ts +0 -12
- package/vitest.config.ts +0 -8
package/dist/branch.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import{c as
|
|
3
|
-
`)}function
|
|
4
|
-
${
|
|
2
|
+
import{c as e,d as t,f as n,g as r,i,s as a,t as o,u as s}from"./utils-CeUs4BjU.js";import{a as c,c as l,d as u,l as d,u as f}from"./messages-ZJeoTfy2.js";import{chdir as p}from"process";import*as m from"@clack/prompts";import{ValiError as h,parse as g}from"valibot";import{execSync as _}from"child_process";import v from"picocolors";import{parse as y}from"@bomb.sh/args";import b from"configstore";var x=class{constructor(e,t,n){this.config=e,this.branch_state=t,this.prompt_cache=n}},S=class extends x{async run(){if(this.#t){let e=await m.select({message:this.#e,initialValue:this.#n,options:o});m.isCancel(e)&&process.exit(),this.#r(e)}}get#e(){return`Checkout a branch or create a worktree?`}get#t(){return this.config.worktrees.enable}get#n(){return this.branch_state.checkout||this.config.branch_action_default}#r(e){this.branch_state.checkout=e}},C=class extends x{async run(){if(!this.#e)return;let e=await m.text({message:this.#n,placeholder:``,initialValue:this.#r,validate:e=>this.#i(e)});m.isCancel(e)&&process.exit(0),this.#a(e??``)}get#e(){return this.config.branch_user.enable}get#t(){return this.config.branch_user.required}get#n(){return this.#t?`Type your git username`:c(`Type your git username`)}get#r(){return this.branch_state.user||s(this.prompt_cache,`username`)}#i(e){if(this.#t&&!e)return`Please enter a username`}#a(e){this.branch_state.user=e.replace(/\s+/g,`-`).toLowerCase(),n(this.prompt_cache,`username`,this.branch_state.user)}},w=class extends x{async run(){if(!this.#e)return;let e=await(this.config.branch_type.autocomplete?m.autocomplete:m.select)({message:this.#t,initialValue:this.#n,options:this.#r});m.isCancel(e)&&process.exit(0),this.#i(e)}get#e(){return this.config.branch_type.enable}get#t(){return`Select a branch type`}get#n(){return this.branch_state.type||this.config.commit_type.initial_value}get#r(){return this.config.commit_type.options}#i(e){this.branch_state.type=e}},T=class extends x{async run(){if(!this.#e)return;let e=await(this.config.branch_scope.autocomplete?m.autocomplete:m.select)({message:this.#t,initialValue:this.#n,options:this.#r});m.isCancel(e)&&process.exit(0),await this.#a(e)}get#e(){return this.config.branch_scope.enable}get#t(){return`Select a branch scope`}get#n(){return this.branch_state.scope||this.config.commit_scope.initial_value}get#r(){return this.config.commit_scope.options}get#i(){return this.config.commit_scope.custom_scope}async#a(e){let t=e;if(t===`custom`&&this.#i){let e=await m.text({message:`Write a custom scope`,placeholder:``});m.isCancel(e)&&process.exit(0),t=e??``}this.branch_state.scope=t}},E=class extends x{async run(){if(!this.#e)return;let e=await m.text({message:this.#n,placeholder:``,validate:e=>this.#r(e),initialValue:this.branch_state.ticket});m.isCancel(e)&&process.exit(0),this.#i(e??``)}get#e(){return this.config.branch_ticket.enable}get#t(){return this.config.branch_ticket.required}get#n(){return this.#t?`Type ticket / issue number`:c(`Type ticket / issue number`)}#r(e){if(this.#t&&!e)return`Please enter a ticket / issue`}#i(e){this.branch_state.ticket=e}},D=class extends x{async run(){if(!this.#e)return;let e=await m.text({message:this.#n,placeholder:``,validate:e=>this.#r(e),initialValue:this.branch_state.version});m.isCancel(e)&&process.exit(0),this.#i(e??``)}get#e(){return this.config.branch_version.enable}get#t(){return this.config.branch_version.required}get#n(){return this.#t?`Type version number`:c(`Type version number`)}#r(e){if(this.#t&&!e)return`Please enter a version`}#i(e){this.branch_state.version=e}},O=class extends x{async run(){let e=await m.text({message:this.#e,placeholder:``,validate:e=>this.#n(e),initialValue:this.branch_state.description});m.isCancel(e)&&process.exit(0),this.#r(e??``)}get#e(){return`Type a short description`}get#t(){return this.config.branch_description.max_length}#n(e){if(!e)return`Please enter a description`;if(e.length>this.#t)return`Exceeded max length. Description max [${this.#t}]`}#r(e){this.branch_state.description=e.replace(/\s+/g,`-`).toLowerCase()}};const k=[`user`,`type`,`scope`,`description`,`ticket`,`branch-version`,`checkout`],A=[`git-dir`,`work-tree`],j=[`interactive`,`dry-run`,`help`,`version`],M=new class{#e;constructor(e){this.#e=e}get interactive(){return!this.#e.no_interactive}get dry_run(){return this.#e.dry_run}get help(){return this.#e.help}get version(){return this.#e.version}get git_args(){return this.#e.git_args}get branch_state(){return this.#e.branch_state}}(N(process.argv.slice(2)));function N(e){let t=y(e,{alias:{h:`help`,v:`version`},boolean:j,string:[...k,...A]}),n={};return k.forEach(e=>{let r=t[e];if(r){let t=e===`branch-version`?`version`:e.replace(`-`,`_`);t===`checkout`?n[t]=r??`branch`:t===`description`?n[t]=r.replace(/\s+/g,`-`).toLowerCase():n[t]=r}}),{help:t.help===!0,version:t.version===!0,git_args:P(t[`git-dir`],t[`work-tree`]),no_interactive:t.interactive===!1,dry_run:t[`dry-run`]===!0,branch_state:n}}function P(e,t){return`${e?`--git-dir=${e}`:``} ${t?`--work-tree=${t}`:``}`.trim()}function F(e,t){let n=``;return t.branch_order.forEach(r=>{let i=`branch_${r}`;e[r]&&(n+=e[r]+t[i].separator)}),n.endsWith(`-`)||n.endsWith(`/`)||n.endsWith(`_`)?n.slice(0,-1).trim():n.trim()}function I(e,t,n){let r=n.split(`/`).pop()||`repo`,i=t.worktrees.folder_template;i=i.replace(`{{repo_name}}`,r).replace(`{{branch_description}}`,e.description).replace(`{{user}}`,e.user||``).replace(`{{type}}`,e.type||``).replace(`{{scope}}`,e.scope||``).replace(`{{ticket}}`,e.ticket||``).replace(`{{version}}`,e.version||``),i=i.replace(/\s/g,``).replace(/--+/g,`-`).replace(/^-+|-+$/g,``);let a=t.worktrees.base_path;return`${a}${a.endsWith(`/`)?``:`/`}${i}`}var L=class extends x{async run(){this.#i(),this.#a(),this.#o()}get#e(){return this.branch_state.checkout===`worktree`}get#t(){return this.#e?this.config.worktree_pre_commands:this.config.branch_pre_commands}get#n(){return this.#e?this.config.worktree_post_commands:this.config.branch_post_commands}get#r(){return F(this.branch_state,this.config)}#i(){this.#s(this.#t,`Something went wrong when executing pre-commands: `)}#a(){let e=this.#r,t=this.#l(e);if(!this.#e){let n=`git ${M.git_args} checkout ${t} ${e}`;if(M.dry_run){this.#c(n);return}try{_(n,{stdio:`inherit`}),m.log.info(`Switched to a new branch '${v.bgGreen(` `+v.black(e)+` `)}'`)}catch{process.exit(0)}return}try{let n=I(this.branch_state,this.config,a(M.git_args)),r=`git ${M.git_args} worktree add ${n} ${t} ${e}`;if(M.dry_run){this.#c(r);return}_(r,{stdio:`inherit`}),m.log.info(`Created a new worktree ${v.bgGreen(` `+v.black(n)+` `)}, checked out branch ${v.bgGreen(` `+v.black(e)+` `)}`),m.log.info(v.bgMagenta(v.black(` cd ${n} `))+` to navigate to your new worktree`),p(n)}catch{process.exit(0)}}#o(){this.#s(this.#n,`Something went wrong when executing post-commands: `)}#s(e,t){e.forEach(e=>{if(M.dry_run){this.#c(e);return}try{_(e,{stdio:`inherit`})}catch(e){m.log.error(t+e),process.exit(0)}})}#c(e){m.log.info(`Dry run: ${e}`)}#l(e){let t=``;try{_(`git ${M.git_args} show-ref ${e}`,{encoding:`utf-8`}),m.log.warning(v.yellow(`${e} already exists! Checking out existing branch.`))}catch{t=`-b`}return t}};const R={"--interactive":`Run in interactive prompt mode (default behavior).`,"--dry-run":`Print branch commands without creating a branch or worktree.`,"--help":`Show help information and exit.`},z={"--user":`Set branch username segment.`,"--type":`Set branch type (for example feat, fix, docs).`,"--scope":`Set branch scope segment.`,"--description":`Set branch description segment.`,"--ticket":`Set branch ticket/issue segment.`,"--branch-version":`Set branch version segment.`,"--checkout":`Choose branch or worktree checkout mode.`},B={"--git-dir":`Set the path to the .git directory.`,"--work-tree":`Set the path to the working tree root.`};function V(e){return Object.entries(e).map(([e,t])=>{let n=Math.max(2,26-e.length);return` ${e}${` `.repeat(n)}${t}`}).join(`
|
|
3
|
+
`)}function H(t,n){let r=e(),i=`(none)`;try{i=_(`git ${M.git_args} branch --show-current`,{stdio:`pipe`}).toString().trim()||`(none)`}catch{}let a=f(t.commit_type.options,M.git_args)||`Unknown`,o=t.check_ticket.infer_ticket?d({append_hashtag:t.check_ticket.append_hashtag,prepend_hashtag:t.check_ticket.prepend_hashtag},M.git_args)||`Unknown`:`Infer Disabled`,s=t.commit_scope.infer_scope_from_branch?l(t.commit_scope.options,M.git_args)||`Unknown`:`Infer Disabled`,c=t.commit_type.options.map(e=>e.value).join(`, `).trim(),u=t.commit_scope.options.map(e=>e.value).join(`, `).trim(),p=V(R),m=V(B),h=V(z);console.log(`
|
|
4
|
+
${v.green(` better-branch`)} ${v.gray(`v`+r)}
|
|
5
5
|
|
|
6
|
-
${
|
|
7
|
-
${
|
|
8
|
-
${
|
|
6
|
+
${v.gray(`BRANCH`)}
|
|
7
|
+
${i}
|
|
8
|
+
${v.gray(`Type`)} ${v.blue(a)} ${v.gray(`·`)} ${v.gray(`Scope`)} ${v.cyan(s)} ${v.gray(`·`)} ${v.gray(`Ticket`)} ${v.magenta(o)}
|
|
9
9
|
|
|
10
|
-
${
|
|
11
|
-
${
|
|
10
|
+
${v.gray(`CONFIGURATION`)}
|
|
11
|
+
${n}
|
|
12
12
|
|
|
13
|
-
${
|
|
14
|
-
${
|
|
13
|
+
${v.gray(`Types`)}
|
|
14
|
+
${c}
|
|
15
15
|
|
|
16
|
-
${
|
|
17
|
-
${
|
|
16
|
+
${v.gray(`Scopes`)}
|
|
17
|
+
${u}
|
|
18
18
|
|
|
19
|
-
${
|
|
20
|
-
${
|
|
19
|
+
${v.gray(`CLI FLAGS`)}
|
|
20
|
+
${p}
|
|
21
21
|
|
|
22
|
-
${
|
|
23
|
-
${
|
|
22
|
+
${v.gray(`Branch Flags`)}
|
|
23
|
+
${h}
|
|
24
24
|
|
|
25
|
-
${
|
|
26
|
-
${
|
|
25
|
+
${v.gray(`Git Flags (Advanced)`)}
|
|
26
|
+
${m}
|
|
27
27
|
|
|
28
|
-
`)}
|
|
28
|
+
`)}const U=[S,C,w,E,T,D,O,L],{config:W,config_source:G}=t(` better-branch `,M.git_args);K(W,G);async function K(t,n){if(p(a(M.git_args)),M.version){let t=e();m.log.step(`Better Commits v`+t);return}if(M.help){H(t,n);return}let o=g(r,M.branch_state);if(!M.interactive)try{g(u(t),o)}catch(e){e instanceof h?m.log.error(`Invalid branch input: ${e.message}`):m.log.error(`Failed to validate branch input: ${e}`),process.exit(0)}let s=t.cache_last_value?new b(`better-commits`):i,c=M.interactive?U:[L];for(let e of c)await new e(t,o,s).run()}export{};
|
package/dist/index.js
CHANGED
|
@@ -1,61 +1,39 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import{a as
|
|
3
|
-
`));let
|
|
4
|
-
`);
|
|
5
|
-
|
|
6
|
-
${
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
${
|
|
13
|
-
|
|
14
|
-
${
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
${
|
|
22
|
-
|
|
23
|
-
${u.dim(i.trailer)}`:`
|
|
24
|
-
|
|
25
|
-
${i.trailer}`),o&&(r=r.replaceAll('"','\\"').replaceAll("`","\\`")),r}import{execSync as kt}from"child_process";import*as P from"@clack/prompts";import X from"picocolors";var vt=["M","T","R","D","A","C"];function st(){let i="";try{i=kt(`git ${n.git_args} status --porcelain`,{stdio:"pipe"}).toString()}catch(s){return P.log.error(X.red("Failed to git status"+s)),{index:[],work_tree:[]}}let t=i.split(`
|
|
26
|
-
`),e=[],o=[];return t.forEach(s=>{let r=s.trimEnd();if(!r)return;let a=r.substring(2).trim(),l=r.charAt(0).trim(),C=r.charAt(1).trim();(l==="?"||C==="?")&&e.push(a),vt.includes(l)&&o.push(a),vt.includes(C)&&e.push(a)}),{index:o,work_tree:e}}function $t(i){let t=i.join(" ");if(t)try{kt(`git ${n.git_args} add ${t}`,{stdio:"pipe"}).toString(),P.log.success(X.green("Changes successfully staged"))}catch{P.log.error(X.red("Failed to stage changes"))}}function Y(){st().index.length||(P.log.error(X.red('no changes added to commit (use "git add" and/or "git commit -a")')),process.exit(0))}var E=class extends p{async run(){n.interactive||Y(),this.#i&&(Ct(`${this.#n} --edit`,this.#o),process.exit(0)),this.#e&&h.note(ot({commit_state:this.commit_state,config:this.config,colorize:!0,escape_quotes:!1,include_trailer:!0}),"Commit Preview",{format:e=>e}),await this.#a()||(h.log.info("Exiting without commit"),process.exit(0));try{h.log.info(n.dry_run?it("Committing changes..."):"Committing changes..."),Ct(this.#n,n.dry_run?this.#s:this.#o)}catch(e){h.log.error("Something went wrong when committing: "+e);return}this.#m()}get#i(){return n.interactive&&this.config.confirm_with_editor}get#e(){return this.config.print_commit_output}get#t(){return this.config.confirm_commit}get#o(){return this.config.overrides.shell?{shell:this.config.overrides.shell,stdio:"inherit"}:{stdio:"inherit"}}get#s(){return this.config.overrides.shell?{shell:this.config.overrides.shell,stdio:"pipe"}:{stdio:"pipe"}}get#r(){return this.commit_state.trailer?`--trailer="${this.commit_state.trailer}"`:""}get#n(){return`git ${n.git_args} commit -m "${ot({commit_state:this.commit_state,config:this.config,colorize:!1,escape_quotes:!0,include_trailer:!1})}" ${this.#r} ${this.#c}`.trim()}get#c(){return n.dry_run?"--dry-run --porcelain --untracked-files=no":""}async#a(){if(!n.interactive||!this.#t)return!0;let t=await h.confirm({message:n.dry_run?it("Confirm Commit?"):"Confirm Commit?"});return h.isCancel(t)&&process.exit(0),t}#m(){h.log.success("Commit Complete");let t=this.prompt_cache.get("username");this.prompt_cache.clear(),t&&this.prompt_cache.set("username",t)}};import*as w from"@clack/prompts";import J from"picocolors";import{styleText as m}from"node:util";import{AutocompletePrompt as Pt}from"@clack/core";import{S_BAR as R,S_BAR_END as Et,S_CHECKBOX_INACTIVE as xt,S_CHECKBOX_SELECTED as Rt,limitOptions as Tt,settings as Nt,symbol as jt}from"@clack/prompts";function Dt(i,t){if(!i)return!0;let e=(t.label??String(t.value??"")).toLowerCase(),o=(t.hint??"").toLowerCase(),s=String(t.value).toLowerCase(),r=i.toLowerCase();return e.includes(r)||o.includes(r)||s.includes(r)}function Lt(i,t){return i===""||t.ctrl===!0&&t.name==="a"}var rt=class extends Pt{constructor(e){super({options:e.options,multiple:!0,filter:e.filter??((o,s)=>Dt(o,s)),validate:o=>e.required&&(!Array.isArray(o)||o.length===0)?"Please select at least one item":e.validate?.(o),initialValue:e.initialValues,signal:e.signal,input:e.input,output:e.output,render(){let o=e.withGuide??Nt.withGuide,s=`${o?`${m("gray",R)}
|
|
27
|
-
`:""}${jt(this.state)} ${e.message}
|
|
28
|
-
`,r=this.userInput,a=this.userInputWithCursor,l=this.options,C=this.filteredOptions.length!==l.length?m("dim",` (${this.filteredOptions.length} match${this.filteredOptions.length===1?"":"es"})`):"";switch(this.state){case"submit":return`${s}${o?`${m("gray",R)} `:""}${m("dim",`${this.selectedValues.length} items selected`)}`;case"cancel":return`${s}${o?`${m("gray",R)} `:""}${m(["strikethrough","dim"],r)}`;default:{let x=this.state==="error"?"yellow":"cyan",y=o?`${m(x,R)} `:"",A=o?m(x,Et):"",c=[`${m("dim","\u2191/\u2193")} to navigate`,`${m("dim","Space/Tab:")} select`,`${m("dim","Ctrl+a:")} select visible`,`${m("dim","Enter:")} confirm`,`${m("dim","Type:")} to search`],b=this.filteredOptions.length===0&&r?[`${y}${m("yellow","No matches found")}`]:[],O=this.state==="error"?[`${y}${m("yellow",this.error)}`]:[],F=[...`${s}${o?m(x,R):""}`.split(`
|
|
29
|
-
`),`${y}${m("dim","Search:")} ${a}${C}`,...b,...O],nt=[`${y}${c.join(" \u2022 ")}`,A],It=Tt({cursor:this.cursor,options:this.filteredOptions,style:(v,Vt)=>{let At=this.selectedValues.includes(v.value),tt=v.label??String(v.value??""),Ft=v.hint&&this.focusedValue!==void 0&&v.value===this.focusedValue?m("dim",` (${v.hint})`):"",at=At?m("green",Rt):m("dim",xt);return v.disabled?`${m("gray",xt)} ${m(["strikethrough","gray"],tt)}`:Vt?`${at} ${tt}${Ft}`:`${at} ${m("dim",tt)}`},maxItems:e.maxItems,output:e.output,rowPadding:F.length+nt.length});return[...F,...It.map(v=>`${y}${v}`),...nt].join(`
|
|
30
|
-
`)}}}});this.promptOptions=e;this.on("key",(o,s)=>{if(s.name==="space"&&!this.isNavigating&&this.focusedValue!==void 0){this.toggleSelected(this.focusedValue),this.#e();return}Lt(o,s)&&(this.#i(),this.isNavigating=!0,this.#e())})}_isActionKey(e,o){return super._isActionKey(e,o)||this.multiple&&o.name==="space"&&e!==void 0&&e!==""}#i(){let e=this.filteredOptions.filter(s=>!s.disabled).map(s=>s.value);if(!e.length)return;let o=e.every(s=>this.selectedValues.includes(s));this.selectedValues=o?this.selectedValues.filter(s=>!e.includes(s)):[...this.selectedValues,...e.filter(s=>!this.selectedValues.includes(s))]}#e(){let e=this.rl;e?.write("",{ctrl:!0,name:"e"}),this._cursor=e?.cursor??this.userInput.length}};function St(i){return new rt(i).prompt()}var Q=class extends p{async run(){if(!this.#i)return;let t=st();if(this.#e(t),t.work_tree.length){let e=await this.#o(t.work_tree);e.length&&$t(e)}Y()}get#i(){return this.config.check_status}#e(t){w.log.step(J.black(J.bgGreen(" Checking Git Status ")));let e=this.#t(t.index,J.green);if(w.log.success(`Changes to be committed:
|
|
31
|
-
`+e),!t.work_tree.length)return;let o=this.#t(t.work_tree,J.red);w.log.error(`Changes not staged for commit:
|
|
32
|
-
`+o)}#t(t,e){return t.reduce((o,s,r)=>e(o+s+gt(t,r)),"")}async#o(t){let e=this.config.check_status_autocomplete?await St({message:"Some files have not been staged, add them now?",options:t.map(o=>({value:o,label:o})),required:!1}):await w.multiselect({message:yt("Some files have not been staged, add them now?"),options:t.map(o=>({value:o,label:o})),required:!1});return w.isCancel(e)&&process.exit(0),e}};import{execSync as Gt}from"child_process";import _ from"picocolors";var Mt={"better-branch":"Create a branch or worktree from a guided prompt flow.","better-commits-init":"Create a .better-commits.jsonc config in this repository."},Bt={"--no-interactive":"Run without tui prompts.","--dry-run":"Print the commit command without creating a commit.","--help":"Show help information and exit."},Wt={"--type":"Set commit type (can be inferred from branch).","--scope":"Set commit scope (can be inferred from branch).","--title":"Set commit title/description.","--body":"Set commit body text.","--ticket":"Set ticket / issue (can be inferred from branch).","--closes":"Set closes footer (true/false).","--trailer":"Set trailer footer value.","--breaking-title":"Set breaking-change title footer.","--breaking-body":"Set breaking-change body footer.","--deprecates-title":"Set deprecates footer title text.","--deprecates-body":"Set deprecates footer body text.","--custom-footer":"Set a custom footer line."},qt={"--git-dir":"Set the path to the .git directory.","--work-tree":"Set the path to the working tree root."};function Z(i){let o=" ";return Object.entries(i).map(([s,r])=>{let a=Math.max(2,26-s.length);return`${o}${s}${" ".repeat(a)}${r}`}).join(`
|
|
33
|
-
`)}function wt(i,t){let e=T(),o="(none)";try{o=Gt(`git ${n.git_args} branch --show-current`,{stdio:"pipe"}).toString().trim()||"(none)"}catch{}let s=N(i.commit_type.options,n.git_args)||"Unknown",r=i.check_ticket.infer_ticket?j({append_hashtag:i.check_ticket.append_hashtag,prepend_hashtag:i.check_ticket.prepend_hashtag},n.git_args)||"Unknown":"Infer Disabled",a=i.commit_scope.infer_scope_from_branch?D(i.commit_scope.options,n.git_args)||"Unknown":"Infer Disabled",l=i.commit_type.options.map(b=>b.value).join(", ").trim(),C=i.commit_scope.options.map(b=>b.value).join(", ").trim(),x=Z(Bt),y=Z(qt),A=Z(Wt),c=Z(Mt);console.log(`
|
|
34
|
-
${_.green("\uF489 better-commits")} ${_.gray("v"+e)}
|
|
35
|
-
|
|
36
|
-
${_.gray("BRANCH")}
|
|
37
|
-
${o}
|
|
38
|
-
${_.gray("Type")} ${_.blue(s)} ${_.gray("\xB7")} ${_.gray("Scope")} ${_.cyan(a)} ${_.gray("\xB7")} ${_.gray("Ticket")} ${_.magenta(r)}
|
|
39
|
-
|
|
40
|
-
${_.gray("CONFIGURATION")}
|
|
41
|
-
${t}
|
|
42
|
-
|
|
43
|
-
${_.gray("Types")}
|
|
2
|
+
import{a as e,c as t,d as n,f as r,i,m as a,n as o,o as s,s as c,u as l,v as u}from"./utils-CeUs4BjU.js";import{a as d,c as f,f as p,i as m,l as h,n as g,o as _,p as v,r as y,s as ee,t as te,u as b}from"./messages-ZJeoTfy2.js";import{chdir as ne}from"process";import*as x from"@clack/prompts";import{S_BAR as S,S_BAR_END as C,S_CHECKBOX_INACTIVE as w,S_CHECKBOX_SELECTED as T,limitOptions as E,settings as D,symbol as O}from"@clack/prompts";import{ValiError as k,parse as A}from"valibot";import{execSync as j}from"child_process";import M from"picocolors";import N from"configstore";import{styleText as P}from"node:util";import{AutocompletePrompt as F}from"@clack/core";var I=class{constructor(e,t,n){this.config=e,this.commit_state=t,this.prompt_cache=n}},L=class extends I{async run(){if(this.#e){let{initial_value:e,message:t}=this.#t,n=await(this.config.commit_type.autocomplete?x.autocomplete:x.select)({message:t,initialValue:e,maxItems:this.#i,options:this.#n});x.isCancel(n)&&process.exit(0),this.#a(n)}}get#e(){return this.config.commit_type.enable}get#t(){let e=l(this.prompt_cache,`commit_type`);if(e)return{initial_value:e,message:g(`Commit type`)};if(this.config.commit_type.infer_type_from_branch){let e=b(this.#n,a.git_args);if(e)return{message:m(`Commit type`),initial_value:e}}return{initial_value:this.config.commit_type.initial_value,message:`Select a commit type`}}get#n(){return this.config.commit_type.options}get#r(){return this.#n.reduce((e,t)=>({...e,[t.value]:{emoji:t.emoji??``,trailer:t.trailer??``}}),{})}get#i(){return this.config.commit_type.max_items}#a(e){r(this.prompt_cache,`commit_type`,e);let t=this.#r;this.commit_state.trailer=t[e].trailer,this.commit_state.type=this.config.commit_type.append_emoji_to_commit&&this.config.commit_type.emoji_commit_position===`Start`?`${t[e].emoji} ${e}`.trim():e}},R=class extends I{async run(){if(!this.#e)return;let{initial_value:e,message:t}=this.#t(),n=await(this.config.commit_scope.autocomplete?x.autocomplete:x.select)({message:t,initialValue:e,maxItems:this.#n,options:this.#r});x.isCancel(n)&&process.exit(0),await this.#a(n)}get#e(){return this.config.commit_scope.enable}#t(){let e=l(this.prompt_cache,`commit_scope`);if(e)return{initial_value:e,message:g(`Commit scope`)};if(this.config.commit_scope.infer_scope_from_branch){let e=f(this.#r,a.git_args);if(e)return{initial_value:e,message:m(`Commit scope`)}}return{initial_value:this.config.commit_scope.initial_value,message:`Select a commit scope`}}get#n(){return this.config.commit_scope.max_items}get#r(){return this.config.commit_scope.options}get#i(){return this.config.commit_scope.custom_scope}async#a(e){r(this.prompt_cache,`commit_scope`,e);let t=e;if(t===`custom`&&this.#i){let e=await x.text({message:`Write a custom scope`,placeholder:``});x.isCancel(e)&&process.exit(0),t=e??``}this.commit_state.scope=t}},z=class extends I{async run(){let{initial_value:e,message:t}=this.#r();if(this.commit_state.ticket=e,this.#t){let n=await x.text({message:t,placeholder:``,initialValue:e});x.isCancel(n)&&process.exit(0),r(this.prompt_cache,`commit_ticket`,n),this.commit_state.ticket=n??``}this.#n&&this.commit_state.ticket&&!this.commit_state.ticket.startsWith(`#`)&&(this.commit_state.ticket=`#`+this.commit_state.ticket)}get#e(){return this.config.check_ticket.infer_ticket}get#t(){return this.config.check_ticket.confirm_ticket}get#n(){return this.config.check_ticket.prepend_hashtag===`Always`}#r(){let e=l(this.prompt_cache,`commit_ticket`);if(e)return{initial_value:e,message:g(`Ticket / issue`)};if(this.#e){let e=h({append_hashtag:this.config.check_ticket.append_hashtag,prepend_hashtag:this.config.check_ticket.prepend_hashtag},a.git_args);if(e)return{initial_value:e,message:m(`Ticket / issue`)}}return{initial_value:this.commit_state.ticket,message:d(`Add ticket / issue`)}}},B=class extends I{async run(){let{initial_value:e,message:t}=this.#e(),n=await x.text({message:t,initialValue:e,placeholder:``,validate:e=>this.#t(e)});x.isCancel(n)&&process.exit(0),this.#o(n??``)}#e(){let e=l(this.prompt_cache,`commit_title`);return e?{initial_value:e,message:g(`Commit title`)}:{initial_value:this.commit_state.title,message:`Write a brief title describing the commit`}}#t(e){if(!e)return`Please enter a title`;if(this.#r(e)>this.#n)return`Exceeded max length. Title max [${this.#n}]`}get#n(){return this.config.commit_title.max_size}#r(e){return v({type:this.commit_state.type,scope:this.commit_state.scope,ticket:this.commit_state.ticket,title:e},{include_ticket:this.config.check_ticket.add_to_title})}get#i(){return this.config.commit_type.options.reduce((e,t)=>({...e,[t.value]:{emoji:t.emoji??``}}),{})}#a(e){return this.config.commit_type.append_emoji_to_commit&&this.config.commit_type.emoji_commit_position===`After-Colon`?`${this.#i[this.commit_state.type]?.emoji??``} ${e}`.trim():e}#o(e){r(this.prompt_cache,`commit_title`,e),this.commit_state.title=s(this.#a(e))}},V=class extends I{async run(){if(!this.#e)return;let{initial_value:e,message:t}=this.#t(),n=await x.text({message:t,initialValue:e,placeholder:``,validate:e=>this.#n(e)});x.isCancel(n)&&process.exit(0),this.#r(n??``)}get#e(){return this.config.commit_body.enable}#t(){let e=l(this.prompt_cache,`commit_body`);return e?{initial_value:e,message:g(`Commit body`)}:{initial_value:``,message:d(`Write a detailed description of the changes`)}}#n(e){if(this.config.commit_body.required&&!e)return`Please enter a description`}#r(e){r(this.prompt_cache,`commit_body`,e),this.commit_state.body=e}},H=class extends I{async run(){if(!this.#e)return;let{initial_values:e,message:t}=this.#r(),n=await x.multiselect({message:t,initialValues:e,options:this.#t,required:!1});x.isCancel(n)&&process.exit(0);let r=this.#a(n),i=await this.#o(r);this.#l(n,r,i)}get#e(){return this.config.commit_footer.enable}get#t(){let e=new Set(this.config.commit_footer.options);return o.filter(t=>e.has(t.value))}get#n(){return this.#t.map(e=>e.value)}#r(){let e=l(this.prompt_cache,`commit_footer`);return e?{initial_values:this.#i(e),message:_(g(`Commit footers`))}:{initial_values:this.config.commit_footer.initial_value.filter(e=>this.#n.includes(e)),message:_(d(`Select optional footers`))}}#i(e){return e.split(`,`).map(e=>e.trim()).filter(e=>this.#n.includes(e))}#a(e){return{includes_breaking_change:e.includes(`breaking-change`),includes_deprecated:e.includes(`deprecated`),includes_closes:e.includes(`closes`),includes_custom:e.includes(`custom`),includes_trailer:e.includes(`trailer`)}}async#o(e){let t={breaking_title:``,breaking_body:``,deprecated_title:``,deprecated_body:``,custom_footer:``};return e.includes_breaking_change&&(t.breaking_title=await this.#s(`Breaking changes: Write a short title / summary`),t.breaking_body=await this.#c(d(`Breaking Changes: Write a description & migration instructions`))),e.includes_deprecated&&(t.deprecated_title=await this.#s(`Deprecated: Write a short title / summary`),t.deprecated_body=await this.#c(d(`Deprecated: Write a description`))),e.includes_custom&&(t.custom_footer=await this.#c(`Write a custom footer`)),t}async#s(e){let t=await x.text({message:e,placeholder:``,validate:e=>{if(!e)return`Please enter a title / summary`}});return x.isCancel(t)&&process.exit(0),t??``}async#c(e){let t=await x.text({message:e,placeholder:``});return x.isCancel(t)&&process.exit(0),t??``}#l(e,t,n){r(this.prompt_cache,`commit_footer`,e.join(`,`)),this.commit_state.breaking_title=n.breaking_title,this.commit_state.breaking_body=n.breaking_body,this.commit_state.deprecates_title=n.deprecated_title,this.commit_state.deprecates_body=n.deprecated_body,this.commit_state.custom_footer=n.custom_footer,this.commit_state.closes=t.includes_closes?`Closes:`:``,t.includes_trailer||(this.commit_state.trailer=``)}};function U({commit_state:e,config:t,colorize:n=!1,escape_quotes:r=!1,include_trailer:i=!1}){let a=``;if(e.type&&(a+=n?M.blue(e.type):e.type),e.scope){let t=n?M.cyan(e.scope):e.scope;a+=`(${t})`}let o=e.ticket,s=t.check_ticket.surround;if(e.ticket&&s){let t=s.charAt(0),n=s.charAt(1);o=`${t}${e.ticket}${n}`}let c=t.check_ticket.title_position===`beginning`;o&&t.check_ticket.add_to_title&&c&&(a=`${n?M.magenta(o):o} ${a}`);let l=t.check_ticket.title_position===`before-colon`;if(o&&t.check_ticket.add_to_title&&l){let r=e.scope||e.type&&!t.check_ticket.surround?` `:``;a+=n?M.magenta(r+o):r+o}e.breaking_title&&t.breaking_change.add_exclamation_to_title&&(a+=n?M.red(`!`):`!`),(e.scope||e.type||o&&l)&&(a+=`: `);let u=t.check_ticket.title_position===`start`,d=t.check_ticket.title_position===`end`;if(o&&t.check_ticket.add_to_title&&u&&(a+=n?M.magenta(o)+` `:o+` `),e.title&&(a+=n?M.reset(e.title):e.title),o&&t.check_ticket.add_to_title&&d&&(a+=` `+(n?M.magenta(o):o)),e.body){let r=e.body;t.commit_body.split_by_period&&(r=r.replace(/\.\s+/g,`.
|
|
3
|
+
`));let i=r.split(`\\n`).map(e=>n?M.reset(e.trim()):e.trim()).join(`
|
|
4
|
+
`);a+=`\n\n${i}`}if(e.breaking_title){let t=n?M.red(`BREAKING CHANGE: ${e.breaking_title}`):`BREAKING CHANGE: ${e.breaking_title}`;a+=`\n\n${t}`}if(e.breaking_body){let t=n?M.red(e.breaking_body):e.breaking_body;a+=`\n\n${t}`}if(e.deprecates_title){let t=n?M.yellow(`DEPRECATED: ${e.deprecates_title}`):`DEPRECATED: ${e.deprecates_title}`;a+=`\n\n${t}`}if(e.deprecates_body){let t=n?M.yellow(e.deprecates_body):e.deprecates_body;a+=`\n\n${t}`}if(e.custom_footer){let t=e.custom_footer.split(`\\n`).map(e=>n?M.reset(e.trim()):e.trim()).join(`
|
|
5
|
+
`);a+=`\n\n${t}`}return e.closes&&e.ticket&&(a+=n?`\n\n${M.reset(e.closes)} ${M.magenta(e.ticket)}`:`\n\n${e.closes} ${e.ticket}`),i&&e.trailer&&(a+=n?`\n\n${M.dim(e.trailer)}`:`\n\n${e.trailer}`),r&&(a=a.replaceAll(`"`,`\\"`).replaceAll("`","\\`")),a}const W=[`M`,`T`,`R`,`D`,`A`,`C`];function G(){let e=``;try{e=j(`git ${a.git_args} status --porcelain`,{stdio:`pipe`}).toString()}catch(e){return x.log.error(M.red(`Failed to git status`+e)),{index:[],work_tree:[]}}let t=e.split(`
|
|
6
|
+
`),n=[],r=[];return t.forEach(e=>{let t=e.trimEnd();if(!t)return;let i=t.substring(2).trim(),a=t.charAt(0).trim(),o=t.charAt(1).trim();(a===`?`||o===`?`)&&n.push(i),W.includes(a)&&r.push(i),W.includes(o)&&n.push(i)}),{index:r,work_tree:n}}function K(e){let t=e.join(` `);if(t)try{j(`git ${a.git_args} add ${t}`,{stdio:`pipe`}).toString(),x.log.success(M.green(`Changes successfully staged`))}catch{x.log.error(M.red(`Failed to stage changes`))}}function q(){G().index.length||(x.log.error(M.red(`no changes added to commit (use "git add" and/or "git commit -a")`)),process.exit(0))}var J=class extends I{async run(){a.interactive||q(),this.#e&&(j(`${this.#o} --edit`,this.#r),process.exit(0)),this.#t&&x.note(U({commit_state:this.commit_state,config:this.config,colorize:!0,escape_quotes:!1,include_trailer:!0}),`Commit Preview`,{format:e=>e}),await this.#c()||(x.log.info(`Exiting without commit`),process.exit(0));try{x.log.info(a.dry_run?y(`Committing changes...`):`Committing changes...`),j(this.#o,a.dry_run?this.#i:this.#r)}catch(e){x.log.error(`Something went wrong when committing: `+e);return}this.#l()}get#e(){return a.interactive&&this.config.confirm_with_editor}get#t(){return this.config.print_commit_output}get#n(){return this.config.confirm_commit}get#r(){return this.config.overrides.shell?{shell:this.config.overrides.shell,stdio:`inherit`}:{stdio:`inherit`}}get#i(){return this.config.overrides.shell?{shell:this.config.overrides.shell,stdio:`pipe`}:{stdio:`pipe`}}get#a(){return this.commit_state.trailer?`--trailer="${this.commit_state.trailer}"`:``}get#o(){return`git ${a.git_args} commit -m "${U({commit_state:this.commit_state,config:this.config,colorize:!1,escape_quotes:!0,include_trailer:!1})}" ${this.#a} ${this.#s}`.trim()}get#s(){return a.dry_run?`--dry-run --porcelain --untracked-files=no`:``}async#c(){if(!a.interactive||!this.#n)return!0;let e=await x.confirm({message:a.dry_run?y(`Confirm Commit?`):`Confirm Commit?`});return x.isCancel(e)&&process.exit(0),e}#l(){x.log.success(`Commit Complete`);let e=this.prompt_cache.get(`username`);this.prompt_cache.clear(),e&&this.prompt_cache.set(`username`,e)}};function Y(e,t){if(!e)return!0;let n=(t.label??String(t.value??``)).toLowerCase(),r=(t.hint??``).toLowerCase(),i=String(t.value).toLowerCase(),a=e.toLowerCase();return n.includes(a)||r.includes(a)||i.includes(a)}function X(e,t){return e===``||t.ctrl===!0&&t.name===`a`}var re=class extends F{_isActionKey(e,t){return super._isActionKey(e,t)||this.multiple&&t.name===`space`&&e!==void 0&&e!==``}constructor(e){super({options:e.options,multiple:!0,filter:e.filter??((e,t)=>Y(e,t)),validate:t=>e.required&&(!Array.isArray(t)||t.length===0)?`Please select at least one item`:e.validate?.(t),initialValue:e.initialValues,signal:e.signal,input:e.input,output:e.output,render(){let t=e.withGuide??D.withGuide,n=`${t?`${P(`gray`,S)}\n`:``}${O(this.state)} ${e.message}\n`,r=this.userInput,i=this.userInputWithCursor,a=this.options,o=this.filteredOptions.length===a.length?``:P(`dim`,` (${this.filteredOptions.length} match${this.filteredOptions.length===1?``:`es`})`);switch(this.state){case`submit`:return`${n}${t?`${P(`gray`,S)} `:``}${P(`dim`,`${this.selectedValues.length} items selected`)}`;case`cancel`:return`${n}${t?`${P(`gray`,S)} `:``}${P([`strikethrough`,`dim`],r)}`;default:{let a=this.state===`error`?`yellow`:`cyan`,s=t?`${P(a,S)} `:``,c=t?P(a,C):``,l=[`${P(`dim`,`↑/↓`)} to navigate`,`${P(`dim`,`Space/Tab:`)} select`,`${P(`dim`,`Ctrl+a:`)} select visible`,`${P(`dim`,`Enter:`)} confirm`,`${P(`dim`,`Type:`)} to search`],u=this.filteredOptions.length===0&&r?[`${s}${P(`yellow`,`No matches found`)}`]:[],d=this.state===`error`?[`${s}${P(`yellow`,this.error)}`]:[],f=[...`${n}${t?P(a,S):``}`.split(`
|
|
7
|
+
`),`${s}${P(`dim`,`Search:`)} ${i}${o}`,...u,...d],p=[`${s}${l.join(` • `)}`,c],m=E({cursor:this.cursor,options:this.filteredOptions,style:(e,t)=>{let n=this.selectedValues.includes(e.value),r=e.label??String(e.value??``),i=e.hint&&this.focusedValue!==void 0&&e.value===this.focusedValue?P(`dim`,` (${e.hint})`):``,a=n?P(`green`,T):P(`dim`,w);return e.disabled?`${P(`gray`,w)} ${P([`strikethrough`,`gray`],r)}`:t?`${a} ${r}${i}`:`${a} ${P(`dim`,r)}`},maxItems:e.maxItems,output:e.output,rowPadding:f.length+p.length});return[...f,...m.map(e=>`${s}${e}`),...p].join(`
|
|
8
|
+
`)}}}}),this.promptOptions=e,this.on(`key`,(e,t)=>{if(t.name===`space`&&!this.isNavigating&&this.focusedValue!==void 0){this.toggleSelected(this.focusedValue),this.#t();return}X(e,t)&&(this.#e(),this.isNavigating=!0,this.#t())})}#e(){let e=this.filteredOptions.filter(e=>!e.disabled).map(e=>e.value);if(!e.length)return;let t=e.every(e=>this.selectedValues.includes(e));this.selectedValues=t?this.selectedValues.filter(t=>!e.includes(t)):[...this.selectedValues,...e.filter(e=>!this.selectedValues.includes(e))]}#t(){let e=this.rl;e?.write(``,{ctrl:!0,name:`e`}),this._cursor=e?.cursor??this.userInput.length}};function ie(e){return new re(e).prompt()}var ae=class extends I{async run(){if(!this.#e)return;let e=G();if(this.#t(e),e.work_tree.length){let t=await this.#r(e.work_tree);t.length&&K(t)}q()}get#e(){return this.config.check_status}#t(e){x.log.step(M.black(M.bgGreen(` Checking Git Status `)));let t=this.#n(e.index,M.green);if(x.log.success(`Changes to be committed:
|
|
9
|
+
`+t),!e.work_tree.length)return;let n=this.#n(e.work_tree,M.red);x.log.error(`Changes not staged for commit:
|
|
10
|
+
`+n)}#n(t,n){return t.reduce((r,i,a)=>n(r+i+e(t,a)),``)}async#r(e){let t=this.config.check_status_autocomplete?await ie({message:`Some files have not been staged, add them now?`,options:e.map(e=>({value:e,label:e})),required:!1}):await x.multiselect({message:te(`Some files have not been staged, add them now?`),options:e.map(e=>({value:e,label:e})),required:!1});return x.isCancel(t)&&process.exit(0),t}};const oe={"better-branch":`Create a branch or worktree from a guided prompt flow.`,"better-commits-init":`Create a .better-commits.jsonc config in this repository.`},se={"--no-interactive":`Run without tui prompts.`,"--dry-run":`Print the commit command without creating a commit.`,"--help":`Show help information and exit.`},ce={"--type":`Set commit type (can be inferred from branch).`,"--scope":`Set commit scope (can be inferred from branch).`,"--title":`Set commit title/description.`,"--body":`Set commit body text.`,"--ticket":`Set ticket / issue (can be inferred from branch).`,"--closes":`Set closes footer (true/false).`,"--trailer":`Set trailer footer value.`,"--breaking-title":`Set breaking-change title footer.`,"--breaking-body":`Set breaking-change body footer.`,"--deprecates-title":`Set deprecates footer title text.`,"--deprecates-body":`Set deprecates footer body text.`,"--custom-footer":`Set a custom footer line.`},Z={"--git-dir":`Set the path to the .git directory.`,"--work-tree":`Set the path to the working tree root.`};function Q(e){return Object.entries(e).map(([e,t])=>{let n=Math.max(2,26-e.length);return` ${e}${` `.repeat(n)}${t}`}).join(`
|
|
11
|
+
`)}function le(e,n){let r=t(),i=`(none)`;try{i=j(`git ${a.git_args} branch --show-current`,{stdio:`pipe`}).toString().trim()||`(none)`}catch{}let o=b(e.commit_type.options,a.git_args)||`Unknown`,s=e.check_ticket.infer_ticket?h({append_hashtag:e.check_ticket.append_hashtag,prepend_hashtag:e.check_ticket.prepend_hashtag},a.git_args)||`Unknown`:`Infer Disabled`,c=e.commit_scope.infer_scope_from_branch?f(e.commit_scope.options,a.git_args)||`Unknown`:`Infer Disabled`,l=e.commit_type.options.map(e=>e.value).join(`, `).trim(),u=e.commit_scope.options.map(e=>e.value).join(`, `).trim(),d=Q(se),p=Q(Z),m=Q(ce),g=Q(oe);console.log(`
|
|
12
|
+
${M.green(` better-commits`)} ${M.gray(`v`+r)}
|
|
13
|
+
|
|
14
|
+
${M.gray(`BRANCH`)}
|
|
15
|
+
${i}
|
|
16
|
+
${M.gray(`Type`)} ${M.blue(o)} ${M.gray(`·`)} ${M.gray(`Scope`)} ${M.cyan(c)} ${M.gray(`·`)} ${M.gray(`Ticket`)} ${M.magenta(s)}
|
|
17
|
+
|
|
18
|
+
${M.gray(`CONFIGURATION`)}
|
|
19
|
+
${n}
|
|
20
|
+
|
|
21
|
+
${M.gray(`Types`)}
|
|
44
22
|
${l}
|
|
45
23
|
|
|
46
|
-
${
|
|
47
|
-
${
|
|
24
|
+
${M.gray(`Scopes`)}
|
|
25
|
+
${u}
|
|
48
26
|
|
|
49
|
-
${
|
|
50
|
-
${
|
|
27
|
+
${M.gray(`CLI FLAGS`)}
|
|
28
|
+
${d}
|
|
51
29
|
|
|
52
|
-
${
|
|
53
|
-
${
|
|
30
|
+
${M.gray(`Commit Flags`)}
|
|
31
|
+
${m}
|
|
54
32
|
|
|
55
|
-
${
|
|
56
|
-
${
|
|
33
|
+
${M.gray(`Git Flags (Advanced)`)}
|
|
34
|
+
${p}
|
|
57
35
|
|
|
58
|
-
${
|
|
59
|
-
${
|
|
36
|
+
${M.gray(`ADDITIONAL COMMANDS`)}
|
|
37
|
+
${g}
|
|
60
38
|
|
|
61
|
-
`)}
|
|
39
|
+
`)}const ue=[ae,L,R,z,B,V,H,J],{config:de,config_source:fe}=n();$(de,fe);async function $(e,n){if(ne(c()),a.version){let e=t();x.log.step(`Better Commits v`+e);return}if(a.help){le(e,n);return}let r=ee(e),o=A(u,{...a.commit_state,type:(a.commit_state.type||r?.type)??``,scope:(a.commit_state.scope||r?.scope)??``,ticket:(a.commit_state.ticket||r?.ticket)??``});if(!a.interactive)try{A(p(e),o)}catch(e){e instanceof k?x.log.error(`Invalid commit input: ${e.message}`):x.log.error(`Failed to validate commit input: ${e}`),process.exit(0)}let s=e.cache_last_value?new N(`better-commits`):i,l=a.interactive?ue:[J];for(let t of l)await new t(e,o,s).run()}export{$ as main};
|
package/dist/init.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import{l as e,p as t,r as n,s as r}from"./utils-CeUs4BjU.js";import*as i from"@clack/prompts";import a from"fs";import o from"picocolors";await s();async function s(){console.clear(),i.intro(`${o.bgCyan(o.black(` better-commits-init `))}`);let s=r(),c=e(s),l=`${s}/${n}`;if(c){let e=await i.confirm({message:`${c.split(`/`).pop()} already exists. Replace with default ${n}?`});if(i.isCancel(e)||!e){i.outro(`Cancelled`);return}}try{a.writeFileSync(l,t)}catch{i.log.error(`${o.red(`Could not determine git root folder. better-commits-init must be used in a git repository`)}`)}i.log.success(`${o.green(`Successfully created ${l.split(`/`).pop()}`)}`),i.outro(`Run ${o.bgBlack(o.white(`better-commits`))} to start the CLI`)}export{s as create_init_config};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,h as t,m as n}from"./utils-CeUs4BjU.js";import*as r from"valibot";import{execSync as i}from"child_process";import a from"picocolors";function o(e,t){let n=e.scope?e.scope.length+2:0,r=e.type?.length??0,i=t.include_ticket?e.ticket?.length??0:0,a=e.title?.length??0;return n+r+i+a}function s(e){return e.map(e=>e===``?`"" (none)`:`"${e}"`).join(`, `)}function c(t){let n=t.commit_type.options.map(e=>e.value),i=t.commit_scope.options.map(e=>e.value);return r.pipe(r.object(e),r.rawCheck(({dataset:e,addIssue:t})=>{if(!e.typed)return;let r=e.value.type?`"${e.value.type}"`:`(empty)`;e.value.type&&!n.includes(e.value.type)&&t({message:`Invalid --type ${r}. Valid types: ${s(n)}.`})}),r.rawCheck(({dataset:e,addIssue:n})=>{if(!e.typed)return;let r=e.value.scope?`"${e.value.scope}"`:`(empty)`;e.value.scope&&!t.commit_scope.custom_scope&&!i.includes(e.value.scope)&&n({message:`Invalid --scope ${r}. Valid scopes: ${s(i)}.`})}),r.rawCheck(({dataset:e,addIssue:t})=>{!e.typed||e.value.title.trim()||t({message:`Missing --title. Provide a non-empty commit title.`})}),r.rawCheck(({dataset:e,addIssue:n})=>{if(!e.typed)return;let r=o(e.value,{include_ticket:t.check_ticket.add_to_title});r>t.commit_title.max_size&&n({message:`Title exceeds max width. Current size is ${r}, max is ${t.commit_title.max_size} (includes type, scope, and ticket when enabled).`})}),r.rawCheck(({dataset:e,addIssue:n})=>{e.typed&&t.commit_body.required&&!e.value.body.trim()&&n({message:`Missing --body. commit_body.required is enabled in config.`})}),r.rawCheck(({dataset:e,addIssue:t})=>{e.typed&&e.value.closes&&!e.value.ticket&&t({message:`Invalid footer values: --closes requires --ticket (for example: --ticket "ABC-123").`})}),r.rawCheck(({dataset:e,addIssue:t})=>{e.typed&&e.value.breaking_body&&!e.value.breaking_title&&t({message:`Invalid breaking change values: --breaking-body requires --breaking-title.`})}),r.rawCheck(({dataset:e,addIssue:t})=>{e.typed&&e.value.deprecates_body&&!e.value.deprecates_title&&t({message:`Invalid deprecation values: --deprecates-body requires --deprecates-title.`})}))}function l(e){let n=e.commit_type.options.map(e=>e.value),i=e.commit_scope.options.map(e=>e.value);return r.pipe(r.object(t),r.rawCheck(({dataset:e,addIssue:t})=>{if(!e.typed)return;let r=e.value.type?`"${e.value.type}"`:`(empty)`;e.value.type&&!n.includes(e.value.type)&&t({message:`Invalid --type ${r}. Valid types: ${s(n)}.`})}),r.rawCheck(({dataset:t,addIssue:n})=>{if(!t.typed)return;let r=t.value.scope?`"${t.value.scope}"`:`(empty)`;t.value.scope&&!e.commit_scope.custom_scope&&!i.includes(t.value.scope)&&n({message:`Invalid --scope ${r}. Valid scopes: ${s(i)}.`})}),r.rawCheck(({dataset:e,addIssue:t})=>{!e.typed||e.value.description.trim()||t({message:`Missing --description. Provide a non-empty branch description.`})}),r.rawCheck(({dataset:t,addIssue:n})=>{if(!t.typed)return;let r=t.value.description.trim();r.length>e.branch_description.max_length&&n({message:`Description exceeds max length. Current length is ${r.length}, max is ${e.branch_description.max_length}.`})}),r.rawCheck(({dataset:t,addIssue:n})=>{t.typed&&e.branch_user.required&&!t.value.user.trim()&&n({message:`Missing --user. branch_user.required is enabled in config.`})}),r.rawCheck(({dataset:t,addIssue:n})=>{t.typed&&e.branch_ticket.required&&!t.value.ticket.trim()&&n({message:`Missing --ticket. branch_ticket.required is enabled in config.`})}),r.rawCheck(({dataset:t,addIssue:n})=>{t.typed&&e.branch_version.required&&!t.value.version.trim()&&n({message:`Missing --branch-version. branch_version.required is enabled in config.`})}))}const u=/\/(\w+-\d+)/,d=/^(\w+-\d+)/,f=/^([A-Z]+-[\[a-zA-Z\]\d]+)_/,p=/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/,m=/\/(\d+)/,h=/^(\d+)/;function g(e){if(n.interactive)return;let t={ticket:``,type:``,scope:``};return e.check_ticket.infer_ticket&&(t.ticket=v({append_hashtag:e.check_ticket.append_hashtag,prepend_hashtag:e.check_ticket.prepend_hashtag},n.git_args)),t.type=_(e.commit_type.options,n.git_args),e.commit_scope.enable&&e.commit_scope.infer_scope_from_branch&&(t.scope=y(e.commit_scope.options,n.git_args)),t}function _(e,t){let n=w(t);return n?x(n,e.map(e=>e.value)):``}function v(e,t){let n=w(t);return n?b(n,e):``}function y(e,t){let n=w(t);return n?C(n,e):``}function b(e,t){let n=[e.match(f),e.match(p),e.match(u),e.match(m),e.match(d),e.match(h)].filter(e=>e!=null).map(e=>e&&e.length>=2?e[1]:``);return!n.length||!n[0]?``:t.append_hashtag||t.prepend_hashtag===`Always`?`#${n[0]}`:n[0]}function x(e,t){return t.find(t=>{let n=RegExp(`^${t}-`),r=RegExp(`-${t}-`),i=RegExp(`${t}/`);return[e.match(n),e.match(r),e.match(i)].filter(e=>e!=null).length>0})??``}function S(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function C(e,t){return t.map(e=>e.value).filter(e=>e&&e!==`custom`).sort((e,t)=>t.length-e.length).find(t=>RegExp(`(?:^|[/_-])${S(t)}(?=$|[/_-])`).test(e))??``}function w(e){try{return i(`git ${e} branch --show-current`,{stdio:`pipe`}).toString().trim()}catch{return``}}function T(e){return`${e} ${a.dim(`· restored from cache`)}`}function E(e){return`${e} ${a.dim(`· inferred from branch`)}`}function D(e){return`${e} ${a.dim(`· optional`)}`}function O(e){return`${e} ${a.dim(`· <space> to select`)}`}function k(e){return`${e} ${a.dim(`· <space> to select · <a> to select all`)}`}function A(e){return`${e} ${a.dim(`· dry run - changes will not be committed`)}`}export{D as a,y as c,l as d,c as f,E as i,v as l,T as n,O as o,o as p,A as r,g as s,k as t,_ as u};
|