forked from matthew-matvei/freeman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.test.js
37 lines (31 loc) · 1.16 KB
/
webpack.test.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
const fs = require("fs");
const path = require("path");
const baseConfig = require("./webpack.common");
// Taken respectively from http://blog.scottlogic.com/2017/06/06/typescript-electron-webpack.html
const readDirRecursiveSync = (folder, filter) => {
const currentPath = fs.readdirSync(folder).map(f => path.join(folder, f))
const files = currentPath.filter(filter);
const directories = currentPath
.filter(f => fs.statSync(f).isDirectory())
.map(f => readDirRecursiveSync(f, filter))
.reduce((cur, next) => [...cur, ...next], []);
return [...files, ...directories];
}
const getEntries = (folder) =>
readDirRecursiveSync(folder, f => f.match(/.*test\.tsx?$/))
.map((file) => {
return {
name: path.basename(file, path.extname(file)),
path: path.resolve(file)
};
})
.reduce((memo, file) => {
memo[file.name] = file.path;
return memo;
}, {});
module.exports = [
Object.assign({}, baseConfig[1], { entry: getEntries('./test/') })
].map(s => {
s.output.path = path.resolve(__dirname, '__tests__');
return s;
});