@eventra_dev/eventra-cli 0.1.11 → 0.1.12

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.
@@ -8,6 +8,7 @@ const chokidar_1 = __importDefault(require("chokidar"));
8
8
  const chalk_1 = __importDefault(require("chalk"));
9
9
  const promises_1 = __importDefault(require("fs/promises"));
10
10
  const fast_glob_1 = __importDefault(require("fast-glob"));
11
+ const path_1 = __importDefault(require("path"));
11
12
  const config_1 = require("../utils/config");
12
13
  const engine_1 = require("../engine/engine");
13
14
  const processFile_1 = require("../utils/processFile");
@@ -20,22 +21,32 @@ async function watch() {
20
21
  ignore: config.sync.exclude,
21
22
  });
22
23
  const engine = new engine_1.EventraEngine(process.cwd());
24
+ const fileCache = [];
25
+ // PRELOAD TS
23
26
  for (const file of files) {
24
27
  try {
25
- const raw = await promises_1.default.readFile(file, "utf-8");
26
- const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
27
- engine.scanFile(virtualFile, content, config);
28
+ const abs = path_1.default.resolve(file);
29
+ const raw = await promises_1.default.readFile(abs, "utf-8");
30
+ const { content, virtualFile } = (0, processFile_1.processFile)(abs, raw);
31
+ fileCache.push({ file: virtualFile, content });
32
+ engine["ts"].updateFile(virtualFile, content);
28
33
  }
29
34
  catch {
30
35
  console.log(chalk_1.default.gray(`skip: ${file}`));
31
36
  }
32
37
  }
38
+ // INITIAL SCAN
39
+ for (const { file, content } of fileCache) {
40
+ engine.scanFile(file, content, config);
41
+ }
33
42
  config.events = engine.getAllEvents().sort();
34
43
  await (0, config_1.saveConfig)(config);
35
44
  console.log(chalk_1.default.gray(`Initial: ${config.events.length} events\n`));
45
+ // WATCH STATE
36
46
  let locked = false;
37
47
  let queued = new Set();
38
48
  let timer = null;
49
+ // RUN BATCH
39
50
  const run = async () => {
40
51
  if (locked)
41
52
  return;
@@ -64,12 +75,15 @@ async function watch() {
64
75
  }
65
76
  locked = false;
66
77
  };
78
+ // SCHEDULER
67
79
  const schedule = (file) => {
68
- queued.add(file);
80
+ const abs = path_1.default.resolve(file);
81
+ queued.add(abs);
69
82
  if (timer)
70
83
  clearTimeout(timer);
71
84
  timer = setTimeout(run, 100);
72
85
  };
