Skip to content

Commit 96d4fb2

Browse files
Merge pull request #126 from MichaelCurrin/add-bin-support-with-npm-link
Add CLI support with npm link
2 parents 4e4da09 + 4cc20d7 commit 96d4fb2

28 files changed

Lines changed: 1251 additions & 456 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ coverage/
88
.vscode-test/
99
out/
1010
build/*.vsix
11+
build-cli/*
1112

1213
# Temporary git repo in the repo, for testing the extension.
1314
sandbox/

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PUBLISHER_NAME = MichaelCurrin
2-
2+
CLI_BUILD_DIR = build-cli
33

44
default: install
55

@@ -14,7 +14,7 @@ hooks:
1414
cd .git/hooks && ln -s -f ../../hooks/pre-push pre-push
1515

1616
install:
17-
npm install
17+
npm ci
1818

1919
outdated:
2020
npm outdated
@@ -57,6 +57,17 @@ e ext:
5757
npm run checks
5858
npm run ext
5959

60+
# Build and install only the CLI tools.
61+
cli-install:
62+
npm run checks
63+
npm run cli:install
64+
65+
# Build CLI tools for distribution.
66+
cli-build:
67+
rm -f $(CLI_BUILD_DIR)/*
68+
npm run cli:build
69+
70+
6071
### Deploy
6172

6273
login:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
<!-- Badges mostly generated with https://michaelcurrin.github.io/badge-generator/#/ -->
55

6+
[![Made with JavaScript](https://img.shields.io/badge/Made_with-JavaScript-blue?logo=javascript&logoColor=white)](https://www.javascript.com/ "Go to JavaScript homepage")
67
[![Node CI](https://github.com/MichaelCurrin/auto-commit-msg/workflows/Node%20CI/badge.svg)](https://github.com/MichaelCurrin/auto-commit-msg/actions?query=workflow:"Node+CI")
78
[![CodeQL](https://github.com/MichaelCurrin/auto-commit-msg/workflows/CodeQL/badge.svg)](https://github.com/MichaelCurrin/auto-commit-msg/actions?query=workflow%3ACodeQL)
89
[![License](https://img.shields.io/badge/License-MIT-blue)](#license "Go to License section")

docs/README.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,11 @@ This project serves to prepare a smart commit message for you, to make your deve
88
- [Quickstart](quickstart.md)
99
- [About](about.md)
1010
- [Features](features.md)
11-
- What it can do, upcoming features, and how it works
11+
- What it can do, upcoming features, and how it works,
1212
- [User manual](manual/)
13-
- How to install and use the installed extension.
13+
- How to install and use the extension.
14+
- [CLI](cli.md)
15+
- How install and run as a CLI tool only.
1416
- [Development](development/)
1517
- Guide for developers to set up and run locally.
1618
- Useful for testing your changes before contributing a PR.
17-
18-
<!--
19-
20-
The docs are split into two features:
21-
22-
- [Extension](extension.md)
23-
- [Terminal hook](terminal-hook.md)
24-
25-
Part ideas:
26-
27-
- A shell script in a repo
28-
- References a concatenated JS script from this repo (just the text handling and not the full extension), which is in a bin directory.
29-
30-
-->

docs/cli.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# CLI
2+
> How to use AutoCommitMsg in the terminal instead of as an extension
3+
4+
See steps below to setup and run the tool in the CLI. VS Code is not needed.
5+
6+
For development, see [CLI Development](development/cli.md).
7+
8+
_This should work on Windows too but has not been tested yet._
9+
10+
11+
## Install
12+
13+
Requires Git and Node.
14+
15+
<!-- TODO replace with instructions for downloading from a release using manual steps and install with curl or npm
16+
Note you do not need Git or Node, you can download the pre-packaged CLI tool as a binary.
17+
-->
18+
19+
```sh
20+
$ git clone git@github.com:MichaelCurrin/auto-commit-msg.git
21+
$ cd auto-commit-msg
22+
$ npm install
23+
$ npm run cli:install
24+
```
25+
26+
To setup as a pre-commit hook, see [Shell](/shell/)
27+
28+
## Usage
29+
30+
Use the `-h` or `--help` flags with any of these to avoid making changes.
31+
32+
<!--
33+
TODO consolidate to one command with commit flag or dry run?
34+
TODO pass params like file names through for either command. For message and committing. The downside is for new files - even if git commit would pick them up by name, diff-index would not. You can also use whatever IDE to stage and still generate+commit with the CLI.
35+
TODO -c not just --cached but pass through as --cached.
36+
And use default behavior for if there is staged then use that for commit message - make it smart.
37+
-->
38+
39+
### Generate a message from changes and commit
40+
41+
This is the **main** command you should use.
42+
43+
Note this will **commit**, so if you want to experiment with commit output **without** committing, use the command below instead.
44+
45+
No flags are needed.
46+
47+
```sh
48+
$ gacm --help
49+
```
50+
51+
### Check Git changes and generate commit message
52+
53+
This will **not** commit.
54+
55+
No flags are needed.
56+
57+
```sh
58+
$ acm --help
59+
```
60+
61+
### Generate a message from staged changes
62+
63+
This is a simpler command which does not interact with Git, intended for integrating with the Bash shell.
64+
65+
```sh
66+
$ auto_commit_message_generate "$CHANGES"
67+
```
68+
69+
### Usage tips
70+
71+
The behavior depends on how Git treats files, so you should know these points:
72+
73+
- The commands will pick up on staged changes and certain unstaged changes (modified and deleted, but not created as they are untracked).
74+
- If you want to handle created files, make sure to stage them first.
75+
- If you want to target only select changes for smaller commit, then stage stages and use the `--cached` flag to ignored unstaged changes.
76+
77+
## Uninstall the linked CLI (optional)
78+
79+
If you get permission denied error, you can do this and then go back to the install step.
80+
81+
```sh
82+
$ npm unlink -g auto-commit-msg
83+
```

docs/development/cli.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# CLI Development
2+
> Maintaining code around the CLI tool
3+
4+
The code is in [src/cli/](/src/cli). The CLI commands are built using steps set in [package.json](/package.json) - see the `cli` command and `bin` section.
5+
6+
7+
8+
## Run directly
9+
10+
```sh
11+
$ npx ts-node src/cli/diffIndexGenerate.ts
12+
```
13+
14+
15+
## Package as a binary
16+
17+
Build the CLI as a binary so you send to someone so they can use it without having Node installed or running a build step on their machine.
18+
19+
```sh
20+
$ make cli-build
21+
```
22+
23+
Check the [build-cli](/build-cli/) directory once it is created.
24+
25+
_Note: Node 18 is set to avoid erros, even though 22 is set in package.json and is active with NVM._
26+
27+
28+
## Troubleshooting
29+
30+
On macOS, installed here as a symlink pointing to the `.js` file in the repo:
31+
32+
```
33+
/opt/homebrew/bin/acm
34+
```
35+
36+
If you get permissions issues, it is because the `.js` file was rebuilt and with standard permissions and needs to be linked again.
37+
38+
```sh
39+
$ npm run cli
40+
```
41+
42+
Check:
43+
44+
```sh
45+
ls -l $(realpath /opt/homebrew/bin/acm)
46+
```
47+
48+
See [package.json](/package.json). Supposedly you should be able to leave out the project name when running `npm link` via an `npm run ...` command but I found this causes issues, so decided to always use the full name in the configuration. And to _always_ unlink then link in one go because of permissions issues.

docs/features.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ A roadmap of features and whether done or not.
1616
- Note that **new** files (including when doing a rename) should **always** be staged so that the extension can pick them up and so git can see that two paths for a renamed file are the same file.
1717
- [x] Generate a single-line commit message for a file to be committed, using action verbs (e.g. `Create`, `Update`, `Delete`)
1818
- [x] Handle changes from a single changed file.
19-
- [ ] Handle changes from two or more files.
20-
- [x] As a list of the same nature e.g. `update foo.txt and fizz/bar.txt`, `feat: create foo.txt, fizz/bar.txt and buzz.js` (including prefix) and `Various changes to foo.txt and fizz/bar.txt` (for one updated and one new file). See [#29](https://github.com/MichaelCurrin/auto-commit-msg/pull/29).
21-
- [x] As a count. e.g. `update 3 files`. See [#38](https://github.com/MichaelCurrin/auto-commit-msg/issues/38).
22-
- [ ] As different verb for each change `create foo.txt and delete bar.txt`. See [#37](https://github.com/MichaelCurrin/auto-commit-msg/issues/37) and See [#52](https://github.com/MichaelCurrin/auto-commit-msg/issues/52).
23-
- [ ] As a count in a directory. `update 3 files in foo`
24-
- [ ] As a count with a conventional commit message. See [#51](https://github.com/MichaelCurrin/auto-commit-msg/issues/51).
25-
- [ ] As a count with a label. e.g. `update 3 config files`. See [#13](https://github.com/MichaelCurrin/auto-commit-msg/issues/13).
26-
- [ ] As count that uses the old message. See [#55](https://github.com/MichaelCurrin/auto-commit-msg/issues/55)
19+
- [x] Handle changes from two or more files.
2720
- [x] Support using multiple repos in one VS Code window.
2821
- [x] Keep user-entered value as a prefix e.g. Keep `docs:` (or ticket number) so message becomes `docs: Update README.md`
2922
- [x] Use conventional commits e.g. `chore: Update package.json`

0 commit comments

Comments
 (0)