forked from jsdoc/jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for default configuration values. Closes Issue jsdoc#129.…
… References Issue jsdoc#126.
- Loading branch information
Showing
4 changed files
with
112 additions
and
6 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
@overview | ||
@author Michael Mathews <[email protected]> | ||
@license Apache License 2.0 - See file 'LICENSE.md' in this project. | ||
*/ | ||
|
||
/** | ||
@module jsdoc/config | ||
@requires common/util | ||
*/ | ||
|
||
// used to do recursive merge | ||
var util = require('common/util'); | ||
|
||
// required config values, override these defaults in your config.json if necessary | ||
const defaults = { | ||
"source": { | ||
"includePattern": ".+\\.js(doc)?$", | ||
"excludePattern": "(^|\\/)_" | ||
}, | ||
"jsVersion": 180 | ||
}; | ||
|
||
module.exports = Config; | ||
|
||
/** | ||
@class | ||
@classdesc Represents a JSDoc application configuration. | ||
@param {string} [json] - The contents of config.json. | ||
*/ | ||
function Config(json) { | ||
var json = JSON.parse( (json || "{}") ); | ||
|
||
this._config = util.mergeRecurse(defaults, json); | ||
} | ||
|
||
/** | ||
Get the merged configuration values. | ||
*/ | ||
Config.prototype.get = function() { | ||
return this._config; | ||
} | ||
|
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,48 @@ | ||
describe("jsdoc/config", function() { | ||
var jsdoc = {config: require('jsdoc/config') }; | ||
|
||
it("should exist", function() { | ||
expect(jsdoc.config).toBeDefined(); | ||
expect(typeof jsdoc.config).toEqual("function"); | ||
}); | ||
|
||
it("should provide a 'get' instance function", function() { | ||
var config = new jsdoc.config(); | ||
expect(config.get).toBeDefined(); | ||
expect(typeof config.get).toEqual("function"); | ||
}); | ||
|
||
describe ("constructor with empty", function() { | ||
it('should be possible to construct a Config with an empty arguments', function() { | ||
var config = new jsdoc.config().get(); | ||
|
||
expect(config.plugins).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe ("constructor with {}", function() { | ||
it('should be possible to construct a Config with JSON of an object literal that is emptys', function() { | ||
var config = new jsdoc.config('{}').get(); | ||
|
||
expect(config.plugins).toEqual([]); | ||
}); | ||
}); | ||
|
||
describe ("constructor with plugins value", function() { | ||
it('should be possible to construct a Config with JSON of an object literal that has a plugin value', function() { | ||
var config = new jsdoc.config('{"plugins":[42]}').get(); | ||
|
||
expect(config.plugins).toEqual([42]); | ||
expect(config.jsVersion).toEqual(180); | ||
}); | ||
}); | ||
|
||
describe ("constructor with source value", function() { | ||
it('should be possible to construct a Config with JSON of an object literal that has a source value', function() { | ||
var config = new jsdoc.config('{"source":{"includePattern":"hello"}}').get(); | ||
|
||
expect(config.source.includePattern).toEqual('hello'); | ||
expect(config.source.excludePattern).toEqual('(^|\\/)_'); | ||
}); | ||
}); | ||
}); |