mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
JSDoc has a few requirements that are somewhat unusual for a Node.js app:
1. We need `require('jsdoc/foo')` to work from any module.
2. We need `require('jsdoc/foo')` to work from external code, such as templates and plugins.
Prior to this commit, JSDoc did two separate things to meet these requirements:
1. Use an npm post-install script to create a symlink from `lib/jsdoc` to `node_modules/jsdoc`.
2. When a user runs JSDoc, copy templates and plugins into the JSDoc directory.
These fixes worked, sort of. But they also caused numerous issues with file permissions, especially on Windows.
We now use the Requizzle module, which hacks the Node.js module system to support JSDoc's use cases. There's no longer a post-install script, and there's no need for a symlink in `node_modules`.
181 lines
3.9 KiB
JavaScript
Executable File
181 lines
3.9 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/*global arguments, require: true */
|
|
/**
|
|
* @project jsdoc
|
|
* @author Michael Mathews <micmath@gmail.com>
|
|
* @license See LICENSE.md file included in this distribution.
|
|
*/
|
|
|
|
/**
|
|
* Data representing the environment in which this app is running.
|
|
*
|
|
* @namespace
|
|
* @name env
|
|
*/
|
|
global.env = {
|
|
/**
|
|
* Running start and finish times.
|
|
*
|
|
* @memberof env
|
|
*/
|
|
run: {
|
|
start: new Date(),
|
|
finish: null
|
|
},
|
|
|
|
/**
|
|
* The command-line arguments passed into JSDoc.
|
|
*
|
|
* @type Array
|
|
* @memberof env
|
|
*/
|
|
args: [],
|
|
|
|
/**
|
|
* The parsed JSON data from the configuration file.
|
|
*
|
|
* @type Object
|
|
* @memberof env
|
|
*/
|
|
conf: {},
|
|
|
|
/**
|
|
* The absolute path to the base directory of the JSDoc application.
|
|
*
|
|
* @private
|
|
* @type string
|
|
* @memberof env
|
|
*/
|
|
dirname: '.',
|
|
|
|
/**
|
|
* The user's working directory at the time that JSDoc was started.
|
|
*
|
|
* @private
|
|
* @type string
|
|
* @memberof env
|
|
*/
|
|
pwd: null,
|
|
|
|
/**
|
|
* The command-line options, parsed into a key/value hash.
|
|
*
|
|
* @type Object
|
|
* @memberof env
|
|
* @example if (global.env.opts.help) { console.log('Helpful message.'); }
|
|
*/
|
|
opts: {},
|
|
|
|
/**
|
|
* The source files that JSDoc will parse.
|
|
* @type Array
|
|
* @memberof env
|
|
*/
|
|
sourceFiles: [],
|
|
|
|
/**
|
|
* The JSDoc version number and revision date.
|
|
*
|
|
* @type Object
|
|
* @memberof env
|
|
*/
|
|
version: {}
|
|
};
|
|
|
|
// initialize the environment for the current JavaScript VM
|
|
(function(args) {
|
|
'use strict';
|
|
|
|
var path;
|
|
|
|
if (args[0] && typeof args[0] === 'object') {
|
|
// we should be on Node.js
|
|
args = [__dirname, process.cwd()];
|
|
path = require('path');
|
|
|
|
// Create a custom require method that adds `lib/jsdoc` to the module lookup path.
|
|
// This makes it possible to `require('jsdoc/foo')` from external templates and plugins,
|
|
// and within JSDoc itself.
|
|
require = require('requizzle')({
|
|
requirePaths: [path.join(__dirname, 'lib')],
|
|
infect: true
|
|
});
|
|
}
|
|
|
|
require('./lib/jsdoc/util/runtime').initialize(args);
|
|
})( Array.prototype.slice.call(arguments, 0) );
|
|
|
|
/**
|
|
* Data that must be shared across the entire application.
|
|
*
|
|
* @namespace
|
|
* @name app
|
|
*/
|
|
global.app = {
|
|
jsdoc: {
|
|
name: require('./lib/jsdoc/name'),
|
|
parser: null,
|
|
scanner: new (require('./lib/jsdoc/src/scanner').Scanner)()
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Recursively print an object's properties to stdout. This method is safe to use with objects that
|
|
* contain circular references. In addition, on Mozilla Rhino, this method is safe to use with
|
|
* native Java objects.
|
|
*
|
|
* @global
|
|
* @name dump
|
|
* @private
|
|
* @param {Object} obj - Object(s) to print to stdout.
|
|
*/
|
|
global.dump = function() {
|
|
'use strict';
|
|
|
|
var doop = require('./lib/jsdoc/util/doop').doop;
|
|
var _dump = require('./lib/jsdoc/util/dumper').dump;
|
|
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
console.log( _dump(doop(arguments[i])) );
|
|
}
|
|
};
|
|
|
|
(function() {
|
|
'use strict';
|
|
|
|
var logger = require('./lib/jsdoc/util/logger');
|
|
var runtime = require('./lib/jsdoc/util/runtime');
|
|
var cli = require('./cli');
|
|
|
|
function cb(errorCode) {
|
|
cli.logFinish();
|
|
cli.exit(errorCode || 0);
|
|
}
|
|
|
|
cli.setVersionInfo()
|
|
.loadConfig();
|
|
|
|
if (!global.env.opts.test) {
|
|
cli.configureLogger();
|
|
}
|
|
|
|
cli.logStart();
|
|
|
|
// On Rhino, we use a try/catch block so we can log the Java exception (if available)
|
|
if ( runtime.isRhino() ) {
|
|
try {
|
|
cli.runCommand(cb);
|
|
}
|
|
catch(e) {
|
|
if (e.rhinoException) {
|
|
logger.fatal( e.rhinoException.printStackTrace() );
|
|
} else {
|
|
console.trace(e);
|
|
cli.exit(1);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
cli.runCommand(cb);
|
|
}
|
|
})();
|