diff --git a/main.js b/main.js index 2e3deac5..add8a973 100644 --- a/main.js +++ b/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); diff --git a/modules/jsdoc/package.js b/modules/jsdoc/package.js new file mode 100644 index 00000000..eb2f7cce --- /dev/null +++ b/modules/jsdoc/package.js @@ -0,0 +1,55 @@ +/** + @overview + @author Michael Mathews + @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} + */ + 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; + } + +})(); \ No newline at end of file