From 9d428ddb3caf3cb7d23425126802818cfd941559 Mon Sep 17 00:00:00 2001 From: Peter Rottmann Date: Thu, 16 May 2013 11:39:44 +0200 Subject: [PATCH] 0.1.10 Add -e exclude option for Files / Directories. --- .gitignore | 3 +-- README.md | 2 ++ bin/apidoc | 7 ++++++ lib/apidoc.js | 1 + lib/utils/find_files.js | 41 +++++++++++++++++++++++++--------- package.json | 2 +- test/fixtures/api_project.js | 4 ++-- test/fixtures/api_project.json | 4 ++-- 8 files changed, 46 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 711b5fba..80e94def 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ -.idea/ .settings/ .project node_modules/ tmp/ -doc/ +doc/ \ No newline at end of file diff --git a/README.md b/README.md index b6c0529e..cc5ea98a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Creates from input files a documentation in path `doc/`. ## Changelog +* `0.1.10` Add `-e` exclude option for Files / Directories, example `apidoc -e node_modules/`. +* `0.1.10` Fix check for a valid title in Template (Ben S. Stahlhood II https://github.com/apidoc/apidoc/pull/7) * `0.1.9` Fix for whitespace before comment block (Brandon Hamilton https://github.com/apidoc/apidoc/pull/2) * `0.1.8` Change templates, enable navigation scroll. * `0.1.7` Add @apiIgnore. Update grunt Modules. diff --git a/bin/apidoc b/bin/apidoc index 3fd20e27..5b05581c 100755 --- a/bin/apidoc +++ b/bin/apidoc @@ -23,6 +23,12 @@ var argv = optimist describe: "RegEx-Filter to select files that should be parsed (many -f can be used)." }) + .option("e", { + alias: "exclude-filters", + "default": "", + describe: "RegEx-Filter to select files / dirs that should not be parsed (many -e can be used).", + }) + .option("i", { alias: "input", "default": "./", @@ -111,6 +117,7 @@ function transformFilters(filters) } // transformFilters var defaults = { + excludeFilters: argv["exclude-filters"], includeFilters: argv["file-filters"], src: argv["input"], dest: argv["output"], diff --git a/lib/apidoc.js b/lib/apidoc.js index fedfddf9..b314f8d5 100644 --- a/lib/apidoc.js +++ b/lib/apidoc.js @@ -13,6 +13,7 @@ var colors = require("colors"); // Options var _defaultOptions = { + excludeFilters: [], includeFilters: [ ".*\\.js$" ], src: path.join(__dirname, "../example/"), diff --git a/lib/utils/find_files.js b/lib/utils/find_files.js index a2b695b9..0d40d9b6 100644 --- a/lib/utils/find_files.js +++ b/lib/utils/find_files.js @@ -1,37 +1,56 @@ var wrench = require("wrench"); /** - * Sucht rekursiv nach Dateien im Source-Verzeichnis und filtert die gewünschten Dateien aus. + * Search files recursivly and filter by include / exlude filters. * - * @param {Object[]} options Programmoptionen. - * @param {String} options.src Pfad zu den Quelldateien. - * @param {String[]} options.includeFilters Filterregeln zu verwendende Dateien. + * @param {Object[]} options Options. + * @param {String} options.src Path to source-files. + * @param {String[]} [options.excludeFilters] Exclude Filters. + * @param {String[]} options.includeFilters Include Filters. * @returns {String[]} */ function findFiles(options) { var files = []; try { - // Dateien rekursiv finden + // Find Files files = wrench.readdirSyncRecursive(options.src); - // RegExp-Filterregeln erstellen - var regExpFilters = []; + // Create RegExp Include Filter List + var regExpIncludeFilters = []; filters = options.includeFilters; if(typeof(filters) === "string") filters = [ filters ]; filters.forEach(function(filter) { - regExpFilters.push( new RegExp(filter) ); + if(filter.length > 0) regExpIncludeFilters.push( new RegExp(filter) ); }); // forEach - // Filtern mit RegExp-Filterregeln - var length = regExpFilters.length; + // RegExp Include Filter + var length = regExpIncludeFilters.length; files = files.filter(function(filename) { for(var i = 0; i < length; i += 1) { - if(regExpFilters[i].test(filename)) return 1; + if(regExpIncludeFilters[i].test(filename)) return 1; } // for return 0; }); // files.filter + + // Create RegExp Exclude Filter List + var regExpExcludeFilters = []; + filters = options.excludeFilters; + if(typeof(filters) === "string") filters = [ filters ]; + filters.forEach(function(filter) { + if(filter.length > 0) regExpExcludeFilters.push( new RegExp(filter) ); + }); // forEach + + // RegExp Exclude Filter + length = regExpExcludeFilters.length; + files = files.filter(function(filename) { + for(var i = 0; i < length; i += 1) + { + if(regExpExcludeFilters[i].test(filename)) return 0; + } // for + return 1; + }); // files.filter } // try finally { diff --git a/package.json b/package.json index 4bea6e73..9e9f1165 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apidoc", - "version": "0.1.9", + "version": "0.1.10", "description": "RESTful web API Documentation Generator", "author": "Peter Rottmann ", "license": "MIT", diff --git a/test/fixtures/api_project.js b/test/fixtures/api_project.js index 2c4bb16c..7ce3c673 100644 --- a/test/fixtures/api_project.js +++ b/test/fixtures/api_project.js @@ -1,10 +1,10 @@ define({ "name": "apidoc", - "version": "0.1.9", + "version": "0.1.10", "description": "RESTful web API Documentation Generator", "apidoc": "", "generator": { - "version": "0.1.9", + "version": "0.1.10", "time": "2013-04-12T16:50:18.630Z" } }); \ No newline at end of file diff --git a/test/fixtures/api_project.json b/test/fixtures/api_project.json index 0f73f059..1f80f92e 100644 --- a/test/fixtures/api_project.json +++ b/test/fixtures/api_project.json @@ -1,10 +1,10 @@ { "name": "apidoc", - "version": "0.1.9", + "version": "0.1.10", "description": "RESTful web API Documentation Generator", "apidoc": "", "generator": { - "version": "0.1.9", + "version": "0.1.10", "time": "2013-04-12T16:50:18.630Z" } } \ No newline at end of file