@bigbinary/neeto-commons-frontend 4.13.63 → 4.13.65

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.
@@ -1,7 +1,27 @@
1
- const path = require("path");
1
+ import fs from "fs";
2
+ import { createRequire } from "module";
3
+ import path from "path";
2
4
 
3
- const globby = require("globby");
4
- const copy = require("rollup-plugin-copy");
5
+ import { globby } from "globby";
6
+ import copy from "rollup-plugin-copy";
7
+
8
+ const require = createRequire(import.meta.url);
9
+
10
+ const getAppArg = () => {
11
+ const argv = process.argv.slice(2);
12
+
13
+ for (let i = 0; i < argv.length; i++) {
14
+ if (argv[i] === "--app" && argv[i + 1] && !argv[i + 1].startsWith("--")) {
15
+ return argv[i + 1];
16
+ }
17
+
18
+ if (argv[i].startsWith("--app=")) {
19
+ return argv[i].split("=")[1];
20
+ }
21
+ }
22
+
23
+ return null;
24
+ };
5
25
 
6
26
  const emitReadyFile = destination => ({
7
27
  name: "emit-ready-file",
@@ -18,15 +38,29 @@ const emitReadyFile = destination => ({
18
38
  const watchPaths = customWatchPaths => ({
19
39
  name: "watch-translations",
20
40
  async buildStart() {
21
- const paths = await globby([
22
- "src/translations",
23
- "app/javascript/src/translations",
24
- "types/**/*",
25
- "*.d.ts",
26
- ...customWatchPaths,
27
- ]);
28
-
29
- paths.forEach(p => this.addWatchFile(p));
41
+ const pathsToWatch = [];
42
+
43
+ if (fs.existsSync("app/javascript/src/translations")) {
44
+ pathsToWatch.push("app/javascript/src/translations");
45
+ } else if (fs.existsSync("src/translations")) {
46
+ pathsToWatch.push("src/translations");
47
+ }
48
+
49
+ if (fs.existsSync("typeTemplates")) {
50
+ pathsToWatch.push("typeTemplates/**/*");
51
+ } else if (fs.existsSync("types")) {
52
+ pathsToWatch.push("types/**/*");
53
+ } else {
54
+ pathsToWatch.push("*.d.ts");
55
+ }
56
+
57
+ if (customWatchPaths && customWatchPaths.length) {
58
+ pathsToWatch.push(...customWatchPaths);
59
+ }
60
+
61
+ const matchedPaths = await globby(pathsToWatch);
62
+
63
+ matchedPaths.forEach(p => this.addWatchFile(path.resolve(p)));
30
64
  },
31
65
  });
32
66
 
@@ -49,30 +83,28 @@ const copyFiles = (destination, customCopyPaths) =>
49
83
  ],
50
84
  });
51
85
 
52
- const buildWatchConfig = ({
53
- args,
54
- customCopyPaths = [],
55
- customWatchPaths = [],
56
- }) => {
57
- if (!args.app) return { watchPlugins: [], appPath: null };
86
+ const getWatchConfig = ({ customCopyPaths = [], customWatchPaths = [] }) => {
87
+ const appArg = getAppArg();
88
+
89
+ if (!appArg) return { watchPlugins: [], appPath: null };
58
90
 
59
91
  const currentDir = process.cwd();
60
92
  const packageJson = require(path.resolve(currentDir, "package.json"));
61
93
 
62
94
  const appPath = path.resolve(
63
95
  currentDir,
64
- args.app,
96
+ appArg,
65
97
  "node_modules",
66
98
  packageJson.name
67
99
  );
68
100
 
69
- const plugins = [
101
+ const watchPlugins = [
70
102
  watchPaths(customWatchPaths),
71
103
  copyFiles(appPath, customCopyPaths),
72
104
  emitReadyFile(appPath),
73
105
  ];
74
106
 
75
- return { watchPlugins: plugins, appPath };
107
+ return { watchPlugins, appPath };
76
108
  };
77
109
 
78
- module.exports = { buildWatchConfig };
110
+ export { getWatchConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "4.13.63",
3
+ "version": "4.13.65",
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>",