@eventra_dev/eventra-cli 0.0.14 → 0.0.16
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
CHANGED
|
@@ -51,31 +51,41 @@ async function sync() {
|
|
|
51
51
|
];
|
|
52
52
|
for (const event of found) {
|
|
53
53
|
const { value, dynamic } = event;
|
|
54
|
-
|
|
54
|
+
if (!value)
|
|
55
|
+
continue;
|
|
56
|
+
// alias
|
|
55
57
|
if (aliases[value]) {
|
|
58
|
+
console.log(chalk_1.default.gray(`alias: ${value} → ${aliases[value]}`));
|
|
56
59
|
events.add(aliases[value]);
|
|
57
60
|
continue;
|
|
58
61
|
}
|
|
59
|
-
//
|
|
60
|
-
if (dynamic
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
// static
|
|
63
|
+
if (!dynamic) {
|
|
64
|
+
events.add(value);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
// already asked
|
|
68
|
+
if (asked.has(value)) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// ask user
|
|
72
|
+
console.log(chalk_1.default.yellow("\nDynamic event detected:"));
|
|
73
|
+
console.log(chalk_1.default.gray(value));
|
|
74
|
+
const { name } = await inquirer_1.default.prompt([
|
|
75
|
+
{
|
|
76
|
+
type: "input",
|
|
77
|
+
name: "name",
|
|
78
|
+
message: "Enter event name (or type 'skip'):"
|
|
73
79
|
}
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
]);
|
|
81
|
+
const normalized = name?.trim();
|
|
82
|
+
asked.add(value);
|
|
83
|
+
if (!normalized || normalized === "skip") {
|
|
76
84
|
continue;
|
|
77
85
|
}
|
|
78
|
-
|
|
86
|
+
// save alias
|
|
87
|
+
aliases[value] = normalized;
|
|
88
|
+
events.add(normalized);
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
91
|
config.aliases = aliases;
|
|
@@ -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/commands/sync.ts
CHANGED
|
@@ -37,10 +37,8 @@ export async function sync() {
|
|
|
37
37
|
const project = new Project();
|
|
38
38
|
const events = new Set<string>();
|
|
39
39
|
|
|
40
|
-
const aliases =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const asked = new Set<string>()
|
|
40
|
+
const aliases = config.aliases ?? {};
|
|
41
|
+
const asked = new Set<string>();
|
|
44
42
|
|
|
45
43
|
const files = await fg(
|
|
46
44
|
config.sync.include,
|
|
@@ -50,14 +48,12 @@ export async function sync() {
|
|
|
50
48
|
);
|
|
51
49
|
|
|
52
50
|
for (const file of files) {
|
|
53
|
-
const parser =
|
|
54
|
-
detectParser(file);
|
|
51
|
+
const parser = detectParser(file);
|
|
55
52
|
|
|
56
|
-
let content =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
);
|
|
53
|
+
let content = await fs.readFile(
|
|
54
|
+
file,
|
|
55
|
+
"utf-8"
|
|
56
|
+
);
|
|
61
57
|
|
|
62
58
|
if (parser === "vue")
|
|
63
59
|
content = parseVue(content);
|
|
@@ -73,12 +69,11 @@ export async function sync() {
|
|
|
73
69
|
? file
|
|
74
70
|
: file + ".tsx";
|
|
75
71
|
|
|
76
|
-
const source =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
);
|
|
72
|
+
const source = project.createSourceFile(
|
|
73
|
+
virtualFile,
|
|
74
|
+
content,
|
|
75
|
+
{ overwrite: true }
|
|
76
|
+
);
|
|
82
77
|
|
|
83
78
|
const found: ExtractedEvent[] = [
|
|
84
79
|
...scanTrack(source, config),
|
|
@@ -95,58 +90,61 @@ export async function sync() {
|
|
|
95
90
|
for (const event of found) {
|
|
96
91
|
const { value, dynamic } = event;
|
|
97
92
|
|
|
98
|
-
|
|
93
|
+
if (!value) continue;
|
|
94
|
+
|
|
95
|
+
// alias
|
|
99
96
|
if (aliases[value]) {
|
|
100
|
-
|
|
101
|
-
aliases[value]
|
|
97
|
+
console.log(
|
|
98
|
+
chalk.gray(`alias: ${value} → ${aliases[value]}`)
|
|
102
99
|
);
|
|
100
|
+
events.add(aliases[value]);
|
|
103
101
|
continue;
|
|
104
102
|
}
|
|
105
103
|
|
|
106
|
-
//
|
|
107
|
-
if (dynamic
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
)
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
console.log(
|
|
115
|
-
chalk.gray(value)
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const { name } =
|
|
119
|
-
await inquirer.prompt([
|
|
120
|
-
{
|
|
121
|
-
type: "input",
|
|
122
|
-
name: "name",
|
|
123
|
-
message:
|
|
124
|
-
"Enter event name (or type 'skip'):"
|
|
125
|
-
}
|
|
126
|
-
]);
|
|
104
|
+
// static
|
|
105
|
+
if (!dynamic) {
|
|
106
|
+
events.add(value);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
127
109
|
|
|
128
|
-
|
|
110
|
+
// already asked
|
|
111
|
+
if (asked.has(value)) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
129
114
|
|
|
130
|
-
|
|
131
|
-
|
|
115
|
+
// ask user
|
|
116
|
+
console.log(
|
|
117
|
+
chalk.yellow("\nDynamic event detected:")
|
|
118
|
+
);
|
|
119
|
+
console.log(chalk.gray(value));
|
|
120
|
+
|
|
121
|
+
const { name } = await inquirer.prompt([
|
|
122
|
+
{
|
|
123
|
+
type: "input",
|
|
124
|
+
name: "name",
|
|
125
|
+
message:
|
|
126
|
+
"Enter event name (or type 'skip'):"
|
|
132
127
|
}
|
|
128
|
+
]);
|
|
133
129
|
|
|
134
|
-
|
|
130
|
+
const normalized = name?.trim();
|
|
135
131
|
|
|
136
|
-
|
|
132
|
+
asked.add(value);
|
|
137
133
|
|
|
134
|
+
if (!normalized || normalized === "skip") {
|
|
138
135
|
continue;
|
|
139
136
|
}
|
|
140
137
|
|
|
141
|
-
|
|
138
|
+
// save alias
|
|
139
|
+
aliases[value] = normalized;
|
|
140
|
+
|
|
141
|
+
events.add(normalized);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
config.aliases = aliases;
|
|
146
146
|
|
|
147
|
-
const list =
|
|
148
|
-
[...events].sort();
|
|
149
|
-
|
|
147
|
+
const list = [...events].sort();
|
|
150
148
|
config.events = list;
|
|
151
149
|
|
|
152
150
|
await saveConfig(config);
|
|
@@ -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
|
}
|