@shopgate/webpack 7.27.5-alpha.2 → 7.27.5
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,71 +2,25 @@ const fs = require('fs');
|
|
|
2
2
|
const importFresh = require('import-fresh');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
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
|
-
*
|
|
5
|
+
* Returns the app settings from the remote project.
|
|
36
6
|
* @param {string} themePath The path of the theme.
|
|
37
|
-
* @return {
|
|
7
|
+
* @return {Object} The app settings.
|
|
38
8
|
*/
|
|
39
9
|
module.exports = function getComponentsSettings(themePath) {
|
|
40
10
|
try {
|
|
41
|
-
const
|
|
11
|
+
const themeWidgets = `${themePath}/widgets`;
|
|
12
|
+
const themeConfig = `${themeWidgets}/widgets.json`;
|
|
42
13
|
|
|
43
|
-
const themeWidgetsV1Config = `${themeWidgetsPath}/widgets.json`;
|
|
44
|
-
const themeWidgetsV2Config = '@shopgate/engage/page/widgets/widgets.json';
|
|
45
|
-
|
|
46
|
-
/** @type {ComponentSettings} */
|
|
47
14
|
const defaultConfig = importFresh(`${themePath}/config/components.json`);
|
|
48
15
|
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
);
|
|
16
|
+
const configExists = (fs.existsSync(themeWidgets) && fs.existsSync(themeConfig));
|
|
17
|
+
const config = configExists ? importFresh(themeConfig) : {};
|
|
60
18
|
|
|
61
19
|
return {
|
|
62
20
|
...defaultConfig,
|
|
63
21
|
widgets: {
|
|
64
22
|
...defaultConfig.widgets,
|
|
65
|
-
...
|
|
66
|
-
},
|
|
67
|
-
widgetsV2: {
|
|
68
|
-
...defaultConfig.widgetsV2,
|
|
69
|
-
...loadConfig(themeWidgetsV2Config),
|
|
23
|
+
...config,
|
|
70
24
|
},
|
|
71
25
|
};
|
|
72
26
|
} catch (e) {
|
package/locales/en.json
CHANGED
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
"TYPE_SUBSCRIBERS": "subscribers",
|
|
18
18
|
"TYPE_TRACKERS": "trackers",
|
|
19
19
|
"TYPE_TRANSLATIONS": "translations",
|
|
20
|
-
"TYPE_WIDGETS": "widgets"
|
|
21
|
-
"TYPE_WIDGETS_V2": "widgets 2.0"
|
|
20
|
+
"TYPE_WIDGETS": "widgets"
|
|
22
21
|
},
|
|
23
22
|
"plugins/ShopgateThemeConfigValidatorPlugin": {
|
|
24
23
|
"VALIDATING_CONFIG": "Validating theme configuration ...",
|
package/package.json
CHANGED
|
@@ -10,7 +10,6 @@ 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';
|
|
14
13
|
const TYPE_TRACKERS = 'TRACKERS';
|
|
15
14
|
const TYPE_PORTALS = 'PORTALS';
|
|
16
15
|
const TYPE_REDUCERS = 'REDUCERS';
|
|
@@ -36,9 +35,8 @@ function getExtensionsPath() {
|
|
|
36
35
|
function componentExists(componentPath) {
|
|
37
36
|
const existsInExtensions = fs.existsSync(path.resolve(themePath, '..', '..', 'extensions', componentPath));
|
|
38
37
|
const existsInWidgets = fs.existsSync(path.resolve(themePath, 'widgets', componentPath));
|
|
39
|
-
const isEngageWidget = componentPath.startsWith('@shopgate/engage/page/widgets');
|
|
40
38
|
|
|
41
|
-
return existsInExtensions
|
|
39
|
+
return !(!existsInExtensions && !existsInWidgets);
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
/**
|
|
@@ -75,7 +73,7 @@ function readConfig(options) {
|
|
|
75
73
|
const imports = importsStart ? [importsStart] : []; // Holds the import strings.
|
|
76
74
|
const exports = [exportsStart]; // Holds the export strings.
|
|
77
75
|
|
|
78
|
-
if (type === TYPE_PORTALS || type === TYPE_WIDGETS
|
|
76
|
+
if (type === TYPE_PORTALS || type === TYPE_WIDGETS) {
|
|
79
77
|
imports.push('import { hot } from \'react-hot-loader/root\';');
|
|
80
78
|
imports.push('import { lazy } from \'react\';');
|
|
81
79
|
imports.push('');
|
|
@@ -93,7 +91,7 @@ function readConfig(options) {
|
|
|
93
91
|
|
|
94
92
|
const isPortalsOrWidgets = (
|
|
95
93
|
(type === TYPE_PORTALS && component.target !== 'app.routes')
|
|
96
|
-
|| type === TYPE_WIDGETS
|
|
94
|
+
|| type === TYPE_WIDGETS
|
|
97
95
|
);
|
|
98
96
|
|
|
99
97
|
if (isPortalsOrWidgets) {
|
|
@@ -242,7 +240,7 @@ function index(options) {
|
|
|
242
240
|
* Indexes the widgets.
|
|
243
241
|
*/
|
|
244
242
|
function indexWidgets() {
|
|
245
|
-
const { widgets = {}
|
|
243
|
+
const { widgets = {} } = getComponentsSettings(themePath);
|
|
246
244
|
|
|
247
245
|
index({
|
|
248
246
|
file: 'widgets.js',
|
|
@@ -252,15 +250,6 @@ function indexWidgets() {
|
|
|
252
250
|
},
|
|
253
251
|
...getIndexLogTranslations(TYPE_WIDGETS),
|
|
254
252
|
});
|
|
255
|
-
|
|
256
|
-
index({
|
|
257
|
-
file: 'widgetsV2.js',
|
|
258
|
-
config: {
|
|
259
|
-
type: TYPE_WIDGETS_V2,
|
|
260
|
-
config: widgetsV2,
|
|
261
|
-
},
|
|
262
|
-
...getIndexLogTranslations(TYPE_WIDGETS_V2),
|
|
263
|
-
});
|
|
264
253
|
}
|
|
265
254
|
|
|
266
255
|
/**
|