-
Notifications
You must be signed in to change notification settings - Fork 5
/
ibexa.webpack.config.manager.js
63 lines (51 loc) · 2.33 KB
/
ibexa.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
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
const fs = require('fs');
/*
We changed all entry names to ibexa-, but for BC change we left possibility to still use ezplatform-
Note that using ezplatform- is deprecate and will be removed in version 5.0
*/
const ibexifyEntryName = (entryName) => {
let ibexaEntryName = entryName;
if (entryName.indexOf('ezplatform-') === 0) {
console.warn('\x1b[43m%s\x1b[0m', 'Using ezplatform- is deprecated and will be removed in 5.0');
ibexaEntryName = entryName.replace('ezplatform-', 'ibexa-');
} else if (entryName.indexOf('ezcommerce-') === 0) {
console.warn('\x1b[43m%s\x1b[0m', 'Using ezcommerce- is deprecated and will be removed in 5.0');
ibexaEntryName = entryName.replace('ezcommerce-', 'ibexa-commerce-');
}
return ibexaEntryName;
}
const findItems = (ibexaConfig, entryName) => {
const items = ibexaConfig.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 = ({ ibexaConfig, eZConfig, entryName, itemToReplace, newItem }) => {
const config = ibexaConfig ? ibexaConfig : eZConfig;
const ibexaEntryName = ibexifyEntryName(entryName);
const items = findItems(config, ibexaEntryName);
const indexToReplace = items.indexOf(fs.realpathSync(itemToReplace));
if (indexToReplace < 0) {
throw new Error(`Couldn't find item "${itemToReplace}" in entry "${ibexaEntryName}". Please check if there is a typo in the name.`);
}
items[indexToReplace] = newItem;
};
const remove = ({ ibexaConfig, eZConfig, entryName, itemsToRemove }) => {
const config = ibexaConfig ? ibexaConfig : eZConfig;
const ibexaEntryName = ibexifyEntryName(entryName);
const items = findItems(config, ibexaEntryName);
const realPathItemsToRemove = itemsToRemove.map((item) => fs.realpathSync(item));
config.entry[ibexaEntryName] = items.filter((item) => !realPathItemsToRemove.includes(item));
};
const add = ({ ibexaConfig, eZConfig, entryName, newItems }) => {
const config = ibexaConfig ? ibexaConfig : eZConfig;
const ibexaEntryName = ibexifyEntryName(entryName);
const items = findItems(config, ibexaEntryName);
config.entry[ibexaEntryName] = [...items, ...newItems];
};
module.exports = {
replace,
remove,
add
};