@cabin-icarus/tooltip_generator 1.7.14 → 1.8.0

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.
Files changed (3) hide show
  1. package/fsWatcher.ts +67 -34
  2. package/install.ts +1 -1
  3. package/package.json +2 -2
package/fsWatcher.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  const fs = require('fs');
2
+ const path = require("path");
2
3
  import { LocalizationCompiler } from './localizationCompiler';
3
4
  const watch = require("node-watch");
4
5
 
@@ -6,57 +7,57 @@ let completeData: {[path: string]: LocalizationData} = {};
6
7
  const resourcePath = "node_modules/~resource";
7
8
  const generatorPath = "node_modules/~generator";
8
9
 
9
- console.log(fs.realpathSync(generatorPath));
10
+ const folderPath = resourcePath + "/localization";
10
11
 
11
- let watcher = watch([resourcePath + "/localization"], {recursive: true})
12
+ let watcher = watch([folderPath], {recursive: true})
12
13
  watcher.on("change", (eventType ?: 'update' | 'remove' | undefined, filePath ?: string) => {
13
- if (!filePath) return;
14
- if (filePath.includes("localizationCompiler.ts")) {
15
- compiler = loadCompiler();
16
- }
17
- let match = /(node_modules[\\/])?(.*[\/|\\](\w+)).ts/g.exec(filePath);
18
- if (eventType == "update" && filePath && match) {
19
- const curpath = match[2];
20
- const data = getDataFromFile(curpath + ".ts");
21
- if (data) {
22
- completeData[curpath] = data;
23
- combineData();
24
- }
25
- } else if (eventType == "remove" && match) {
26
- if (completeData.hasOwnProperty(match[2])) {
27
- delete completeData[match[2]];
28
- combineData();
29
- }
30
- }
14
+ if (!filePath) return;
15
+ if (filePath.includes("localizationCompiler.ts")) {
16
+ compiler = loadCompiler();
17
+ }
18
+ let match = /(node_modules[\\/])?(.*[\/|\\](.+)).ts/g.exec(filePath);
19
+ if (eventType == "update" && filePath && match) {
20
+ const curpath = match[2];
21
+ const data = getDataFromFile(curpath + ".ts");
22
+ if (data) {
23
+ completeData[curpath] = data;
24
+ combineData();
25
+ }
26
+ } else if (eventType == "remove" && match) {
27
+ if (completeData.hasOwnProperty(match[2])) {
28
+ delete completeData[match[2]];
29
+ combineData();
30
+ }
31
+ }
31
32
  })
32
33
 
33
34
  // not really neccessarry:
34
35
  watcher.on("error", (error: Error) => {
35
- console.log("\x1b[31m%s\x1b[0m", "Something went wrong!");
36
- console.log(error);
36
+ console.log("\x1b[31m%s\x1b[0m", "Something went wrong!");
37
+ console.log(error);
37
38
  })
38
39
 
39
40
  watcher.on("ready", () => {
40
- console.log("\x1b[32m%s\x1b[0m", "Ready!");
41
+ console.log("\x1b[32m%s\x1b[0m", "Ready!");
41
42
  })
42
43
 
43
44
  let compiler = loadCompiler();
44
45
 
45
46
  function getDataFromFile(filePath: string): LocalizationData | undefined {
46
- if (!fs.existsSync("node_modules/" + filePath)){
47
- return;
48
- }
49
- delete require.cache[require.resolve(filePath)]
50
- let file = require(filePath);
51
- if (file["GenerateLocalizationData"]) {
52
- const localizationArr: LocalizationData = file["GenerateLocalizationData"]();
53
- return localizationArr;
54
- }
55
- return;
47
+ if (!fs.existsSync("node_modules/" + filePath)){
48
+ return;
49
+ }
50
+ delete require.cache[require.resolve(filePath)]
51
+ let file = require(filePath);
52
+ if (file["GenerateLocalizationData"]) {
53
+ const localizationArr: LocalizationData = file["GenerateLocalizationData"]();
54
+ return localizationArr;
55
+ }
56
+ return;
56
57
  }
57
58
 
58
59
  function combineData() {
59
- compiler.OnLocalizationDataChanged(completeData);
60
+ compiler.OnLocalizationDataChanged(completeData);
60
61
  }
61
62
 
62
63
  function loadCompiler(): LocalizationCompiler
@@ -67,3 +68,35 @@ function loadCompiler(): LocalizationCompiler
67
68
  const compilerClass: new () => LocalizationCompiler = require("~generator/localizationCompiler").LocalizationCompiler;
68
69
  return new compilerClass();
69
70
  }
71
+
72
+ const __getAllFiles = (dirPath: string, arrayOfFiles?: string[]) =>
73
+ {
74
+ const files = fs.readdirSync(dirPath)
75
+
76
+ arrayOfFiles = arrayOfFiles ?? []
77
+
78
+ files.forEach(function (file)
79
+ {
80
+ if (fs.statSync(dirPath + "/" + file).isDirectory())
81
+ {
82
+ arrayOfFiles = __getAllFiles(path.join(dirPath, file), arrayOfFiles)
83
+ } else
84
+ {
85
+ arrayOfFiles?.push(path.join(dirPath, file))
86
+ }
87
+ })
88
+
89
+ return arrayOfFiles
90
+ }
91
+
92
+ const files = __getAllFiles(folderPath);
93
+
94
+ Promise.all(files.map(x =>
95
+ {
96
+ const temp = fs.readFileSync(x);
97
+ fs.writeFile(x, ' ', err =>
98
+ {
99
+ fs.writeFileSync(x, temp);
100
+ });
101
+ }
102
+ ))
package/install.ts CHANGED
@@ -10,7 +10,7 @@ interface packageSnippet {
10
10
 
11
11
  // define package insertions
12
12
  const devScripts = [
13
- ["dev:runlocalizationWatcher", "ts-node node_modules/~generator/fsWatcher.ts"]
13
+ ["dev:runlocalizationWatcher", "ts-node -P node_modules/~resource/tsconfig.json node_modules/~generator/fsWatcher.ts"]
14
14
  ]
15
15
  const initSCript = ["init", "link-module-alias && ts-node node_modules/~generator/init.ts"]
16
16
  const aliases = [
package/package.json CHANGED
@@ -41,8 +41,8 @@
41
41
  },
42
42
  "scripts": {
43
43
  "dev": "run-p dev:*",
44
- "dev:runlocalizationWatcher": "ts-node node_modules/~generator/fsWatcher.ts",
44
+ "dev:runlocalizationWatcher": "ts-node -P node_modules/~resource/tsconfig.json node_modules/~generator/fsWatcher.ts",
45
45
  "init": "link-module-alias && ts-node node_modules/~generator/init.ts"
46
46
  },
47
- "version": "1.7.14"
47
+ "version": "1.8.0"
48
48
  }