diff --git a/docs/args/index.mustache b/docs/args/index.mustache index 5d1c2a90..07ae870f 100644 --- a/docs/args/index.mustache +++ b/docs/args/index.mustache @@ -309,7 +309,7 @@ project: "linkNatives": "true", "attributesEmit": "true", "paths": [ - "./lib" + "lib/**" ], "outdir": "./output/api" } diff --git a/lib/utils.js b/lib/utils.js index 328a409e..e5f22b41 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -6,6 +6,7 @@ 'use strict'; var path = require('path'), + glob = require('glob'), minimatch = require('minimatch'), fs = require('graceful-fs'); @@ -336,119 +337,23 @@ YUI.add('utils', function (Y) { Y.getProjectData = getProjectData; - - /** - * Walks the tree from this dir and returns all the subdirs - * @method getDirs - * @param {String} dir The dir to begin at - * @return {Array} The array of directories.. - */ - var getDirs = function (dir) { - var dirs = fs.readdirSync(dir), - paths = []; - - dirs.forEach(function (d) { - var _dir = path.join(dir, d), - stat = fs.lstatSync(_dir); - - if (stat.isDirectory()) { - if (_dir.indexOf('.') !== 0) { - paths = [].concat(paths, _dir, getDirs(_dir)); - } - } - }); - - return paths; - }; - - Y.getDirs = getDirs; - /** - * Make sure all the paths passed are directories and that they are not in the ignore list. + * globpaths and ignore are both arrays of globs or a globstring. They should resolve to the actual files + * you want yuidoc to parse. * @method validatePaths - * @param {Array} paths The array of paths to validate - * @param {String} [ignore=false] A string to call `.indexOf` on a path to determine if it should be ignored + * @param {Array} globpaths The array of globs to expand and validate + * @param {String} [ignore=false] array of globs to expand and filter paths array by */ - var validatePaths = function (paths, ignore) { - var newpaths = []; - //Shortcut the *, . & ./ shortcuts that shall globbing fixes for us - if (paths === '*' || paths === '.' || paths === './') { - paths = [process.cwd()]; - } - - // Ensure that we always have an array of some kind. - paths = paths || []; - if (!Y.Lang.isArray(paths)) { - paths = [paths]; - } - paths.forEach(function (validatePath) { - var glob = validatePath || ''; - - if (process.platform === 'win32') { - glob = validatePath.replace(/\//g, '\\\\'); - } - - var glob_paths = getDirs('.'), - is_globbed = false; - - glob_paths.forEach(function (dir) { - //Don't scan things in node_modules - if (dir.indexOf('node_modules') > -1) { - return; - } - if (minimatch(dir, glob, { - period: true - })) { - newpaths.push(dir); - is_globbed = true; - } - }); - - if (!is_globbed && (Y.Files.isDirectory(glob))) { - //If minimatch fails, check to see if it's a relative directory - // if it is, add it directly - newpaths.push(glob); - } - }); - - paths = newpaths; - paths.forEach(function (newPath) { - try { - if (!Y.Files.isDirectory(newPath)) { - throw ('Path not a directory: ' + newPath); - } - } catch (e) { - throw new Error(e.message); - } - }); - - if (!paths || !paths.forEach) { - throw ('Paths should be an array of paths'); - } - - if (ignore) { - if (!(ignore instanceof Array)) { - ignore = [ignore]; - } - var p = [], - shouldIgnore = false; - - paths.forEach(function (v) { - shouldIgnore = false; - ignore.forEach(function (i) { - if (!shouldIgnore && v.indexOf(i) !== -1) { - shouldIgnore = true; - } - }); - if (!shouldIgnore) { - p.push(v); - } + var validatePaths = function(globpaths, ignore) { + ignore = [].concat(ignore || []); + return [].concat(globpaths || process.cwd()) + .reduce(function(filepaths, globpath){ return filepaths.concat(glob.sync(globpath)); }, []) + .filter(function(filepath){ + return !ignore.filter(function(ignoreGlob){ return minimatch(filepath, ignoreGlob); }).length; + }) + .filter(function(filepath, i, filepaths){ + return !filepaths.slice(i + 1).filter(function(filepath2){ return filepath === filepath2; }).length; }); - paths = p; - } - - paths = paths.sort(); - return paths; }; Y.validatePaths = validatePaths; diff --git a/lib/yuidoc.js b/lib/yuidoc.js index 3c6cc91a..188eb0e8 100755 --- a/lib/yuidoc.js +++ b/lib/yuidoc.js @@ -86,13 +86,6 @@ YUI.add('yuidoc', function (Y) { * @private */ this.filemap = {}; - /** - * Holder for the list of directories we are processing. - * @property dirmap - * @type Object - * @private - */ - this.dirmap = {}; /** * Internal holder for configuration options. @@ -138,87 +131,30 @@ YUI.add('yuidoc', function (Y) { }, /** - * Walks the paths and parses the directory contents - * @method walk - * @private - */ - walk: function () { - Y.each(this.options.paths, function (dir) { - this.parsedir(dir); - }, this); - }, - - /** - * Walks the passed directory and grabs all the files recursively. - * @method parsedir - * @param {String} dir The directory to parse the contents of. - * @private - */ - parsedir: function (dir) { - if (!Y.Files.isDirectory(dir)) { - throw ('Can not find directory: ' + dir); - } - - var allfiles = fs.readdirSync(dir), - stats, - files = [], - fullpath, self = this; - - if (dir in self.options.excludes) { - return; - } - - allfiles = allfiles.sort(); - - Y.each(allfiles, function (filename) { - if (!(filename in self.options.excludes)) { - fullpath = path.join(dir, filename); - - stats = fs.statSync(fullpath); - - if (stats.isDirectory() && !self.options.norecurse) { - self.parsedir(fullpath); - } else { - files.push(filename); - } - } - }); - - if (!(dir in self.options.excludes)) { - this.parsefiles(dir, files); - } - }, - - /** - * Gathers all the file data and populates the filemap and dirmap hashes. + * Gathers all the file data and populates the filemap and. * @method parsefiles - * @param {String} dir The directory to start from. * @param {Array} files List of files to parse. * @private */ - parsefiles: function (dir, files) { + parsefiles: function (files) { var self = this; files = files.sort(); Y.each(files, function (filename) { var ext = path.extname(filename), - text, - fullpath; + text; if (ext) { if (ext in self.options.extensions) { - fullpath = path.join(dir, filename); - - if (Y.Files.exists(fullpath)) { + if (Y.Files.exists(filename)) { self.filecount++; - text = fs.readFileSync(fullpath, Y.charset); + text = fs.readFileSync(filename, Y.charset); - self.filemap[fullpath] = text.replace(/\r?\n|\r/g, '\n'); - self.dirmap[fullpath] = dir; - self.getSelleck(fullpath); + self.filemap[filename] = text.replace(/\r?\n|\r/g, '\n'); + self.getSelleck(filename); } else { - Y.log('File skipped: ' + fullpath, 'warn', 'yuidoc'); + Y.log('File skipped: ' + filename, 'warn', 'yuidoc'); } } } @@ -390,12 +326,11 @@ YUI.add('yuidoc', function (Y) { this.starttime = new Date().getTime(); this._processConfig(); - this.walk(); + this.parsefiles(this.options.paths); var json = this.writeJSON(new Y.DocParser({ syntaxtype: this.options.syntaxtype, - filemap: this.filemap, - dirmap: this.dirmap + filemap: this.filemap }).parse()); if (this.options.lint) { diff --git a/output/api/classes/CLI.html b/output/api/classes/CLI.html index 834b8357..d85cb22a 100644 --- a/output/api/classes/CLI.html +++ b/output/api/classes/CLI.html @@ -17,7 +17,7 @@
lib/cli.js:9
+ Defined in: lib/cli.js:10
lib/builder.js:12
+ Defined in: lib/builder.js:14
_addHelpers