simple-pre-commit
Advanced tools
Comparing version 1.1.3 to 1.2.0
#!/usr/bin/env node | ||
const os = require('os') | ||
const {getCommandFromConfig, setPreCommitHook} = require('./simple-pre-commit') | ||
const command = getCommandFromConfig(process.cwd()) | ||
if (!command) { | ||
@@ -10,3 +13,5 @@ console.log(`Couldn't parse command! Please add command to package.json or .simple-pre-commit.json. See README.md for details`) | ||
} | ||
setPreCommitHook(command) | ||
console.log('Set pre commit hook: ' + command) |
{ | ||
"name": "simple-pre-commit", | ||
"version": "1.1.3", | ||
"version": "1.2.0", | ||
"description": "A simple, zero dependency tool for setting up git pre-commit hook for small projects", | ||
@@ -5,0 +5,0 @@ "author": "Mikhail Gorbunov <toplenboren@gmail.com> (toplenboren.gituhb.io)", |
@@ -7,2 +7,3 @@ #!/usr/bin/env node | ||
let projectDirectory; | ||
const parsedProjectDirectory = getProjectRootDirectoryFromNodeModules(process.cwd()) | ||
@@ -14,2 +15,3 @@ if (parsedProjectDirectory !== undefined) { | ||
} | ||
if (checkSimplePreCommitInDependencies(projectDirectory)) { | ||
@@ -16,0 +18,0 @@ try { |
@@ -15,6 +15,33 @@ # simple-pre-commit | ||
| husky v5 `5.0.9` | `24.5 kB` | | ||
| pre-commit `1.2.2` | `~80kB` | | ||
| **simple-pre-commit** `1.1.3` | `9.0 kB` | | ||
| pre-commit `1.2.2` | `~80 kB` | | ||
| **simple-pre-commit** `1.1.3` | `9.02 kB` | | ||
### What is pre-commit hook? | ||
Pre-commit hook is a command that is going to be run every time you commit a file to git. | ||
If pre-commit hook fails, then commit aborts. | ||
Usually you would like to run `linters` and `code-formatters` on every staged file to ensure code quality in your project | ||
Check out [lint-staged](https://github.com/okonet/lint-staged#readme). It works really well with `simple-pre-commit` | ||
You can look up about git hooks on [git book](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) | ||
### When to use it | ||
`simple-pre-commit` works well for small-sized projects when you need quickly setup `pre-commit` hook with one or a few commands and forget about it. | ||
However, this package only allows you to set the `pre-commit` hook. If you need, for example `pre-push` hook or something else — this package wouln't be able to help you | ||
Also, this package requires you to manually update the `pre-commit` hook. If you want update `pre-commit` hook often - this is probably not the best choice | ||
If you need multiple hooks, flexible configuration or git hook automatic update feature — please check out other packages: | ||
* [Lefthook](https://github.com/Arkweid/lefthook) | ||
* [husky](https://github.com/Arkweid/lefthook) | ||
* [pre-commit](https://github.com/pre-commit/pre-commit) | ||
## Usage | ||
@@ -30,3 +57,3 @@ | ||
2. Add the `simple-pre-commit` to your `package.json`. Feed it with any command you would like to run as a pre-commit hook. | ||
2. Add the `simple-pre-commit` to your `package.json`. Feed it with any command you would like to run as a `pre-commit` hook. | ||
@@ -45,3 +72,3 @@ ```json | ||
Now the command from `package.json` is set up as executable git pre-commit hook. | ||
Now the command from `package.json` is set up as executable git `pre-commit` hook. | ||
@@ -66,1 +93,7 @@ ### Update a pre-commit hook command | ||
``` | ||
### Uninstall pre-commit-hook | ||
```sh | ||
npm uninstall --save-dev simple-pre-commit | ||
``` |
@@ -35,2 +35,3 @@ const fs = require('fs') | ||
} | ||
function getProjectRootDirectoryFromNodeModules(projectPath) { | ||
@@ -54,2 +55,3 @@ function _arraysAreEqual(a1, a2) { | ||
} | ||
function checkSimplePreCommitInDependencies(projectRootPath) { | ||
@@ -72,2 +74,3 @@ if (typeof projectRootPath !== 'string') { | ||
} | ||
function getCommandFromConfig(projectRootPath) { | ||
@@ -94,2 +97,3 @@ if (typeof projectRootPath !== 'string') { | ||
} | ||
function setPreCommitHook(command) { | ||
@@ -104,2 +108,10 @@ const gitRoot = getGitProjectRoot(process.cwd()) | ||
} | ||
function removePreCommitHook() { | ||
const gitRoot = getGitProjectRoot(process.cwd()) | ||
const preCommitHookPath = path.normalize(gitRoot + '/hooks/pre-commit') | ||
fs.unlinkSync(preCommitHookPath) | ||
} | ||
function _getPackageJson(projectPath = process.cwd()) { | ||
@@ -119,2 +131,3 @@ if (typeof projectPath !== "string") { | ||
} | ||
function _getCommandFromPackageJson(projectRootPath = process.cwd()) { | ||
@@ -124,2 +137,3 @@ const {packageJsonContent} = _getPackageJson(projectRootPath) | ||
} | ||
function _getCommandFromFile(projectRootPath, fileName) { | ||
@@ -149,3 +163,4 @@ if (typeof projectRootPath !== "string") { | ||
getProjectRootDirectoryFromNodeModules, | ||
getGitProjectRoot | ||
getGitProjectRoot, | ||
removePreCommitHook | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10906
6
176
96