@eventra_dev/eventra-cli 0.1.10 → 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.
- package/dist/commands/watch.js +22 -6
- package/dist/engine/resolver.js +21 -0
- package/package.json +1 -1
- package/src/commands/watch.ts +29 -8
- package/src/engine/resolver.ts +31 -0
package/dist/commands/watch.js
CHANGED
|
@@ -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
|
|
26
|
-
const
|
|
27
|
-
|
|
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
|
-
|
|
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)(
|
|
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/dist/engine/resolver.js
CHANGED
|
@@ -70,6 +70,7 @@ function resolveNodeValue(node, checker, paramMap, seen = new Set()) {
|
|
|
70
70
|
if (s.flags & typescript_1.default.SymbolFlags.Alias) {
|
|
71
71
|
s = checker.getAliasedSymbol(s);
|
|
72
72
|
}
|
|
73
|
+
// ENUM support
|
|
73
74
|
for (const decl of s.getDeclarations() ?? []) {
|
|
74
75
|
if (typescript_1.default.isEnumMember(decl) && decl.initializer) {
|
|
75
76
|
if (typescript_1.default.isStringLiteral(decl.initializer)) {
|
|
@@ -81,6 +82,26 @@ function resolveNodeValue(node, checker, paramMap, seen = new Set()) {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
}
|
|
85
|
+
// OBJECT support
|
|
86
|
+
if (typescript_1.default.isIdentifier(node.expression)) {
|
|
87
|
+
const objSymbol = checker.getSymbolAtLocation(node.expression);
|
|
88
|
+
if (objSymbol) {
|
|
89
|
+
for (const decl of objSymbol.getDeclarations() ?? []) {
|
|
90
|
+
if (typescript_1.default.isVariableDeclaration(decl) &&
|
|
91
|
+
decl.initializer &&
|
|
92
|
+
typescript_1.default.isObjectLiteralExpression(decl.initializer)) {
|
|
93
|
+
for (const prop of decl.initializer.properties) {
|
|
94
|
+
if (!typescript_1.default.isPropertyAssignment(prop))
|
|
95
|
+
continue;
|
|
96
|
+
const name = prop.name.getText();
|
|
97
|
+
if (name === node.name.text) {
|
|
98
|
+
return resolveNodeValue(prop.initializer, checker, paramMap, seen);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
84
105
|
}
|
|
85
106
|
if (typescript_1.default.isObjectLiteralExpression(node)) {
|
|
86
107
|
const values = [];
|
package/package.json
CHANGED
package/src/commands/watch.ts
CHANGED
|
@@ -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
|
|
28
|
+
const abs = path.resolve(file);
|
|
29
|
+
const raw = await fs.readFile(abs, "utf-8");
|
|
25
30
|
|
|
26
|
-
const { content, virtualFile } = processFile(
|
|
31
|
+
const { content, virtualFile } = processFile(abs, raw);
|
|
27
32
|
|
|
28
|
-
|
|
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
|
-
|
|
100
|
+
const abs = path.resolve(file);
|
|
88
101
|
|
|
89
|
-
|
|
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(
|
|
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 () => {
|
package/src/engine/resolver.ts
CHANGED
|
@@ -107,6 +107,7 @@ export function resolveNodeValue(
|
|
|
107
107
|
s = checker.getAliasedSymbol(s);
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
// ENUM support
|
|
110
111
|
for (const decl of s.getDeclarations() ?? []) {
|
|
111
112
|
if (ts.isEnumMember(decl) && decl.initializer) {
|
|
112
113
|
if (ts.isStringLiteral(decl.initializer)) {
|
|
@@ -118,6 +119,36 @@ export function resolveNodeValue(
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
}
|
|
122
|
+
|
|
123
|
+
// OBJECT support
|
|
124
|
+
if (ts.isIdentifier(node.expression)) {
|
|
125
|
+
const objSymbol = checker.getSymbolAtLocation(node.expression);
|
|
126
|
+
|
|
127
|
+
if (objSymbol) {
|
|
128
|
+
for (const decl of objSymbol.getDeclarations() ?? []) {
|
|
129
|
+
if (
|
|
130
|
+
ts.isVariableDeclaration(decl) &&
|
|
131
|
+
decl.initializer &&
|
|
132
|
+
ts.isObjectLiteralExpression(decl.initializer)
|
|
133
|
+
) {
|
|
134
|
+
for (const prop of decl.initializer.properties) {
|
|
135
|
+
if (!ts.isPropertyAssignment(prop)) continue;
|
|
136
|
+
|
|
137
|
+
const name = prop.name.getText();
|
|
138
|
+
|
|
139
|
+
if (name === node.name.text) {
|
|
140
|
+
return resolveNodeValue(
|
|
141
|
+
prop.initializer,
|
|
142
|
+
checker,
|
|
143
|
+
paramMap,
|
|
144
|
+
seen
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
121
152
|
}
|
|
122
153
|
|
|
123
154
|
if (ts.isObjectLiteralExpression(node)) {
|