Skip to content

Commit feea958

Browse files
authored
Merge pull request #3 from toplenboren/dev
Enhance UX and add an ability to set command from `simple-pre-commit.json`
2 parents 395aa2d + 4efaae8 commit feea958

File tree

14 files changed

+196
-64
lines changed

14 files changed

+196
-64
lines changed

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.github
2+
node_modules
3+
.idea
4+
.vscode
5+
6+
_tests
7+
simple-pre-commit.test.js
8+
9+
.eslintrc.js
10+
.eslintignore

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ You can look up about git hooks [here](https://git-scm.com/book/en/v2/Customizin
2828

2929
## Updating a pre-commit hook command
3030

31-
Run `npx simple-pre-commit`
31+
Run `npx simple-pre-commit` **from root of your project**
3232

3333
Note that you should manually run `npx simple-pre-commit` every time you change the command
34+
35+
36+
## Additional configuration options
37+
38+
You can also add the `.simple-pre-commit.json` to the project and write the command inside it, if you do not want to put command inside `package.json`
39+
40+
That way, `.simple-pre-commit.json` should look like this and `package.json` may not have `simple-pre-commit` configuration inside it
41+
42+
```(json)
43+
{
44+
"simple-pre-commit":"npx lint staged"
45+
}
46+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "simple-pre-commit-test-package",
3+
"version": "1.0.0",
4+
"simple-pre-commit": "test",
5+
"devDependencies": {
6+
"simple-pre-commit": "1.0.0"
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "simple-pre-commit-test-package",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"simple-pre-commit": "1.0.0"
6+
}
7+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"simple-pre-commit": "test"
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "simple-pre-commit-test-package",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"simple-pre-commit": "1.0.0"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "simple-pre-commit-test-package",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"simple-pre-commit": "1.0.0"
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "simple-pre-commit-test-package",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
"simple-pre-commit": "1.0.0"
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "simple-pre-commit-test-package",
3+
"version": "1.0.0",
4+
"devDependencies": {
5+
},
6+
"dependencies": {
7+
}
8+
}

cli.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ const os = require('os')
66
* It really has only one function — to set new pre commit hook.
77
* Checks the package.json for simple-pre-commit hook command and sets the found command as hook
88
*/
9-
const {getCommandFromPackageJson, setPreCommitHook} = require('./simple-pre-commit')
9+
const {getCommandFromConfig, setPreCommitHook} = require('./simple-pre-commit')
1010

11-
const command = getCommandFromPackageJson()
11+
const command = getCommandFromConfig(process.cwd())
1212

1313
if (!command) {
14-
console.log(`Couldn't parse command! Please add command to package.json or .simpleprecommit.json. See README.md for details`)
14+
console.log(`Couldn't parse command! Please add command to package.json or .simple-pre-commit.json. See README.md for details`)
1515
os.exit(1)
1616
}
1717

1818
setPreCommitHook(command)
19+
20+
console.log('Set pre commit hooK: ' + command)

0 commit comments

Comments
 (0)