This repository has been archived by the owner on Feb 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): config through rc file, has precedence over package.json (
#62)
- Loading branch information
1 parent
e60ec37
commit d924a34
Showing
8 changed files
with
156 additions
and
28 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"helpMessage": "\nPlease fix your commit message (and consider using http://npm.im/commitizen)\n", | ||
"types": [ | ||
"feat", | ||
"fix", | ||
"docs", | ||
"style", | ||
"refactor", | ||
"perf", | ||
"test", | ||
"chore", | ||
"revert", | ||
"custom" | ||
], | ||
"warnOnFail": false, | ||
"autoFix": false | ||
} |
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,34 @@ | ||
'use strict'; | ||
|
||
var findup = require('findup'); | ||
var fs = require('fs'); | ||
var resolve = require('path').resolve; | ||
|
||
function getConfigObject(filename) { | ||
try { | ||
var rcFile = findup.sync(process.cwd(), filename); | ||
return JSON.parse(fs.readFileSync(resolve(rcFile, filename))); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
|
||
function getRcConfig() { | ||
return getConfigObject('.vcmrc'); | ||
} | ||
|
||
function getPackageConfig() { | ||
var configObject = getConfigObject('package.json'); | ||
return configObject && configObject.config && configObject.config['validate-commit-msg']; | ||
} | ||
|
||
function getConfig() { | ||
return getRcConfig() || getPackageConfig() || {}; | ||
} | ||
|
||
module.exports = { | ||
getConfig: getConfig, | ||
getRcConfig: getRcConfig, | ||
getPackageConfig: getPackageConfig, | ||
getConfigObject: getConfigObject | ||
}; |
This file was deleted.
Oops, something went wrong.
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,86 @@ | ||
'use strict'; | ||
|
||
var config = require('../lib/config'); | ||
var expect = require('chai').expect; | ||
var sinon = require('sinon'); | ||
var fs = require('fs'); | ||
|
||
function testConfigObject(configObject) { | ||
expect(configObject.helpMessage).to.contain('fix your commit'); | ||
} | ||
|
||
describe('config', function() { | ||
before(function() { | ||
sinon.stub(fs, 'readFileSync', function() { | ||
return JSON.stringify({ | ||
config: { | ||
'validate-commit-msg': { | ||
helpMessage: 'fix your commit' | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getPackageConfig', function() { | ||
it('returns the validate-commit-msg config object if it exists', function() { | ||
var configObject = config.getPackageConfig(); | ||
testConfigObject(configObject); | ||
}); | ||
}); | ||
|
||
describe('getRcConfig', function() { | ||
it('returns the config object if it exists', function() { | ||
fs.readFileSync.restore(); | ||
sinon.stub(fs, 'readFileSync', function() { | ||
return JSON.stringify({ | ||
helpMessage: 'fix your commit' | ||
}); | ||
}); | ||
var configObject = config.getRcConfig(); | ||
testConfigObject(configObject); | ||
}); | ||
}); | ||
|
||
describe('getConfig', function() { | ||
it('returns .vcmrc config by default', function() { | ||
var configObject = config.getConfig(); | ||
testConfigObject(configObject); | ||
}); | ||
|
||
it('spec name', function() { | ||
sinon.stub(config, 'getRcConfig', function() { | ||
throw null; | ||
}); | ||
var configObject = config.getConfig(); | ||
testConfigObject(configObject); | ||
config.getRcConfig.restore(); | ||
}); | ||
}); | ||
|
||
describe('getConfigObject', function() { | ||
it('returns config object given filename', function() { | ||
fs.readFileSync.restore(); | ||
sinon.stub(fs, 'readFileSync', function() { | ||
return JSON.stringify({ | ||
helpMessage: 'fix your commit' | ||
}); | ||
}); | ||
var configObject = config.getConfigObject('package.json'); | ||
expect(configObject.helpMessage).to.equal('fix your commit'); | ||
}); | ||
|
||
it('returns null on error', function() { | ||
fs.readFileSync.restore(); | ||
sinon.stub(fs, 'readFileSync', function() { | ||
throw new Error(); | ||
}); | ||
var configObject = config.getConfigObject('package.json'); | ||
expect(configObject).to.equal(null); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
fs.readFileSync.restore(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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