mirror of
https://github.com/konvajs/konva.git
synced 2026-03-03 16:58:33 +08:00
checking in jsdoc dir so people can generate docs themselves
This commit is contained in:
179
jsdoc-master/lib/jsdoc/opts/argparser.js
Normal file
179
jsdoc-master/lib/jsdoc/opts/argparser.js
Normal file
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
Parse the command line arguments.
|
||||
@module jsdoc/opts/argparser
|
||||
@author Michael Mathews <micmath@gmail.com>
|
||||
@license Apache License 2.0 - See file 'LICENSE.md' in this project.
|
||||
*/
|
||||
|
||||
var _ = require('underscore');
|
||||
|
||||
var hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
|
||||
/**
|
||||
Create an instance of the parser.
|
||||
@classdesc A parser to interpret the key-value pairs entered on the command
|
||||
line.
|
||||
@constructor
|
||||
*/
|
||||
var ArgParser = function() {
|
||||
this._options = [];
|
||||
this._shortNameIndex = {};
|
||||
this._longNameIndex = {};
|
||||
};
|
||||
|
||||
ArgParser.prototype._getOptionByShortName = function(name) {
|
||||
if (hasOwnProp.call(this._shortNameIndex, name)) {
|
||||
return this._options[this._shortNameIndex[name]];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
ArgParser.prototype._getOptionByLongName = function(name) {
|
||||
if (hasOwnProp.call(this._longNameIndex, name)) {
|
||||
return this._options[this._longNameIndex[name]];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Provide information about a legal option.
|
||||
* @param {character} shortName The short name of the option, entered like: -T.
|
||||
* @param {string} longName The equivalent long name of the option, entered like: --test.
|
||||
* @param {boolean} hasValue Does this option require a value? Like: -t templatename
|
||||
* @param {string} helpText A brief description of the option.
|
||||
* @param {boolean} [canHaveMultiple=false] Set to `true` if the option can be provided more than once.
|
||||
* @param {function} [coercer] A function to coerce the given value to a specific type.
|
||||
* @example
|
||||
* myParser.addOption('t', 'template', true, 'The path to the template.');
|
||||
* myParser.addOption('h', 'help', false, 'Show the help message.');
|
||||
*/
|
||||
ArgParser.prototype.addOption = function(shortName, longName, hasValue, helpText, canHaveMultiple, coercer) {
|
||||
this._options.push({
|
||||
shortName: shortName,
|
||||
longName: longName,
|
||||
hasValue: hasValue,
|
||||
helpText: helpText,
|
||||
canHaveMultiple: (canHaveMultiple || false),
|
||||
coercer: coercer
|
||||
});
|
||||
|
||||
if (shortName) {
|
||||
this._shortNameIndex[shortName] = this._options.length - 1;
|
||||
}
|
||||
if (longName) {
|
||||
this._longNameIndex[longName] = this._options.length - 1;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
Generate a summary of all the options with corresponding help text.
|
||||
@returns {string}
|
||||
*/
|
||||
ArgParser.prototype.help = function() {
|
||||
var helpArr = ['OPTIONS:'],
|
||||
option, optionHelp;
|
||||
|
||||
for (var i = 0, leni = this._options.length; i < leni; i++) {
|
||||
option = this._options[i];
|
||||
optionHelp = '\t';
|
||||
|
||||
if (option.shortName) {
|
||||
optionHelp += '-' + option.shortName + (option.longName ? ', ' : '');
|
||||
}
|
||||
|
||||
if (option.longName) {
|
||||
optionHelp += '--' + option.longName;
|
||||
}
|
||||
|
||||
if (option.hasValue) {
|
||||
optionHelp += ' <value>';
|
||||
}
|
||||
|
||||
optionHelp += '\t\t' + option.helpText;
|
||||
helpArr.push(optionHelp);
|
||||
}
|
||||
|
||||
return helpArr.join('\n');
|
||||
};
|
||||
|
||||
/**
|
||||
Get the options.
|
||||
@param {Array.<string>} args An array, like ['-x', 'hello']
|
||||
@param {Object} [defaults={}] An optional collection of default values.
|
||||
@returns {Object} The keys will be the longNames, or the shortName if
|
||||
no longName is defined for that option. The values will be the values
|
||||
provided, or `true` if the option accepts no value.
|
||||
*/
|
||||
ArgParser.prototype.parse = function(args, defaults) {
|
||||
var result = defaults && _.defaults({}, defaults) || {};
|
||||
|
||||
result._ = [];
|
||||
for (var i = 0, leni = args.length; i < leni; i++) {
|
||||
var arg = '' + args[i],
|
||||
next = (i < leni-1)? '' + args[i+1] : null,
|
||||
option,
|
||||
shortName = null,
|
||||
longName,
|
||||
name,
|
||||
value = null;
|
||||
|
||||
// like -t
|
||||
if (arg.charAt(0) === '-') {
|
||||
|
||||
// like --template
|
||||
if (arg.charAt(1) === '-') {
|
||||
name = longName = arg.slice(2);
|
||||
option = this._getOptionByLongName(longName);
|
||||
}
|
||||
else {
|
||||
name = shortName = arg.slice(1);
|
||||
option = this._getOptionByShortName(shortName);
|
||||
}
|
||||
|
||||
if (option === null) {
|
||||
throw new Error( 'Unknown command line option found: ' + name );
|
||||
}
|
||||
|
||||
if (option.hasValue) {
|
||||
value = next;
|
||||
i++;
|
||||
|
||||
if (value === null || value.charAt(0) === '-') {
|
||||
throw new Error( 'Command line option requires a value: ' + name );
|
||||
}
|
||||
}
|
||||
else {
|
||||
value = true;
|
||||
}
|
||||
|
||||
if (option.longName && shortName) {
|
||||
name = option.longName;
|
||||
}
|
||||
|
||||
if (typeof option.coercer === 'function') {
|
||||
value = option.coercer(value);
|
||||
}
|
||||
|
||||
// Allow for multiple options of the same type to be present
|
||||
if (option.canHaveMultiple && hasOwnProp.call(result, name)) {
|
||||
var val = result[name];
|
||||
|
||||
if (val instanceof Array) {
|
||||
val.push(value);
|
||||
} else {
|
||||
result[name] = [val, value];
|
||||
}
|
||||
}
|
||||
else {
|
||||
result[name] = value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
result._.push(arg);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = ArgParser;
|
||||
127
jsdoc-master/lib/jsdoc/opts/args.js
Normal file
127
jsdoc-master/lib/jsdoc/opts/args.js
Normal file
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
@module jsdoc/opts/args
|
||||
@requires jsdoc/opts/argparser
|
||||
@author Michael Mathews <micmath@gmail.com>
|
||||
@license Apache License 2.0 - See file 'LICENSE.md' in this project.
|
||||
*/
|
||||
|
||||
var ArgParser = require('jsdoc/opts/argparser'),
|
||||
argParser = new ArgParser(),
|
||||
hasOwnProp = Object.prototype.hasOwnProperty,
|
||||
ourOptions,
|
||||
querystring = require('querystring'),
|
||||
util = require('util');
|
||||
|
||||
|
||||
// cast strings to booleans or integers where appropriate
|
||||
function castTypes(item) {
|
||||
var result = item;
|
||||
|
||||
switch (result) {
|
||||
case 'true':
|
||||
return true;
|
||||
case 'false':
|
||||
return false;
|
||||
default:
|
||||
// might be an integer
|
||||
var integer = parseInt(result, 10);
|
||||
if (String(integer) === result && integer !== 'NaN') {
|
||||
return integer;
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check for strings that we need to cast to other types
|
||||
function fixTypes(item) {
|
||||
var result = item;
|
||||
|
||||
// recursively process arrays and objects
|
||||
if ( util.isArray(result) ) {
|
||||
for (var i = 0, l = result.length; i < l; i++) {
|
||||
result[i] = fixTypes(result[i]);
|
||||
}
|
||||
} else if (typeof result === 'object') {
|
||||
Object.keys(result).forEach(function(prop) {
|
||||
result[prop] = fixTypes(result[prop]);
|
||||
});
|
||||
} else {
|
||||
result = castTypes(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseQuery(str) {
|
||||
var result = querystring.parse(str);
|
||||
|
||||
Object.keys(result).forEach(function(prop) {
|
||||
result[prop] = fixTypes(result[prop]);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
argParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template');
|
||||
argParser.addOption('c', 'configure', true, 'The path to the configuration file. Default: jsdoc __dirname + /conf.json');
|
||||
argParser.addOption('e', 'encoding', true, 'Assume this encoding when reading all source files. Default: utf8');
|
||||
argParser.addOption('T', 'test', false, 'Run all tests and quit.');
|
||||
argParser.addOption('d', 'destination', true, 'The path to the output folder. Use "console" to dump data to the console. Default: ./out/');
|
||||
argParser.addOption('p', 'private', false, 'Display symbols marked with the @private tag. Default: false');
|
||||
argParser.addOption('r', 'recurse', false, 'Recurse into subdirectories when scanning for source code files.');
|
||||
argParser.addOption('l', 'lenient', false, 'Continue to generate output if a doclet is incomplete or contains errors. Default: false');
|
||||
argParser.addOption('h', 'help', false, 'Print this message and quit.');
|
||||
argParser.addOption('X', 'explain', false, 'Dump all found doclet internals to console and quit.');
|
||||
argParser.addOption('q', 'query', true, 'A query string to parse and store in env.opts.query. Example: foo=bar&baz=true', false, parseQuery);
|
||||
argParser.addOption('u', 'tutorials', true, 'Directory in which JSDoc should search for tutorials.');
|
||||
argParser.addOption('v', 'version', false, 'Display the version number and quit.');
|
||||
|
||||
//TODO [-R, recurseonly] = a number representing the depth to recurse
|
||||
//TODO [-f, filter] = a regex to filter on <-- this can be better defined in the configs?
|
||||
|
||||
//Here are options specific to tests
|
||||
argParser.addOption(null, 'verbose', false, 'Display verbose output for tests');
|
||||
argParser.addOption(null, 'match', true, 'Only run tests containing <value>', true);
|
||||
argParser.addOption(null, 'nocolor', false, 'Do not use color in console output from tests');
|
||||
|
||||
/**
|
||||
Set the options for this app.
|
||||
@throws {Error} Illegal arguments will throw errors.
|
||||
@param {string|String[]} args The command line arguments for this app.
|
||||
*/
|
||||
exports.parse = function(args) {
|
||||
args = args || [];
|
||||
|
||||
if (typeof args === 'string' || args.constructor === String) {
|
||||
args = (''+args).split(/\s+/g);
|
||||
}
|
||||
|
||||
ourOptions = argParser.parse(args);
|
||||
|
||||
return ourOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
Display help message for options.
|
||||
*/
|
||||
exports.help = function() {
|
||||
return argParser.help();
|
||||
};
|
||||
|
||||
/**
|
||||
Get a named option.
|
||||
@param {string} name The name of the option.
|
||||
@return {string} The value associated with the given name.
|
||||
*//**
|
||||
Get all the options for this app.
|
||||
@return {Object} A collection of key/values representing all the options.
|
||||
*/
|
||||
exports.get = function(name) {
|
||||
if (typeof name === 'undefined') {
|
||||
return ourOptions;
|
||||
}
|
||||
else {
|
||||
return ourOptions[name];
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user