Skip to content

Commit

Permalink
commitlint done
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur-kushwaha committed Jan 23, 2018
1 parent 4c6fc9d commit 4b35880
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const printError = require('./lib/print-error')

const bump = require('./lib/lifecycles/bump')
const analyzeCommits = require('./lib/lifecycles/analyzeCommits');
const changelog = require('./lib/lifecycles/changelog')
const commit = require('./lib/lifecycles/commit')
const tag = require('./lib/lifecycles/tag')
Expand All @@ -14,6 +15,9 @@ module.exports = function standardVersion (argv) {
var args = Object.assign({}, defaults, argv)

return Promise.resolve()
.then(()=>{
return analyzeCommits();
})
.then(() => {
return bump(args, pkg)
})
Expand All @@ -29,7 +33,7 @@ module.exports = function standardVersion (argv) {
.then(() => {
return tag(newVersion, pkg.private, args)
})
.catch((err) => {
.catch((err) => {
printError(args, err.message)
throw err
})
Expand Down
43 changes: 43 additions & 0 deletions lib/lifecycles/analyzeCommits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const core = require('@commitlint/core');
var gitSemverTags = require('git-semver-tags');
const RULES = require('conventional-changelog-meso/commitlint.config');

module.exports = function () {
const check = commit => {
return core.lint(commit, RULES)
.then(report => {
return {
commit,
report
}
})
}
return new Promise((resolve, reject) => {
gitSemverTags(function (err, tags) {
if (err) {
reject(err);
}
resolve(tags[0]);
});
}).then(function (tag) {
return core.read({ to: 'HEAD', from: tag })
}).then(commits => {
return Promise.all(commits.map(check))
}).then(tasks => {
var failedTasks=[];
for(var task of tasks){
if(task.report.valid==false){
failedTasks.push({
commit:task.commit,
errors:task.report.errors
});
}
}

if(failedTasks.length>0){
return Promise.reject({
message:"ERRORS: "+JSON.stringify(failedTasks)
})
}
});
}
2 changes: 1 addition & 1 deletion lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const path = require('path')
const runLifecycleScript = require('../run-lifecycle-script')
const semver = require('semver')
const writeFile = require('../write-file')
const config = require('conventional-changelog-meso/bump');
const config = require('conventional-changelog-meso/config');

var configsToUpdate = {}

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
},
"homepage": "https://github.com/conventional-changelog/standard-version#readme",
"dependencies": {
"@commitlint/core": "^6.0.2",
"chalk": "^1.1.3",
"conventional-changelog": "^1.1.0",
"conventional-changelog-meso": "git+https://github.com/ankur-kushwaha/conventional-changelog-meso.git",
"conventional-recommended-bump": "^1.0.0",
"dotgitignore": "^1.0.3",
"figures": "^1.5.0",
"fs-access": "^1.0.0",
"git-semver-tags": "^1.2.3",
"semver": "^5.1.0",
"yargs": "^8.0.1"
},
Expand Down

0 comments on commit 4b35880

Please sign in to comment.