86
+ // WATCHER
73
87
  const watcher = chokidar_1.default.watch(config.sync.include, {
74
88
  ignored: config.sync.exclude,
75
89
  ignoreInitial: true,
@@ -78,12 +92,14 @@ async function watch() {
78
92
  .on("add", schedule)
79
93
  .on("change", schedule)
80
94
  .on("unlink", async (file) => {
95
+ const abs = path_1.default.resolve(file);
81
96
  console.log(chalk_1.default.gray(`remove: ${file}`));
82
- const { virtualFile } = (0, processFile_1.processFile)(file, "");
83
- engine.removeFile(virtualFile);
97
+ const { virtualFile } = (0, processFile_1.processFile)(abs, "");
98
+ engine.removeFile(virtualFile, config);
84
99
  const next = engine.getAllEvents();
85
100
  config.events = next.sort();
86
101
  await (0, config_1.saveConfig)(config);
102
+ console.log(chalk_1.default.gray(`Total: ${config.events.length} events\n`));
87
103
  });
88
104
  process.on("SIGINT", async () => {
89
105
  console.log(chalk_1.default.yellow("\nStopping watcher..."));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventra_dev/eventra-cli",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Eventra CLI",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -2,6 +2,7 @@ import chokidar from "chokidar";
2
2
  import chalk from "chalk";
3
3
  import fs from "fs/promises";
4
4
  import fg from "fast-glob";
5
+ import path from "path";
5
6
 
6
7
  import { loadConfig, saveConfig } from "../utils/config";
7
8
  import { EventraEngine } from "../engine/engine";
@@ -19,19 +20,29 @@ export async function watch() {
19
20
 
20
21
  const engine = new EventraEngine(process.cwd());
21
22
 
23
+ const fileCache: { file: string; content: string }[] = [];
24
+
25
+ // PRELOAD TS
22
26
  for (const file of files) {
23
27
  try {
24
- const raw = await fs.readFile(file, "utf-8");
28
+ const abs = path.resolve(file);
29
+ const raw = await fs.readFile(abs, "utf-8");
25
30
 
26
- const { content, virtualFile } = processFile(file, raw);
31
+ const { content, virtualFile } = processFile(abs, raw);
27
32
 
28
- engine.scanFile(virtualFile, content, config);
33
+ fileCache.push({ file: virtualFile, content });
29
34
 
35
+ engine["ts"].updateFile(virtualFile, content);
30
36
  } catch {
31
37
  console.log(chalk.gray(`skip: ${file}`));
32
38
  }
33
39
  }
34
40
 
41
+ // INITIAL SCAN
42
+ for (const { file, content } of fileCache) {
43
+ engine.scanFile(file, content, config);
44
+ }
45
+
35
46
  config.events = engine.getAllEvents().sort();
36
47
  await saveConfig(config);
37
48
 
@@ -39,10 +50,12 @@ export async function watch() {
39
50
  chalk.gray(`Initial: ${config.events.length} events\n`)
40
51
  );
41
52
 
53
+ // WATCH STATE
42
54
  let locked = false;
43
55
  let queued = new Set<string>();
44
56
  let timer: NodeJS.Timeout | null = null;
45
57
 
58
+ // RUN BATCH
46
59
  const run = async () => {
47
60
  if (locked) return;
48
61
  locked = true;
@@ -53,7 +66,6 @@ export async function watch() {
53
66
  for (const file of batch) {
54
67
  try {
55
68
  const raw = await fs.readFile(file, "utf-8");
56
-
57
69
  const { content, virtualFile } = processFile(file, raw);
58
70
 
59
71
  engine.updateFile(virtualFile, content, config);
@@ -83,14 +95,17 @@ export async function watch() {
83
95
  locked = false;
84
96
  };
85
97
 
98
+ // SCHEDULER
86
99
  const schedule = (file: string) => {
87
- queued.add(file);
100
+ const abs = path.resolve(file);
88
101
 
89
- if (timer) clearTimeout(timer);
102
+ queued.add(abs);
90
103
 
104
+ if (timer) clearTimeout(timer);
91
105
  timer = setTimeout(run, 100);
92
106
  };
93
107
 
108
+ // WATCHER
94
109
  const watcher = chokidar.watch(config.sync.include, {
95
110
  ignored: config.sync.exclude,
96
111
  ignoreInitial: true,
@@ -100,16 +115,22 @@ export async function watch() {
100
115
  .on("add", schedule)
101
116
  .on("change", schedule)
102
117
  .on("unlink", async (file) => {
118
+ const abs = path.resolve(file);
119
+
103
120
  console.log(chalk.gray(`remove: ${file}`));
104
121
 
105
- const { virtualFile } = processFile(file, "");
122
+ const { virtualFile } = processFile(abs, "");
106
123
 
107
- engine.removeFile(virtualFile);
124
+ engine.removeFile(virtualFile, config);
108
125
 
109
126
  const next = engine.getAllEvents();
110
127
 
111
128
  config.events = next.sort();
112
129
  await saveConfig(config);
130
+
131
+ console.log(
132
+ chalk.gray(`Total: ${config.events.length} events\n`)
133
+ );
113
134
  });
114
135
 
115
136
  process.on("SIGINT", async () => {