@eventra_dev/eventra-cli 0.1.19 → 0.1.20
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/parsers/astro.js +15 -5
- package/dist/utils/parsers/svelte.js +12 -3
- package/dist/utils/parsers/utils.js +21 -0
- package/dist/utils/parsers/vue.js +10 -2
- package/package.json +1 -1
- package/src/utils/parsers/astro.ts +18 -5
- package/src/utils/parsers/svelte.ts +15 -3
- package/src/utils/parsers/utils.ts +18 -0
- package/src/utils/parsers/vue.ts +11 -2
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseAstro = parseAstro;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
8
9
|
function parseAstro(content, file) {
|
|
9
10
|
const parts = [];
|
|
10
11
|
const deps = [];
|
|
@@ -23,13 +24,22 @@ function parseAstro(content, file) {
|
|
|
23
24
|
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
24
25
|
if (!src)
|
|
25
26
|
continue;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
let resolved;
|
|
28
|
+
if (src.startsWith("/")) {
|
|
29
|
+
resolved = path_1.default.join(process.cwd(), src); // FIX
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
resolved = path_1.default.resolve(path_1.default.dirname(file), src);
|
|
33
|
+
}
|
|
29
34
|
deps.push(resolved);
|
|
35
|
+
continue;
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
parts.push(body);
|
|
38
|
+
const imports = body.matchAll(/import\s+.*?from\s+["'](.+?)["']/g);
|
|
39
|
+
for (const im of imports) {
|
|
40
|
+
const resolved = (0, utils_1.resolveImport)(file, im[1]);
|
|
41
|
+
if (resolved)
|
|
42
|
+
deps.push(resolved);
|
|
33
43
|
}
|
|
34
44
|
}
|
|
35
45
|
return {
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseSvelte = parseSvelte;
|
|
4
|
-
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
function parseSvelte(content, file) {
|
|
5
6
|
const parts = [];
|
|
6
7
|
const deps = [];
|
|
7
8
|
// script
|
|
8
9
|
const scripts = content.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g);
|
|
9
10
|
for (const m of scripts) {
|
|
10
|
-
|
|
11
|
+
const code = m[1];
|
|
12
|
+
parts.push(code);
|
|
13
|
+
// imports
|
|
14
|
+
const imports = code.matchAll(/import\s+.*?from\s+["'](.+?)["']/g);
|
|
15
|
+
for (const im of imports) {
|
|
16
|
+
const resolved = (0, utils_1.resolveImport)(file, im[1]);
|
|
17
|
+
if (resolved)
|
|
18
|
+
deps.push(resolved);
|
|
19
|
+
}
|
|
11
20
|
}
|
|
12
|
-
//
|
|
21
|
+
// handlers
|
|
13
22
|
const handlers = content.matchAll(/on:\w+=\{([^}]+)\}/g);
|
|
14
23
|
for (const h of handlers) {
|
|
15
24
|
parts.push(h[1] + ";");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveImport = resolveImport;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function resolveImport(from, src) {
|
|
10
|
+
if (!src.startsWith("."))
|
|
11
|
+
return null;
|
|
12
|
+
const base = path_1.default.resolve(path_1.default.dirname(from), src);
|
|
13
|
+
const exts = [".ts", ".tsx", ".js", ".jsx"];
|
|
14
|
+
for (const ext of exts) {
|
|
15
|
+
if (fs_1.default.existsSync(base + ext))
|
|
16
|
+
return base + ext;
|
|
17
|
+
}
|
|
18
|
+
if (fs_1.default.existsSync(base))
|
|
19
|
+
return base;
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseVue = parseVue;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
8
9
|
function parseVue(content, file) {
|
|
9
10
|
const parts = [];
|
|
10
11
|
const deps = [];
|
|
@@ -18,12 +19,19 @@ function parseVue(content, file) {
|
|
|
18
19
|
if (!src)
|
|
19
20
|
continue;
|
|
20
21
|
const resolved = src.startsWith("/")
|
|
21
|
-
? path_1.default.
|
|
22
|
+
? path_1.default.join(process.cwd(), src)
|
|
22
23
|
: path_1.default.resolve(path_1.default.dirname(file), src);
|
|
23
24
|
deps.push(resolved);
|
|
24
25
|
continue;
|
|
25
26
|
}
|
|
26
27
|
parts.push(body);
|
|
28
|
+
// imports
|
|
29
|
+
const imports = body.matchAll(/import\s+.*?from\s+["'](.+?)["']/g);
|
|
30
|
+
for (const im of imports) {
|
|
31
|
+
const resolved = (0, utils_1.resolveImport)(file, im[1]);
|
|
32
|
+
if (resolved)
|
|
33
|
+
deps.push(resolved);
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
// TEMPLATE
|
|
29
37
|
const templateMatch = content.match(/<template[^>]*>([\s\S]*?)<\/template>/);
|
|
@@ -39,7 +47,7 @@ function parseVue(content, file) {
|
|
|
39
47
|
for (const v of vOn) {
|
|
40
48
|
parts.push(v[1] + ";");
|
|
41
49
|
}
|
|
42
|
-
// :
|
|
50
|
+
// :bind
|
|
43
51
|
const binds = template.matchAll(/:[\w-]+="([^"]+)"/g);
|
|
44
52
|
for (const b of binds) {
|
|
45
53
|
parts.push(b[1] + ";");
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { ParseResult } from "../../types";
|
|
3
|
+
import { resolveImport } from "./utils";
|
|
3
4
|
|
|
4
5
|
export function parseAstro(content: string, file: string): ParseResult {
|
|
5
6
|
const parts: string[] = [];
|
|
@@ -23,13 +24,25 @@ export function parseAstro(content: string, file: string): ParseResult {
|
|
|
23
24
|
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
24
25
|
if (!src) continue;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
let resolved: string;
|
|
28
|
+
|
|
29
|
+
if (src.startsWith("/")) {
|
|
30
|
+
resolved = path.join(process.cwd(), src); // FIX
|
|
31
|
+
} else {
|
|
32
|
+
resolved = path.resolve(path.dirname(file), src);
|
|
33
|
+
}
|
|
29
34
|
|
|
30
35
|
deps.push(resolved);
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
parts.push(body);
|
|
40
|
+
|
|
41
|
+
const imports = body.matchAll(/import\s+.*?from\s+["'](.+?)["']/g);
|
|
42
|
+
|
|
43
|
+
for (const im of imports) {
|
|
44
|
+
const resolved = resolveImport(file, im[1]);
|
|
45
|
+
if (resolved) deps.push(resolved);
|
|
33
46
|
}
|
|
34
47
|
}
|
|
35
48
|
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { ParseResult } from "../../types";
|
|
2
|
+
import { resolveImport } from "./utils";
|
|
2
3
|
|
|
3
|
-
export function parseSvelte(content: string): ParseResult {
|
|
4
|
+
export function parseSvelte(content: string, file: string): ParseResult {
|
|
4
5
|
const parts: string[] = [];
|
|
5
6
|
const deps: string[] = [];
|
|
6
7
|
|
|
7
8
|
// script
|
|
8
9
|
const scripts = content.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g);
|
|
10
|
+
|
|
9
11
|
for (const m of scripts) {
|
|
10
|
-
|
|
12
|
+
const code = m[1];
|
|
13
|
+
|
|
14
|
+
parts.push(code);
|
|
15
|
+
|
|
16
|
+
// imports
|
|
17
|
+
const imports = code.matchAll(/import\s+.*?from\s+["'](.+?)["']/g);
|
|
18
|
+
|
|
19
|
+
for (const im of imports) {
|
|
20
|
+
const resolved = resolveImport(file, im[1]);
|
|
21
|
+
if (resolved) deps.push(resolved);
|
|
22
|
+
}
|
|
11
23
|
}
|
|
12
24
|
|
|
13
|
-
//
|
|
25
|
+
// handlers
|
|
14
26
|
const handlers = content.matchAll(/on:\w+=\{([^}]+)\}/g);
|
|
15
27
|
|
|
16
28
|
for (const h of handlers) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export function resolveImport(from: string, src: string): string | null {
|
|
5
|
+
if (!src.startsWith(".")) return null;
|
|
6
|
+
|
|
7
|
+
const base = path.resolve(path.dirname(from), src);
|
|
8
|
+
|
|
9
|
+
const exts = [".ts", ".tsx", ".js", ".jsx"];
|
|
10
|
+
|
|
11
|
+
for (const ext of exts) {
|
|
12
|
+
if (fs.existsSync(base + ext)) return base + ext;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (fs.existsSync(base)) return base;
|
|
16
|
+
|
|
17
|
+
return null;
|
|
18
|
+
}
|
package/src/utils/parsers/vue.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { ParseResult } from "../../types";
|
|
3
|
+
import { resolveImport } from "./utils";
|
|
3
4
|
|
|
4
5
|
export function parseVue(content: string, file: string): ParseResult {
|
|
5
6
|
const parts: string[] = [];
|
|
@@ -17,7 +18,7 @@ export function parseVue(content: string, file: string): ParseResult {
|
|
|
17
18
|
if (!src) continue;
|
|
18
19
|
|
|
19
20
|
const resolved = src.startsWith("/")
|
|
20
|
-
? path.
|
|
21
|
+
? path.join(process.cwd(), src)
|
|
21
22
|
: path.resolve(path.dirname(file), src);
|
|
22
23
|
|
|
23
24
|
deps.push(resolved);
|
|
@@ -25,6 +26,14 @@ export function parseVue(content: string, file: string): ParseResult {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
parts.push(body);
|
|
29
|
+
|
|
30
|
+
// imports
|
|
31
|
+
const imports = body.matchAll(/import\s+.*?from\s+["'](.+?)["']/g);
|
|
32
|
+
|
|
33
|
+
for (const im of imports) {
|
|
34
|
+
const resolved = resolveImport(file, im[1]);
|
|
35
|
+
if (resolved) deps.push(resolved);
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
|
|
30
39
|
// TEMPLATE
|
|
@@ -45,7 +54,7 @@ export function parseVue(content: string, file: string): ParseResult {
|
|
|
45
54
|
parts.push(v[1] + ";");
|
|
46
55
|
}
|
|
47
56
|
|
|
48
|
-
// :
|
|
57
|
+
// :bind
|
|
49
58
|
const binds = template.matchAll(/:[\w-]+="([^"]+)"/g);
|
|
50
59
|
for (const b of binds) {
|
|
51
60
|
parts.push(b[1] + ";");
|