@shopgate/webpack 7.27.4 → 7.27.5-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,25 +2,71 @@ const fs = require('fs');
|
|
|
2
2
|
const importFresh = require('import-fresh');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* @typedef {Object} ComponentSettingsEntry
|
|
6
|
+
* @property {string} path Path to the file to be imported
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Object.<string, ComponentSettingsEntry>} ComponentSettingsMap
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {Object} ComponentSettings
|
|
15
|
+
* @property {ComponentSettingsMap} [portals] Portal component mapping
|
|
16
|
+
* @property {ComponentSettingsMap} [translations] Translation file mapping
|
|
17
|
+
* @property {ComponentSettingsMap} [tracking] Tracking plugin mapping
|
|
18
|
+
* @property {ComponentSettingsMap} [subscribers] RxJS subscriber mapping
|
|
19
|
+
* @property {ComponentSettingsMap} [reducers] Redux reducer mapping
|
|
20
|
+
* @property {ComponentSettingsMap} [widgets] Widget component mapping
|
|
21
|
+
* @property {ComponentSettingsMap} [widgetsV2] Widget component mapping for version 2 of the widget
|
|
22
|
+
* system
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Returns contents of the `config/components.json` file from the theme.
|
|
27
|
+
*
|
|
28
|
+
* This file is created by the SDK during startup and contains mappings for different types of
|
|
29
|
+
* resources provided by attached extensions (portals, translations, widgets...).
|
|
30
|
+
* The ShopgateIndexer Webpack plugin uses this file to generate different mapping files inside
|
|
31
|
+
* the `extensions` folder of the theme. Those files contains import declarations to enable loading
|
|
32
|
+
* of the different resources.
|
|
33
|
+
*
|
|
34
|
+
* Additionally it merges the widgets provided by the PWA into its return value.
|
|
35
|
+
*
|
|
6
36
|
* @param {string} themePath The path of the theme.
|
|
7
|
-
* @return {
|
|
37
|
+
* @return {ComponentSettings} The app settings.
|
|
8
38
|
*/
|
|
9
39
|
module.exports = function getComponentsSettings(themePath) {
|
|
10
40
|
try {
|
|
11
|
-
const
|
|
12
|
-
const themeConfig = `${themeWidgets}/widgets.json`;
|
|
41
|
+
const themeWidgetsPath = `${themePath}/widgets`;
|
|
13
42
|
|
|
43
|
+
const themeWidgetsV1Config = `${themeWidgetsPath}/widgets.json`;
|
|
44
|
+
const themeWidgetsV2Config = '@shopgate/engage/page/widgets/widgets.json';
|
|
45
|
+
|
|
46
|
+
/** @type {ComponentSettings} */
|
|
14
47
|
const defaultConfig = importFresh(`${themePath}/config/components.json`);
|
|
15
48
|
|
|
16
|
-
|
|
17
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Loads a JSON config file using `import-fresh`, if it exists.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} path - The absolute path to the config file.
|
|
53
|
+
* @returns {Object} The imported configuration object, or an empty object if the file doesn't
|
|
54
|
+
* exist.
|
|
55
|
+
*/
|
|
56
|
+
const loadConfig = path => (fs.existsSync(path) || path.startsWith('@shopgate/engage') ?
|
|
57
|
+
importFresh(path) :
|
|
58
|
+
{}
|
|
59
|
+
);
|
|
18
60
|
|
|
19
61
|
return {
|
|
20
62
|
...defaultConfig,
|
|
21
63
|
widgets: {
|
|
22
64
|
...defaultConfig.widgets,
|
|
23
|
-
...
|
|
65
|
+
...loadConfig(themeWidgetsV1Config),
|
|
66
|
+
},
|
|
67
|
+
widgetsV2: {
|
|
68
|
+
...defaultConfig.widgetsV2,
|
|
69
|
+
...loadConfig(themeWidgetsV2Config),
|
|
24
70
|
},
|
|
25
71
|
};
|
|
26
72
|
} catch (e) {
|
package/locales/en.json
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"TYPE_SUBSCRIBERS": "subscribers",
|
|
18
18
|
"TYPE_TRACKERS": "trackers",
|
|
19
19
|
"TYPE_TRANSLATIONS": "translations",
|
|
20
|
-
"TYPE_WIDGETS": "widgets"
|
|
20
|
+
"TYPE_WIDGETS": "widgets",
|
|
21
|
+
"TYPE_WIDGETS_V2": "widgets 2.0"
|
|
21
22
|
},
|
|
22
23
|
"plugins/ShopgateThemeConfigValidatorPlugin": {
|
|
23
24
|
"VALIDATING_CONFIG": "Validating theme configuration ...",
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ const i18n = require('../lib/i18n');
|
|
|
10
10
|
const t = i18n(__filename);
|
|
11
11
|
|
|
12
12
|
const TYPE_WIDGETS = 'WIDGETS';
|
|
13
|
+
const TYPE_WIDGETS_V2 = 'WIDGETS_V2';
|
|
13
14
|
const TYPE_TRACKERS = 'TRACKERS';
|
|
14
15
|
const TYPE_PORTALS = 'PORTALS';
|
|
15
16
|
const TYPE_REDUCERS = 'REDUCERS';
|
|
@@ -35,8 +36,9 @@ function getExtensionsPath() {
|
|
|
35
36
|
function componentExists(componentPath) {
|
|
36
37
|
const existsInExtensions = fs.existsSync(path.resolve(themePath, '..', '..', 'extensions', componentPath));
|
|
37
38
|
const existsInWidgets = fs.existsSync(path.resolve(themePath, 'widgets', componentPath));
|
|
39
|
+
const isEngageWidget = componentPath.startsWith('@shopgate/engage/page/widgets');
|
|
38
40
|
|
|
39
|
-
return
|
|
41
|
+
return existsInExtensions || existsInWidgets || isEngageWidget;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/**
|
|
@@ -73,7 +75,7 @@ function readConfig(options) {
|
|
|
73
75
|
const imports = importsStart ? [importsStart] : []; // Holds the import strings.
|
|
74
76
|
const exports = [exportsStart]; // Holds the export strings.
|
|
75
77
|
|
|
76
|
-
if (type === TYPE_PORTALS || type === TYPE_WIDGETS) {
|
|
78
|
+
if (type === TYPE_PORTALS || type === TYPE_WIDGETS || type === TYPE_WIDGETS_V2) {
|
|
77
79
|
imports.push('import { hot } from \'react-hot-loader/root\';');
|
|
78
80
|
imports.push('import { lazy } from \'react\';');
|
|
79
81
|
imports.push('');
|
|
@@ -91,7 +93,7 @@ function readConfig(options) {
|
|
|
91
93
|
|
|
92
94
|
const isPortalsOrWidgets = (
|
|
93
95
|
(type === TYPE_PORTALS && component.target !== 'app.routes')
|
|
94
|
-
|| type === TYPE_WIDGETS
|
|
96
|
+
|| type === TYPE_WIDGETS || type === TYPE_WIDGETS_V2
|
|
95
97
|
);
|
|
96
98
|
|
|
97
99
|
if (isPortalsOrWidgets) {
|
|
@@ -240,7 +242,7 @@ function index(options) {
|
|
|
240
242
|
* Indexes the widgets.
|
|
241
243
|
*/
|
|
242
244
|
function indexWidgets() {
|
|
243
|
-
const { widgets = {} } = getComponentsSettings(themePath);
|
|
245
|
+
const { widgets = {}, widgetsV2 = {} } = getComponentsSettings(themePath);
|
|
244
246
|
|
|
245
247
|
index({
|
|
246
248
|
file: 'widgets.js',
|
|
@@ -250,6 +252,15 @@ function indexWidgets() {
|
|
|
250
252
|
},
|
|
251
253
|
...getIndexLogTranslations(TYPE_WIDGETS),
|
|
252
254
|
});
|
|
255
|
+
|
|
256
|
+
index({
|
|
257
|
+
file: 'widgetsV2.js',
|
|
258
|
+
config: {
|
|
259
|
+
type: TYPE_WIDGETS_V2,
|
|
260
|
+
config: widgetsV2,
|
|
261
|
+
},
|
|
262
|
+
...getIndexLogTranslations(TYPE_WIDGETS_V2),
|
|
263
|
+
});
|
|
253
264
|
}
|
|
254
265
|
|
|
255
266
|
/**
|