-
Notifications
You must be signed in to change notification settings - Fork 5
/
script.clean.js
34 lines (28 loc) · 873 Bytes
/
script.clean.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
const fs = require('node:fs');
const path = require('node:path');
const weblog = require('webpack-log');
const logger = weblog({ name: 'clean' });
const ENV = require('./app.env');
const UTILS = require('./webpack.utils');
const cleanIgnore = UTILS.readIgnoreFile('./.cleanignore');
UTILS.glob(`${ENV.OUTPUT_PATH}/**/*`, {
nodir: true,
dot: true,
})
.then((files) => {
files.forEach((filepath) => {
const relativePath = UTILS.slash(path.relative(ENV.OUTPUT_PATH, filepath));
if (cleanIgnore.ignores(relativePath)) {
return;
}
fs.unlink(filepath, (unlinkError) => {
if (unlinkError) {
logger.error(unlinkError);
}
});
});
return files;
})
.catch((error) => {
logger.error(error);
});