forked from webpack-contrib/copy-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobalSetup.js
66 lines (54 loc) · 1.72 KB
/
globalSetup.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
62
63
64
65
66
const path = require("path");
const fs = require("fs");
// eslint-disable-next-line import/no-extraneous-dependencies
const mkdirp = require("mkdirp");
const webpack = require("webpack");
const removeIllegalCharacterForWindows = require("./test/helpers/removeIllegalCharacterForWindows");
const baseDir = path.resolve(__dirname, "test/fixtures");
const specialFiles = {
"[special$directory]/nested/nestedfile.txt": "",
"[special$directory]/(special-*file).txt": "special",
"[special$directory]/directoryfile.txt": "new",
};
module.exports = () => {
Object.keys(specialFiles).forEach((originFile) => {
const file = removeIllegalCharacterForWindows(originFile);
const dir = path.dirname(file);
mkdirp.sync(path.join(baseDir, dir));
fs.writeFileSync(path.join(baseDir, file), specialFiles[originFile]);
});
return Promise.resolve()
.then(() => {
const compiler = webpack({
devtool: false,
mode: "development",
target: "node",
entry: path.resolve(__dirname, "node_modules/globby/index.js"),
output: {
path: path.resolve(__dirname, "test/bundled/globby"),
filename: "index.js",
library: {
type: "commonjs2",
},
},
});
return new Promise((resolve, reject) => {
compiler.run((error, stats) => {
if (error) {
reject(error);
return;
}
// eslint-disable-next-line no-console
console.log(stats.toString());
compiler.close(() => {
resolve();
});
});
});
})
.catch((error) => {
// eslint-disable-next-line no-console
console.log(error);
process.exit(1);
});
};