@@ -3,12 +3,32 @@ const glob = require('glob');
3
3
const isFunction = require ( 'lodash/isFunction' ) ;
4
4
const isString = require ( 'lodash/isString' ) ;
5
5
6
+ const getComponentGlobs = components => {
7
+ if ( isFunction ( components ) ) {
8
+ return components ( ) ;
9
+ } else if ( Array . isArray ( components ) ) {
10
+ return components ;
11
+ } else if ( isString ( components ) ) {
12
+ return [ components ] ;
13
+ }
14
+ throw new Error (
15
+ `Styleguidist: components should be string, function or array, received ${ typeof components } .`
16
+ ) ;
17
+ } ;
18
+
6
19
const getFilesMatchingGlobs = ( components , rootDir , ignore ) =>
7
20
components
8
21
. map ( listItem => {
9
22
// Check if the string looks like a glob pattern by using hasMagic
10
23
if ( glob . hasMagic ( listItem ) ) {
11
- return glob . sync ( path . resolve ( rootDir , listItem ) , { ignore } ) ;
24
+ return glob . sync ( listItem , {
25
+ cwd : rootDir ,
26
+ ignore,
27
+ // in order to avoid detecting each component twice on windows
28
+ // when matching 2 cases of the same word, like {Src,src}
29
+ // we remove case-sensitivity on windows
30
+ nocase : process . platform === 'win32' ,
31
+ } ) ;
12
32
}
13
33
// Wrap path in an array so reduce always gets an array of arrays
14
34
return [ listItem ] ;
@@ -28,21 +48,14 @@ module.exports = function getComponentFiles(components, rootDir, ignore) {
28
48
return [ ] ;
29
49
}
30
50
31
- let componentFiles ;
32
- if ( isFunction ( components ) ) {
33
- componentFiles = getFilesMatchingGlobs ( components ( ) , rootDir , ignore ) ;
34
- } else if ( Array . isArray ( components ) ) {
35
- componentFiles = getFilesMatchingGlobs ( components , rootDir , ignore ) ;
36
- } else if ( isString ( components ) ) {
37
- componentFiles = glob . sync ( path . resolve ( rootDir , components ) , { ignore } ) ;
38
- } else {
39
- throw new Error (
40
- `Styleguidist: components should be string, function or array, received ${ typeof components } .`
41
- ) ;
42
- }
51
+ // Normalize components option into an Array
52
+ const componentGlobs = getComponentGlobs ( components ) ;
53
+
54
+ // Resolve list of components from globs
55
+ const componentFiles = getFilesMatchingGlobs ( componentGlobs , rootDir , ignore ) ;
43
56
44
57
// Make paths absolute
45
- componentFiles = componentFiles . map ( file => path . resolve ( rootDir , file ) ) ;
58
+ const componentFilesAbsolute = componentFiles . map ( file => path . resolve ( rootDir , file ) ) ;
46
59
47
- return componentFiles ;
60
+ return componentFilesAbsolute ;
48
61
} ;
0 commit comments