@oroinc/oro-webpack-config-builder 5.1.0-alpha3 → 5.1.0-alpha30

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.
package/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  An integration of OroPlatform based applications with the Webpack.
4
4
 
5
- For more details see [the documentation](https://doc.oroinc.com/backend/bundles/platform/AssetBundle/).
5
+ For more details see [the documentation](https://doc.oroinc.com/bundles/platform/AssetBundle/).
package/messages.js ADDED
@@ -0,0 +1,29 @@
1
+ const doc = "Please, find more information in the documentation ";
2
+ const CSSError = "Failed assembly styles.\n";
3
+ const CSSDoc = "https://doc.oroinc.com/backend/bundles/platform/AssetBundle/#load-scss-or-css-files-from-the-bundle";
4
+ const JSError = `Failed assembly JS.\n`;
5
+ const JSDoc = "https://doc.oroinc.com/backend/bundles/platform/AssetBundle/#create-jsmodules-yml-configuration";
6
+ const JSExtraBuildDoc = "https://doc.oroinc.com/master/frontend/storefront/how-to/how-to-create-extra-js-build-for-landing-page";
7
+
8
+ module.exports = {
9
+ assetsMissedOutput(group, theme) {
10
+ const error = `The "output" for "${group}" entry point in "${theme}" theme is not defined.\n`;
11
+
12
+ return `${CSSError}${error}${doc}${CSSDoc}`;
13
+ },
14
+ assetsMissedInput(group, theme) {
15
+ const error = `The "output" for "${group}" entry point in "${theme}" theme is not defined.\n`;
16
+
17
+ return `${CSSError}${error}${doc}${CSSDoc}`
18
+ },
19
+ jsModulesError(theme) {
20
+ const error = `Failed assembly JS for the "${theme}" theme.\n`;
21
+
22
+ return `${error}${doc}${JSDoc}`
23
+ },
24
+ jsExtraModulesError(parts) {
25
+ const error = `Sections ["${parts.join('", "')}"] are not allowed in extra js build definition\n`;
26
+
27
+ return `${JSError}${error}${doc}${JSExtraBuildDoc}`;
28
+ }
29
+ };
@@ -4,10 +4,10 @@ const ModulesConfigLoader = require('./modules-config-loader');
4
4
 
5
5
  class LayoutModulesConfigLoader extends ModulesConfigLoader {
6
6
  /**
7
- * {@inheritdoc}
7
+ * @inheritdoc
8
8
  */
9
9
  loadConfig(theme, filePath) {
10
- let themeConfig = super.loadConfig(theme, path.join('/Resources/views/layouts/', theme, filePath));
10
+ let themeConfig = super.loadConfig(theme, path.join('Resources/views/layouts/', theme, filePath));
11
11
  // recursive process parent theme
12
12
  const {parent: parentTheme} = this.themes[theme];
13
13
  if (typeof parentTheme === 'string') {
@@ -17,6 +17,66 @@ class LayoutModulesConfigLoader extends ModulesConfigLoader {
17
17
 
18
18
  return themeConfig;
19
19
  }
20
+
21
+ /**
22
+ * All build names:
23
+ * - based on theme names
24
+ * - and theme's extra js builds
25
+ *
26
+ * @return {string[]}
27
+ */
28
+ get buildNames() {
29
+ const buildNames = super.buildNames;
30
+ this.themeNames.forEach(theme => {
31
+ buildNames.push(...this.extraJSBuildNames(theme));
32
+ });
33
+ return buildNames;
34
+ }
35
+
36
+ /**
37
+ * Collect extra js-build names for a theme
38
+ *
39
+ * @param {string} theme name on the theme
40
+ * @return {string[]}
41
+ */
42
+ extraJSBuildNames(theme) {
43
+ const {extra_js_builds: extraJSBuilds = []} = this._themes[theme] || {}
44
+ return [...extraJSBuilds.map(suffix => `${theme}-${suffix}`)];
45
+ }
46
+
47
+ /**
48
+ * Check if buildName is an extra js build of layout theme
49
+ *
50
+ * @param {string} buildName name of the build
51
+ * @return {boolean}
52
+ */
53
+ isExtraJSBuild(buildName) {
54
+ const [, suffix] = this.splitBuildName(buildName);
55
+ return suffix !== void 0;
56
+ }
57
+
58
+ /**
59
+ * Splits build name on parts theme name and suffix (name of extra js build)
60
+ * @param {string} buildName
61
+ * @return {[string]|[string, string]}
62
+ */
63
+ splitBuildName(buildName) {
64
+ // suffix can not contain '-'
65
+ const marches = buildName.match(/(.+)-([^\-]+)?/);
66
+ const result = [];
67
+ if (marches) {
68
+ const [, theme, suffix] = marches;
69
+ const {extra_js_builds: extraJSBuilds = []} = this._themes[theme] || {}
70
+ if (extraJSBuilds.includes(suffix)) {
71
+ result.push(marches[1], marches[2]);
72
+ } else {
73
+ result.push(buildName);
74
+ }
75
+ } else {
76
+ result.push(buildName);
77
+ }
78
+ return result;
79
+ }
20
80
  }
21
81
 
22
82
  module.exports = LayoutModulesConfigLoader;
@@ -3,6 +3,9 @@ const fs = require('fs');
3
3
  const merge = require('deepmerge');
4
4
  const yaml = require('js-yaml');
5
5
 
6
+ // merge only unique items
7
+ const arrayMerge = (target, source) => target.concat(source.filter(item => !target.includes(item)));
8
+
6
9
  class ModulesConfigLoader {
7
10
  /**
8
11
  * @returns {Array}
@@ -18,10 +21,17 @@ class ModulesConfigLoader {
18
21
  return Object.keys(this._themes);
19
22
  }
20
23
 
24
+ /**
25
+ * @returns {Array}
26
+ */
27
+ get buildNames() {
28
+ return this.themeNames;
29
+ }
30
+
21
31
  /**
22
32
  * @param {Array} bundles Array of ordered symfony bundle paths
23
33
  * @param {string} themesLocation Path inside the bundle, where to find the theme
24
- * @param {string} themeInfoFileName Yml File name with theme info
34
+ * @param {string} themeInfoFileName Yaml File name with theme info
25
35
  */
26
36
  constructor(bundles, themesLocation, themeInfoFileName) {
27
37
  this._bundles = bundles;
@@ -43,17 +53,15 @@ class ModulesConfigLoader {
43
53
  if (!fs.existsSync(source)) return;
44
54
 
45
55
  fs.readdirSync(source).forEach(name => {
46
- const theme = path.resolve(source, name);
47
- if (!fs.lstatSync(theme).isDirectory()) {
56
+ const themePath = path.resolve(source, name);
57
+ if (!fs.lstatSync(themePath).isDirectory()) {
48
58
  return;
49
59
  }
50
- const themeFile = path.resolve(theme, themeInfoFileName);
60
+ const themeFile = path.resolve(themePath, themeInfoFileName);
51
61
  if (!fs.existsSync(themeFile)) return;
52
62
 
53
- if (!(name in themes)) {
54
- themes[name] = null;
55
- }
56
- themes[name] = yaml.load(fs.readFileSync(themeFile, 'utf8'));
63
+ const theme = yaml.load(fs.readFileSync(themeFile, 'utf8'));
64
+ themes[name] = merge(themes[name] || {}, theme, {arrayMerge});
57
65
  });
58
66
  });
59
67
 
@@ -62,17 +70,27 @@ class ModulesConfigLoader {
62
70
 
63
71
  /**
64
72
  * @param {string} theme Theme name
65
- * @param {string} filePath Path to the file inside bundle directory where to find the configs
66
- * @return {Object} Merged Configs loaded from all the bundles Yml files matched by filePath
73
+ * @param {string|string[]} filePath Path (or paths with fallback) to the file inside bundle directory where to find the configs
74
+ * @return {Object} Merged Configs loaded from all the bundles Yaml files matched by filePath
67
75
  */
68
76
  loadConfig(theme, filePath) {
69
77
  let configs = {};
78
+ const filePaths = [].concat(filePath);
70
79
  this._bundles.forEach(bundle => {
71
- const absolutePath = bundle + filePath;
72
- if (!fs.existsSync(absolutePath)) return;
80
+ let absolutePath;
81
+
82
+ for (const file of filePaths) {
83
+ absolutePath = path.resolve(bundle, file);
84
+ if (fs.existsSync(absolutePath)) {
85
+ break;
86
+ }
87
+ absolutePath = void 0;
88
+ }
73
89
 
74
- const doc = yaml.load(fs.readFileSync(absolutePath, 'utf8'));
75
- configs = merge(configs, doc);
90
+ if (absolutePath) {
91
+ const doc = yaml.load(fs.readFileSync(absolutePath, 'utf8'));
92
+ configs = merge(configs, doc);
93
+ }
76
94
  });
77
95
  return configs;
78
96
  }