@eventra_dev/eventra-cli 0.0.13 → 0.0.15
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/utils/config.js
CHANGED
|
@@ -16,6 +16,7 @@ function normalizeConfig(config) {
|
|
|
16
16
|
events: config.events ?? [],
|
|
17
17
|
wrappers: config.wrappers ?? [],
|
|
18
18
|
functionWrappers: config.functionWrappers ?? [],
|
|
19
|
+
aliases: config.aliases ?? {},
|
|
19
20
|
sync: config.sync ?? {
|
|
20
21
|
include: [
|
|
21
22
|
"**/*.{ts,tsx,js,jsx,vue,svelte,astro}"
|
package/dist/utils/extract.js
CHANGED
|
@@ -15,28 +15,92 @@ function extractExpression(expr) {
|
|
|
15
15
|
ts_morph_1.SyntaxKind.NoSubstitutionTemplateLiteral) {
|
|
16
16
|
return {
|
|
17
17
|
values: [
|
|
18
|
-
expr
|
|
19
|
-
.getText()
|
|
20
|
-
.replace(/`/g, "")
|
|
18
|
+
expr.getText().replace(/`/g, "")
|
|
21
19
|
],
|
|
22
20
|
dynamic: false
|
|
23
21
|
};
|
|
24
22
|
}
|
|
25
|
-
// identifier
|
|
23
|
+
// identifier (TEST)
|
|
26
24
|
if (ts_morph_1.Node.isIdentifier(expr)) {
|
|
25
|
+
const name = expr.getText();
|
|
26
|
+
const defs = "getDefinitions" in expr
|
|
27
|
+
? expr.getDefinitions()
|
|
28
|
+
: [];
|
|
29
|
+
if (defs && defs.length > 0) {
|
|
30
|
+
const decl = defs[0]?.getDeclarationNode();
|
|
31
|
+
if (decl && ts_morph_1.Node.isVariableDeclaration(decl)) {
|
|
32
|
+
const initializer = decl.getInitializer();
|
|
33
|
+
// const TEST = "event"
|
|
34
|
+
if (initializer &&
|
|
35
|
+
ts_morph_1.Node.isStringLiteral(initializer)) {
|
|
36
|
+
return {
|
|
37
|
+
values: [initializer.getLiteralText()],
|
|
38
|
+
dynamic: false
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// const TEST = `event`
|
|
42
|
+
if (initializer &&
|
|
43
|
+
initializer.getKind() ===
|
|
44
|
+
ts_morph_1.SyntaxKind.NoSubstitutionTemplateLiteral) {
|
|
45
|
+
return {
|
|
46
|
+
values: [
|
|
47
|
+
initializer.getText().replace(/`/g, "")
|
|
48
|
+
],
|
|
49
|
+
dynamic: false
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
27
54
|
return {
|
|
28
|
-
values: [
|
|
55
|
+
values: [name],
|
|
29
56
|
dynamic: true
|
|
30
57
|
};
|
|
31
58
|
}
|
|
32
|
-
// property access (
|
|
59
|
+
// property access (EVENTS.CLICK)
|
|
33
60
|
if (ts_morph_1.Node.isPropertyAccessExpression(expr)) {
|
|
61
|
+
const fullName = expr.getText(); // EVENTS.CLICK
|
|
62
|
+
const propName = expr.getName(); // CLICK
|
|
63
|
+
const defs = "getDefinitions" in expr
|
|
64
|
+
? expr.getDefinitions()
|
|
65
|
+
: [];
|
|
66
|
+
if (defs && defs.length > 0) {
|
|
67
|
+
const decl = defs[0]?.getDeclarationNode();
|
|
68
|
+
// const EVENTS = { CLICK: "event" }
|
|
69
|
+
if (decl && ts_morph_1.Node.isVariableDeclaration(decl)) {
|
|
70
|
+
const init = decl.getInitializer();
|
|
71
|
+
if (init && ts_morph_1.Node.isObjectLiteralExpression(init)) {
|
|
72
|
+
const prop = init.getProperty(propName);
|
|
73
|
+
if (prop &&
|
|
74
|
+
ts_morph_1.Node.isPropertyAssignment(prop)) {
|
|
75
|
+
const value = prop.getInitializer();
|
|
76
|
+
if (value &&
|
|
77
|
+
ts_morph_1.Node.isStringLiteral(value)) {
|
|
78
|
+
return {
|
|
79
|
+
values: [value.getLiteralText()],
|
|
80
|
+
dynamic: false
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// fallback
|
|
87
|
+
if (decl && ts_morph_1.Node.isPropertyAssignment(decl)) {
|
|
88
|
+
const initializer = decl.getInitializer();
|
|
89
|
+
if (initializer &&
|
|
90
|
+
ts_morph_1.Node.isStringLiteral(initializer)) {
|
|
91
|
+
return {
|
|
92
|
+
values: [initializer.getLiteralText()],
|
|
93
|
+
dynamic: false
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
34
98
|
return {
|
|
35
|
-
values: [
|
|
99
|
+
values: [fullName],
|
|
36
100
|
dynamic: true
|
|
37
101
|
};
|
|
38
102
|
}
|
|
39
|
-
// ternary
|
|
103
|
+
// ternary (a ? b : c)
|
|
40
104
|
if (ts_morph_1.Node.isConditionalExpression(expr)) {
|
|
41
105
|
const values = [];
|
|
42
106
|
const whenTrue = extractExpression(expr.getWhenTrue());
|
|
@@ -50,20 +114,20 @@ function extractExpression(expr) {
|
|
|
50
114
|
dynamic: true
|
|
51
115
|
};
|
|
52
116
|
}
|
|
53
|
-
// template
|
|
117
|
+
// template `${}`
|
|
54
118
|
if (ts_morph_1.Node.isTemplateExpression(expr)) {
|
|
55
119
|
return {
|
|
56
|
-
values: [
|
|
120
|
+
values: [
|
|
121
|
+
expr.getText().replace(/`/g, "")
|
|
122
|
+
],
|
|
57
123
|
dynamic: true
|
|
58
124
|
};
|
|
59
125
|
}
|
|
60
|
-
// call
|
|
126
|
+
// call (fn())
|
|
61
127
|
if (ts_morph_1.Node.isCallExpression(expr)) {
|
|
62
128
|
return {
|
|
63
129
|
values: [
|
|
64
|
-
expr
|
|
65
|
-
.getExpression()
|
|
66
|
-
.getText()
|
|
130
|
+
expr.getExpression().getText()
|
|
67
131
|
],
|
|
68
132
|
dynamic: true
|
|
69
133
|
};
|
|
@@ -15,11 +15,14 @@ function scanComponentWrappers(source, wrappers) {
|
|
|
15
15
|
.getText()
|
|
16
16
|
.toLowerCase();
|
|
17
17
|
for (const wrapper of wrappers) {
|
|
18
|
-
if (name !==
|
|
19
|
-
wrapper.name.toLowerCase())
|
|
18
|
+
if (name !== wrapper.name.toLowerCase())
|
|
20
19
|
continue;
|
|
21
20
|
const attrs = el.getAttributes();
|
|
22
21
|
for (const attr of attrs) {
|
|
22
|
+
// ❗ NO spread props
|
|
23
|
+
if (ts_morph_1.Node.isJsxSpreadAttribute(attr)) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
23
26
|
const attrNode = attr.asKind(ts_morph_1.SyntaxKind.JsxAttribute);
|
|
24
27
|
if (!attrNode)
|
|
25
28
|
continue;
|
|
@@ -27,20 +30,26 @@ function scanComponentWrappers(source, wrappers) {
|
|
|
27
30
|
.getNameNode()
|
|
28
31
|
.getText()
|
|
29
32
|
.toLowerCase();
|
|
30
|
-
if (key !==
|
|
31
|
-
wrapper.prop.toLowerCase())
|
|
33
|
+
if (key !== wrapper.prop.toLowerCase())
|
|
32
34
|
continue;
|
|
33
35
|
const init = attrNode.getInitializer();
|
|
34
|
-
|
|
36
|
+
// <Button event />
|
|
37
|
+
if (!init) {
|
|
38
|
+
events.add({
|
|
39
|
+
value: key,
|
|
40
|
+
dynamic: true
|
|
41
|
+
});
|
|
35
42
|
continue;
|
|
36
|
-
|
|
43
|
+
}
|
|
44
|
+
// string: <Button event="click" />
|
|
37
45
|
if (ts_morph_1.Node.isStringLiteral(init)) {
|
|
38
46
|
events.add({
|
|
39
47
|
value: init.getLiteralText(),
|
|
40
48
|
dynamic: false
|
|
41
49
|
});
|
|
50
|
+
continue;
|
|
42
51
|
}
|
|
43
|
-
// jsx expression
|
|
52
|
+
// jsx expression: <Button event={"click"} />
|
|
44
53
|
if (ts_morph_1.Node.isJsxExpression(init)) {
|
|
45
54
|
const expr = init.getExpression();
|
|
46
55
|
if (!expr)
|
|
@@ -52,6 +61,7 @@ function scanComponentWrappers(source, wrappers) {
|
|
|
52
61
|
value,
|
|
53
62
|
dynamic: result.dynamic
|
|
54
63
|
}));
|
|
64
|
+
continue;
|
|
55
65
|
}
|
|
56
66
|
}
|
|
57
67
|
}
|
package/package.json
CHANGED
package/src/utils/config.ts
CHANGED
package/src/utils/extract.ts
CHANGED
|
@@ -27,59 +27,133 @@ export function extractExpression(
|
|
|
27
27
|
) {
|
|
28
28
|
return {
|
|
29
29
|
values: [
|
|
30
|
-
expr
|
|
31
|
-
.getText()
|
|
32
|
-
.replace(/`/g, "")
|
|
30
|
+
expr.getText().replace(/`/g, "")
|
|
33
31
|
],
|
|
34
32
|
dynamic: false
|
|
35
33
|
};
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
// identifier
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
// identifier (TEST)
|
|
37
|
+
if (Node.isIdentifier(expr)) {
|
|
38
|
+
const name = expr.getText();
|
|
39
|
+
|
|
40
|
+
const defs =
|
|
41
|
+
"getDefinitions" in expr
|
|
42
|
+
? (expr as any).getDefinitions()
|
|
43
|
+
: [];
|
|
44
|
+
|
|
45
|
+
if (defs && defs.length > 0) {
|
|
46
|
+
const decl = defs[0]?.getDeclarationNode();
|
|
47
|
+
|
|
48
|
+
if (decl && Node.isVariableDeclaration(decl)) {
|
|
49
|
+
const initializer = decl.getInitializer();
|
|
50
|
+
|
|
51
|
+
// const TEST = "event"
|
|
52
|
+
if (
|
|
53
|
+
initializer &&
|
|
54
|
+
Node.isStringLiteral(initializer)
|
|
55
|
+
) {
|
|
56
|
+
return {
|
|
57
|
+
values: [initializer.getLiteralText()],
|
|
58
|
+
dynamic: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// const TEST = `event`
|
|
63
|
+
if (
|
|
64
|
+
initializer &&
|
|
65
|
+
initializer.getKind() ===
|
|
66
|
+
SyntaxKind.NoSubstitutionTemplateLiteral
|
|
67
|
+
) {
|
|
68
|
+
return {
|
|
69
|
+
values: [
|
|
70
|
+
initializer.getText().replace(/`/g, "")
|
|
71
|
+
],
|
|
72
|
+
dynamic: false
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
42
78
|
return {
|
|
43
|
-
values: [
|
|
79
|
+
values: [name],
|
|
44
80
|
dynamic: true
|
|
45
81
|
};
|
|
46
82
|
}
|
|
47
83
|
|
|
48
|
-
// property access (
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
84
|
+
// property access (EVENTS.CLICK)
|
|
85
|
+
if (Node.isPropertyAccessExpression(expr)) {
|
|
86
|
+
const fullName = expr.getText(); // EVENTS.CLICK
|
|
87
|
+
const propName = expr.getName(); // CLICK
|
|
88
|
+
|
|
89
|
+
const defs =
|
|
90
|
+
"getDefinitions" in expr
|
|
91
|
+
? (expr as any).getDefinitions()
|
|
92
|
+
: [];
|
|
93
|
+
|
|
94
|
+
if (defs && defs.length > 0) {
|
|
95
|
+
const decl = defs[0]?.getDeclarationNode();
|
|
96
|
+
|
|
97
|
+
// const EVENTS = { CLICK: "event" }
|
|
98
|
+
if (decl && Node.isVariableDeclaration(decl)) {
|
|
99
|
+
const init = decl.getInitializer();
|
|
100
|
+
|
|
101
|
+
if (init && Node.isObjectLiteralExpression(init)) {
|
|
102
|
+
const prop = init.getProperty(propName);
|
|
103
|
+
|
|
104
|
+
if (
|
|
105
|
+
prop &&
|
|
106
|
+
Node.isPropertyAssignment(prop)
|
|
107
|
+
) {
|
|
108
|
+
const value = prop.getInitializer();
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
value &&
|
|
112
|
+
Node.isStringLiteral(value)
|
|
113
|
+
) {
|
|
114
|
+
return {
|
|
115
|
+
values: [value.getLiteralText()],
|
|
116
|
+
dynamic: false
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// fallback
|
|
124
|
+
if (decl && Node.isPropertyAssignment(decl)) {
|
|
125
|
+
const initializer = decl.getInitializer();
|
|
126
|
+
|
|
127
|
+
if (
|
|
128
|
+
initializer &&
|
|
129
|
+
Node.isStringLiteral(initializer)
|
|
130
|
+
) {
|
|
131
|
+
return {
|
|
132
|
+
values: [initializer.getLiteralText()],
|
|
133
|
+
dynamic: false
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
52
139
|
return {
|
|
53
|
-
values: [
|
|
140
|
+
values: [fullName],
|
|
54
141
|
dynamic: true
|
|
55
142
|
};
|
|
56
143
|
}
|
|
57
144
|
|
|
58
|
-
// ternary
|
|
59
|
-
if (
|
|
60
|
-
Node.isConditionalExpression(expr)
|
|
61
|
-
) {
|
|
145
|
+
// ternary (a ? b : c)
|
|
146
|
+
if (Node.isConditionalExpression(expr)) {
|
|
62
147
|
const values: string[] = [];
|
|
63
148
|
|
|
64
149
|
const whenTrue =
|
|
65
|
-
extractExpression(
|
|
66
|
-
expr.getWhenTrue()
|
|
67
|
-
);
|
|
150
|
+
extractExpression(expr.getWhenTrue());
|
|
68
151
|
|
|
69
152
|
const whenFalse =
|
|
70
|
-
extractExpression(
|
|
71
|
-
expr.getWhenFalse()
|
|
72
|
-
);
|
|
153
|
+
extractExpression(expr.getWhenFalse());
|
|
73
154
|
|
|
74
|
-
if (whenTrue)
|
|
75
|
-
|
|
76
|
-
...whenTrue.values
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (whenFalse)
|
|
80
|
-
values.push(
|
|
81
|
-
...whenFalse.values
|
|
82
|
-
);
|
|
155
|
+
if (whenTrue) values.push(...whenTrue.values);
|
|
156
|
+
if (whenFalse) values.push(...whenFalse.values);
|
|
83
157
|
|
|
84
158
|
return {
|
|
85
159
|
values,
|
|
@@ -87,25 +161,21 @@ export function extractExpression(
|
|
|
87
161
|
};
|
|
88
162
|
}
|
|
89
163
|
|
|
90
|
-
// template
|
|
91
|
-
if (
|
|
92
|
-
Node.isTemplateExpression(expr)
|
|
93
|
-
) {
|
|
164
|
+
// template `${}`
|
|
165
|
+
if (Node.isTemplateExpression(expr)) {
|
|
94
166
|
return {
|
|
95
|
-
values: [
|
|
167
|
+
values: [
|
|
168
|
+
expr.getText().replace(/`/g, "")
|
|
169
|
+
],
|
|
96
170
|
dynamic: true
|
|
97
171
|
};
|
|
98
172
|
}
|
|
99
173
|
|
|
100
|
-
// call
|
|
101
|
-
if (
|
|
102
|
-
Node.isCallExpression(expr)
|
|
103
|
-
) {
|
|
174
|
+
// call (fn())
|
|
175
|
+
if (Node.isCallExpression(expr)) {
|
|
104
176
|
return {
|
|
105
177
|
values: [
|
|
106
|
-
expr
|
|
107
|
-
.getExpression()
|
|
108
|
-
.getText()
|
|
178
|
+
expr.getExpression().getText()
|
|
109
179
|
],
|
|
110
180
|
dynamic: true
|
|
111
181
|
};
|
|
@@ -15,8 +15,7 @@ export function scanComponentWrappers(
|
|
|
15
15
|
source: SourceFile,
|
|
16
16
|
wrappers: ComponentWrapper[]
|
|
17
17
|
) {
|
|
18
|
-
const events =
|
|
19
|
-
new Set<ExtractedEvent>();
|
|
18
|
+
const events = new Set<ExtractedEvent>();
|
|
20
19
|
|
|
21
20
|
const elements = [
|
|
22
21
|
...source.getDescendantsOfKind(
|
|
@@ -34,20 +33,20 @@ export function scanComponentWrappers(
|
|
|
34
33
|
.toLowerCase();
|
|
35
34
|
|
|
36
35
|
for (const wrapper of wrappers) {
|
|
37
|
-
if (
|
|
38
|
-
name !==
|
|
39
|
-
wrapper.name.toLowerCase()
|
|
40
|
-
)
|
|
36
|
+
if (name !== wrapper.name.toLowerCase())
|
|
41
37
|
continue;
|
|
42
38
|
|
|
43
|
-
const attrs =
|
|
44
|
-
el.getAttributes();
|
|
39
|
+
const attrs = el.getAttributes();
|
|
45
40
|
|
|
46
41
|
for (const attr of attrs) {
|
|
42
|
+
|
|
43
|
+
// ❗ NO spread props
|
|
44
|
+
if (Node.isJsxSpreadAttribute(attr)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
47
48
|
const attrNode =
|
|
48
|
-
attr.asKind(
|
|
49
|
-
SyntaxKind.JsxAttribute
|
|
50
|
-
);
|
|
49
|
+
attr.asKind(SyntaxKind.JsxAttribute);
|
|
51
50
|
|
|
52
51
|
if (!attrNode) continue;
|
|
53
52
|
|
|
@@ -57,34 +56,32 @@ export function scanComponentWrappers(
|
|
|
57
56
|
.getText()
|
|
58
57
|
.toLowerCase();
|
|
59
58
|
|
|
60
|
-
if (
|
|
61
|
-
key !==
|
|
62
|
-
wrapper.prop.toLowerCase()
|
|
63
|
-
)
|
|
59
|
+
if (key !== wrapper.prop.toLowerCase())
|
|
64
60
|
continue;
|
|
65
61
|
|
|
66
|
-
const init =
|
|
67
|
-
attrNode.getInitializer();
|
|
62
|
+
const init = attrNode.getInitializer();
|
|
68
63
|
|
|
69
|
-
|
|
64
|
+
// <Button event />
|
|
65
|
+
if (!init) {
|
|
66
|
+
events.add({
|
|
67
|
+
value: key,
|
|
68
|
+
dynamic: true
|
|
69
|
+
});
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
70
72
|
|
|
71
|
-
// string
|
|
72
|
-
if (
|
|
73
|
-
Node.isStringLiteral(init)
|
|
74
|
-
) {
|
|
73
|
+
// string: <Button event="click" />
|
|
74
|
+
if (Node.isStringLiteral(init)) {
|
|
75
75
|
events.add({
|
|
76
|
-
value:
|
|
77
|
-
init.getLiteralText(),
|
|
76
|
+
value: init.getLiteralText(),
|
|
78
77
|
dynamic: false
|
|
79
78
|
});
|
|
79
|
+
continue;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// jsx expression
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
) {
|
|
86
|
-
const expr =
|
|
87
|
-
init.getExpression();
|
|
82
|
+
// jsx expression: <Button event={"click"} />
|
|
83
|
+
if (Node.isJsxExpression(init)) {
|
|
84
|
+
const expr = init.getExpression();
|
|
88
85
|
|
|
89
86
|
if (!expr) continue;
|
|
90
87
|
|
|
@@ -93,14 +90,14 @@ export function scanComponentWrappers(
|
|
|
93
90
|
|
|
94
91
|
if (!result) continue;
|
|
95
92
|
|
|
96
|
-
result.values.forEach(
|
|
97
|
-
(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
result.dynamic
|
|
102
|
-
})
|
|
93
|
+
result.values.forEach((value) =>
|
|
94
|
+
events.add({
|
|
95
|
+
value,
|
|
96
|
+
dynamic: result.dynamic
|
|
97
|
+
})
|
|
103
98
|
);
|
|
99
|
+
|
|
100
|
+
continue;
|
|
104
101
|
}
|
|
105
102
|
}
|
|
106
103
|
}
|