mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Added support for parsing package.json files.
This commit is contained in:
parent
92b54f6f32
commit
9f58b0fed1
17
main.js
17
main.js
@ -164,6 +164,7 @@ function exit(n) {
|
||||
*/
|
||||
function main() {
|
||||
var sourceFiles,
|
||||
packageJson,
|
||||
docs,
|
||||
jsdoc = {
|
||||
opts: {
|
||||
@ -201,7 +202,15 @@ function main() {
|
||||
include(env.conf.plugins[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// any source file named package.json is treated special
|
||||
for (var i = 0, l = env.opts._.length; i < l; i++ ) {
|
||||
if (/\bpackage\.json$/i.test(env.opts._[i])) {
|
||||
packageJson = require('fs').read( env.opts._[i] );
|
||||
env.opts._.splice(i--, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (env.opts._.length > 0) { // are there any files to scan and parse?
|
||||
|
||||
// allow filtering of found source files
|
||||
@ -219,6 +228,12 @@ function main() {
|
||||
require('jsdoc/src/handlers').attachTo(app.jsdoc.parser);
|
||||
|
||||
docs = app.jsdoc.parser.parse(sourceFiles, env.opts.encoding);
|
||||
|
||||
if (packageJson) {
|
||||
var packageDocs = new (require('jsdoc/package').Package)(packageJson);
|
||||
packageDocs.files = sourceFiles || [];
|
||||
docs.push(packageDocs);
|
||||
}
|
||||
|
||||
if (env.opts.expel) {
|
||||
dump(docs);
|
||||
|
||||
55
modules/jsdoc/package.js
Normal file
55
modules/jsdoc/package.js
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
@overview
|
||||
@author Michael Mathews <micmath@gmail.com>
|
||||
@license Apache License 2.0 - See file 'LICENSE.md' in this project.
|
||||
*/
|
||||
|
||||
/**
|
||||
@module jsdoc/package
|
||||
@see http://wiki.commonjs.org/wiki/Packages/1.0
|
||||
*/
|
||||
(function() {
|
||||
/**
|
||||
@class
|
||||
@classdesc Represents a JavaScript package.
|
||||
@param {string} json - The contents of package.json.
|
||||
*/
|
||||
exports.Package = function(json) {
|
||||
/** The source files associated with this package.
|
||||
@type {Array<String>}
|
||||
*/
|
||||
this.files = [];
|
||||
|
||||
/** The name of this package.
|
||||
@default
|
||||
*/
|
||||
this.kind = 'package';
|
||||
|
||||
json = JSON.parse(json);
|
||||
|
||||
/** The name of this package. */
|
||||
this.name = json.name;
|
||||
|
||||
/** The longname of this package. */
|
||||
this.longname = this.kind + ':' + this.name;
|
||||
|
||||
/** The description of this package. */
|
||||
this.description = json.description;
|
||||
|
||||
/** The version of this package. */
|
||||
this.version = json.version;
|
||||
|
||||
/** The licenses of this package.
|
||||
|
||||
@example
|
||||
"licenses": [
|
||||
{
|
||||
"type": "GPLv2",
|
||||
"url": "http://www.example.com/licenses/gpl.html",
|
||||
}
|
||||
]
|
||||
*/
|
||||
this.licenses = json.licenses;
|
||||
}
|
||||
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user