-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict' | ||
|
||
const lint = require('@commitlint/lint') | ||
const read = require('@commitlint/read') | ||
const load = require('@commitlint/load') | ||
const util = require('util') | ||
|
||
function exec (command) { | ||
return new Promise((resolve, reject) => { | ||
require('child_process').exec(command, (err, stdout, stderr) => { | ||
if (err) { | ||
return reject(err) | ||
} else { | ||
return resolve(stdout) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
function runLinter () { | ||
return exec('git rev-parse --abbrev-ref HEAD') | ||
.then((branch) => exec(`git rev-list --left-right --count master...${branch}`)) | ||
.then((count) => count.split(/\s+/)[1]) | ||
.then((commits) => read({to: 'HEAD', from: `HEAD~${commits}`})) | ||
.then((commits) => Promise.all([commits, load({ extends: ['@commitlint/config-conventional'] })])) | ||
.then(([commits, opts]) => Promise.all(commits.map((commit) => lint( | ||
commit, | ||
opts.rules, | ||
opts.parserPreset ? {parserOpts: opts.parserPreset.parserOpts} : {} | ||
)))) | ||
.then(results => results.filter((r) => !r.valid)) | ||
.then(invalid => { | ||
if (invalid.length) { | ||
console.log(util.inspect(invalid, false, null)) | ||
return 1 | ||
} else { | ||
return 0 | ||
} | ||
}) | ||
.then(process.exit) | ||
.catch((error) => { | ||
console.log(error) | ||
process.exit(1) | ||
}) | ||
} | ||
|
||
function checkOutAndLint () { | ||
return exec('git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*') | ||
.then(() => exec('git fetch')) | ||
.then(runLinter) | ||
.catch((error) => { | ||
console.log(error) | ||
process.exit(1) | ||
}) | ||
} | ||
|
||
exec('git rev-parse --verify master') | ||
.then(runLinter) | ||
.catch(checkOutAndLint) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
"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", | ||
"commitlint": "node cli.js commitlint" | ||
}, | ||
"keywords": [ | ||
"webpack", | ||
|
@@ -29,6 +30,10 @@ | |
"author": "Friedel Ziegelmayer <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@commitlint/config-conventional": "^6.1.2", | ||
"@commitlint/lint": "^6.1.2", | ||
"@commitlint/load": "^6.1.2", | ||
"@commitlint/read": "^6.1.2", | ||
"async": "^2.6.0", | ||
"browserify-zlib": "^0.2.0", | ||
"chalk": "^2.3.0", | ||
|