git-pull-run
Advanced tools
Comparing version
@@ -15,4 +15,5 @@ #!/usr/bin/env node | ||
.requiredOption('-p, --pattern <glob>', 'pattern to match files (required)') | ||
.option('-c, --command <command>', 'execute shell command for each matched file', '') | ||
.option('-s, --script <script>', 'execute npm script for each matched file', '') | ||
.option('-c, --command <command>', 'execute shell command for each matched file') | ||
.option('-s, --script <script>', 'execute npm script for each matched file') | ||
.option('-m, --message <message>', 'print message to the console if matches were found') | ||
.option('-d, --debug', 'print additional debug information', false) | ||
@@ -19,0 +20,0 @@ .parse(); |
@@ -0,3 +1,3 @@ | ||
import debugLog from 'debug'; | ||
import { runGit } from './runGit.js'; | ||
import debugLog from 'debug'; | ||
const debug = debugLog('git-pull-run:getGitDirectory'); | ||
@@ -4,0 +4,0 @@ export async function getGitDirectory() { |
import debugLog from 'debug'; | ||
import { echoMessage } from './echoMessage.js'; | ||
import { getAbsolutePath } from './getAbsolutePath.js'; | ||
@@ -10,3 +11,4 @@ import { getChanges } from './getChanges.js'; | ||
info.log = console.log.bind(console); | ||
export async function gitPullRun({ pattern, command, script }) { | ||
export { info }; | ||
export async function gitPullRun({ pattern, message, command, script }) { | ||
try { | ||
@@ -22,2 +24,5 @@ const gitDir = await getGitDirectory(); | ||
} | ||
if (message) { | ||
echoMessage(message); | ||
} | ||
for (const change of changes) { | ||
@@ -27,7 +32,7 @@ const { directory } = getAbsolutePath(gitDir, change); | ||
info(`Running command '${command}' for change '${change}' in directory ${directory}...`); | ||
const result = await runCommand(command, directory); | ||
await runCommand(command, directory); | ||
} | ||
if (script) { | ||
info(`Running script '${script}' for change '${change}' in directory ${directory}...`); | ||
const result = await runScript(script, directory); | ||
await runScript(script, directory); | ||
} | ||
@@ -34,0 +39,0 @@ } |
{ | ||
"name": "git-pull-run", | ||
"version": "1.0.2", | ||
"version": "1.1.1-next.0", | ||
"description": "Run commands and scripts after git pull", | ||
@@ -9,6 +9,8 @@ "bin": "./dist/cli.js", | ||
"scripts": { | ||
"compile": "rimraf dist && tsc", | ||
"compile:watch": "tsc --watch", | ||
"build": "rimraf dist && tsc --project tsconfig.build.json", | ||
"build:watch": "tsc --watch", | ||
"release": "npm version $(semver $npm_package_version -i patch) && npm publish --tag latest", | ||
"release:next": "npm version $(semver $npm_package_version -i prerelease --preid next ) && npm publish --tag next", | ||
"start": "DEBUG=* node dist/git-pull-run", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "jest" | ||
}, | ||
@@ -35,5 +37,8 @@ "repository": { | ||
"devDependencies": { | ||
"@gmrchk/cli-testing-library": "^0.1.2", | ||
"@tsconfig/node14": "^1.0.1", | ||
"@tsconfig/node16": "^1.0.2", | ||
"@tsconfig/node16-strictest-esm": "^1.0.3", | ||
"@types/debug": "^4.1.7", | ||
"@types/jest": "^29.2.0", | ||
"@types/micromatch": "^4.0.2", | ||
@@ -46,4 +51,8 @@ "@types/node": "^16.11.12", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^29.2.2", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^3.0.2", | ||
"semver": "^7.3.8", | ||
"ts-jest": "^29.0.3", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.5.3" | ||
@@ -54,5 +63,5 @@ }, | ||
"debug": "^4.3.3", | ||
"execa": "^6.0.0", | ||
"execa": "^6.1.0", | ||
"micromatch": "^4.0.4" | ||
} | ||
} |
@@ -6,3 +6,3 @@ [](https://badge.fury.io/js/git-pull-run) | ||
## How It Works | ||
Git invokes the [`post-merge`](https://git-scm.com/docs/githooks#_post_merge) after a `git pull` was done a local repository. This package will then run `git diff-tree` to get a list of changed files. Each changed file is being matched against the specified pattern and in case of a match, then specified command or script will be executed. | ||
Git invokes the [`post-merge`](https://git-scm.com/docs/githooks#_post_merge) hook after a `git pull` was done a local repository. This package will then run `git diff-tree` to get a list of changed files. Each changed file is being matched against the specified pattern and in case of a match, the specified command or script will be executed. | ||
@@ -24,4 +24,5 @@ For more information, please refer to my post: [Automatically Install NPM Dependencies on Git Pull](https://dev.to/zirkelc/automatically-install-npm-dependencies-on-git-pull-bg0) | ||
-p, --pattern <glob> pattern to match files (required) | ||
-c, --command <command> execute shell command for each matched file (default: "") | ||
-s, --script <script> execute npm script for each matched file (default: "") | ||
-c, --command <command> execute shell command for each matched file | ||
-s, --script <script> execute npm script for each matched file | ||
-m, --message <message> print message to the console if matches were found | ||
-d, --debug print additional debug information (default: false) | ||
@@ -31,6 +32,7 @@ -h, --help display help for command | ||
- **`--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. | ||
- uses [micromatch](https://www.npmjs.com/package/micromatch) internally and supports all matching features like wildcards, negation, extglobs and more. | ||
- uses [micromatch](https://www.npmjs.com/package/micromatch) internally and supports all matching features like wildcards, negation, extglobs and more. | ||
- **`--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. | ||
- uses [execa](https://github.com/sindresorhus/execa) internally with the `cwd` option set as directory of the matched file. | ||
- **`--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. | ||
- **`--message <message>`**: Message to print to the shell if any changed files matches the `pattern`. The message is printed only once and not for each changed file. | ||
- **`--debug`**: Run in debug mode and print additional information about the changed files and commands and scripts that are being executed. | ||
@@ -47,4 +49,5 @@ | ||
# matches only the package-lock.json inside project directory | ||
npx git-pull-run -p 'package-lock.json' -c 'npm install' | ||
npx git-pull-run --pattern "package-lock.json" --command "npm install" | ||
``` | ||
_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"` | ||
@@ -59,6 +62,5 @@ ### Run `npm install` in a multi-package monorepo | ||
# matches any of these package-lock.json | ||
npx git-pull-run -p 'packages/*/package-lock.json' -c 'npm install' | ||
npx git-pull-run --pattern "packages/*/package-lock.json" --command "npm install" | ||
``` | ||
## FAQ | ||
@@ -74,1 +76,9 @@ ### Match `package.json` or `package-lock.json`? | ||
### Error: Command failed with exit code 1: npm | ||
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"` | ||
[Issue: Command failed with exit code 1: npm #1](https://github.com/zirkelc/git-pull-run/issues/1) | ||
## What about Yarn? | ||
The `yarn.lock` should be used as pattern option (instead of `package-lock.json`) and the `yarn install` should be used as command option (instead of `npm install`). If you want to run scripts defined in the `package.json` with yarn instead of npm, please use the command option with `--command "yarn run <script>"` instead of `--script "<script>"`. |
@@ -11,2 +11,3 @@ #!/usr/bin/env node | ||
pattern: string; | ||
message: string; | ||
command: string; | ||
@@ -25,4 +26,5 @@ script: string; | ||
.requiredOption('-p, --pattern <glob>', 'pattern to match files (required)') | ||
.option('-c, --command <command>', 'execute shell command for each matched file', '') | ||
.option('-s, --script <script>', 'execute npm script for each matched file', '') | ||
.option('-c, --command <command>', 'execute shell command for each matched file',) | ||
.option('-s, --script <script>', 'execute npm script for each matched file',) | ||
.option('-m, --message <message>', 'print message to the console if matches were found',) | ||
.option('-d, --debug', 'print additional debug information', false) | ||
@@ -29,0 +31,0 @@ .parse(); |
@@ -0,4 +1,3 @@ | ||
import debugLog from 'debug'; | ||
import { runGit } from './runGit.js'; | ||
import debugLog from 'debug'; | ||
import micromatch from 'micromatch'; | ||
@@ -5,0 +4,0 @@ const debug = debugLog('git-pull-run:getGitDirectory'); |
import debugLog from 'debug'; | ||
import { echoMessage } from './echoMessage.js'; | ||
import { getAbsolutePath } from './getAbsolutePath.js'; | ||
@@ -10,2 +11,3 @@ import { getChanges } from './getChanges.js'; | ||
pattern: string; | ||
message: string; | ||
command: string; | ||
@@ -20,3 +22,5 @@ script: string; | ||
export async function gitPullRun({ pattern, command, script }: Options): Promise<void> { | ||
export { info }; | ||
export async function gitPullRun({ pattern, message, command, script }: Options): Promise<void> { | ||
try { | ||
@@ -33,2 +37,6 @@ const gitDir = await getGitDirectory(); | ||
if (message) { | ||
echoMessage(message); | ||
} | ||
for (const change of changes) { | ||
@@ -39,3 +47,3 @@ const { directory } = getAbsolutePath(gitDir, change); | ||
info(`Running command '${command}' for change '${change}' in directory ${directory}...`); | ||
const result = await runCommand(command, directory); | ||
await runCommand(command, directory); | ||
} | ||
@@ -45,3 +53,3 @@ | ||
info(`Running script '${script}' for change '${change}' in directory ${directory}...`); | ||
const result = await runScript(script, directory); | ||
await runScript(script, directory); | ||
} | ||
@@ -48,0 +56,0 @@ } |
{ | ||
"extends": "@tsconfig/node14/tsconfig.json", | ||
"extends": "@tsconfig/node16-strictest-esm/tsconfig.json", | ||
"compilerOptions": { | ||
@@ -8,8 +8,7 @@ "removeComments": true, | ||
"outDir": "dist", | ||
"module": "es2020", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true | ||
"resolveJsonModule": true, | ||
"noUnusedLocals": false, | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"**/*.ts", | ||
], | ||
@@ -19,2 +18,6 @@ "exclude": [ | ||
], | ||
"ts-node": { | ||
// Tell ts-node CLI to install the --loader automatically, explained below | ||
"esm": true | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
42365
54.9%43
38.71%607
64.95%79
14.49%20
53.85%1
Infinity%Updated