@bigbinary/neeto-commons-frontend 2.1.23 → 2.1.24

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/configs/babel.js CHANGED
@@ -35,6 +35,7 @@ module.exports = function (api) {
35
35
  "@bigbinary/neeto",
36
36
  ].filter(Boolean),
37
37
  plugins: [
38
+ "preval",
38
39
  "babel-plugin-macros",
39
40
  "@babel/plugin-transform-runtime",
40
41
  isTestEnv
@@ -9,5 +9,6 @@ module.exports = {
9
9
  module: "writable",
10
10
  // Makes props obtained from Rails backend available everywhere in this project.
11
11
  globalProps: "readonly",
12
+ preval: "readonly",
12
13
  },
13
14
  };
@@ -2,6 +2,12 @@ const { mergeLeft } = require("ramda");
2
2
 
3
3
  const commonConfiguration = require("../../eslint");
4
4
 
5
+ const isCommonsFrontend = !__dirname.includes("node_modules");
6
+
7
+ const configsPath = isCommonsFrontend
8
+ ? "./configs"
9
+ : "./node_modules/@bigbinary/neeto-commons-frontend/configs";
10
+
5
11
  const nanosConfiguration = {
6
12
  extends: [
7
13
  "plugin:@bigbinary/neeto/nanos-recommended",
@@ -9,12 +15,12 @@ const nanosConfiguration = {
9
15
  "plugin:json/recommended",
10
16
  "eslint:recommended",
11
17
  "plugin:react/recommended",
12
- "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/globals",
13
- "./node_modules/@bigbinary/neeto-commons-frontend/configs/nanos/eslint/imports/order",
14
- "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/overrides",
15
- "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/imports/enforced",
16
- "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/react",
17
- "./node_modules/@bigbinary/neeto-commons-frontend/configs/eslint/promise",
18
+ `${configsPath}/eslint/globals`,
19
+ `${configsPath}/nanos/eslint/imports/order`,
20
+ `${configsPath}/eslint/overrides`,
21
+ `${configsPath}/eslint/imports/enforced`,
22
+ `${configsPath}/eslint/react`,
23
+ `${configsPath}/eslint/promise`,
18
24
  "prettier",
19
25
  ],
20
26
  };
@@ -1,7 +1,11 @@
1
1
  const path = require("path");
2
2
 
3
+ const isCommonsFrontend = !__dirname.includes("node_modules");
4
+
3
5
  const absolutePath = basePath =>
4
- path.join(__dirname, "../../../../../../", basePath);
6
+ isCommonsFrontend
7
+ ? path.join(__dirname, "../../../", basePath)
8
+ : path.join(__dirname, "../../../../../../", basePath);
5
9
 
6
10
  module.exports = {
7
11
  alias: {
@@ -0,0 +1,38 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const { mergeDeepLeft } = require("ramda");
5
+
6
+ const packageDir = path.join(__dirname, "../");
7
+
8
+ const getPkgTransPath = pkg => path.join(packageDir, pkg, "src/translations");
9
+
10
+ const packages = fs.readdirSync(packageDir);
11
+
12
+ const loadTranslations = translationsDir => {
13
+ try {
14
+ const jsonFiles = fs
15
+ .readdirSync(translationsDir)
16
+ .filter(file => file.endsWith(".json"))
17
+ .map(file => path.join(translationsDir, file));
18
+
19
+ const translations = {};
20
+
21
+ jsonFiles.forEach(jsonFile => {
22
+ const content = fs.readFileSync(jsonFile, "utf8");
23
+ const basename = path.basename(jsonFile, ".json");
24
+
25
+ translations[basename] = { translation: JSON.parse(content) };
26
+ });
27
+
28
+ return translations;
29
+ } catch {
30
+ return {};
31
+ }
32
+ };
33
+
34
+ const packageTranslations = packages
35
+ .map(pkg => loadTranslations(getPkgTransPath(pkg)))
36
+ .reduce(mergeDeepLeft);
37
+
38
+ module.exports = packageTranslations;
@@ -4,9 +4,7 @@ module.exports = [
4
4
  use: [
5
5
  {
6
6
  loader: "@svgr/webpack",
7
- options: {
8
- svgoConfig: { plugins: ["preset-default"] },
9
- },
7
+ options: { svgoConfig: { plugins: ["preset-default"] } },
10
8
  },
11
9
  ],
12
10
  },
@@ -20,15 +18,16 @@ module.exports = [
20
18
  },
21
19
  },
22
20
  },
21
+ {
22
+ test: /\.js$/,
23
+ include: /node_modules\/@bigbinary\/neeto-commons-frontend\/initializers/,
24
+ use: { loader: "babel-loader", options: { plugins: ["preval"] } },
25
+ },
23
26
  {
24
27
  test: /\.m?js$/,
25
28
  resolve: {
26
29
  fullySpecified: false, // allows webpack to ignore some package rules as the Strict EcmaScript Module mode.
27
30
  },
28
31
  },
29
- {
30
- test: /\.js$/,
31
- enforce: "pre",
32
- use: ["source-map-loader"],
33
- },
32
+ { test: /\.js$/, enforce: "pre", use: ["source-map-loader"] },
34
33
  ];
@@ -2402,18 +2402,6 @@ var commonsEn = {
2402
2402
  neetoCommons: neetoCommons
2403
2403
  };
2404
2404
 
2405
- var packageNames = ["neeto-molecules", "neeto-integrations-frontend", "neeto-team-members-frontend", "neeto-tags-frontend", "neeto-form-frontend"];
2406
- var getPackageTranslations = function getPackageTranslations(language, packageNames) {
2407
- var loadTranslations = ramda.curry(function (language, packageName) {
2408
- try {
2409
- return require("../".concat(packageName, "/src/translations/").concat(language, ".json"));
2410
- } catch (_unused) {
2411
- return {};
2412
- }
2413
- });
2414
- var allTranslations = packageNames.map(loadTranslations(language));
2415
- return ramda.mergeAll(allTranslations);
2416
- };
2417
2405
  var sentenceCasePlaceholderAndTypographyProcessor = {
2418
2406
  type: "postProcessor",
2419
2407
  name: "sentenceCasePlaceholderAndTypography",
@@ -2426,20 +2414,17 @@ var sentenceCasePlaceholderAndTypographyProcessor = {
2426
2414
  return value;
2427
2415
  }
2428
2416
  };
2429
- var packageEnTranslations = getPackageTranslations("en", packageNames);
2430
- var en = ramda.mergeDeepLeft(commonsEn, packageEnTranslations);
2431
- var de = getPackageTranslations("de", packageNames);
2432
- var initializeI18n = function initializeI18n(resources) {
2417
+ var commonsTranslations = {
2418
+ en: {
2419
+ translation: commonsEn
2420
+ }
2421
+ };
2422
+ var initializeI18n = function initializeI18n(hostTranslations) {
2433
2423
  var _i18n$services$format;
2424
+ var packageTranslations = preval.require("./configs/scripts/getPkgTranslations.js");
2425
+ var resources = [hostTranslations, commonsTranslations, packageTranslations].reduce(ramda.mergeDeepLeft);
2434
2426
  i18n__default["default"].use(Browser).use(reactI18next.initReactI18next).use(sentenceCasePlaceholderAndTypographyProcessor).init({
2435
- resources: ramda.mergeDeepLeft(resources, {
2436
- en: {
2437
- translation: en
2438
- },
2439
- de: {
2440
- translation: de
2441
- }
2442
- }),
2427
+ resources: resources,
2443
2428
  fallbackLng: "en",
2444
2429
  interpolation: {
2445
2430
  escapeValue: false,