@bigbinary/neeto-commons-frontend 4.13.64 → 4.13.66

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,31 @@ const copyFiles = (destination, customCopyPaths) =>
49
83
  ],
50
84
  });
51
85
 
52
- const getAppWatchConfig = ({
53
- args,
86
+ const getWatchConfig = ({
54
87
  customCopyPaths = [],
55
88
  customWatchPaths = [],
56
- }) => {
57
- if (!args.app) return { watchPlugins: [], appPath: null };
89
+ } = {}) => {
90
+ const appArg = getAppArg();
91
+
92
+ if (!appArg) return { watchPlugins: [], appPath: null };
58
93
 
59
94
  const currentDir = process.cwd();
60
95
  const packageJson = require(path.resolve(currentDir, "package.json"));
61
96
 
62
97
  const appPath = path.resolve(
63
98
  currentDir,
64
- args.app,
99
+ appArg,
65
100
  "node_modules",
66
101
  packageJson.name
67
102
  );
68
103
 
69
- const appWatchPlugins = [
104
+ const watchPlugins = [
70
105
  watchPaths(customWatchPaths),
71
106
  copyFiles(appPath, customCopyPaths),
72
107
  emitReadyFile(appPath),
73
108
  ];
74
109
 
75
- return { appWatchPlugins, appPath };
110
+ return { watchPlugins, appPath };
76
111
  };
77
112
 
78
- module.exports = { getAppWatchConfig };
113
+ export { getWatchConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "4.13.64",
3
+ "version": "4.13.66",
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>",