@bigbinary/neeto-commons-frontend 4.8.12 → 4.11.0-beta.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.
package/README.md CHANGED
@@ -135,6 +135,7 @@ Web utility functions [↗](./docs/utils/README.md)
135
135
  - [captureAnalyticsEvent](./docs/utils/captureAnalyticsEvent.md)
136
136
  - [captureAnalyticsPageView](./docs/utils/captureAnalyticsPageView.md)
137
137
  - [buildNestedAttributesPayload](./docs/utils/buildNestedAttributesPayload.md)
138
+ - [loadGoogleFonts](./docs/utils/loadGoogleFonts.md)
138
139
 
139
140
  </td>
140
141
 
@@ -0,0 +1,25 @@
1
+ const path = require("path");
2
+
3
+ const commonResolve = require("@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
4
+
5
+ const appResolve = require("../webpack/resolve.js");
6
+
7
+ module.exports = {
8
+ ...commonResolve.alias,
9
+ ...appResolve.alias,
10
+ images: path.resolve(process.cwd(), "app/assets/images"),
11
+ assert: require.resolve("assert/"),
12
+ buffer: require.resolve("buffer/"),
13
+ crypto: require.resolve("crypto-browserify"),
14
+ http: require.resolve("stream-http"),
15
+ https: require.resolve("https-browserify"),
16
+ os: require.resolve("os-browserify/browser"),
17
+ path: require.resolve("path-browserify"),
18
+ perf_hooks: require.resolve("perf_hooks"),
19
+ stream: require.resolve("stream-browserify"),
20
+ tty: require.resolve("tty-browserify"),
21
+ url: require.resolve("url/"),
22
+ util: require.resolve("util/"),
23
+ vm: require.resolve("vm-browserify"),
24
+ zlib: require.resolve("browserify-zlib"),
25
+ };
@@ -0,0 +1,25 @@
1
+ const {
2
+ TRANSFORM_RULES,
3
+ } = require("@bigbinary/neeto-commons-frontend/configs/constants.js");
4
+
5
+ module.exports = api => {
6
+ api.cache(true);
7
+
8
+ return {
9
+ presets: ["@bigbinary/neeto"],
10
+ plugins: [
11
+ [
12
+ "module-resolver",
13
+ {
14
+ root: ["./src"],
15
+ alias: {
16
+ "dayjs/plugin/timezone":
17
+ "@bigbinary/neeto-commons-frontend/utils/timezonePlugin",
18
+ },
19
+ loglevel: "silent",
20
+ },
21
+ ],
22
+ ...TRANSFORM_RULES,
23
+ ],
24
+ };
25
+ };
@@ -0,0 +1,90 @@
1
+ const path = require("path");
2
+
3
+ const commonResolve = require("@bigbinary/neeto-commons-frontend/configs/webpack/resolve.js");
4
+ const dotenv = require("dotenv");
5
+ const rails = require("esbuild-rails");
6
+ const { sassPlugin } = require("esbuild-sass-plugin");
7
+ const postcss = require("postcss");
8
+
9
+ const alias = require("./alias.js");
10
+ const { babelPlugin } = require("./plugins/babel.js");
11
+ const { prevalPlugin } = require("./plugins/preval.js");
12
+ const {
13
+ createDefinitions,
14
+ entryPoint,
15
+ createModuleEntryPoints,
16
+ build,
17
+ watch,
18
+ createBigbinaryEntryPoints,
19
+ } = require("./utils.js");
20
+
21
+ // @ts-ignore
22
+ const postCssConfig = require("../../../../../postcss.config.js");
23
+
24
+ const isProduction = process.env.NODE_ENV === "production";
25
+ const isWatchMode = process.argv.includes("--watch");
26
+
27
+ dotenv.config({ path: isProduction ? ".env" : ".env.development" });
28
+
29
+ const config = {
30
+ entryPoints: {
31
+ application: entryPoint("app/javascript/packs/application.js"),
32
+ ...createBigbinaryEntryPoints(),
33
+ ...createModuleEntryPoints(["antd", "recharts", "emojiMart"]),
34
+ },
35
+ bundle: true,
36
+ splitting: true,
37
+ outdir: path.join(process.cwd(), "app/assets/builds"),
38
+ minify: isProduction,
39
+ sourcemap: true,
40
+ assetNames: "assets/[name]-[hash].digested",
41
+ chunkNames: "chunks/[name]-[hash].digested",
42
+ publicPath: `${process.env.ASSET_HOST ?? ""}/assets`,
43
+ plugins: [
44
+ rails(),
45
+ prevalPlugin(),
46
+ babelPlugin(),
47
+ sassPlugin({
48
+ async transform(source) {
49
+ const { css } = await postcss(postCssConfig.plugins).process(source);
50
+
51
+ return css;
52
+ },
53
+ importMapper: path =>
54
+ path.replace("@bigbinary/neetoui", "@bigbinary/neetoui/dist"),
55
+ }),
56
+ ],
57
+ conditions: ["style"],
58
+ logLevel: "error",
59
+ format: "esm",
60
+ metafile: true,
61
+ platform: "browser",
62
+ mainFields: ["browser", "module", "main"],
63
+ loader: {
64
+ ".png": "file",
65
+ ".jpeg": "file",
66
+ ".jpg": "file",
67
+ ".svg": "file",
68
+ ".ico": "file",
69
+ },
70
+ external: ["fs", "path", "os", "events"],
71
+ alias,
72
+ jsx: "automatic",
73
+ resolveExtensions: [...commonResolve.extensions, ".jsx"],
74
+ define: {
75
+ "process.env.RAILS_ENV": "'development'",
76
+ "process.env.NODE_DEBUG": "'development'",
77
+ ...createDefinitions(process),
78
+ },
79
+ banner: {
80
+ js: isWatchMode
81
+ ? `(() => new EventSource("http://localhost:${
82
+ process.env.ESBUILD_PORT || 8000
83
+ }/esbuild").addEventListener('change', () => location.reload()))();`
84
+ : "",
85
+ },
86
+ };
87
+
88
+ isWatchMode ? watch(config) : build(config);
89
+
90
+ exports.config = config;
@@ -0,0 +1,24 @@
1
+ const babel = require("@babel/core");
2
+ const parser = require("@babel/parser");
3
+
4
+ const babelPlugin = () => ({
5
+ name: "babel-plugin",
6
+ setup(build) {
7
+ build.onLoad({ filter: /app\/javascript\/.*\.*\.jsx?$/ }, async args => {
8
+ const fs = require("fs").promises;
9
+ const contents = await fs.readFile(args.path, "utf8");
10
+
11
+ const ast = parser.parse(contents, {
12
+ sourceType: "module",
13
+ plugins: ["jsx"],
14
+ });
15
+
16
+ const result = babel.transformFromAstSync(ast, contents);
17
+ const transformedContents = result?.code;
18
+
19
+ return { contents: transformedContents, loader: "jsx" };
20
+ });
21
+ },
22
+ });
23
+
24
+ module.exports = { babelPlugin };
@@ -0,0 +1,26 @@
1
+ const PkgTranslations = require("@bigbinary/neeto-commons-frontend/configs/scripts/getPkgTranslations.js");
2
+
3
+ const prevalPlugin = () => ({
4
+ name: "preval-plugin",
5
+ setup(build) {
6
+ build.onLoad(
7
+ {
8
+ filter:
9
+ /node_modules\/@bigbinary\/neeto-commons-frontend\/dist\/(cjs\/)?initializers\/i18n.js/,
10
+ },
11
+ async args => {
12
+ const fs = require("fs").promises;
13
+ const contents = await fs.readFile(args.path, "utf8");
14
+
15
+ const transformedContents = contents.replace(
16
+ `preval.require("../../configs/scripts/getPkgTranslations.js")`,
17
+ JSON.stringify(PkgTranslations)
18
+ );
19
+
20
+ return { contents: transformedContents, loader: "js" };
21
+ }
22
+ );
23
+ },
24
+ });
25
+
26
+ module.exports = { prevalPlugin };
@@ -0,0 +1,93 @@
1
+ const esbuild = require("esbuild");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+
5
+ // colors for console output
6
+ const consoleColors = {
7
+ info: "\x1b[34m", // Blue
8
+ success: "\x1b[32m", // Green
9
+ warning: "\x1b[33m", // Yellow
10
+ error: "\x1b[31m", // Red
11
+ reset: "\x1b[0m", // Reset
12
+ };
13
+
14
+ const createDefinitions = process => {
15
+ return Object.keys(process.env).reduce((acc, key) => {
16
+ acc[`process.env.${key}`] = JSON.stringify(process.env[key]);
17
+ return acc;
18
+ }, {});
19
+ };
20
+
21
+ const entryPoint = file => path.join(process.cwd(), file);
22
+
23
+ const createBigbinaryEntryPoints = () => {
24
+ const directoryPath = "node_modules/@bigbinary";
25
+ const excludeList = ["babel-preset-neeto", "eslint-plugin-neeto"];
26
+ const entries = {};
27
+ try {
28
+ const items = fs.readdirSync(directoryPath);
29
+ items.forEach(item => {
30
+ if (excludeList.includes(item)) return;
31
+ const itemPath = path.join(directoryPath, item, "/dist/index.js");
32
+ try {
33
+ fs.accessSync(itemPath);
34
+ entries[item] = entryPoint(itemPath);
35
+ } catch {
36
+ console.log(itemPath, "doesn't exist");
37
+ }
38
+ });
39
+ return entries;
40
+ } catch (error) {
41
+ console.error(`Error reading directory ${directoryPath}:`, error);
42
+ return {};
43
+ }
44
+ };
45
+
46
+ const createModuleEntryPoints = modules => {
47
+ const entries = {};
48
+ modules.forEach(module => {
49
+ const modulePath = `node_modules/${
50
+ module instanceof String ? module : module.path
51
+ }`;
52
+ const name = module instanceof String ? module : module.name;
53
+ if (fs.existsSync(modulePath)) {
54
+ entries[name] = entryPoint(modulePath);
55
+ }
56
+ });
57
+ return entries;
58
+ };
59
+
60
+ const build = async config => {
61
+ try {
62
+ console.info(
63
+ `${consoleColors.info}[esbuild]${consoleColors.reset} Building...`
64
+ );
65
+ await esbuild.build(config);
66
+ console.info(
67
+ `${consoleColors.success}[esbuild]${consoleColors.reset} Build successful`
68
+ );
69
+ } catch {
70
+ console.error(
71
+ `${consoleColors.error}[esbuild]${consoleColors.reset} Build failed`
72
+ );
73
+ }
74
+ };
75
+
76
+ const watch = async config => {
77
+ const ctx = await esbuild.context(config);
78
+ await ctx.watch();
79
+ await ctx.serve({
80
+ servedir: config.outdir,
81
+ port: parseInt(process.env.ESBUILD_PORT || "8000"),
82
+ });
83
+ console.log("watching...");
84
+ };
85
+
86
+ module.exports = {
87
+ createDefinitions,
88
+ entryPoint,
89
+ createModuleEntryPoints,
90
+ build,
91
+ watch,
92
+ createBigbinaryEntryPoints,
93
+ };
@@ -10,6 +10,7 @@ var utils_validators_slug = require('./validators/slug.js');
10
10
  var utils_captureAnalyticsEvent = require('./captureAnalyticsEvent.js');
11
11
  var utils_captureAnalyticsPageView = require('./captureAnalyticsPageView.js');
12
12
  var utils_buildNestedAttributesPayload = require('./buildNestedAttributesPayload.js');
13
+ var utils_loadGoogleFonts = require('./loadGoogleFonts.js');
13
14
  var utils_dayjs = require('./dayjs.js');
14
15
  require('axios');
15
16
  require('../initializers/constants.js');
@@ -60,5 +61,6 @@ exports.slugValidator = utils_validators_slug.slugValidator;
60
61
  exports.captureAnalyticsEvent = utils_captureAnalyticsEvent.captureAnalyticsEvent;
61
62
  exports.captureAnalyticsPageView = utils_captureAnalyticsPageView.captureAnalyticsPageView;
62
63
  exports.buildNestedAttributesPayload = utils_buildNestedAttributesPayload.buildNestedAttributesPayload;
64
+ exports.loadGoogleFonts = utils_loadGoogleFonts.loadGoogleFonts;
63
65
  exports.dayjs = utils_dayjs;
64
66
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var loadGoogleFonts = function loadGoogleFonts(fontFamilies) {
4
+ fontFamilies.forEach(function (fontFamily) {
5
+ var link = document.createElement("link");
6
+ link.href = "https://fonts.googleapis.com/css2?family=".concat(fontFamily);
7
+ link.rel = "stylesheet";
8
+ document.head.appendChild(link);
9
+ });
10
+ };
11
+
12
+ exports.loadGoogleFonts = loadGoogleFonts;
13
+ //# sourceMappingURL=loadGoogleFonts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadGoogleFonts.js","sources":["../../../src/utils/loadGoogleFonts.js"],"sourcesContent":["export const loadGoogleFonts = fontFamilies => {\n fontFamilies.forEach(fontFamily => {\n const link = document.createElement(\"link\");\n link.href = `https://fonts.googleapis.com/css2?family=${fontFamily}`;\n link.rel = \"stylesheet\";\n document.head.appendChild(link);\n });\n};\n"],"names":["loadGoogleFonts","fontFamilies","forEach","fontFamily","link","document","createElement","href","concat","rel","head","appendChild"],"mappings":";;IAAaA,eAAe,GAAG,SAAlBA,eAAeA,CAAGC,YAAY,EAAI;AAC7CA,EAAAA,YAAY,CAACC,OAAO,CAAC,UAAAC,UAAU,EAAI;AACjC,IAAA,IAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAC,MAAM,CAAC,CAAA;AAC3CF,IAAAA,IAAI,CAACG,IAAI,GAAA,2CAAA,CAAAC,MAAA,CAA+CL,UAAU,CAAE,CAAA;IACpEC,IAAI,CAACK,GAAG,GAAG,YAAY,CAAA;AACvBJ,IAAAA,QAAQ,CAACK,IAAI,CAACC,WAAW,CAACP,IAAI,CAAC,CAAA;AACjC,GAAC,CAAC,CAAA;AACJ;;;;"}
@@ -8,6 +8,7 @@ export { slugValidator } from './validators/slug.js';
8
8
  export { captureAnalyticsEvent } from './captureAnalyticsEvent.js';
9
9
  export { captureAnalyticsPageView } from './captureAnalyticsPageView.js';
10
10
  export { buildNestedAttributesPayload } from './buildNestedAttributesPayload.js';
11
+ export { loadGoogleFonts } from './loadGoogleFonts.js';
11
12
  export { default as dayjs } from './dayjs.js';
12
13
  import 'axios';
13
14
  import '../initializers/constants.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,11 @@
1
+ var loadGoogleFonts = function loadGoogleFonts(fontFamilies) {
2
+ fontFamilies.forEach(function (fontFamily) {
3
+ var link = document.createElement("link");
4
+ link.href = "https://fonts.googleapis.com/css2?family=".concat(fontFamily);
5
+ link.rel = "stylesheet";
6
+ document.head.appendChild(link);
7
+ });
8
+ };
9
+
10
+ export { loadGoogleFonts };
11
+ //# sourceMappingURL=loadGoogleFonts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadGoogleFonts.js","sources":["../../src/utils/loadGoogleFonts.js"],"sourcesContent":["export const loadGoogleFonts = fontFamilies => {\n fontFamilies.forEach(fontFamily => {\n const link = document.createElement(\"link\");\n link.href = `https://fonts.googleapis.com/css2?family=${fontFamily}`;\n link.rel = \"stylesheet\";\n document.head.appendChild(link);\n });\n};\n"],"names":["loadGoogleFonts","fontFamilies","forEach","fontFamily","link","document","createElement","href","concat","rel","head","appendChild"],"mappings":"IAAaA,eAAe,GAAG,SAAlBA,eAAeA,CAAGC,YAAY,EAAI;AAC7CA,EAAAA,YAAY,CAACC,OAAO,CAAC,UAAAC,UAAU,EAAI;AACjC,IAAA,IAAMC,IAAI,GAAGC,QAAQ,CAACC,aAAa,CAAC,MAAM,CAAC,CAAA;AAC3CF,IAAAA,IAAI,CAACG,IAAI,GAAA,2CAAA,CAAAC,MAAA,CAA+CL,UAAU,CAAE,CAAA;IACpEC,IAAI,CAACK,GAAG,GAAG,YAAY,CAAA;AACvBJ,IAAAA,QAAQ,CAACK,IAAI,CAACC,WAAW,CAACP,IAAI,CAAC,CAAA;AACjC,GAAC,CAAC,CAAA;AACJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "4.8.12",
3
+ "version": "4.11.0-beta.1",
4
4
  "description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
5
5
  "repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
@@ -142,6 +142,9 @@
142
142
  "cypress": "11.2.0",
143
143
  "dayjs": "1.11.10",
144
144
  "dompurify": "^2.4.0",
145
+ "esbuild": "^0.24.0",
146
+ "esbuild-rails": "^1.0.7",
147
+ "esbuild-sass-plugin": "^3.3.1",
145
148
  "eslint": "8.14.0",
146
149
  "eslint-config-prettier": "8.5.0",
147
150
  "eslint-plugin-cypress": "2.12.1",
@@ -227,6 +230,9 @@
227
230
  "dayjs": "1.11.10",
228
231
  "dompurify": "^2.4.0",
229
232
  "dotenv-webpack": "^8.0.1",
233
+ "esbuild": "^0.24.0",
234
+ "esbuild-rails": "^1.0.7",
235
+ "esbuild-sass-plugin": "^3.3.1",
230
236
  "formik": "2.2.9",
231
237
  "framer-motion": "11.2.14",
232
238
  "husky": "7.0.4",
package/utils.d.ts CHANGED
@@ -663,4 +663,21 @@ export function buildNestedAttributesPayload(modifiedValues: {
663
663
  [key: string]: any;
664
664
  }, nestedKeyToModify: string, nestedAttributeKeyInPayload: string, nestedAttributesForArrayKey: string): {
665
665
  [key: string]: any;
666
- };
666
+ };
667
+ /**
668
+ *
669
+ * The loadGoogleFonts is a utility function which facilitates loading multiple Google Fonts dynamically by injecting link elements into the document head.
670
+ *
671
+ * @example
672
+ *
673
+ * import { useEffect } from "react";
674
+ *
675
+ * import { loadGoogleFonts } from "@bigbinary/neeto-commons-frontend/utils";
676
+ *
677
+ * useEffect(() => {
678
+ * const fontFamilies = ['Roboto', 'Open Sans', 'Lato'];
679
+ * loadGoogleFonts(fontFamilies);
680
+ * }, []);
681
+ * @endexample
682
+ */
683
+ export function loadGoogleFonts(fontFamilies: string[]): void;