Skip to content

Commit

Permalink
feat: commit lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Jan 15, 2018
1 parent 858c1fd commit b3dbcd1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 1 deletion.
19 changes: 19 additions & 0 deletions bin/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const utils = require('../src/utils')

const exists = require('fs').existsSync
const rename = require('fs').renameSync
const join = require('path').join
const read = require('fs').readFileSync
const write = require('fs').writeFileSync

const hooksDir = utils.getPathToHooks()
const hook = join(hooksDir, 'commit-msg')

if (exists(hook)) {
console.log('Old hook is going to be moved to commit-msg.bak')
rename(hook, join(hooksDir, 'commit-msg.bak'))
}

write(hook, read(join(__dirname, '..', 'hooks', 'commit-msg')))
20 changes: 20 additions & 0 deletions bin/uninstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const utils = require('../src/utils')

const exists = require('fs').existsSync
const rename = require('fs').renameSync
const remove = require('fs').unlinkSync
const join = require('path').join

const hooksDir = utils.getPathToHooks()
const hook = join(hooksDir, 'commit-msg')
const oldHook = join(hook, '.bak')

if (exists(hook)) {
remove(hook)
}

if (exists(oldHook)) {
rename(oldHook, hook)
}
3 changes: 3 additions & 0 deletions hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

./node_modules/.bin/commitlint -x "@commitlint/config-conventional" -e $1
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"watch": "cross-env AEGIR_TEST=hello node cli.js test -t node --watch",
"release": "npm run test && node cli.js release --no-build --no-test",
"release-minor": "npm run test && node cli.js release --no-build --no-test --type minor",
"release-major": "npm run test && node cli.js release --no-build --no-test --type major"
"release-major": "npm run test && node cli.js release --no-build --no-test --type major",
"install": "node ./bin/install.js",
"uninstall": "node ./bin/uninstall.js"
},
"keywords": [
"webpack",
Expand All @@ -29,6 +31,8 @@
"author": "Friedel Ziegelmayer <[email protected]>",
"license": "MIT",
"dependencies": {
"@commitlint/cli": "^6.0.2",
"@commitlint/config-conventional": "^6.0.2",
"async": "^2.6.0",
"browserify-zlib": "^0.2.0",
"chalk": "^2.3.0",
Expand Down
16 changes: 16 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ exports.getPathToDocsMdFile = () => {
return path.join(exports.getPathToDocs(), 'index.md')
}

/**
* Path to the git hooks directory.
*
* @returns {string}
*/
exports.getPathToHooks = () => {
let basePath = exports.getBasePath()
const parentName = path.basename(path.dirname(basePath))

if (parentName === 'node_modules') {
basePath = path.normalize(path.join(basePath, '..', '..'))
}

return path.join(basePath, '.git', 'hooks')
}

exports.hook = (env, key) => (ctx) => {
if (ctx && ctx.hooks) {
if (ctx.hooks[env] && ctx.hooks[env][key]) {
Expand Down

0 comments on commit b3dbcd1

Please sign in to comment.