forked from undp/design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.entries.js
61 lines (52 loc) · 1.63 KB
/
webpack.entries.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
57
58
59
60
61
const path = require('path');
const glob = require('glob');
const cssPathPrefix = 'css';
/*
* Get entry points for webpack
* CSS and JS seperately
*/
module.exports = (type = 'css') => {
let files = {};
let suggestFiles = '/**/*.scss';
let ignoreFiles = [
'./node_modules',
'./stories/assets/**/lib/**',
'./stories/**/_!(swiper)*.scss', // no partials
'./stories/**/normalize.scss', // merged atom into base styling
'./stories/**/style.scss', // we don't need this file
'./stories/Atom/**', // merged atom into base styling
'./stories/**/*.mdx',
'./stories/**/*.jsx',
];
// change pattern if finding for JS only
if (type == 'js') {
suggestFiles = '/assets/**/*.js';
}
// wildcard file discovery
glob.sync(`./stories${suggestFiles}`, {
ignore: ignoreFiles,
}).map((file) => {
let fileName = path.basename(file, path.extname(file));
let objKey = `${cssPathPrefix}/components/${fileName}`;
// if js no 'components' in directory
if (type == 'js') {
objKey = `js/${fileName}`;
}
// if templates/pages create a seperate directory
if (file.indexOf('Templates') > 0) {
objKey = `${cssPathPrefix}/templates/${fileName}`;
}
// if base styling keep it in root
if (file.indexOf('assets/scss') > 0) {
objKey = `${cssPathPrefix}/${fileName}`;
}
// if scss is a partial then remove the leading '_'.
if (file.indexOf('/_') > 0) {
fileName = fileName.replace(/[_]/g, '');
objKey = `${cssPathPrefix}/components/${fileName}`;
}
// add 'css' and 'js' prefix to create auto directory
files[objKey] = file;
});
return files;
};