@eventra_dev/eventra-cli 0.0.4 → 0.0.6

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.
Files changed (40) hide show
  1. package/.github/workflows/release.yml +3 -0
  2. package/README.md +125 -44
  3. package/dist/commands/init.js +4 -1
  4. package/dist/commands/send.js +41 -7
  5. package/dist/commands/sync.js +35 -194
  6. package/dist/index.js +0 -0
  7. package/dist/types.js +2 -0
  8. package/dist/utils/config.js +4 -1
  9. package/dist/utils/extract.js +44 -0
  10. package/dist/utils/parsers/astro.js +6 -0
  11. package/dist/utils/parsers/router.js +12 -0
  12. package/dist/utils/parsers/svelte.js +6 -0
  13. package/dist/utils/parsers/vue.js +18 -0
  14. package/dist/utils/scanners/component-wrappers.js +55 -0
  15. package/dist/utils/scanners/function-wrappers.js +45 -0
  16. package/dist/utils/scanners/track.js +42 -0
  17. package/package.json +6 -4
  18. package/src/commands/init.ts +4 -1
  19. package/src/commands/send.ts +101 -17
  20. package/src/commands/sync.ts +66 -345
  21. package/src/types.ts +20 -0
  22. package/src/utils/config.ts +24 -7
  23. package/src/utils/extract.ts +74 -0
  24. package/src/utils/parsers/astro.ts +5 -0
  25. package/src/utils/parsers/router.ts +14 -0
  26. package/src/utils/parsers/svelte.ts +5 -0
  27. package/src/utils/parsers/vue.ts +25 -0
  28. package/src/utils/scanners/component-wrappers.ts +108 -0
  29. package/src/utils/scanners/function-wrappers.ts +98 -0
  30. package/src/utils/scanners/track.ts +84 -0
  31. package/tests/fixtures/backend/express/app.ts +78 -0
  32. package/tests/fixtures/backend/nest/service.ts +70 -0
  33. package/tests/fixtures/backend/node/index.ts +63 -0
  34. package/tests/fixtures/frontend/next/page.tsx +101 -0
  35. package/tests/fixtures/frontend/react/App.tsx +104 -0
  36. package/tests/fixtures/frontend/vue/App.vue +83 -0
  37. package/tests/fixtures/wrappers/component/test.tsx +62 -0
  38. package/tests/fixtures/wrappers/function/test.ts +60 -0
  39. package/tests/run.ts +120 -0
  40. package/tsconfig.json +2 -0
