-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafterBuild.js
34 lines (30 loc) · 1.04 KB
/
afterBuild.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('fs');
const path = require('path');
const packagesFolderPath = path.resolve(__dirname, 'packages');
const clearJSFilesFromFolder = (folderPath) => {
fs.readdir(folderPath, (err, fileNames) => {
if (err) {
if (!err.message.includes('no such file or directory')) {
console.info(`Error while getting lib/api directory fileNames: ${err.message}`);
}
} else {
fileNames.forEach((itemName) => {
const fullPath = `${folderPath}/${itemName}`;
const extension = itemName.split('.')[1];
if (!extension) {
clearJSFilesFromFolder(fullPath);
}
if (extension === 'js' && itemName !== 'index.js') {
try {
fs.unlinkSync(fullPath);
} catch (error) {
console.info(`Can not delete file ${fullPath}: ${error.message}`);
}
}
});
}
});
};
fs.readdir(packagesFolderPath, (err, fileNames) => {
fileNames.forEach((packageName) => clearJSFilesFromFolder(`${packagesFolderPath}/${packageName}/lib/api`));
});