@eventra_dev/eventra-cli 0.0.12 → 0.0.13
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/sync.js +1 -1
- package/dist/utils/scanners/track.js +22 -6
- package/package.json +1 -1
- package/src/commands/sync.ts +1 -1
- package/src/utils/scanners/track.ts +50 -36
package/dist/commands/sync.js
CHANGED
|
@@ -45,7 +45,7 @@ async function sync() {
|
|
|
45
45
|
: file + ".tsx";
|
|
46
46
|
const source = project.createSourceFile(virtualFile, content, { overwrite: true });
|
|
47
47
|
const found = [
|
|
48
|
-
...(0, track_1.scanTrack)(source),
|
|
48
|
+
...(0, track_1.scanTrack)(source, config),
|
|
49
49
|
...(0, function_wrappers_1.scanFunctionWrappers)(source, config.functionWrappers ?? []),
|
|
50
50
|
...(0, component_wrappers_1.scanComponentWrappers)(source, config.wrappers ?? [])
|
|
51
51
|
];
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.scanTrack = scanTrack;
|
|
4
4
|
const ts_morph_1 = require("ts-morph");
|
|
5
5
|
const extract_1 = require("../extract");
|
|
6
|
-
function scanTrack(source) {
|
|
6
|
+
function scanTrack(source, config) {
|
|
7
7
|
const events = new Set();
|
|
8
8
|
const calls = source.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
9
9
|
for (const call of calls) {
|
|
@@ -11,16 +11,32 @@ function scanTrack(source) {
|
|
|
11
11
|
let isTrack = false;
|
|
12
12
|
// track()
|
|
13
13
|
if (ts_morph_1.Node.isIdentifier(expr)) {
|
|
14
|
-
isTrack =
|
|
15
|
-
expr.getText() === "track";
|
|
14
|
+
isTrack = expr.getText() === "track";
|
|
16
15
|
}
|
|
17
16
|
// analytics.track()
|
|
18
17
|
if (ts_morph_1.Node.isPropertyAccessExpression(expr)) {
|
|
19
|
-
isTrack =
|
|
20
|
-
expr.getName() === "track";
|
|
18
|
+
isTrack = expr.getName() === "track";
|
|
21
19
|
}
|
|
22
20
|
if (!isTrack)
|
|
23
21
|
continue;
|
|
22
|
+
const func = call.getFirstAncestorByKind(ts_morph_1.SyntaxKind.FunctionDeclaration) ||
|
|
23
|
+
call.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ArrowFunction) ||
|
|
24
|
+
call.getFirstAncestorByKind(ts_morph_1.SyntaxKind.FunctionExpression);
|
|
25
|
+
let fnName;
|
|
26
|
+
if (func) {
|
|
27
|
+
if (ts_morph_1.Node.isFunctionDeclaration(func)) {
|
|
28
|
+
fnName = func.getName();
|
|
29
|
+
}
|
|
30
|
+
if (ts_morph_1.Node.isArrowFunction(func) ||
|
|
31
|
+
ts_morph_1.Node.isFunctionExpression(func)) {
|
|
32
|
+
const varDecl = func.getFirstAncestorByKind(ts_morph_1.SyntaxKind.VariableDeclaration);
|
|
33
|
+
fnName = varDecl?.getName();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (fnName &&
|
|
37
|
+
config.functionWrappers?.some((w) => w.name === fnName)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
24
40
|
const arg = call.getArguments()[0];
|
|
25
41
|
if (!arg)
|
|
26
42
|
continue;
|
|
@@ -29,7 +45,7 @@ function scanTrack(source) {
|
|
|
29
45
|
continue;
|
|
30
46
|
result.values.forEach((value) => events.add({
|
|
31
47
|
value,
|
|
32
|
-
dynamic: result.dynamic
|
|
48
|
+
dynamic: result.dynamic,
|
|
33
49
|
}));
|
|
34
50
|
}
|
|
35
51
|
return events;
|
package/package.json
CHANGED
package/src/commands/sync.ts
CHANGED
|
@@ -2,67 +2,81 @@ import {
|
|
|
2
2
|
SourceFile,
|
|
3
3
|
SyntaxKind,
|
|
4
4
|
Node,
|
|
5
|
-
CallExpression,
|
|
6
|
-
PropertyAccessExpression
|
|
7
5
|
} from "ts-morph";
|
|
8
6
|
|
|
9
|
-
import { ExtractedEvent } from "../../types";
|
|
7
|
+
import { ExtractedEvent, EventraConfig } from "../../types";
|
|
10
8
|
import { extractExpression } from "../extract";
|
|
11
9
|
|
|
12
10
|
export function scanTrack(
|
|
13
|
-
source: SourceFile
|
|
11
|
+
source: SourceFile,
|
|
12
|
+
config: EventraConfig
|
|
14
13
|
) {
|
|
15
|
-
const events =
|
|
16
|
-
new Set<ExtractedEvent>();
|
|
14
|
+
const events = new Set<ExtractedEvent>();
|
|
17
15
|
|
|
18
|
-
const calls =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
);
|
|
16
|
+
const calls = source.getDescendantsOfKind(
|
|
17
|
+
SyntaxKind.CallExpression
|
|
18
|
+
);
|
|
22
19
|
|
|
23
20
|
for (const call of calls) {
|
|
24
|
-
const expr =
|
|
25
|
-
call.getExpression();
|
|
21
|
+
const expr = call.getExpression();
|
|
26
22
|
|
|
27
23
|
let isTrack = false;
|
|
28
24
|
|
|
29
25
|
// track()
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
) {
|
|
33
|
-
isTrack =
|
|
34
|
-
expr.getText() === "track";
|
|
26
|
+
if (Node.isIdentifier(expr)) {
|
|
27
|
+
isTrack = expr.getText() === "track";
|
|
35
28
|
}
|
|
36
29
|
|
|
37
30
|
// analytics.track()
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
expr
|
|
41
|
-
)
|
|
42
|
-
) {
|
|
43
|
-
isTrack =
|
|
44
|
-
expr.getName() === "track";
|
|
31
|
+
if (Node.isPropertyAccessExpression(expr)) {
|
|
32
|
+
isTrack = expr.getName() === "track";
|
|
45
33
|
}
|
|
46
34
|
|
|
47
35
|
if (!isTrack) continue;
|
|
48
36
|
|
|
49
|
-
const
|
|
50
|
-
call.
|
|
37
|
+
const func =
|
|
38
|
+
call.getFirstAncestorByKind(SyntaxKind.FunctionDeclaration) ||
|
|
39
|
+
call.getFirstAncestorByKind(SyntaxKind.ArrowFunction) ||
|
|
40
|
+
call.getFirstAncestorByKind(SyntaxKind.FunctionExpression);
|
|
51
41
|
|
|
52
|
-
|
|
42
|
+
let fnName: string | undefined;
|
|
43
|
+
|
|
44
|
+
if (func) {
|
|
45
|
+
if (Node.isFunctionDeclaration(func)) {
|
|
46
|
+
fnName = func.getName();
|
|
47
|
+
}
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
if (
|
|
50
|
+
Node.isArrowFunction(func) ||
|
|
51
|
+
Node.isFunctionExpression(func)
|
|
52
|
+
) {
|
|
53
|
+
const varDecl = func.getFirstAncestorByKind(
|
|
54
|
+
SyntaxKind.VariableDeclaration
|
|
55
|
+
);
|
|
56
|
+
fnName = varDecl?.getName();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
fnName &&
|
|
62
|
+
config.functionWrappers?.some(
|
|
63
|
+
(w) => w.name === fnName
|
|
64
|
+
)
|
|
65
|
+
) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const arg = call.getArguments()[0];
|
|
70
|
+
if (!arg) continue;
|
|
56
71
|
|
|
72
|
+
const result = extractExpression(arg);
|
|
57
73
|
if (!result) continue;
|
|
58
74
|
|
|
59
|
-
result.values.forEach(
|
|
60
|
-
(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
result.dynamic
|
|
65
|
-
})
|
|
75
|
+
result.values.forEach((value) =>
|
|
76
|
+
events.add({
|
|
77
|
+
value,
|
|
78
|
+
dynamic: result.dynamic,
|
|
79
|
+
})
|
|
66
80
|
);
|
|
67
81
|
}
|
|
68
82
|
|