better-commits 1.23.2 → 1.23.3
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 +628 -19
- package/dist/chunk-GAAS3VS3.js +922 -0
- package/dist/chunk-H5CLUQIL.js +313 -0
- package/dist/index.js +1122 -41
- package/dist/init.js +44 -1
- package/package.json +12 -4
- 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/init.js
CHANGED
|
@@ -1,2 +1,45 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
CONFIG_FILE_NAME,
|
|
4
|
+
DEFAULT_CONFIG_TEMPLATE,
|
|
5
|
+
get_git_root,
|
|
6
|
+
get_repository_config_path
|
|
7
|
+
} from "./chunk-GAAS3VS3.js";
|
|
8
|
+
|
|
9
|
+
// src/init.ts
|
|
10
|
+
import * as p from "@clack/prompts";
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
import color from "picocolors";
|
|
13
|
+
await create_init_config();
|
|
14
|
+
async function create_init_config() {
|
|
15
|
+
console.clear();
|
|
16
|
+
p.intro(`${color.bgCyan(color.black(" better-commits-init "))}`);
|
|
17
|
+
const root = get_git_root();
|
|
18
|
+
const existing_config_path = get_repository_config_path(root);
|
|
19
|
+
const root_path = `${root}/${CONFIG_FILE_NAME}`;
|
|
20
|
+
if (existing_config_path) {
|
|
21
|
+
const should_overwrite = await p.confirm({
|
|
22
|
+
message: `${existing_config_path.split("/").pop()} already exists. Replace with default ${CONFIG_FILE_NAME}?`
|
|
23
|
+
});
|
|
24
|
+
if (p.isCancel(should_overwrite) || !should_overwrite) {
|
|
25
|
+
p.outro("Cancelled");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
fs.writeFileSync(root_path, DEFAULT_CONFIG_TEMPLATE);
|
|
31
|
+
} catch {
|
|
32
|
+
p.log.error(
|
|
33
|
+
`${color.red("Could not determine git root folder. better-commits-init must be used in a git repository")}`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
p.log.success(
|
|
37
|
+
`${color.green(`Successfully created ${root_path.split("/").pop()}`)}`
|
|
38
|
+
);
|
|
39
|
+
p.outro(
|
|
40
|
+
`Run ${color.bgBlack(color.white("better-commits"))} to start the CLI`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
create_init_config
|
|
45
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-commits",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.23.
|
|
4
|
+
"version": "1.23.3",
|
|
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",
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
"commit"
|
|
14
14
|
],
|
|
15
15
|
"main": "dist/index.js",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=20"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"readme.md"
|
|
23
|
+
],
|
|
16
24
|
"bin": {
|
|
17
25
|
"better-commits-init": "./dist/init.js",
|
|
18
26
|
"better-commits": "./dist/index.js",
|
|
@@ -29,7 +37,7 @@
|
|
|
29
37
|
"@bomb.sh/args": "^0.3.1",
|
|
30
38
|
"@clack/core": "^1.2.0",
|
|
31
39
|
"@clack/prompts": "^1.2.0",
|
|
32
|
-
"configstore": "^
|
|
40
|
+
"configstore": "^8.0.0",
|
|
33
41
|
"jsonc-parser": "^3.3.1",
|
|
34
42
|
"picocolors": "^1.0.0",
|
|
35
43
|
"valibot": "^1.3.1"
|
|
@@ -44,12 +52,12 @@
|
|
|
44
52
|
},
|
|
45
53
|
"devDependencies": {
|
|
46
54
|
"@semantic-release/git": "^10.0.1",
|
|
47
|
-
"@semantic-release/npm": "^13.1.
|
|
55
|
+
"@semantic-release/npm": "^13.1.5",
|
|
48
56
|
"@types/configstore": "^6.0.0",
|
|
49
57
|
"@types/node": "^24.10.1",
|
|
50
58
|
"jiti": "^1.17.0",
|
|
51
59
|
"prettier": "3.2.5",
|
|
52
|
-
"semantic-release": "^25.0.
|
|
60
|
+
"semantic-release": "^25.0.3",
|
|
53
61
|
"tsup": "^8.0.2",
|
|
54
62
|
"tsx": "^3.12.3",
|
|
55
63
|
"typescript": "^5.4.5",
|
package/readme.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|

|
|
4
4
|
|
|
5
5
|
[](https://github.com/Everduin94/better-commits)
|
|
6
|
-
[](https://
|
|
6
|
+
[](https://npmx.dev/package/better-commits)
|
|
7
7
|
[](https://discord.gg/grHVnZwYup)
|
|
8
8
|
|
|
9
9
|
</h3>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
A CLI for writing better commits, following the conventional commits specification.
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
<video src="https://github.com/Everduin94/better-commits/assets/14320878/8fb15d46-17c4-4e5d-80d9-79abe0a2a00a"></video>
|
|
15
|
+
<video src="https://github.com/Everduin94/better-commits/assets/14320878/8fb15d46-17c4-4e5d-80d9-79abe0a2a00a"></video>
|
|
16
16
|
|
|
17
17
|
## ✨ Features
|
|
18
18
|
|
|
@@ -36,6 +36,8 @@ As a side-effect of formatting messages
|
|
|
36
36
|
|
|
37
37
|
## 📦 Installation
|
|
38
38
|
|
|
39
|
+
> Requires Node.js 20 or newer.
|
|
40
|
+
|
|
39
41
|
```sh
|
|
40
42
|
npm install -g better-commits
|
|
41
43
|
```
|
package/.better-commits.json
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"commit_type": {
|
|
3
|
-
"append_emoji_to_label": true,
|
|
4
|
-
"append_emoji_to_commit": false
|
|
5
|
-
},
|
|
6
|
-
"commit_body": {
|
|
7
|
-
"split_by_period": true
|
|
8
|
-
},
|
|
9
|
-
"commit_scope": {
|
|
10
|
-
"enable": true,
|
|
11
|
-
"initial_value": "commit",
|
|
12
|
-
"options": [
|
|
13
|
-
{
|
|
14
|
-
"value": "commit",
|
|
15
|
-
"label": "commit"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"value": "branch",
|
|
19
|
-
"label": "branch"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"value": "init",
|
|
23
|
-
"label": "init"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"value": "util",
|
|
27
|
-
"label": "util"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"value": "build",
|
|
31
|
-
"label": "build"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
"value": "help",
|
|
35
|
-
"label": "help"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"value": "",
|
|
39
|
-
"label": "none"
|
|
40
|
-
}
|
|
41
|
-
]
|
|
42
|
-
},
|
|
43
|
-
"check_ticket": {
|
|
44
|
-
"prepend_hashtag": "Always"
|
|
45
|
-
},
|
|
46
|
-
"branch_pre_commands": [
|
|
47
|
-
"git stash",
|
|
48
|
-
"git checkout main",
|
|
49
|
-
"git pull -r origin main",
|
|
50
|
-
"npm install"
|
|
51
|
-
]
|
|
52
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
name: Publish to NPM
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
publish:
|
|
10
|
-
name: Publish
|
|
11
|
-
runs-on: ubuntu-latest
|
|
12
|
-
permissions:
|
|
13
|
-
contents: write
|
|
14
|
-
issues: write
|
|
15
|
-
pull-requests: write
|
|
16
|
-
id-token: write
|
|
17
|
-
steps:
|
|
18
|
-
- name: Checkout
|
|
19
|
-
uses: actions/checkout@v4
|
|
20
|
-
with:
|
|
21
|
-
fetch-depth: 0
|
|
22
|
-
- name: Setup Node.js
|
|
23
|
-
uses: actions/setup-node@v4
|
|
24
|
-
with:
|
|
25
|
-
node-version: "lts/*"
|
|
26
|
-
registry-url: "https://registry.npmjs.org"
|
|
27
|
-
- name: Install dependencies
|
|
28
|
-
run: npm ci
|
|
29
|
-
- name: Build package
|
|
30
|
-
run: npm run build
|
|
31
|
-
- name: Release
|
|
32
|
-
env:
|
|
33
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
34
|
-
run: npx semantic-release
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
name: Test
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
push:
|
|
6
|
-
branches:
|
|
7
|
-
- main
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
test:
|
|
11
|
-
name: npm test
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
steps:
|
|
14
|
-
- name: Checkout
|
|
15
|
-
uses: actions/checkout@v4
|
|
16
|
-
|
|
17
|
-
- name: Setup Node.js
|
|
18
|
-
uses: actions/setup-node@v4
|
|
19
|
-
with:
|
|
20
|
-
node-version: "lts/*"
|
|
21
|
-
cache: npm
|
|
22
|
-
|
|
23
|
-
- name: Install dependencies
|
|
24
|
-
run: npm ci
|
|
25
|
-
|
|
26
|
-
- name: Run tests
|
|
27
|
-
run: npm run test
|
package/.prettierignore
DELETED
package/.prettierrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
package/dist/chunk-43H72S6V.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as _,b as u,d as l,f as p}from"./chunk-B7AGSPP3.js";import*as s from"valibot";function g(t,n){let r=t.scope?t.scope.length+2:0,e=t.type?.length??0,i=n.include_ticket?t.ticket?.length??0:0,o=t.title?.length??0;return r+e+i+o}function a(t){return t.map(r=>r===""?'"" (none)':`"${r}"`).join(", ")}function G(t){let n=t.commit_type.options.map(e=>e.value),r=t.commit_scope.options.map(e=>e.value);return s.pipe(s.object(u),s.rawCheck(({dataset:e,addIssue:i})=>{if(!e.typed)return;let o=e.value.type?`"${e.value.type}"`:"(empty)";e.value.type&&!n.includes(e.value.type)&&i({message:`Invalid --type ${o}. Valid types: ${a(n)}.`})}),s.rawCheck(({dataset:e,addIssue:i})=>{if(!e.typed)return;let o=e.value.scope?`"${e.value.scope}"`:"(empty)";e.value.scope&&!t.commit_scope.custom_scope&&!r.includes(e.value.scope)&&i({message:`Invalid --scope ${o}. Valid scopes: ${a(r)}.`})}),s.rawCheck(({dataset:e,addIssue:i})=>{!e.typed||e.value.title.trim()||i({message:"Missing --title. Provide a non-empty commit title."})}),s.rawCheck(({dataset:e,addIssue:i})=>{if(!e.typed)return;let o=g(e.value,{include_ticket:t.check_ticket.add_to_title});o>t.commit_title.max_size&&i({message:`Title exceeds max width. Current size is ${o}, max is ${t.commit_title.max_size} (includes type, scope, and ticket when enabled).`})}),s.rawCheck(({dataset:e,addIssue:i})=>{e.typed&&t.commit_body.required&&!e.value.body.trim()&&i({message:"Missing --body. commit_body.required is enabled in config."})}),s.rawCheck(({dataset:e,addIssue:i})=>{e.typed&&e.value.closes&&!e.value.ticket&&i({message:'Invalid footer values: --closes requires --ticket (for example: --ticket "ABC-123").'})}),s.rawCheck(({dataset:e,addIssue:i})=>{e.typed&&e.value.breaking_body&&!e.value.breaking_title&&i({message:"Invalid breaking change values: --breaking-body requires --breaking-title."})}),s.rawCheck(({dataset:e,addIssue:i})=>{e.typed&&e.value.deprecates_body&&!e.value.deprecates_title&&i({message:"Invalid deprecation values: --deprecates-body requires --deprecates-title."})}))}function N(t){let n=t.commit_type.options.map(e=>e.value),r=t.commit_scope.options.map(e=>e.value);return s.pipe(s.object(l),s.rawCheck(({dataset:e,addIssue:i})=>{if(!e.typed)return;let o=e.value.type?`"${e.value.type}"`:"(empty)";e.value.type&&!n.includes(e.value.type)&&i({message:`Invalid --type ${o}. Valid types: ${a(n)}.`})}),s.rawCheck(({dataset:e,addIssue:i})=>{if(!e.typed)return;let o=e.value.scope?`"${e.value.scope}"`:"(empty)";e.value.scope&&!t.commit_scope.custom_scope&&!r.includes(e.value.scope)&&i({message:`Invalid --scope ${o}. Valid scopes: ${a(r)}.`})}),s.rawCheck(({dataset:e,addIssue:i})=>{!e.typed||e.value.description.trim()||i({message:"Missing --description. Provide a non-empty branch description."})}),s.rawCheck(({dataset:e,addIssue:i})=>{if(!e.typed)return;let o=e.value.description.trim();o.length>t.branch_description.max_length&&i({message:`Description exceeds max length. Current length is ${o.length}, max is ${t.branch_description.max_length}.`})}),s.rawCheck(({dataset:e,addIssue:i})=>{e.typed&&t.branch_user.required&&!e.value.user.trim()&&i({message:"Missing --user. branch_user.required is enabled in config."})}),s.rawCheck(({dataset:e,addIssue:i})=>{e.typed&&t.branch_ticket.required&&!e.value.ticket.trim()&&i({message:"Missing --ticket. branch_ticket.required is enabled in config."})}),s.rawCheck(({dataset:e,addIssue:i})=>{e.typed&&t.branch_version.required&&!e.value.version.trim()&&i({message:"Missing --branch-version. branch_version.required is enabled in config."})}))}import{execSync as h}from"child_process";var v=/\/(\w+-\d+)/,y=/^(\w+-\d+)/,k=/^([A-Z]+-[\[a-zA-Z\]\d]+)_/,b=/\/([A-Z]+-[\[a-zA-Z\]\d]+)_/,$=/\/(\d+)/,C=/^(\d+)/;function V(t){if(p.interactive)return;let n={ticket:"",type:"",scope:""};if(t.check_ticket.infer_ticket){let e=w({append_hashtag:t.check_ticket.append_hashtag,prepend_hashtag:t.check_ticket.prepend_hashtag},p.git_args);n.ticket=e}let r=x(t.commit_type.options,p.git_args);if(n.type=r,t.commit_scope.enable&&t.commit_scope.infer_scope_from_branch){let e=E(t.commit_scope.options,p.git_args);n.scope=e}return n}function x(t,n){let r=m(n);return r?T(r,t.map(e=>e.value)):""}function w(t,n){let r=m(n);return r?S(r,t):""}function E(t,n){let r=m(n);return r?z(r,t):""}function S(t,n){let r=[t.match(k),t.match(b),t.match(v),t.match($),t.match(y),t.match(C)].filter(e=>e!=null).map(e=>e&&e.length>=2?e[1]:"");return!r.length||!r[0]?"":n.append_hashtag||n.prepend_hashtag==="Always"?`#${r[0]}`:r[0]}function T(t,n){return n.find(e=>{let i=new RegExp(`^${e}-`),o=new RegExp(`-${e}-`),d=new RegExp(`${e}/`);return[t.match(i),t.match(o),t.match(d)].filter(f=>f!=null).length>0})??""}function A(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function z(t,n){return n.map(i=>i.value).filter(i=>i&&i!==_).sort((i,o)=>o.length-i.length).find(i=>new RegExp(`(?:^|[/_-])${A(i)}(?=$|[/_-])`).test(t))??""}function m(t){try{return h(`git ${t} branch --show-current`,{stdio:"pipe"}).toString().trim()}catch{return""}}import c from"picocolors";function D(t){return`${t} ${c.dim("\xB7 restored from cache")}`}function L(t){return`${t} ${c.dim("\xB7 inferred from branch")}`}function B(t){return`${t} ${c.dim("\xB7 optional")}`}function K(t){return`${t} ${c.dim("\xB7 <space> to select")}`}function Y(t){return`${t} ${c.dim("\xB7 <space> to select \xB7 <a> to select all")}`}function F(t){return`${t} ${c.dim("\xB7 dry run - changes will not be committed")}`}export{g as a,G as b,N as c,V as d,x as e,w as f,E as g,D as h,L as i,B as j,K as k,Y as l,F as m};
|
package/dist/chunk-B7AGSPP3.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import*as e from"valibot";import*as s from"valibot";var c="custom",d=["closes","trailer","breaking-change","deprecated","custom"],m=s.picklist(["branch","worktree"]),_=s.picklist(["closes","trailer","breaking-change","deprecated","custom"]),C=s.picklist(["user","version","type","scope","ticket","description"]),K=s.picklist(["branch_user","branch_version","branch_type","branch_scope","branch_ticket","branch_description"]),y=["user","version","type","ticket","scope","description"],k=[{value:"app",label:"app"},{value:"shared",label:"shared"},{value:"server",label:"server"},{value:"tools",label:"tools"},{value:"",label:"none"}],O=[{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"}];var N=e.pipe(e.optional(e.object({enable:e.optional(e.boolean(),!0),initial_value:e.optional(e.string(),"feat"),max_items:e.optional(e.pipe(e.number(),e.minValue(1)),20),infer_type_from_branch:e.optional(e.boolean(),!0),append_emoji_to_label:e.optional(e.boolean(),!1),append_emoji_to_commit:e.optional(e.boolean(),!1),emoji_commit_position:e.optional(e.picklist(["Start","After-Colon"]),"Start"),autocomplete:e.optional(e.boolean(),!0),options:e.optional(e.array(e.object({value:e.string(),label:e.optional(e.string()),hint:e.optional(e.string()),emoji:e.optional(e.pipe(e.string(),e.emoji())),trailer:e.optional(e.string())})),O)}),{}),e.rawCheck(({dataset:o,addIssue:t})=>{o.typed&&!o.value.options.some(r=>r.value===o.value.initial_value)&&t({message:`Type: initial_value "${o.value.initial_value}" must exist in options`})}),e.transform(o=>({...o,options:o.options.map(t=>({...t,label:t.emoji&&o.append_emoji_to_label?`${t.emoji} ${t.label}`:t.label}))}))),R=e.pipe(e.optional(e.object({enable:e.optional(e.boolean(),!0),custom_scope:e.optional(e.boolean(),!1),max_items:e.optional(e.pipe(e.number(),e.minValue(1)),20),initial_value:e.optional(e.string(),"app"),infer_scope_from_branch:e.optional(e.boolean(),!0),autocomplete:e.optional(e.boolean(),!0),options:e.optional(e.array(e.object({value:e.string(),label:e.optional(e.string()),hint:e.optional(e.string())})),k)}),{}),e.rawCheck(({dataset:o,addIssue:t})=>{if(!o.typed)return;let r=o.value.options.map(n=>n.value);o.value.custom_scope&&r.push(c),r.includes(o.value.initial_value)||t({message:`Scope: initial_value "${o.value.initial_value}" must exist in options`})}),e.transform(o=>{let t=o.options.map(r=>r.value);return o.custom_scope&&!t.includes(c)?{...o,options:[...o.options,{label:c,value:c,hint:"Write a custom scope"}]}:o})),f=e.object({check_status:e.optional(e.boolean(),!0),check_status_autocomplete:e.optional(e.boolean(),!0),commit_type:N,commit_scope:R,check_ticket:e.optional(e.object({infer_ticket:e.optional(e.boolean(),!0),confirm_ticket:e.optional(e.boolean(),!0),add_to_title:e.optional(e.boolean(),!0),append_hashtag:e.optional(e.boolean(),!1),prepend_hashtag:e.optional(e.picklist(["Never","Always","Prompt"]),"Never"),surround:e.optional(e.picklist(["","()","[]","{}"]),""),title_position:e.optional(e.picklist(["start","end","before-colon","beginning"]),"start")}),{}),commit_title:e.optional(e.object({max_size:e.optional(e.pipe(e.number(),e.minValue(1)),70)}),{}),commit_body:e.optional(e.object({enable:e.optional(e.boolean(),!0),required:e.optional(e.boolean(),!1),split_by_period:e.optional(e.boolean(),!1)}),{}),commit_footer:e.optional(e.object({enable:e.optional(e.boolean(),!0),initial_value:e.optional(e.array(_),[]),options:e.optional(e.array(_),d)}),{}),breaking_change:e.optional(e.object({add_exclamation_to_title:e.optional(e.boolean(),!0)}),{}),cache_last_value:e.optional(e.boolean(),!0),confirm_with_editor:e.optional(e.boolean(),!1),confirm_commit:e.optional(e.boolean(),!0),print_commit_output:e.optional(e.boolean(),!0),branch_pre_commands:e.optional(e.array(e.string()),[]),branch_post_commands:e.optional(e.array(e.string()),[]),worktree_pre_commands:e.optional(e.array(e.string()),[]),worktree_post_commands:e.optional(e.array(e.string()),[]),branch_user:e.optional(e.object({enable:e.optional(e.boolean(),!0),required:e.optional(e.boolean(),!1),separator:e.optional(e.picklist(["/","-","_"]),"/")}),{}),branch_type:e.optional(e.object({enable:e.optional(e.boolean(),!0),separator:e.optional(e.picklist(["/","-","_"]),"/"),autocomplete:e.optional(e.boolean(),!0)}),{}),branch_scope:e.optional(e.object({enable:e.optional(e.boolean(),!0),separator:e.optional(e.picklist(["/","-","_"]),"-"),autocomplete:e.optional(e.boolean(),!0)}),{}),branch_version:e.optional(e.object({enable:e.optional(e.boolean(),!1),required:e.optional(e.boolean(),!1),separator:e.optional(e.picklist(["/","-","_"]),"/")}),{}),branch_ticket:e.optional(e.object({enable:e.optional(e.boolean(),!0),required:e.optional(e.boolean(),!1),separator:e.optional(e.picklist(["/","-","_"]),"-")}),{}),branch_description:e.optional(e.object({max_length:e.optional(e.pipe(e.number(),e.minValue(1)),70),separator:e.optional(e.picklist(["","/","-","_"]),"")}),{}),branch_action_default:e.optional(m,"branch"),branch_order:e.optional(e.array(C),y),enable_worktrees:e.optional(e.boolean(),!0),worktrees:e.optional(e.object({enable:e.optional(e.boolean(),!0),base_path:e.optional(e.string(),".."),folder_template:e.optional(e.string(),"{{repo_name}}-{{ticket}}-{{branch_description}}")}),{}),overrides:e.optional(e.object({shell:e.optional(e.string())}),{})}),P={type:e.optional(e.string(),""),scope:e.optional(e.string(),""),title:e.optional(e.string(),""),body:e.optional(e.string(),""),closes:e.optional(e.string(),""),ticket:e.optional(e.string(),""),breaking_title:e.optional(e.string(),""),breaking_body:e.optional(e.string(),""),deprecates:e.optional(e.string(),""),deprecates_title:e.optional(e.string(),""),deprecates_body:e.optional(e.string(),""),custom_footer:e.optional(e.string(),""),trailer:e.optional(e.string(),"")},X=e.optional(e.object(P),{}),F={user:e.optional(e.string(),""),type:e.optional(e.string(),""),scope:e.optional(e.string(),""),ticket:e.optional(e.string(),""),description:e.optional(e.string(),""),version:e.optional(e.string(),""),checkout:e.optional(m,"branch")},Z=e.optional(e.object(F),{});import{parse as L}from"@bomb.sh/args";var S=["type","scope","title","body","ticket","closes","trailer","breaking-title","breaking-body","deprecates-title","deprecates-body","custom-footer"],D=["git-dir","work-tree"],$=["interactive","dry-run","help","version"],g=class{#e;constructor(t){this.#e=t}get git_args(){return this.#e.git_args}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 commit_state(){return this.#e.commit_state}},b=new g(M(process.argv.slice(2)));function M(o){let t=L(o,{alias:{h:"help",v:"version"},boolean:$,string:[...S,...D]}),r={};return S.forEach(n=>{let a=t[n],l=V(n,a);if(l!==void 0){let u=n.replace("-","_");r[u]=l}}),{help:t.help===!0,version:t.version===!0,git_args:B(t["git-dir"],t["work-tree"]),no_interactive:t.interactive===!1,dry_run:t["dry-run"]===!0,commit_state:r}}function V(o,t){if(t===void 0)return;if(o!=="closes")return t;let r=t.trim().toLowerCase();if(r!=="false"&&(t===""||r))return"Closes:"}function B(o,t){return`${o?`--git-dir=${o}`:""} ${t?`--work-tree=${t}`:""}`.trim()}var x=`{
|
|
2
|
-
// Run interactive \`git status\` before composing a commit
|
|
3
|
-
"check_status": true,
|
|
4
|
-
"check_status_autocomplete": true,
|
|
5
|
-
|
|
6
|
-
/* COMMIT FIELDS */
|
|
7
|
-
"commit_type": {
|
|
8
|
-
"enable": true,
|
|
9
|
-
|
|
10
|
-
// Default selected type from options
|
|
11
|
-
"initial_value": "feat",
|
|
12
|
-
|
|
13
|
-
"max_items": 20,
|
|
14
|
-
|
|
15
|
-
// Infer type from the current branch name: user/TYPE/my-branch
|
|
16
|
-
"infer_type_from_branch": true,
|
|
17
|
-
|
|
18
|
-
// Include emoji in prompt label
|
|
19
|
-
"append_emoji_to_label": false,
|
|
20
|
-
|
|
21
|
-
// Include emoji from prompt label in commit message
|
|
22
|
-
"append_emoji_to_commit": false,
|
|
23
|
-
|
|
24
|
-
// "Start" | "After-Colon"
|
|
25
|
-
"emoji_commit_position": "Start",
|
|
26
|
-
|
|
27
|
-
"autocomplete": true,
|
|
28
|
-
|
|
29
|
-
"options": [
|
|
30
|
-
{
|
|
31
|
-
"value": "feat",
|
|
32
|
-
"label": "feat",
|
|
33
|
-
"hint": "A new feature",
|
|
34
|
-
"emoji": "\u{1F31F}",
|
|
35
|
-
"trailer": "Changelog: feature"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"value": "fix",
|
|
39
|
-
"label": "fix",
|
|
40
|
-
"hint": "A bug fix",
|
|
41
|
-
"emoji": "\u{1F41B}",
|
|
42
|
-
"trailer": "Changelog: fix"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"value": "docs",
|
|
46
|
-
"label": "docs",
|
|
47
|
-
"hint": "Documentation only changes",
|
|
48
|
-
"emoji": "\u{1F4DA}",
|
|
49
|
-
"trailer": "Changelog: documentation"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
"value": "refactor",
|
|
53
|
-
"label": "refactor",
|
|
54
|
-
"hint": "A code change that neither fixes a bug nor adds a feature",
|
|
55
|
-
"emoji": "\u{1F528}",
|
|
56
|
-
"trailer": "Changelog: refactor"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"value": "perf",
|
|
60
|
-
"label": "perf",
|
|
61
|
-
"hint": "A code change that improves performance",
|
|
62
|
-
"emoji": "\u{1F680}",
|
|
63
|
-
"trailer": "Changelog: performance"
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"value": "test",
|
|
67
|
-
"label": "test",
|
|
68
|
-
"hint": "Adding missing tests or correcting existing tests",
|
|
69
|
-
"emoji": "\u{1F6A8}",
|
|
70
|
-
"trailer": "Changelog: test"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
"value": "build",
|
|
74
|
-
"label": "build",
|
|
75
|
-
"hint": "Changes that affect the build system or external dependencies",
|
|
76
|
-
"emoji": "\u{1F6A7}",
|
|
77
|
-
"trailer": "Changelog: build"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
"value": "ci",
|
|
81
|
-
"label": "ci",
|
|
82
|
-
"hint": "Changes to our CI configuration files and scripts",
|
|
83
|
-
"emoji": "\u{1F916}",
|
|
84
|
-
"trailer": "Changelog: ci"
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"value": "chore",
|
|
88
|
-
"label": "chore",
|
|
89
|
-
"hint": "Other changes that do not modify src or test files",
|
|
90
|
-
"emoji": "\u{1F9F9}",
|
|
91
|
-
"trailer": "Changelog: chore"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
"value": "",
|
|
95
|
-
"label": "none"
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
"commit_scope": {
|
|
101
|
-
"enable": true,
|
|
102
|
-
|
|
103
|
-
// If true, users can type a scope not listed in options
|
|
104
|
-
"custom_scope": false,
|
|
105
|
-
|
|
106
|
-
// Default selected scope from options
|
|
107
|
-
"initial_value": "app",
|
|
108
|
-
|
|
109
|
-
// Infer scope from the current branch name: user/type/ticket-SCOPE-my-branch
|
|
110
|
-
"infer_scope_from_branch": true,
|
|
111
|
-
|
|
112
|
-
"max_items": 20,
|
|
113
|
-
"autocomplete": true,
|
|
114
|
-
"options": [
|
|
115
|
-
{ "value": "app", "label": "app" },
|
|
116
|
-
{ "value": "shared", "label": "shared" },
|
|
117
|
-
{ "value": "server", "label": "server" },
|
|
118
|
-
{ "value": "tools", "label": "tools" },
|
|
119
|
-
{ "value": "", "label": "none" }
|
|
120
|
-
]
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
"check_ticket": {
|
|
124
|
-
// Infer ticket / issue from the branch name - user/type/TICKET-my-branch
|
|
125
|
-
"infer_ticket": true,
|
|
126
|
-
|
|
127
|
-
// Prompt for confirmation / edit before using an inferred ticket
|
|
128
|
-
"confirm_ticket": true,
|
|
129
|
-
|
|
130
|
-
// Add the ticket to the commit title - feat(app): TICKET my commit title
|
|
131
|
-
"add_to_title": true,
|
|
132
|
-
|
|
133
|
-
// Deprecated, prefer \`prepend_hashtag\`
|
|
134
|
-
"append_hashtag": false,
|
|
135
|
-
|
|
136
|
-
// "Never" | "Prompt" | "Always" - 12345 --> #12345
|
|
137
|
-
"prepend_hashtag": "Never",
|
|
138
|
-
|
|
139
|
-
// Wrap the ticket in the commit title: "" | "[]" | "()" | "{}"
|
|
140
|
-
"surround": "",
|
|
141
|
-
|
|
142
|
-
// "start" | "end" | "before-colon" | "beginning"
|
|
143
|
-
"title_position": "start"
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
"commit_title": {
|
|
147
|
-
// Includes total size of title + type + scope + ticket
|
|
148
|
-
"max_size": 70
|
|
149
|
-
},
|
|
150
|
-
|
|
151
|
-
"commit_body": {
|
|
152
|
-
"enable": true,
|
|
153
|
-
"required": false,
|
|
154
|
-
|
|
155
|
-
// Split sentences into multiple lines automatically
|
|
156
|
-
"split_by_period": false
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
"commit_footer": {
|
|
160
|
-
"enable": true,
|
|
161
|
-
"initial_value": [],
|
|
162
|
-
|
|
163
|
-
// "closes", "trailer", "breaking-change", "deprecated", "custom"
|
|
164
|
-
"options": ["closes", "trailer", "breaking-change", "deprecated", "custom"]
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
"breaking_change": {
|
|
168
|
-
// Adds \`!\` to the commit title when a breaking change is selected
|
|
169
|
-
"add_exclamation_to_title": true
|
|
170
|
-
},
|
|
171
|
-
|
|
172
|
-
// Confirm / edit with $GIT_EDITOR or $EDITOR
|
|
173
|
-
"confirm_with_editor": false,
|
|
174
|
-
|
|
175
|
-
// Show a final confirmation prompt before running git commit
|
|
176
|
-
"confirm_commit": true,
|
|
177
|
-
|
|
178
|
-
// Reuse the last known value from a previous canceled or failed commit
|
|
179
|
-
"cache_last_value": true,
|
|
180
|
-
|
|
181
|
-
// Pretty-print the final commit preview before execution
|
|
182
|
-
"print_commit_output": true,
|
|
183
|
-
|
|
184
|
-
/* BRANCH FIELDS */
|
|
185
|
-
// Optional shell commands to run before / after creating branches or worktrees
|
|
186
|
-
"branch_pre_commands": [],
|
|
187
|
-
"branch_post_commands": [],
|
|
188
|
-
"worktree_pre_commands": [],
|
|
189
|
-
"worktree_post_commands": [],
|
|
190
|
-
|
|
191
|
-
"branch_user": {
|
|
192
|
-
"enable": true,
|
|
193
|
-
"required": false,
|
|
194
|
-
|
|
195
|
-
// "/" | "-" | "_" - user/feat/my-branch
|
|
196
|
-
"separator": "/"
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
"branch_type": {
|
|
200
|
-
"enable": true,
|
|
201
|
-
"separator": "/",
|
|
202
|
-
"autocomplete": true,
|
|
203
|
-
},
|
|
204
|
-
|
|
205
|
-
"branch_scope": {
|
|
206
|
-
"enable": true,
|
|
207
|
-
"separator": "-",
|
|
208
|
-
"autocomplete": true,
|
|
209
|
-
},
|
|
210
|
-
|
|
211
|
-
"branch_ticket": {
|
|
212
|
-
"enable": true,
|
|
213
|
-
"required": false,
|
|
214
|
-
"separator": "-"
|
|
215
|
-
},
|
|
216
|
-
|
|
217
|
-
"branch_version": {
|
|
218
|
-
"enable": false,
|
|
219
|
-
"required": false,
|
|
220
|
-
"separator": "/"
|
|
221
|
-
},
|
|
222
|
-
|
|
223
|
-
"branch_description": {
|
|
224
|
-
// Maximum length for the description segment of the branch name
|
|
225
|
-
"max_length": 70,
|
|
226
|
-
|
|
227
|
-
// Allowed values: "" | "/" | "-" | "_"
|
|
228
|
-
"separator": ""
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
// "branch" | "worktree"
|
|
232
|
-
"branch_action_default": "branch",
|
|
233
|
-
|
|
234
|
-
// Order of values in the final branch name
|
|
235
|
-
"branch_order": ["user", "version", "type", "ticket", "scope", "description"],
|
|
236
|
-
|
|
237
|
-
// Deprecated, prefer \`worktrees.enable\`
|
|
238
|
-
"enable_worktrees": true,
|
|
239
|
-
|
|
240
|
-
"worktrees": {
|
|
241
|
-
// If false, always create a branch instead of prompting for a worktree
|
|
242
|
-
"enable": true,
|
|
243
|
-
|
|
244
|
-
// Directory where worktrees are created
|
|
245
|
-
"base_path": "..",
|
|
246
|
-
|
|
247
|
-
// Available template variables include:
|
|
248
|
-
// {{repo_name}}, {{branch_description}}, {{user}}, {{type}}, {{scope}}, {{ticket}}, {{version}}
|
|
249
|
-
"folder_template": "{{repo_name}}-{{ticket}}-{{branch_description}}"
|
|
250
|
-
},
|
|
251
|
-
|
|
252
|
-
/* OTHER FIELDS */
|
|
253
|
-
"overrides": {
|
|
254
|
-
// Useful on Windows or for shells with different multiline behavior
|
|
255
|
-
"shell": "/bin/sh"
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
`;import*as i from"@clack/prompts";import{execSync as H}from"child_process";import p from"fs";import{homedir as I}from"os";import{parse as U}from"jsonc-parser";import h from"picocolors";import{ValiError as G,parse as A}from"valibot";var E=[".better-commits.jsonc",".better-commits.json"],j=E[0],_e=[{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"}],fe=[{value:"branch",label:"Branch"},{value:"worktree",label:"Worktree"}],ge={get:()=>"",set:(o,t)=>{},clear:()=>{}};function be(o=" better-commits ",t=b.git_args){console.clear(),i.intro(`${h.bgCyan(h.black(o))}`);let r=null,n=W();p.existsSync(n)&&(r=T(n));let a=z(t),l=Y(a);if(l){i.log.step("Reading from Repository Config");let v=T(l);return{config:r?{...v,overrides:r.overrides.shell?r.overrides:v.overrides,confirm_with_editor:r.confirm_with_editor,cache_last_value:r.cache_last_value}:v,config_source:"repository"}}if(r)return i.log.step("Reading from Global Config"),{config:r,config_source:"global"};let u=A(f,{});return i.log.step(`Config not found. Generating default ${j} at $HOME`),p.writeFileSync(n,x),{config:u,config_source:"none"}}function T(o){let t=null;try{t=U(p.readFileSync(o,"utf8"))}catch(r){i.log.error(`Invalid JSON/JSONC config file at ${o}. Exiting.
|
|
259
|
-
`+r),process.exit(0)}return q(t)}function q(o){try{return A(f,o)}catch(t){if(t instanceof G){let n=(t.issues[0].path??[]).map(a=>a.key).filter(a=>typeof a=="string"||typeof a=="number").join(".");i.log.error(`Invalid Configuration: ${h.red(n)}
|
|
260
|
-
`+t.message)}process.exit(0)}}function z(o=b.git_args){let t=".";try{t=H(`git ${o} rev-parse --show-toplevel`).toString().trim()}catch{i.log.warn("Could not find git root. If in a --bare repository, ignore this warning.")}return t}function W(){return w(I())??I()+"/"+j}function Y(o){return w(o)}function w(o){for(let t of E){let r=`${o}/${t}`;if(p.existsSync(r))return r}return null}function he(){try{return JSON.parse(p.readFileSync(new URL("../package.json",import.meta.url),"utf8")).version??"unknown"}catch{return"unknown"}}function de(o,t){return t===o.length-1?"":`
|
|
261
|
-
`}function Ce(o){let t=o.trim();return t.endsWith(".")?t.substring(0,t.length-1).trim():o.trim()}function ye(o,t){try{return o.get(t)??""}catch{i.log.warn(`Could not access ${t} from cache. Check that "~/.config" exists. Set "cache_last_value" to false to disable.`)}return""}function ke(o,t,r){try{o.set(t,r)}catch{i.log.warn(`Could not access ${t} from cache. Check that "~/.config" exists. Set "cache_last_value" to false to disable.`)}}export{c as a,P as b,X as c,F as d,Z as e,b as f,x as g,j as h,_e as i,fe as j,ge as k,be as l,z as m,Y as n,he as o,de as p,Ce as q,ye as r,ke as s};
|
package/src/args.test.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { parse_runtime_flags } from "./args";
|
|
3
|
-
|
|
4
|
-
describe("parse_runtime_flags", () => {
|
|
5
|
-
it("uses interactive mode by default", () => {
|
|
6
|
-
const parsed = parse_runtime_flags([]);
|
|
7
|
-
|
|
8
|
-
expect(parsed.no_interactive).toBe(false);
|
|
9
|
-
expect(parsed.dry_run).toBe(false);
|
|
10
|
-
expect(parsed.git_args).toBe("");
|
|
11
|
-
expect(parsed.commit_state).toEqual({});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("parses --no-interactive and --dry-run", () => {
|
|
15
|
-
const parsed = parse_runtime_flags(["--no-interactive", "--dry-run"]);
|
|
16
|
-
|
|
17
|
-
expect(parsed.no_interactive).toBe(true);
|
|
18
|
-
expect(parsed.dry_run).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("parses --version and -v", () => {
|
|
22
|
-
const long_flag = parse_runtime_flags(["--version"]);
|
|
23
|
-
const short_flag = parse_runtime_flags(["-v"]);
|
|
24
|
-
|
|
25
|
-
expect(long_flag.version).toBe(true);
|
|
26
|
-
expect(short_flag.version).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("maps commit flags into commit_state keys", () => {
|
|
30
|
-
const parsed = parse_runtime_flags([
|
|
31
|
-
"--type",
|
|
32
|
-
"feat",
|
|
33
|
-
"--title",
|
|
34
|
-
"ship feature",
|
|
35
|
-
"--breaking-title",
|
|
36
|
-
"api changed",
|
|
37
|
-
"--custom-footer",
|
|
38
|
-
"Reviewed-by: Jane",
|
|
39
|
-
]);
|
|
40
|
-
|
|
41
|
-
expect(parsed.commit_state).toEqual({
|
|
42
|
-
type: "feat",
|
|
43
|
-
title: "ship feature",
|
|
44
|
-
breaking_title: "api changed",
|
|
45
|
-
custom_footer: "Reviewed-by: Jane",
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("treats bare --closes as enabling the default closes footer", () => {
|
|
50
|
-
const parsed = parse_runtime_flags(["--closes"]);
|
|
51
|
-
|
|
52
|
-
expect(parsed.commit_state).toEqual({
|
|
53
|
-
closes: "Closes:",
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("normalizes boolean-style closes values", () => {
|
|
58
|
-
const enabled = parse_runtime_flags(["--closes=true"]);
|
|
59
|
-
const disabled = parse_runtime_flags(["--closes=false"]);
|
|
60
|
-
|
|
61
|
-
expect(enabled.commit_state).toEqual({
|
|
62
|
-
closes: "Closes:",
|
|
63
|
-
});
|
|
64
|
-
expect(disabled.commit_state).toEqual({});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("treats any truthy closes value as the default closes footer", () => {
|
|
68
|
-
const parsed = parse_runtime_flags(["--closes", "Resolves:"]);
|
|
69
|
-
|
|
70
|
-
expect(parsed.commit_state).toEqual({
|
|
71
|
-
closes: "Closes:",
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("builds git args from --git-dir and --work-tree", () => {
|
|
76
|
-
const parsed = parse_runtime_flags([
|
|
77
|
-
"--git-dir",
|
|
78
|
-
"/tmp/repo/.git",
|
|
79
|
-
"--work-tree",
|
|
80
|
-
"/tmp/repo",
|
|
81
|
-
]);
|
|
82
|
-
|
|
83
|
-
expect(parsed.git_args).toBe(
|
|
84
|
-
"--git-dir=/tmp/repo/.git --work-tree=/tmp/repo",
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("builds git args when only one git location flag is provided", () => {
|
|
89
|
-
const with_git_dir = parse_runtime_flags(["--git-dir", "/tmp/repo/.git"]);
|
|
90
|
-
const with_work_tree = parse_runtime_flags(["--work-tree", "/tmp/repo"]);
|
|
91
|
-
|
|
92
|
-
expect(with_git_dir.git_args).toBe("--git-dir=/tmp/repo/.git");
|
|
93
|
-
expect(with_work_tree.git_args).toBe("--work-tree=/tmp/repo");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("maps dashed commit flags to snake_case commit_state keys", () => {
|
|
97
|
-
const parsed = parse_runtime_flags([
|
|
98
|
-
"--breaking-body",
|
|
99
|
-
"major impact",
|
|
100
|
-
"--deprecates-title",
|
|
101
|
-
"legacy endpoint",
|
|
102
|
-
"--deprecates-body",
|
|
103
|
-
"use v2 endpoint",
|
|
104
|
-
"--custom-footer",
|
|
105
|
-
"Reviewed-by: Alex",
|
|
106
|
-
"--breaking-title",
|
|
107
|
-
"v1 removed",
|
|
108
|
-
]);
|
|
109
|
-
|
|
110
|
-
expect(parsed.commit_state).toEqual({
|
|
111
|
-
breaking_body: "major impact",
|
|
112
|
-
deprecates_title: "legacy endpoint",
|
|
113
|
-
deprecates_body: "use v2 endpoint",
|
|
114
|
-
custom_footer: "Reviewed-by: Alex",
|
|
115
|
-
breaking_title: "v1 removed",
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("honors interactive flag semantics", () => {
|
|
120
|
-
const default_flags = parse_runtime_flags([]);
|
|
121
|
-
const explicit_interactive = parse_runtime_flags(["--interactive"]);
|
|
122
|
-
const no_interactive = parse_runtime_flags(["--no-interactive"]);
|
|
123
|
-
|
|
124
|
-
expect(default_flags.no_interactive).toBe(false);
|
|
125
|
-
expect(explicit_interactive.no_interactive).toBe(false);
|
|
126
|
-
expect(no_interactive.no_interactive).toBe(true);
|
|
127
|
-
});
|
|
128
|
-
});
|