You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-11Lines changed: 12 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -14,59 +14,60 @@ For more information, please refer to my post: [Automatically Install NPM Depend
14
14
npm install --save-dev git-pull-run
15
15
```
16
16
This package should be executed as a [`post-merge`](https://git-scm.com/docs/githooks#_post_merge) git hook.
17
+
17
18
## Command Line Options
18
19
```sh
19
20
> npx git-pull-run --help
20
21
Usage: git-pull-run [options]
21
22
22
23
Options:
23
24
-V --version output the version number
24
-
-p, --pattern <glob> pattern to match files (required)
25
+
-p, --pattern <glob> pattern to match files
25
26
-c, --command <command> execute shell commandfor each matched file
26
27
-s, --script <script> execute npm script for each matched file
28
+
-i, --install detect the right package manager and run install command
27
29
-m, --message <message> print message to the console if matches were found
28
30
-d, --debug print additional debug information (default: false)
29
31
-o, --once run command only once if any files match the pattern (default: false)
30
32
-h, --help display helpforcommand
31
33
```
32
-
- **`--pattern <pattern>`**: Required glob pattern to detect if certain files have changed on the remote repository when pulling changes. Each changed file (including path from root) is matched against this pattern.
34
+
- **`--pattern <pattern>`**: Glob pattern to detect if certain files have changed on the remote repository when pulling changes. Each changed file (including path from root) is matched against this pattern.
33
35
- uses [micromatch](https://www.npmjs.com/package/micromatch) internally and supports all matching features like wildcards, negation, extglobs and more.
34
36
- **`--command <command>`**: Command to execute on the shell for each changed file that matches the `pattern`. The command is going to be executed inside the directory of the changed file.
35
37
- uses [execa](https://github.com/sindresorhus/execa) internally with the `cwd` option set as directory of the matched file.
36
38
- **`--script <script>`**: NPM script to execute on the shell for each changed file that matches the `pattern`. Same as option **`--command "npm run <script>"`**. The script is going to be executed inside the directory of the changed file.
39
+
- **`--install`**: Install dependencies with the right package manager (npm, pnpm, yarn, bun, deno). It implicitly sets the `pattern` and `command` options to the appropriate values for the package manager.
37
40
- **`--message <message>`**: Message to print on the shell if any changed files matches the `pattern`. The message is printed only once and not for each changed file.
38
41
- **`--once`**: Run the command or script only once in the git root directory if any files match the pattern, instead of running it for each matched file.
39
42
- **`--debug`**: Run in debug mode and print additional information about the changed files and commands and scripts that are being executed.
40
43
44
+
[!TIP] The `--install` option is a shortcut to automatically detect the right package manager and run the install command. It cannot be used with the `--pattern` and `--command` options, because they are overwritten with the appropriate values for the package manager.
45
+
41
46
## Usage
42
47
48
+
Install [Husky](https://typicode.github.io/husky/how-to.html) or any other git hook manager to create a `post-merge` git hook.
49
+
43
50
### Run `npm install` when `package-lock.json` changes
44
-
`post-merge` git hook with [Husky](https://github.com/typicode/husky):
45
51
```sh
46
-
#!/bin/sh
47
-
."$(dirname "$0")/_/husky.sh"
52
+
# .husky/post-merge
48
53
49
54
# matches only the package-lock.json inside project directory
_On Windows, white spaces in the command like `npm install` must be escaped with backslashes, for example:_ `npx git-pull-run --pattern "package-lock.json" --command "npm\ install"`
53
58
54
59
### Run `npm install` in a multi-package monorepo
55
-
`post-merge` git hook with [Husky](https://github.com/typicode/husky):
56
60
```sh
57
-
#!/bin/sh
58
-
."$(dirname "$0")/_/husky.sh"
61
+
# .husky/post-merge
59
62
60
63
# assumes monorepo structure with multiple packages in directory /packages
0 commit comments