feat(bin): Support globs on windows and use smarter recursion (#629) · documentationjs/documentation@cb8fdfa
11'use strict';
223-var mdeps = require('module-deps-sortable'),
4-fs = require('fs'),
5-path = require('path'),
6-babelify = require('babelify'),
7-filterJS = require('../filter_js'),
8-concat = require('concat-stream'),
9-moduleFilters = require('../../lib/module_filters'),
10-expandDirectories = require('./expand_directories');
3+var mdeps = require('module-deps-sortable');
4+var fs = require('fs');
5+var path = require('path');
6+var babelify = require('babelify');
7+var concat = require('concat-stream');
8+var moduleFilters = require('../../lib/module_filters');
9+var smartGlob = require('../smart_glob.js');
11101211/**
1312 * Returns a readable stream of dependencies, given an array of entry
@@ -22,8 +21,6 @@ var mdeps = require('module-deps-sortable'),
2221 * @returns {undefined} calls callback
2322 */
2423function dependencyStream(indexes, options, callback) {
25-var filterer = filterJS(options.extension, options.polyglot);
26-2724var md = mdeps({
2825/**
2926 * Determine whether a module should be included in documentation
@@ -33,11 +30,11 @@ function dependencyStream(indexes, options, callback) {
3330filter: function (id) {
3431return !!options.external || moduleFilters.internalOnly(id);
3532},
36-extensions: [].concat(options.extension || [])
37-.concat(['js', 'es6', 'jsx', 'json'])
33+extensions: [].concat(options.requireExtension || [])
3834.map(function (ext) {
39-return '.' + ext;
40-}),
35+return '.' + ext.replace(/^\./, '');
36+})
37+.concat(['.js', '.json', '.es6', '.jsx']),
4138transform: [babelify.configure({
4239sourceMap: false,
4340compact: false,
@@ -55,19 +52,30 @@ function dependencyStream(indexes, options, callback) {
5552})],
5653postFilter: moduleFilters.externals(indexes, options)
5754});
58-expandDirectories(indexes, filterer).forEach(function (index) {
55+smartGlob(indexes, options.parseExtensions).forEach(function (index) {
5956md.write(path.resolve(index));
6057});
6158md.end();
6259md.once('error', function (error) {
6360return callback(error);
6461});
6562md.pipe(concat(function (inputs) {
66-callback(null, inputs.map(function (input) {
67-// un-transform babelify transformed source
68-input.source = fs.readFileSync(input.file, 'utf8');
69-return input;
70-}));
63+callback(null, inputs
64+.filter(function (input) {
65+// At this point, we may have allowed a JSON file to be caught by
66+// module-deps, or anything else allowed by requireExtension.
67+// otherwise module-deps would complain about
68+// it not being found. But Babel can't parse JSON, so we filter non-JavaScript
69+// files away.
70+return options.parseExtensions.indexOf(
71+path.extname(input.file).replace(/^\./, '')
72+) > -1;
73+})
74+.map(function (input) {
75+// un-transform babelify transformed source
76+input.source = fs.readFileSync(input.file, 'utf8');
77+return input;
78+}));
7179}));
7280}
7381