Skip to content

Commit bb1d507

Browse files
authored
Merge pull request #19 from toplenboren/uninstall-script
Uninstall script
2 parents 71ffd38 + cdb9d97 commit bb1d507

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-pre-commit",
3-
"version": "1.1.3",
3+
"version": "1.2.0",
44
"description": "A simple, zero dependency tool for setting up git pre-commit hook for small projects",
55
"author": "Mikhail Gorbunov <[email protected]> (toplenboren.gituhb.io)",
66
"main": "./simple-pre-commit.js",
@@ -9,7 +9,8 @@
99
"postinstall": "node ./postinstall.js",
1010
"lint": "eslint *.js",
1111
"test": "jest",
12-
"publish": "clean-publish"
12+
"publish": "clean-publish",
13+
"uninstall": "node ./uninstall.js"
1314
},
1415
"keywords": [
1516
"pre-commit",

simple-pre-commit.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ function setPreCommitHook(command) {
130130
fs.chmodSync(preCommitHookPath, 0o0755)
131131
}
132132

133+
/**
134+
* Removes the pre-commit hook from .git/hooks
135+
*/
136+
function removePreCommitHook() {
137+
const gitRoot = getGitProjectRoot(process.cwd())
138+
const preCommitHookPath = path.normalize(gitRoot + '/hooks/pre-commit')
139+
140+
fs.unlinkSync(preCommitHookPath)
141+
}
142+
133143
/** Reads package.json file, returns package.json content and path
134144
* @param {string} projectPath - a path to the project, defaults to process.cwd
135145
* @return {{packageJsonContent: any, packageJsonPath: string}}
@@ -195,5 +205,6 @@ module.exports = {
195205
setPreCommitHook,
196206
getCommandFromConfig,
197207
getProjectRootDirectoryFromNodeModules,
198-
getGitProjectRoot
208+
getGitProjectRoot,
209+
removePreCommitHook
199210
}

uninstall.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
const {removePreCommitHook} = require("./simple-pre-commit");
4+
5+
6+
/**
7+
* Removes the pre-commit from command in config by default
8+
*/
9+
function uninstall() {
10+
console.log("[INFO] Removing pre-commit hook from .git/hooks")
11+
12+
try {
13+
removePreCommitHook()
14+
console.log("[INFO] Successfully removed pre-commit hook")
15+
} catch (e) {
16+
console.log("[INFO] Couldn't remove pre-commit hook. Reason: " + e)
17+
}
18+
}
19+
20+
uninstall()

0 commit comments

Comments
 (0)