better-commits 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Erik Verduin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -90,6 +90,9 @@ function infer_type_from_branch(types) {
90
90
  });
91
91
  return found ?? "";
92
92
  }
93
+ function get_git_root() {
94
+ return (0, import_child_process.execSync)("git rev-parse --show-toplevel").toString().trim();
95
+ }
93
96
  function get_default_config_path() {
94
97
  return (0, import_os.homedir)() + "/" + CONFIG_FILE_NAME;
95
98
  }
@@ -190,7 +193,7 @@ main(load_setup());
190
193
  function load_setup() {
191
194
  console.clear();
192
195
  p.intro(`${import_picocolors2.default.bgCyan(import_picocolors2.default.black(" better-commits "))}`);
193
- const root = (0, import_child_process2.execSync)("git rev-parse --show-toplevel").toString().trim();
196
+ const root = get_git_root();
194
197
  const root_path = `${root}/${CONFIG_FILE_NAME}`;
195
198
  if (import_fs.default.existsSync(root_path)) {
196
199
  p.log.step("Found repository config");
@@ -203,7 +206,7 @@ function load_setup() {
203
206
  }
204
207
  const default_config = Config.parse({});
205
208
  p.log.step("Config not found. Generating default .better-commit.json at $HOME");
206
- import_fs.default.writeFileSync(home_path, JSON.stringify(default_config, null, " "));
209
+ import_fs.default.writeFileSync(home_path, JSON.stringify(default_config, null, 4));
207
210
  return default_config;
208
211
  }
209
212
  function read_config_from_path(config_path) {
@@ -226,7 +229,8 @@ function validate_config(config) {
226
229
  }
227
230
  async function main(config) {
228
231
  let commit_state = CommitState.parse({});
229
- let git_status = await (0, import_simple_git.simpleGit)().status();
232
+ const simple_git = (0, import_simple_git.simpleGit)({ baseDir: get_git_root() });
233
+ let git_status = await simple_git.status();
230
234
  if (config.check_status) {
231
235
  p.log.step(import_picocolors2.default.black(import_picocolors2.default.bgGreen(" Checking Git Status ")));
232
236
  const missing_files = check_missing_stage(git_status);
@@ -242,8 +246,8 @@ async function main(config) {
242
246
  });
243
247
  if (p.isCancel(selected_for_staging))
244
248
  process.exit(0);
245
- await (0, import_simple_git.simpleGit)().add(selected_for_staging);
246
- git_status = await (0, import_simple_git.simpleGit)().status();
249
+ await simple_git.add(selected_for_staging);
250
+ git_status = await simple_git.status();
247
251
  if (selected_for_staging?.length) {
248
252
  p.log.success(import_picocolors2.default.green("Changes successfully staged"));
249
253
  }
package/dist/init.js CHANGED
@@ -29,6 +29,7 @@ var import_zod2 = require("zod");
29
29
  // src/utils.ts
30
30
  var import_zod = require("zod");
31
31
  var import_picocolors = __toESM(require("picocolors"));
32
+ var import_child_process = require("child_process");
32
33
  var CONFIG_FILE_NAME = ".better-commits.json";
33
34
  var SPACE_TO_SELECT = `${import_picocolors.default.dim("(<space> to select)")}`;
34
35
  var OPTIONAL_PROMPT = `${import_picocolors.default.dim("(optional)")}`;
@@ -58,6 +59,9 @@ var DEFAULT_SCOPE_OPTIONS = [
58
59
  var CUSTOM_SCOPE_KEY = "custom";
59
60
  var Z_FOOTER_OPTIONS = import_zod.z.enum(["closes", "breaking-change", "deprecated", "custom"]);
60
61
  var FOOTER_OPTION_VALUES = ["closes", "breaking-change", "deprecated", "custom"];
62
+ function get_git_root() {
63
+ return (0, import_child_process.execSync)("git rev-parse --show-toplevel").toString().trim();
64
+ }
61
65
 
62
66
  // src/zod-state.ts
63
67
  var Config = import_zod2.z.object({
@@ -139,15 +143,14 @@ var CommitState = import_zod2.z.object({
139
143
  // src/init.ts
140
144
  var import_picocolors2 = __toESM(require("picocolors"));
141
145
  var import_fs = __toESM(require("fs"));
142
- var import_child_process = require("child_process");
143
146
  var p = __toESM(require("@clack/prompts"));
144
147
  try {
145
148
  console.clear();
146
149
  p.intro(`${import_picocolors2.default.bgCyan(import_picocolors2.default.black(" better-commits-init "))}`);
147
- const root = (0, import_child_process.execSync)("git rev-parse --show-toplevel").toString().trim();
150
+ const root = get_git_root();
148
151
  const root_path = `${root}/${CONFIG_FILE_NAME}`;
149
152
  const default_config = Config.parse({});
150
- import_fs.default.writeFileSync(root_path, JSON.stringify(default_config, null, " "));
153
+ import_fs.default.writeFileSync(root_path, JSON.stringify(default_config, null, 4));
151
154
  p.log.success(`${import_picocolors2.default.green("Successfully created .better-commits.json")}`);
152
155
  p.outro(`Run ${import_picocolors2.default.bgBlack(import_picocolors2.default.white("better-commits"))} to start the CLI`);
153
156
  } catch (err) {
package/dist/utils.js CHANGED
@@ -47,6 +47,7 @@ __export(utils_exports, {
47
47
  check_missing_stage: () => check_missing_stage,
48
48
  clean_commit_title: () => clean_commit_title,
49
49
  get_default_config_path: () => get_default_config_path,
50
+ get_git_root: () => get_git_root,
50
51
  infer_type_from_branch: () => infer_type_from_branch
51
52
  });
52
53
  module.exports = __toCommonJS(utils_exports);
@@ -105,6 +106,9 @@ function infer_type_from_branch(types) {
105
106
  });
106
107
  return found ?? "";
107
108
  }
109
+ function get_git_root() {
110
+ return (0, import_child_process.execSync)("git rev-parse --show-toplevel").toString().trim();
111
+ }
108
112
  function get_default_config_path() {
109
113
  return (0, import_os.homedir)() + "/" + CONFIG_FILE_NAME;
110
114
  }
@@ -141,5 +145,6 @@ function clean_commit_title(title) {
141
145
  check_missing_stage,
142
146
  clean_commit_title,
143
147
  get_default_config_path,
148
+ get_git_root,
144
149
  infer_type_from_branch
145
150
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "better-commits",
3
3
  "private": false,
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "description": "A CLI for creating better commits following the conventional commit guidelines",
6
6
  "author": "Erik Verduin (https://github.com/everduin94)",
7
7
  "keywords": [
package/readme.md CHANGED
@@ -61,136 +61,143 @@ All properties are optional, they can be removed from your configuration and wil
61
61
 
62
62
  ```json
63
63
  {
64
- "check_status": true,
65
- "commit_type": {
66
- "enable": true,
67
- "initial_value": "feat",
68
- "infer_type_from_branch": true,
69
- "options": [
70
- {
71
- "value": "feat",
72
- "label": "feat",
73
- "hint": "A new feature"
74
- },
75
- {
76
- "value": "fix",
77
- "label": "fix",
78
- "hint": "A bug fix"
79
- },
80
- {
81
- "value": "docs",
82
- "label": "docs",
83
- "hint": "Documentation only changes"
84
- },
85
- {
86
- "value": "refactor",
87
- "label": "refactor",
88
- "hint": "A code change that neither fixes a bug nor adds a feature"
89
- },
90
- {
91
- "value": "perf",
92
- "label": "perf",
93
- "hint": "A code change that improves performance"
94
- },
95
- {
96
- "value": "test",
97
- "label": "test",
98
- "hint": "Adding missing tests or correcting existing tests"
99
- },
100
- {
101
- "value": "build",
102
- "label": "build",
103
- "hint": "Changes that affect the build system or external dependencies"
104
- },
105
- {
106
- "value": "ci",
107
- "label": "ci",
108
- "hint": "Changes to our CI configuration files and scripts"
109
- },
110
- {
111
- "value": "chore",
112
- "label": "chore",
113
- "hint": "Other changes that do not modify src or test files"
114
- },
115
- {
116
- "value": "",
117
- "label": "none"
118
- }
119
- ]
120
- },
121
- "commit_scope": {
122
- "enable": true,
123
- "custom_scope": false,
124
- "initial_value": "app",
125
- "options": [
126
- {
127
- "value": "app",
128
- "label": "app"
129
- },
130
- {
131
- "value": "shared",
132
- "label": "shared"
133
- },
134
- {
135
- "value": "server",
136
- "label": "server"
137
- },
138
- {
139
- "value": "tools",
140
- "label": "tools"
141
- },
142
- {
143
- "value": "",
144
- "label": "none"
145
- }
146
- ]
147
- },
148
- "check_ticket": {
149
- "infer_ticket": true,
150
- "confirm_ticket": true,
151
- "add_to_title": true,
152
- "append_hashtag": false
153
- },
154
- "commit_title": {
155
- "max_size": 70
156
- },
157
- "commit_body": {
158
- "enable": true,
159
- "required": false
160
- },
161
- "commit_footer": {
162
- "enable": true,
163
- "initial_value": [],
164
- "options": [
165
- "closes",
166
- "breaking-change",
167
- "deprecated",
168
- "custom"
169
- ]
170
- },
171
- "breaking_change": {
172
- "add_exclamation_to_title": true
173
- },
174
- "confirm_commit": true,
175
- "print_commit_output": true
64
+ "check_status": true,
65
+ "commit_type": {
66
+ "enable": true,
67
+ "initial_value": "feat",
68
+ "infer_type_from_branch": true,
69
+ "options": [
70
+ {
71
+ "value": "feat",
72
+ "label": "feat",
73
+ "hint": "A new feature"
74
+ },
75
+ {
76
+ "value": "fix",
77
+ "label": "fix",
78
+ "hint": "A bug fix"
79
+ },
80
+ {
81
+ "value": "docs",
82
+ "label": "docs",
83
+ "hint": "Documentation only changes"
84
+ },
85
+ {
86
+ "value": "refactor",
87
+ "label": "refactor",
88
+ "hint": "A code change that neither fixes a bug nor adds a feature"
89
+ },
90
+ {
91
+ "value": "perf",
92
+ "label": "perf",
93
+ "hint": "A code change that improves performance"
94
+ },
95
+ {
96
+ "value": "test",
97
+ "label": "test",
98
+ "hint": "Adding missing tests or correcting existing tests"
99
+ },
100
+ {
101
+ "value": "build",
102
+ "label": "build",
103
+ "hint": "Changes that affect the build system or external dependencies"
104
+ },
105
+ {
106
+ "value": "ci",
107
+ "label": "ci",
108
+ "hint": "Changes to our CI configuration files and scripts"
109
+ },
110
+ {
111
+ "value": "chore",
112
+ "label": "chore",
113
+ "hint": "Other changes that do not modify src or test files"
114
+ },
115
+ {
116
+ "value": "",
117
+ "label": "none"
118
+ }
119
+ ]
120
+ },
121
+ "commit_scope": {
122
+ "enable": true,
123
+ "custom_scope": false,
124
+ "initial_value": "app",
125
+ "options": [
126
+ {
127
+ "value": "app",
128
+ "label": "app"
129
+ },
130
+ {
131
+ "value": "shared",
132
+ "label": "shared"
133
+ },
134
+ {
135
+ "value": "server",
136
+ "label": "server"
137
+ },
138
+ {
139
+ "value": "tools",
140
+ "label": "tools"
141
+ },
142
+ {
143
+ "value": "",
144
+ "label": "none"
145
+ }
146
+ ]
147
+ },
148
+ "check_ticket": {
149
+ "infer_ticket": true,
150
+ "confirm_ticket": true,
151
+ "add_to_title": true,
152
+ "append_hashtag": false
153
+ },
154
+ "commit_title": {
155
+ "max_size": 70
156
+ },
157
+ "commit_body": {
158
+ "enable": true,
159
+ "required": false
160
+ },
161
+ "commit_footer": {
162
+ "enable": true,
163
+ "initial_value": [],
164
+ "options": [
165
+ "closes",
166
+ "breaking-change",
167
+ "deprecated",
168
+ "custom"
169
+ ]
170
+ },
171
+ "breaking_change": {
172
+ "add_exclamation_to_title": true
173
+ },
174
+ "confirm_commit": true,
175
+ "print_commit_output": true
176
176
  }
177
177
  ```
178
178
 
179
- #### ✅ Config Validation
180
- To simplify the CLI, some rules are enforced at runtime to make sure the program runs properly.
181
- - any property can be removed from the config, it will be replaced by the default at run-time
182
- - if a property is a string/number/boolean in the default, it must stay that type
183
- - the `initial_value` must be a valid value in the corresponding `options`
184
- - `commit_scope` and `commit_type` can be populated with as many or whatever options
185
- - must maintain the shape `{value: string, label?: string, hint?: string}`
186
- - `hint` and `label` are optional
187
- - to force scope or type to be required, remove `None`
188
- - `commit_footer` options are supplied from a fixed list, because they have specific functionality
189
- - thus, you can remove from that list, but you can't add custom values to it
179
+ ### ✅ Config Validation
180
+
181
+ Any property can be removed from the config, it will be replaced by the default at run-time
182
+ - See `.better-commits.json` in this repository as an example
183
+
184
+ #### Types
185
+ if a property is a string/number/boolean in the default, it must stay that type
186
+
187
+ #### Scope & Type
188
+ The `initial_value` must be a `value` in the corresponding `options`
189
+
190
+ `commit_scope` and `commit_type` can be populated with as many or whatever options you like
191
+ - `hint` and `label` are optional
192
+ - to make scope or type required, remove `None`
193
+
194
+ #### Footer
195
+ `commit_footer` options are supplied from a fixed list, because they have specific functionality
196
+ - You can remove from that list, but you can't add custom values to it
190
197
 
191
198
  TODO: Add table explaining properties
192
199
 
193
- #### 🔎 Inference
200
+ ### 🔎 Inference
194
201
 
195
202
  `better-commits` will attempt to infer the ticket/issue and the type from your branch name. It will auto populate the corresponding field if found.
196
203
 
@@ -208,23 +215,30 @@ TODO: Add table explaining properties
208
215
  - `-TYPE-` -- If a type is between two dashes
209
216
 
210
217
  ## 😮 Mildly Interesting
211
- - `better-commits` works with [Semantic Release](https://github.com/semantic-release/semantic-release)
212
- - if you use `better-commits` to create your *first* commit on a new branch, when you open a PR for that branch, it will properly **auto-populate the title and body**.
213
- - when you squash / merge with github, if `better-commits` is your *first* commit, all later commits like "addressing comments", "fixing mistake". Will be prefixed with an asterisk for easy deletion. This way you **maintain your pretty commit even when squashing**.
214
- - if you use a branch name like the ones below, better-commits will be able to infer your ticket/issue and type
215
- - `TYPE/TICKET-description`
216
- - `USER/TYPE/TICKET-description`
217
- - if you're using Github issues to track your work, and select the `closes` footer option when writing your commit. Github will **automatically link and close** that issue when your **pr is merged**
218
- - [better-commits](https://packagephobia.com/result?p=better-commits) is much smaller than its alternative [commitizen](https://packagephobia.com/result?p=commitizen)
219
- - `better-commits` uses native `git` commands under the hood. So any hooks, tools, or staging should work as if it was a normal commit.
220
- - You can add this badge to your repository to display that you're using a better-commits repository config
218
+
219
+ ### Building / Versioning
220
+ `better-commits` works with [Semantic Release](https://github.com/semantic-release/semantic-release)
221
+
222
+ ### Github
223
+ if you use `better-commits` to create your *first* commit on a new branch
224
+ - when you open a PR for that branch, it will properly **auto-populate the title and body**.
225
+ - when you squash/merge, all later commits like "addressing comments" or "fixing mistake". Will be prefixed with an asterisk for easy deletion. This way, you **maintain your pretty commit even when squashing**.
226
+
227
+ if you're using Github issues to track your work, and select the `closes` footer option when writing your commit. Github will **automatically link and close** that issue when your **pr is merged**
228
+
229
+ ### Fun Facts
230
+ [better-commits](https://packagephobia.com/result?p=better-commits) is much smaller than its alternative [commitizen](https://packagephobia.com/result?p=commitizen)
231
+
232
+ `better-commits` uses native `git` commands under the hood. So any hooks, tools, or staging should work as if it was a normal commit.
233
+
234
+ You can add this badge to your repository to display that you're using a better-commits repository config
221
235
  ```
222
236
  [![better commits is enabled](https://img.shields.io/badge/better--commits-enabled?style=for-the-badge&logo=git&color=a6e3a1&logoColor=D9E0EE&labelColor=302D41)](https://github.com/Everduin94/better-commits)
223
237
  ```
224
238
 
225
239
  [![better commits is enabled](https://img.shields.io/badge/better--commits-enabled?style=for-the-badge&logo=git&color=a6e3a1&logoColor=D9E0EE&labelColor=302D41)](https://github.com/Everduin94/better-commits)
226
240
 
227
-
241
+ ---
228
242
 
229
243
  ## ❓ Troubleshooting
230
244
 
package/src/index.ts CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  import * as p from '@clack/prompts';
4
4
  import color from 'picocolors';
5
- import { simpleGit } from "simple-git"
5
+ import { SimpleGit, simpleGit } from "simple-git"
6
6
  import fs from 'fs'
7
7
  import { execSync } from 'child_process';
8
8
  import { z } from "zod";
9
9
  import { fromZodError } from 'zod-validation-error';
10
10
  import { CommitState, Config } from './zod-state';
11
- import { CONFIG_FILE_NAME, get_default_config_path, check_missing_stage, addNewLine, SPACE_TO_SELECT, REGEX_SLASH_TAG, REGEX_SLASH_NUM, REGEX_START_TAG, REGEX_START_NUM, OPTIONAL_PROMPT, clean_commit_title, COMMIT_FOOTER_OPTIONS, infer_type_from_branch, Z_FOOTER_OPTIONS, CUSTOM_SCOPE_KEY } from './utils';
11
+ import { CONFIG_FILE_NAME, get_default_config_path, check_missing_stage, addNewLine, SPACE_TO_SELECT, REGEX_SLASH_TAG, REGEX_SLASH_NUM, REGEX_START_TAG, REGEX_START_NUM, OPTIONAL_PROMPT, clean_commit_title, COMMIT_FOOTER_OPTIONS, infer_type_from_branch, Z_FOOTER_OPTIONS, CUSTOM_SCOPE_KEY, get_git_root } from './utils';
12
12
 
13
13
  main(load_setup());
14
14
 
@@ -16,7 +16,7 @@ function load_setup(): z.infer<typeof Config> {
16
16
  console.clear();
17
17
  p.intro(`${color.bgCyan(color.black(' better-commits '))}`);
18
18
 
19
- const root = execSync('git rev-parse --show-toplevel').toString().trim();
19
+ const root = get_git_root();
20
20
  const root_path = `${root}/${CONFIG_FILE_NAME}`
21
21
  if (fs.existsSync(root_path)) {
22
22
  p.log.step('Found repository config')
@@ -31,7 +31,7 @@ function load_setup(): z.infer<typeof Config> {
31
31
 
32
32
  const default_config = Config.parse({})
33
33
  p.log.step('Config not found. Generating default .better-commit.json at $HOME')
34
- fs.writeFileSync(home_path, JSON.stringify(default_config, null, '\t'));
34
+ fs.writeFileSync(home_path, JSON.stringify(default_config, null, 4));
35
35
  return default_config;
36
36
  }
37
37
 
@@ -58,7 +58,8 @@ function validate_config(config: z.infer<typeof Config>): z.infer<typeof Config>
58
58
 
59
59
  async function main(config: z.infer<typeof Config>) {
60
60
  let commit_state = CommitState.parse({})
61
- let git_status = await simpleGit().status();
61
+ const simple_git = simpleGit({ baseDir: get_git_root() })
62
+ let git_status = await simple_git.status();
62
63
  if (config.check_status) {
63
64
  p.log.step(color.black(color.bgGreen(' Checking Git Status ')))
64
65
  const missing_files = check_missing_stage(git_status);
@@ -74,8 +75,8 @@ async function main(config: z.infer<typeof Config>) {
74
75
  }) as string[]
75
76
  if (p.isCancel(selected_for_staging)) process.exit(0)
76
77
 
77
- await simpleGit().add(selected_for_staging)
78
- git_status = await simpleGit().status();
78
+ await simple_git.add(selected_for_staging)
79
+ git_status = await simple_git.status();
79
80
  if (selected_for_staging?.length){
80
81
  p.log.success(color.green('Changes successfully staged'))
81
82
  }
package/src/init.ts CHANGED
@@ -3,17 +3,16 @@
3
3
  import { Config } from "./zod-state";
4
4
  import color from 'picocolors';
5
5
  import fs from 'fs'
6
- import { execSync } from "child_process";
7
6
  import * as p from '@clack/prompts';
8
- import { CONFIG_FILE_NAME } from "./utils";
7
+ import { CONFIG_FILE_NAME, get_git_root } from "./utils";
9
8
 
10
9
  try {
11
10
  console.clear();
12
11
  p.intro(`${color.bgCyan(color.black(' better-commits-init '))}`)
13
- const root = execSync('git rev-parse --show-toplevel').toString().trim();
12
+ const root = get_git_root();
14
13
  const root_path = `${root}/${CONFIG_FILE_NAME}`
15
14
  const default_config = Config.parse({})
16
- fs.writeFileSync(root_path, JSON.stringify(default_config, null, '\t'));
15
+ fs.writeFileSync(root_path, JSON.stringify(default_config, null, 4));
17
16
  p.log.success(`${color.green('Successfully created .better-commits.json')}`)
18
17
  p.outro(`Run ${color.bgBlack(color.white('better-commits'))} to start the CLI`)
19
18
  } catch (err: any) {
package/src/utils.ts CHANGED
@@ -60,6 +60,10 @@ export function infer_type_from_branch(types: string[]): string {
60
60
  return found ?? ''
61
61
  }
62
62
 
63
+ export function get_git_root(): string {
64
+ return execSync('git rev-parse --show-toplevel').toString().trim();
65
+ }
66
+
63
67
  export function get_default_config_path(): string {
64
68
  return homedir()+'/'+CONFIG_FILE_NAME
65
69
  }
package/src/zod-state.ts CHANGED
@@ -63,7 +63,7 @@ export const Config = z.object({
63
63
  add_exclamation_to_title: z.boolean().default(true)
64
64
  }).default({}),
65
65
  confirm_commit: z.boolean().default(true),
66
- print_commit_output: z.boolean().default(true)
66
+ print_commit_output: z.boolean().default(true),
67
67
  }).default({})
68
68
 
69
69
  export const CommitState = z.object({