├── .editorconfig ├── .gitattributes ├── .github ├── renovate.json └── workflows │ └── ci.yml ├── .gitignore ├── .husky ├── post-checkout └── post-merge ├── .nvmrc ├── .swcrc ├── .vscode ├── launch.json └── settings.json ├── LICENSE ├── README.md ├── __tests__ └── cli.test.ts ├── biome.jsonc ├── jest.config.js ├── package-lock.json ├── package.json ├── src ├── cli.ts ├── getAbsolutePath.ts ├── getChanges.ts ├── getGitDirectory.ts ├── index.ts ├── runCommand.ts ├── runGit.ts └── runScript.ts └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | # 5 | # Some of these options are also respected by Prettier/Biome 6 | 7 | # top-most EditorConfig file 8 | root = true 9 | 10 | [*] 11 | indent_style = space 12 | indent_size = 2 13 | end_of_line = lf 14 | charset = utf-8 15 | trim_trailing_whitespace = true 16 | insert_final_newline = true 17 | 18 | [*.{js,jsx,ts,tsx}] 19 | indent_style = space 20 | indent_size = 2 21 | end_of_line = lf 22 | 23 | [*.{json,jsonc}] 24 | indent_style = space 25 | indent_size = 2 26 | end_of_line = lf 27 | 28 | [*.md] 29 | indent_style = space 30 | indent_size = 4 31 | end_of_line = lf 32 | 33 | [*.{yaml,yml}] 34 | indent_style = space 35 | indent_size = 2 36 | end_of_line = lf 37 | 38 | [.husky/*] 39 | indent_style = space 40 | indent_size = 4 41 | end_of_line = lf 42 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | .husky/* text eol=lf 4 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:best-practices", 5 | "config:js-app", 6 | "customManagers:biomeVersions", 7 | "customManagers:githubActionsVersions", 8 | "npm:unpublishSafe", 9 | ":automergeBranch", 10 | ":automergeLinters", 11 | ":automergeStableNonMajor", 12 | ":automergeTesters", 13 | ":automergeTypes", 14 | ":enableVulnerabilityAlerts", 15 | ":maintainLockFilesWeekly", 16 | ":renovatePrefix" 17 | ], 18 | "baseBranches": ["$default"] 19 | } 20 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | 11 | permissions: 12 | checks: write 13 | id-token: write # needed for npm publish with provenance 14 | contents: write # needed for github release 15 | pull-requests: write # needed for coverage comment 16 | 17 | jobs: 18 | lint: 19 | name: Lint 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 23 | 24 | - name: Setup Biome 25 | uses: biomejs/setup-biome@a9763ed3d2388f5746f9dc3e1a55df7f4609bc89 # v2 26 | 27 | - name: Lint 28 | run: biome ci --no-errors-on-unmatched . 29 | 30 | test: 31 | name: Test 32 | runs-on: ubuntu-latest 33 | timeout-minutes: 15 34 | steps: 35 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 36 | 37 | - name: Setup and Install 38 | id: install 39 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 40 | with: 41 | node-version: 20 42 | 43 | - name: Install 44 | run: npm install 45 | 46 | - name: Test 47 | run: npm run test 48 | 49 | release: 50 | name: Release 51 | runs-on: ubuntu-latest 52 | needs: [lint, test] 53 | if: github.ref == 'refs/heads/main' 54 | 55 | steps: 56 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 57 | 58 | - name: Setup and Install 59 | id: install 60 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 61 | with: 62 | node-version: 20 63 | 64 | - name: Install 65 | run: npm install 66 | 67 | - name: Build 68 | run: npm run build 69 | 70 | - name: Publish to NPM 71 | id: publish 72 | uses: JS-DevTools/npm-publish@19c28f1ef146469e409470805ea4279d47c3d35c # v3 73 | with: 74 | token: ${{ secrets.NPM_TOKEN }} 75 | dry-run: false 76 | provenance: true 77 | 78 | - name: Post publish 79 | if: steps.publish.outputs.type != '' 80 | run: | 81 | echo "Published ${{ steps.publish.outputs.type }} version: ${{ steps.publish.outputs.version }}" 82 | 83 | - name: Publish skipped 84 | if: steps.publish.outputs.type == '' 85 | run: | 86 | echo "Version in package.json has not changed. Skipping." 87 | exit 0 88 | 89 | - name: Create Release 90 | if: steps.publish.outputs.type != '' 91 | id: release 92 | uses: ncipollo/release-action@440c8c1cb0ed28b9f43e4d1d670870f059653174 # v1 # https://github.com/ncipollo/release-action 93 | with: 94 | allowUpdates: true 95 | generateReleaseNotes: true 96 | commit: ${{ github.sha }} 97 | draft: false 98 | name: v${{ steps.publish.outputs.version }} 99 | tag: v${{ steps.publish.outputs.version }} 100 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /.husky/post-checkout: -------------------------------------------------------------------------------- 1 | npx -- git-pull-run --install 2 | -------------------------------------------------------------------------------- /.husky/post-merge: -------------------------------------------------------------------------------- 1 | npx -- git-pull-run --install 2 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 22.16.0 2 | -------------------------------------------------------------------------------- /.swcrc: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://swc.rs/schema.json", 3 | "jsc": { 4 | "parser": { 5 | "syntax": "typescript" 6 | }, 7 | "target": "es5" 8 | }, 9 | "minify": true 10 | } 11 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // https://code.visualstudio.com/docs/editor/debugging 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "type": "node-terminal", 7 | "name": "Debug Test File (npm run test)", 8 | "request": "launch", 9 | "command": "npm run test -- ${fileBasenameNoExtension}", 10 | "cwd": "${fileDirname}" 11 | }, 12 | { 13 | "type": "node-terminal", 14 | "name": "Debug Current File (ts-node)", 15 | "request": "launch", 16 | "command": "ts-node -- ${fileBasenameNoExtension}", 17 | "cwd": "${fileDirname}" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "biomejs.biome" 4 | }, 5 | "[javascriptreact]": { 6 | "editor.defaultFormatter": "biomejs.biome" 7 | }, 8 | "[json]": { 9 | "editor.defaultFormatter": "biomejs.biome" 10 | }, 11 | "[jsonc]": { 12 | "editor.defaultFormatter": "biomejs.biome" 13 | }, 14 | "[typescript]": { 15 | "editor.defaultFormatter": "biomejs.biome" 16 | }, 17 | "[typescriptreact]": { 18 | "editor.defaultFormatter": "biomejs.biome" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Chris 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm](https://img.shields.io/npm/v/git-pull-run?label=git-pull-run)](https://www.npmjs.com/package/git-pull-run) 2 | [![npm](https://img.shields.io/npm/dt/git-pull-run)](https://www.npmjs.com/package/git-pull-run) 3 | 4 | # Run Commands on Changes after Git Pull 5 | Automatically run commands like **npm install** when fetching changes from git, but only if certain files have changed. 6 | 7 | ## How It Works 8 | 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. 9 | 10 | 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) 11 | 12 | ## Install 13 | ```sh 14 | npm install --save-dev git-pull-run 15 | ``` 16 | This package should be executed as a [`post-merge`](https://git-scm.com/docs/githooks#_post_merge) git hook. 17 | 18 | ## Command Line Options 19 | ```sh 20 | > npx git-pull-run --help 21 | Usage: git-pull-run [options] 22 | 23 | Options: 24 | -V --version output the version number 25 | -p, --pattern pattern to match files 26 | -c, --command execute shell command for each matched file 27 | -s, --script