@@ -0,0 +1,83 @@
1
+ <script setup lang="ts">
2
+ /* eslint-disable */
3
+
4
+ declare function track(event: string): void
5
+ declare function trackFeature(event: string): void
6
+
7
+ declare const analytics: any
8
+
9
+ const eventName = "variable_event"
10
+
11
+ // ===== direct =====
12
+ track("vue_event")
13
+
14
+ // ===== multiline =====
15
+ track(
16
+ "multiline_event"
17
+ )
18
+
19
+ // ===== template string =====
20
+ track(`template_event`)
21
+
22
+ // ===== wrapper function =====
23
+ trackFeature("wrapper_function")
24
+
25
+ // ===== object =====
26
+ analytics.track("object_track")
27
+
28
+ // ===== nested object =====
29
+ analytics.events.track("nested_track")
30
+
31
+ // ===== variable =====
32
+ track(eventName)
33
+
34
+ // ===== conditional =====
35
+ if (true) {
36
+ track("conditional_event")
37
+ }
38
+
39
+ // ===== ternary =====
40
+ true
41
+ ? track("ternary_a")
42
+ : track("ternary_b")
43
+
44
+ // ===== function =====
45
+ function test() {
46
+ track("function_event")
47
+ }
48
+
49
+ // ===== arrow =====
50
+ const run = () => {
51
+ track("arrow_event")
52
+ }
53
+
54
+ // ===== class =====
55
+ class Service {
56
+ run() {
57
+ track("class_event")
58
+ }
59
+ }
60
+ </script>
61
+
62
+ <template>
63
+ <!-- basic -->
64
+ <Button event="vue_button" />
65
+
66
+ <!-- expression -->
67
+ <Button event="expression_event" />
68
+
69
+ <!-- nested -->
70
+ <div>
71
+ <Button event="nested_button" />
72
+ </div>
73
+
74
+ <!-- conditional -->
75
+ <Button
76
+ v-if="true"
77
+ event="conditional_button"
78
+ />
79
+
80
+ <!-- array -->
81
+ <Button event="array_1" />
82
+ <Button event="array_2" />
83
+ </template>
@@ -0,0 +1,62 @@
1
+ /* eslint-disable */
2
+
3
+ declare const Button: any;
4
+ declare const TrackedButton: any;
5
+ declare const MyButton: any;
6
+
7
+ const eventName = "variable_event";
8
+
9
+ export default function WrapperTest() {
10
+ return (
11
+ <>
12
+ {/* basic */}
13
+ <Button event="wrapper_button" />
14
+
15
+ {/* expression */}
16
+ <Button event={"expression_button"} />
17
+
18
+ {/* nested */}
19
+ <div>
20
+ <Button event="nested_button" />
21
+ </div>
22
+
23
+ {/* fragment */}
24
+ <>
25
+ <Button event="fragment_button" />
26
+ </>
27
+
28
+ {/* conditional */}
29
+ {true && (
30
+ <Button event="conditional_button" />
31
+ )}
32
+
33
+ {/* ternary */}
34
+ {true
35
+ ? <Button event="ternary_a_button" />
36
+ : <Button event="ternary_b_button" />
37
+ }
38
+
39
+ {/* array */}
40
+ {[
41
+ <Button key="1" event="array_1" />,
42
+ <Button key="2" event="array_2" />
43
+ ]}
44
+
45
+ {/* wrapper components */}
46
+ <TrackedButton event="tracked_button" />
47
+ <MyButton event="my_button" />
48
+
49
+ {/* multiline */}
50
+ <Button
51
+ event="multiline_button"
52
+ />
53
+
54
+ {/* deep nested */}
55
+ <div>
56
+ <section>
57
+ <Button event="deep_nested" />
58
+ </section>
59
+ </div>
60
+ </>
61
+ );
62
+ }
@@ -0,0 +1,60 @@
1
+ /* eslint-disable */
2
+
3
+ declare function trackFeature(event: string): void;
4
+ declare const analytics: any;
5
+
6
+ const eventName = "variable_event";
7
+
8
+ // ===== basic =====
9
+ trackFeature("wrapper_function");
10
+
11
+ // ===== multiline =====
12
+ trackFeature(
13
+ "multiline_function"
14
+ );
15
+
16
+ // ===== template string =====
17
+ trackFeature(`template_function`);
18
+
19
+ // ===== conditional =====
20
+ if (true) {
21
+ trackFeature("conditional_function");
22
+ }
23
+
24
+ // ===== ternary =====
25
+ true
26
+ ? trackFeature("ternary_a")
27
+ : trackFeature("ternary_b");
28
+
29
+ // ===== variable =====
30
+ trackFeature(eventName);
31
+
32
+ // ===== function =====
33
+ function run() {
34
+ trackFeature("function_event");
35
+ }
36
+
37
+ // ===== arrow =====
38
+ const test = () => {
39
+ trackFeature("arrow_event");
40
+ };
41
+
42
+ // ===== class =====
43
+ class Service {
44
+ run() {
45
+ trackFeature("class_event");
46
+ }
47
+ }
48
+
49
+ // ===== nested function =====
50
+ function outer() {
51
+ function inner() {
52
+ trackFeature("nested_function");
53
+ }
54
+ }
55
+
56
+ // ===== object wrapper =====
57
+ analytics.trackFeature("object_wrapper");
58
+
59
+ // ===== nested object wrapper =====
60
+ analytics.events.trackFeature("nested_object_wrapper");
package/tests/run.ts ADDED
@@ -0,0 +1,120 @@
1
+ import { spawnSync } from "child_process";
2
+ import * as path from "path";
3
+ import * as fs from "fs";
4
+
5
+ const ROOT = path.resolve(__dirname, "..");
6
+ const CLI = path.resolve(ROOT, "dist/index.js");
7
+
8
+ const fixtures = [
9
+ "frontend/react",
10
+ "frontend/vue",
11
+ "frontend/next",
12
+
13
+ "backend/node",
14
+ "backend/express",
15
+ "backend/nest",
16
+
17
+ "wrappers/component",
18
+ "wrappers/function"
19
+ ];
20
+
21
+ function runCLI(args: string[], cwd: string) {
22
+ const result = spawnSync(
23
+ process.execPath,
24
+ [CLI, ...args],
25
+ {
26
+ cwd,
27
+ encoding: "utf-8",
28
+ input: "\n"
29
+ }
30
+ );
31
+
32
+ return (result.stdout ?? "") + (result.stderr ?? "");
33
+ }
34
+
35
+ function ensureTestConfig(dir: string) {
36
+ const configPath = path.join(dir, "eventra.json");
37
+
38
+ if (fs.existsSync(configPath)) return;
39
+
40
+ const config = {
41
+ apiKey: "",
42
+ events: [],
43
+ wrappers: [
44
+ {
45
+ name: "Button",
46
+ prop: "event"
47
+ }
48
+ ],
49
+ functionWrappers: [
50
+ {
51
+ name: "trackFeature",
52
+ path: "0"
53
+ }
54
+ ],
55
+ sync: {
56
+ include: [
57
+ "**/*.{ts,tsx,js,jsx,vue,svelte,astro}"
58
+ ],
59
+ exclude: [
60
+ "node_modules",
61
+ "dist",
62
+ ".next",
63
+ ".git"
64
+ ]
65
+ }
66
+ };
67
+
68
+ fs.writeFileSync(
69
+ configPath,
70
+ JSON.stringify(config, null, 2)
71
+ );
72
+ }
73
+
74
+ function cleanup(dir: string) {
75
+ const configPath = path.join(dir, "eventra.json");
76
+
77
+ if (fs.existsSync(configPath)) {
78
+ fs.unlinkSync(configPath);
79
+ }
80
+ }
81
+
82
+ function runFixture(name: string) {
83
+ const dir = path.resolve(
84
+ __dirname,
85
+ "fixtures",
86
+ name
87
+ );
88
+
89
+ console.log(`\nRunning: ${name}`);
90
+
91
+ ensureTestConfig(dir);
92
+
93
+ runCLI(["init"], dir);
94
+
95
+ const output = runCLI(["sync"], dir);
96
+
97
+ const match =
98
+ output.match(/Found (\d+) events/);
99
+
100
+ const count = match ? match[1] : "0";
101
+
102
+ console.log(
103
+ `✓ ${name} OK (${count} events)`
104
+ );
105
+
106
+ // cleanup
107
+ cleanup(dir);
108
+ }
109
+
110
+ function run() {
111
+ for (const fixture of fixtures) {
112
+ runFixture(fixture);
113
+ }
114
+
115
+ console.log(
116
+ "\nAll fixtures passed"
117
+ );
118
+ }
119
+
120
+ run();
package/tsconfig.json CHANGED
@@ -2,7 +2,9 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
4
  "module": "CommonJS",
5
+ "rootDir": "src",
5
6
  "outDir": "dist",
7
+ "resolveJsonModule": true,
6
8
  "esModuleInterop": true,
7
9
  "strict": true,
8
10
  "skipLibCheck": true,