forked from ezsystems/ezplatform-com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ez.webpack.config.manager.js
37 lines (30 loc) · 1.18 KB
/
ez.webpack.config.manager.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 findItems = (eZConfig, entryName) => {
const items = eZConfig.entry[entryName];
if (!items) {
throw new Error(`Couldn't find entry with name: "${entryName}". Please check if there is a typo in the name.`);
}
return items;
};
const replace = ({ eZConfig, entryName, itemToReplace, newItem }) => {
const items = findItems(eZConfig, entryName);
const indexToReplace = items.indexOf(fs.realpathSync(itemToReplace));
if (indexToReplace < 0) {
throw new Error(`Couldn't find item "${itemToReplace}" in entry "${entryName}". Please check if there is a typo in the name.`);
}
items[indexToReplace] = newItem;
};
const remove = ({ eZConfig, entryName, itemsToRemove }) => {
const items = findItems(eZConfig, entryName);
const realPathItemsToRemove = itemsToRemove.map((item) => fs.realpathSync(item));
eZConfig.entry[entryName] = items.filter((item) => !realPathItemsToRemove.includes(item));
};
const add = ({ eZConfig, entryName, newItems }) => {
const items = findItems(eZConfig, entryName);
eZConfig.entry[entryName] = [...items, ...newItems];
};
module.exports = {
replace,
remove,
add
};