Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

globbing paths:[] and ignorePaths:[] changed a lot #351

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/args/index.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ project:
"linkNatives": "true",
"attributesEmit": "true",
"paths": [
"./lib"
"lib/**"
],
"outdir": "./output/api"
}
Expand Down
123 changes: 14 additions & 109 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'use strict';

var path = require('path'),
glob = require('glob'),
minimatch = require('minimatch'),
fs = require('graceful-fs');

Expand Down Expand Up @@ -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;
Expand Down
85 changes: 10 additions & 75 deletions lib/yuidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions output/api/classes/CLI.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<h1><img src="../assets/css/logo.png" title="yuidoc-root" width="117" height="52"></h1>
</div>
<div class="yui3-u-1-4 version">
<em>API Docs for: 0.7.0</em>
<em>API Docs for: 0.8.0</em>
</div>
</div>
<div id="bd" class="yui3-g">
Expand Down Expand Up @@ -91,7 +91,7 @@ <h1>CLI Class</h1>


<div class="foundat">
Defined in: <a href="../files/lib_cli.js.html#l9"><code>lib&#x2F;cli.js:9</code></a>
Defined in: <a href="../files/lib_cli.js.html#l10"><code>lib&#x2F;cli.js:10</code></a>
</div>

Module: <a href="../modules/yuidoc.html">yuidoc</a>
Expand Down
Loading