forked from italia/design-web-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (47 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const Config = require('./config')
/* Promise polyfill for IE10 */
import Promise from 'promise-polyfill'
if (!window.Promise) {
window.Promise = Promise
}
/* eslint-disable */
if (window.__PUBLIC_PATH__) {
__webpack_public_path__ = window.__PUBLIC_PATH__
}
/* eslint-enable */
function _findIndex(ar, predicate) {
for (let index = 0; index < ar.length; index++) {
if (predicate(ar[index])) {
return index
}
}
return -1
}
/*
* Every index.js found in src/** directory will be required.
*
* Too exclude components or modules
* @see config.js
*/
function requireAll(requireContext) {
let keys = []
requireContext.keys().forEach((filename) => {
const dirname = filename.replace(/\\/g, '/').replace(/\/[^\/]*$/, '')
const exclude = -1 !== _findIndex(Config.excludes, function (v) {
return dirname.match(new RegExp(v)) !== null
})
const include = !exclude &&
(Config.includes.length === 0 ||
(-1 !== _findIndex(Config.includes, function (v) {
return dirname.match(new RegExp(v)) !== null
})))
if (include) {
// console.log('including: %s', dirname)
keys.push(filename)
} else {
// console.log('excluding: %s', dirname)
}
})
return keys.map(requireContext)
}
export default requireAll(require.context('./src', true, /(.*)index\.js$/))