@eventra_dev/eventra-cli 0.0.5 → 0.0.7
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/.github/workflows/release.yml +3 -0
- package/README.md +2 -0
- package/dist/commands/init.js +80 -13
- package/dist/commands/sync.js +13 -3
- package/dist/utils/config.js +1 -1
- package/dist/utils/extract.js +28 -13
- package/dist/utils/parsers/vue.js +11 -3
- package/dist/utils/scanners/component-wrappers.js +0 -2
- package/dist/utils/scanners/function-wrappers.js +52 -16
- package/package.json +4 -2
- package/src/commands/init.ts +135 -29
- package/src/commands/sync.ts +21 -3
- package/src/types.ts +1 -1
- package/src/utils/config.ts +1 -1
- package/src/utils/extract.ts +43 -20
- package/src/utils/parsers/vue.ts +9 -3
- package/src/utils/scanners/component-wrappers.ts +0 -2
- package/src/utils/scanners/function-wrappers.ts +104 -31
- package/tests/fixtures/backend/express/app.ts +78 -0
- package/tests/fixtures/backend/nest/service.ts +70 -0
- package/tests/fixtures/backend/node/index.ts +63 -0
- package/tests/fixtures/frontend/next/page.tsx +101 -0
- package/tests/fixtures/frontend/react/App.tsx +104 -0
- package/tests/fixtures/frontend/vue/App.vue +83 -0
- package/tests/fixtures/wrappers/component/test.tsx +62 -0
- package/tests/fixtures/wrappers/function/test.ts +60 -0
- package/tests/run.ts +120 -0
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
[](https://www.npmjs.com/package/@eventra_dev/eventra-cli)
|
|
8
8
|
[](https://www.npmjs.com/package/@eventra_dev/eventra-cli)
|
|
9
9
|
[](https://www.typescriptlang.org/)
|
|
10
|
+
[]()
|
|
11
|
+
[]()
|
|
10
12
|
|
|
11
13
|
Eventra CLI automatically discovers feature usage events in your codebase and syncs them with Eventra.
|
|
12
14
|
|
package/dist/commands/init.js
CHANGED
|
@@ -5,31 +5,97 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
8
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
11
9
|
const config_1 = require("../utils/config");
|
|
12
10
|
async function init() {
|
|
13
11
|
console.log(chalk_1.default.blue("Initializing Eventra..."));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
console.log(chalk_1.default.yellow("eventra.json already exists"));
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const answers = await inquirer_1.default.prompt([
|
|
12
|
+
// API KEY
|
|
13
|
+
const { apiKey } = await inquirer_1.default.prompt([
|
|
20
14
|
{
|
|
21
15
|
type: "input",
|
|
22
16
|
name: "apiKey",
|
|
23
17
|
message: "API Key (optional):"
|
|
24
18
|
}
|
|
25
19
|
]);
|
|
20
|
+
console.log(chalk_1.default.gray("\nEventra automatically detects:"));
|
|
21
|
+
console.log(chalk_1.default.gray("• track('event')"));
|
|
22
|
+
console.log(chalk_1.default.gray("• tracker.track('event')"));
|
|
23
|
+
const wrappers = [];
|
|
24
|
+
const functionWrappers = [];
|
|
25
|
+
// COMPONENT WRAPPERS
|
|
26
|
+
console.log(chalk_1.default.blue("\nComponent wrappers"));
|
|
27
|
+
let addComponent = true;
|
|
28
|
+
while (addComponent) {
|
|
29
|
+
const { useWrapper } = await inquirer_1.default.prompt([
|
|
30
|
+
{
|
|
31
|
+
type: "confirm",
|
|
32
|
+
name: "useWrapper",
|
|
33
|
+
message: "Add component wrapper?",
|
|
34
|
+
default: false
|
|
35
|
+
}
|
|
36
|
+
]);
|
|
37
|
+
if (!useWrapper)
|
|
38
|
+
break;
|
|
39
|
+
const { name, prop } = await inquirer_1.default.prompt([
|
|
40
|
+
{
|
|
41
|
+
type: "input",
|
|
42
|
+
name: "name",
|
|
43
|
+
message: "Component name:",
|
|
44
|
+
validate: (v) => v ? true : "Required"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: "input",
|
|
48
|
+
name: "prop",
|
|
49
|
+
message: "Event prop:",
|
|
50
|
+
default: "event"
|
|
51
|
+
}
|
|
52
|
+
]);
|
|
53
|
+
wrappers.push({
|
|
54
|
+
name,
|
|
55
|
+
prop
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// FUNCTION WRAPPERS
|
|
59
|
+
console.log(chalk_1.default.blue("\nFunction wrappers"));
|
|
60
|
+
let addFunction = true;
|
|
61
|
+
while (addFunction) {
|
|
62
|
+
const { useWrapper } = await inquirer_1.default.prompt([
|
|
63
|
+
{
|
|
64
|
+
type: "confirm",
|
|
65
|
+
name: "useWrapper",
|
|
66
|
+
message: "Add function wrapper?",
|
|
67
|
+
default: false
|
|
68
|
+
}
|
|
69
|
+
]);
|
|
70
|
+
if (!useWrapper)
|
|
71
|
+
break;
|
|
72
|
+
const { name, event } = await inquirer_1.default.prompt([
|
|
73
|
+
{
|
|
74
|
+
type: "input",
|
|
75
|
+
name: "name",
|
|
76
|
+
message: "Function name:"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: "input",
|
|
80
|
+
name: "event",
|
|
81
|
+
message: "Event field (leave empty if string argument):",
|
|
82
|
+
default: ""
|
|
83
|
+
}
|
|
84
|
+
]);
|
|
85
|
+
functionWrappers.push({
|
|
86
|
+
name,
|
|
87
|
+
event: event || undefined
|
|
88
|
+
});
|
|
89
|
+
}
|
|
26
90
|
const config = {
|
|
27
|
-
apiKey
|
|
91
|
+
apiKey,
|
|
28
92
|
events: [],
|
|
29
|
-
wrappers
|
|
30
|
-
functionWrappers
|
|
93
|
+
wrappers,
|
|
94
|
+
functionWrappers,
|
|
31
95
|
sync: {
|
|
32
|
-
include: [
|
|
96
|
+
include: [
|
|
97
|
+
"**/*.{ts,tsx,js,jsx,vue,svelte,astro}"
|
|
98
|
+
],
|
|
33
99
|
exclude: [
|
|
34
100
|
"node_modules",
|
|
35
101
|
"dist",
|
|
@@ -39,5 +105,6 @@ async function init() {
|
|
|
39
105
|
}
|
|
40
106
|
};
|
|
41
107
|
await (0, config_1.saveConfig)(config);
|
|
42
|
-
console.log(chalk_1.default.green("
|
|
108
|
+
console.log(chalk_1.default.green("\neventra.json created"));
|
|
109
|
+
console.log(chalk_1.default.gray("\nRun `eventra sync`"));
|
|
43
110
|
}
|
package/dist/commands/sync.js
CHANGED
|
@@ -28,6 +28,13 @@ async function sync() {
|
|
|
28
28
|
const files = await (0, fast_glob_1.default)(config.sync.include, {
|
|
29
29
|
ignore: config.sync.exclude
|
|
30
30
|
});
|
|
31
|
+
const functionWrappers = (config.functionWrappers ?? []).map((w) => ({
|
|
32
|
+
name: w.name,
|
|
33
|
+
path: w.event
|
|
34
|
+
? `0.${w.event}`
|
|
35
|
+
: "0"
|
|
36
|
+
}));
|
|
37
|
+
const componentWrappers = config.wrappers ?? [];
|
|
31
38
|
for (const file of files) {
|
|
32
39
|
const parser = (0, router_1.detectParser)(file);
|
|
33
40
|
let content = await promises_1.default.readFile(file, "utf-8");
|
|
@@ -37,10 +44,13 @@ async function sync() {
|
|
|
37
44
|
content = (0, svelte_1.parseSvelte)(content);
|
|
38
45
|
if (parser === "astro")
|
|
39
46
|
content = (0, astro_1.parseAstro)(content);
|
|
40
|
-
const
|
|
47
|
+
const virtualFile = parser === "ts"
|
|
48
|
+
? file
|
|
49
|
+
: file + ".tsx";
|
|
50
|
+
const source = project.createSourceFile(virtualFile, content, { overwrite: true });
|
|
41
51
|
(0, track_1.scanTrack)(source).forEach((e) => events.add(e));
|
|
42
|
-
(0, function_wrappers_1.scanFunctionWrappers)(source,
|
|
43
|
-
(0, component_wrappers_1.scanComponentWrappers)(source,
|
|
52
|
+
(0, function_wrappers_1.scanFunctionWrappers)(source, functionWrappers).forEach((e) => events.add(e));
|
|
53
|
+
(0, component_wrappers_1.scanComponentWrappers)(source, componentWrappers).forEach((e) => events.add(e));
|
|
44
54
|
}
|
|
45
55
|
const list = [...events].sort();
|
|
46
56
|
config.events = list;
|
package/dist/utils/config.js
CHANGED
package/dist/utils/extract.js
CHANGED
|
@@ -7,23 +7,38 @@ function extractEvent(call, path) {
|
|
|
7
7
|
let node = call.getArguments()[Number(parts[0])];
|
|
8
8
|
if (!node)
|
|
9
9
|
return null;
|
|
10
|
+
node = unwrap(node);
|
|
10
11
|
for (let i = 1; i < parts.length; i++) {
|
|
11
|
-
if (ts_morph_1.Node.isObjectLiteralExpression(node)) {
|
|
12
|
-
|
|
13
|
-
const prop = obj.getProperty(parts[i]);
|
|
14
|
-
if (!prop)
|
|
15
|
-
return null;
|
|
16
|
-
if (ts_morph_1.Node.isPropertyAssignment(prop)) {
|
|
17
|
-
const initializer = prop.getInitializer();
|
|
18
|
-
if (!initializer)
|
|
19
|
-
return null;
|
|
20
|
-
node = initializer;
|
|
21
|
-
}
|
|
12
|
+
if (!ts_morph_1.Node.isObjectLiteralExpression(node)) {
|
|
13
|
+
return null;
|
|
22
14
|
}
|
|
15
|
+
const obj = node;
|
|
16
|
+
const prop = obj.getProperty(parts[i]);
|
|
17
|
+
if (!prop)
|
|
18
|
+
return null;
|
|
19
|
+
if (!ts_morph_1.Node.isPropertyAssignment(prop)) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const initializer = prop.getInitializer();
|
|
23
|
+
if (!initializer)
|
|
24
|
+
return null;
|
|
25
|
+
node = unwrap(initializer);
|
|
23
26
|
}
|
|
24
|
-
if (node
|
|
25
|
-
ts_morph_1.Node.isStringLiteral(node)) {
|
|
27
|
+
if (ts_morph_1.Node.isStringLiteral(node)) {
|
|
26
28
|
return node.getLiteralText();
|
|
27
29
|
}
|
|
30
|
+
if (node.getKind() ===
|
|
31
|
+
ts_morph_1.SyntaxKind.NoSubstitutionTemplateLiteral) {
|
|
32
|
+
return node
|
|
33
|
+
.getText()
|
|
34
|
+
.replace(/`/g, "");
|
|
35
|
+
}
|
|
28
36
|
return null;
|
|
29
37
|
}
|
|
38
|
+
function unwrap(node) {
|
|
39
|
+
let current = node;
|
|
40
|
+
while (ts_morph_1.Node.isParenthesizedExpression(current)) {
|
|
41
|
+
current = current.getExpression();
|
|
42
|
+
}
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
@@ -4,7 +4,15 @@ exports.parseVue = parseVue;
|
|
|
4
4
|
function parseVue(content) {
|
|
5
5
|
const template = content.match(/<template[\s\S]*?>([\s\S]*?)<\/template>/);
|
|
6
6
|
const script = content.match(/<script[\s\S]*?>([\s\S]*?)<\/script>/);
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
return `
|
|
8
|
+
${script?.[1] ?? ""}
|
|
9
|
+
|
|
10
|
+
function __vue_template__() {
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
${template?.[1] ?? ""}
|
|
14
|
+
</>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
10
18
|
}
|
|
@@ -32,13 +32,11 @@ function scanComponentWrappers(source, wrappers) {
|
|
|
32
32
|
const init = attrNode.getInitializer();
|
|
33
33
|
if (!init)
|
|
34
34
|
continue;
|
|
35
|
-
// event="signup"
|
|
36
35
|
if (init.getKind() ===
|
|
37
36
|
ts_morph_1.SyntaxKind.StringLiteral) {
|
|
38
37
|
const value = init.asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral);
|
|
39
38
|
events.add(value.getLiteralText());
|
|
40
39
|
}
|
|
41
|
-
// event={"signup"}
|
|
42
40
|
if (init.getKind() ===
|
|
43
41
|
ts_morph_1.SyntaxKind.JsxExpression) {
|
|
44
42
|
const expr = init
|
|
@@ -7,29 +7,65 @@ function scanFunctionWrappers(source, wrappers) {
|
|
|
7
7
|
const events = new Set();
|
|
8
8
|
const calls = source.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
|
|
9
9
|
for (const call of calls) {
|
|
10
|
-
const
|
|
11
|
-
let name = null;
|
|
12
|
-
// trackFeature()
|
|
13
|
-
if (expression.getKind() ===
|
|
14
|
-
ts_morph_1.SyntaxKind.Identifier) {
|
|
15
|
-
name =
|
|
16
|
-
expression.getText();
|
|
17
|
-
}
|
|
18
|
-
// analytics.trackFeature()
|
|
19
|
-
if (expression.getKind() ===
|
|
20
|
-
ts_morph_1.SyntaxKind.PropertyAccessExpression) {
|
|
21
|
-
const prop = expression.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
|
|
22
|
-
name = prop.getName();
|
|
23
|
-
}
|
|
10
|
+
const name = getFunctionName(call);
|
|
24
11
|
if (!name)
|
|
25
12
|
continue;
|
|
26
13
|
for (const wrapper of wrappers) {
|
|
27
|
-
if (name !==
|
|
14
|
+
if (wrapper.name !== name)
|
|
28
15
|
continue;
|
|
29
|
-
const event = (
|
|
16
|
+
const event = extractEventFromArgs(call, wrapper.event);
|
|
30
17
|
if (event)
|
|
31
18
|
events.add(event);
|
|
32
19
|
}
|
|
33
20
|
}
|
|
34
21
|
return events;
|
|
35
22
|
}
|
|
23
|
+
function getFunctionName(call) {
|
|
24
|
+
const expression = call.getExpression();
|
|
25
|
+
// trackFeature()
|
|
26
|
+
if (ts_morph_1.Node.isIdentifier(expression)) {
|
|
27
|
+
return expression.getText();
|
|
28
|
+
}
|
|
29
|
+
// analytics.trackFeature()
|
|
30
|
+
if (ts_morph_1.Node.isPropertyAccessExpression(expression)) {
|
|
31
|
+
return getDeepName(expression);
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function getDeepName(node) {
|
|
36
|
+
let current = node;
|
|
37
|
+
let name = "";
|
|
38
|
+
while (ts_morph_1.Node.isPropertyAccessExpression(current)) {
|
|
39
|
+
name =
|
|
40
|
+
current.getName();
|
|
41
|
+
current =
|
|
42
|
+
current.getExpression();
|
|
43
|
+
}
|
|
44
|
+
return name;
|
|
45
|
+
}
|
|
46
|
+
function extractEventFromArgs(call, event) {
|
|
47
|
+
const args = call.getArguments();
|
|
48
|
+
for (let i = 0; i < args.length; i++) {
|
|
49
|
+
const arg = args[i];
|
|
50
|
+
// string case
|
|
51
|
+
if (!event) {
|
|
52
|
+
if (ts_morph_1.Node.isStringLiteral(arg)) {
|
|
53
|
+
return arg.getLiteralText();
|
|
54
|
+
}
|
|
55
|
+
// template literal
|
|
56
|
+
if (arg.getKind() ===
|
|
57
|
+
ts_morph_1.SyntaxKind.NoSubstitutionTemplateLiteral) {
|
|
58
|
+
return arg
|
|
59
|
+
.getText()
|
|
60
|
+
.replace(/`/g, "");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// object case
|
|
64
|
+
if (event) {
|
|
65
|
+
const result = (0, extract_1.extractEvent)(call, `${i}.${event}`);
|
|
66
|
+
if (result)
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventra_dev/eventra-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Eventra CLI",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc",
|
|
18
|
-
"dev": "tsx src/index.ts"
|
|
18
|
+
"dev": "tsx src/index.ts",
|
|
19
|
+
"test": "tsx tests/run.ts"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"chalk": "^4.1.2",
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"@types/fs-extra": "^11.0.4",
|
|
30
31
|
"@types/inquirer": "^9.0.9",
|
|
31
32
|
"@types/node": "^20.0.0",
|
|
33
|
+
"cross-spawn": "^7.0.6",
|
|
32
34
|
"tsx": "^4.7.0",
|
|
33
35
|
"typescript": "^5.3.0"
|
|
34
36
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -1,47 +1,147 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
-
import fs from "fs-extra";
|
|
3
|
-
import path from "path";
|
|
4
2
|
import inquirer from "inquirer";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "../utils/config";
|
|
3
|
+
|
|
4
|
+
import { saveConfig } from "../utils/config";
|
|
5
|
+
import {ComponentWrapper, FunctionWrapper} from "../types";
|
|
9
6
|
|
|
10
7
|
export async function init() {
|
|
11
8
|
console.log(
|
|
12
9
|
chalk.blue("Initializing Eventra...")
|
|
13
10
|
);
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
// API KEY
|
|
13
|
+
const { apiKey } =
|
|
14
|
+
await inquirer.prompt([
|
|
15
|
+
{
|
|
16
|
+
type: "input",
|
|
17
|
+
name: "apiKey",
|
|
18
|
+
message:
|
|
19
|
+
"API Key (optional):"
|
|
20
|
+
}
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
console.log(
|
|
24
|
+
chalk.gray(
|
|
25
|
+
"\nEventra automatically detects:"
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
console.log(
|
|
30
|
+
chalk.gray("• track('event')")
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
console.log(
|
|
34
|
+
chalk.gray(
|
|
35
|
+
"• tracker.track('event')"
|
|
36
|
+
)
|
|
18
37
|
);
|
|
19
38
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
const wrappers: ComponentWrapper[] = [];
|
|
40
|
+
const functionWrappers: FunctionWrapper[] = [];
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// COMPONENT WRAPPERS
|
|
44
|
+
console.log(
|
|
45
|
+
chalk.blue(
|
|
46
|
+
"\nComponent wrappers"
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
let addComponent = true;
|
|
51
|
+
|
|
52
|
+
while (addComponent) {
|
|
53
|
+
const { useWrapper } =
|
|
54
|
+
await inquirer.prompt([
|
|
55
|
+
{
|
|
56
|
+
type: "confirm",
|
|
57
|
+
name: "useWrapper",
|
|
58
|
+
message:
|
|
59
|
+
"Add component wrapper?",
|
|
60
|
+
default: false
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
if (!useWrapper) break;
|
|
65
|
+
|
|
66
|
+
const { name, prop } =
|
|
67
|
+
await inquirer.prompt([
|
|
68
|
+
{
|
|
69
|
+
type: "input",
|
|
70
|
+
name: "name",
|
|
71
|
+
message: "Component name:",
|
|
72
|
+
validate: (v) =>
|
|
73
|
+
v ? true : "Required"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: "input",
|
|
77
|
+
name: "prop",
|
|
78
|
+
message:
|
|
79
|
+
"Event prop:",
|
|
80
|
+
default: "event"
|
|
81
|
+
}
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
wrappers.push({
|
|
85
|
+
name,
|
|
86
|
+
prop
|
|
87
|
+
});
|
|
27
88
|
}
|
|
28
89
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
90
|
+
// FUNCTION WRAPPERS
|
|
91
|
+
console.log(
|
|
92
|
+
chalk.blue(
|
|
93
|
+
"\nFunction wrappers"
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
let addFunction = true;
|
|
98
|
+
|
|
99
|
+
while (addFunction) {
|
|
100
|
+
const { useWrapper } =
|
|
101
|
+
await inquirer.prompt([
|
|
102
|
+
{
|
|
103
|
+
type: "confirm",
|
|
104
|
+
name: "useWrapper",
|
|
105
|
+
message:
|
|
106
|
+
"Add function wrapper?",
|
|
107
|
+
default: false
|
|
108
|
+
}
|
|
109
|
+
]);
|
|
110
|
+
|
|
111
|
+
if (!useWrapper) break;
|
|
112
|
+
|
|
113
|
+
const { name, event } =
|
|
114
|
+
await inquirer.prompt([
|
|
115
|
+
{
|
|
116
|
+
type: "input",
|
|
117
|
+
name: "name",
|
|
118
|
+
message:
|
|
119
|
+
"Function name:"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
type: "input",
|
|
123
|
+
name: "event",
|
|
124
|
+
message:
|
|
125
|
+
"Event field (leave empty if string argument):",
|
|
126
|
+
default: ""
|
|
127
|
+
}
|
|
128
|
+
]);
|
|
129
|
+
|
|
130
|
+
functionWrappers.push({
|
|
131
|
+
name,
|
|
132
|
+
event: event || undefined
|
|
133
|
+
});
|
|
134
|
+
}
|
|
37
135
|
|
|
38
136
|
const config = {
|
|
39
|
-
apiKey
|
|
137
|
+
apiKey,
|
|
40
138
|
events: [],
|
|
41
|
-
wrappers
|
|
42
|
-
functionWrappers
|
|
139
|
+
wrappers,
|
|
140
|
+
functionWrappers,
|
|
43
141
|
sync: {
|
|
44
|
-
include: [
|
|
142
|
+
include: [
|
|
143
|
+
"**/*.{ts,tsx,js,jsx,vue,svelte,astro}"
|
|
144
|
+
],
|
|
45
145
|
exclude: [
|
|
46
146
|
"node_modules",
|
|
47
147
|
"dist",
|
|
@@ -55,7 +155,13 @@ export async function init() {
|
|
|
55
155
|
|
|
56
156
|
console.log(
|
|
57
157
|
chalk.green(
|
|
58
|
-
"
|
|
158
|
+
"\neventra.json created"
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
console.log(
|
|
163
|
+
chalk.gray(
|
|
164
|
+
"\nRun `eventra sync`"
|
|
59
165
|
)
|
|
60
166
|
);
|
|
61
167
|
}
|
package/src/commands/sync.ts
CHANGED
|
@@ -41,6 +41,18 @@ export async function sync() {
|
|
|
41
41
|
}
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
+
const functionWrappers =
|
|
45
|
+
(config.functionWrappers ?? []).map(
|
|
46
|
+
(w) => ({
|
|
47
|
+
name: w.name,
|
|
48
|
+
path: w.event
|
|
49
|
+
? `0.${w.event}`
|
|
50
|
+
: "0"
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
const componentWrappers =
|
|
54
|
+
config.wrappers ?? [];
|
|
55
|
+
|
|
44
56
|
for (const file of files) {
|
|
45
57
|
const parser =
|
|
46
58
|
detectParser(file);
|
|
@@ -60,9 +72,14 @@ export async function sync() {
|
|
|
60
72
|
if (parser === "astro")
|
|
61
73
|
content = parseAstro(content);
|
|
62
74
|
|
|
75
|
+
const virtualFile =
|
|
76
|
+
parser === "ts"
|
|
77
|
+
? file
|
|
78
|
+
: file + ".tsx";
|
|
79
|
+
|
|
63
80
|
const source =
|
|
64
81
|
project.createSourceFile(
|
|
65
|
-
|
|
82
|
+
virtualFile,
|
|
66
83
|
content,
|
|
67
84
|
{ overwrite: true }
|
|
68
85
|
);
|
|
@@ -71,16 +88,17 @@ export async function sync() {
|
|
|
71
88
|
(e) => events.add(e)
|
|
72
89
|
);
|
|
73
90
|
|
|
91
|
+
|
|
74
92
|
scanFunctionWrappers(
|
|
75
93
|
source,
|
|
76
|
-
|
|
94
|
+
functionWrappers
|
|
77
95
|
).forEach((e) =>
|
|
78
96
|
events.add(e)
|
|
79
97
|
);
|
|
80
98
|
|
|
81
99
|
scanComponentWrappers(
|
|
82
100
|
source,
|
|
83
|
-
|
|
101
|
+
componentWrappers
|
|
84
102
|
).forEach((e) =>
|
|
85
103
|
events.add(e)
|
|
86
104
|
);
|
package/src/types.ts
CHANGED