@eventra_dev/eventra-cli 0.1.18 → 0.1.19
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/check.js +9 -4
- package/dist/commands/sync.js +12 -4
- package/dist/commands/watch.js +10 -1
- package/dist/utils/parsers/astro.js +8 -2
- package/dist/utils/parsers/router.js +4 -1
- package/dist/utils/parsers/svelte.js +13 -23
- package/dist/utils/parsers/vue.js +18 -8
- package/dist/utils/processFile.js +11 -11
- package/package.json +1 -1
- package/src/commands/check.ts +15 -5
- package/src/commands/sync.ts +21 -4
- package/src/commands/watch.ts +17 -1
- package/src/types.ts +7 -1
- package/src/utils/parsers/astro.ts +10 -3
- package/src/utils/parsers/router.ts +4 -1
- package/src/utils/parsers/svelte.ts +15 -24
- package/src/utils/parsers/vue.ts +21 -9
- package/src/utils/processFile.ts +11 -9
package/dist/commands/check.js
CHANGED
|
@@ -24,14 +24,19 @@ async function check({ fix = false }) {
|
|
|
24
24
|
for (const file of files) {
|
|
25
25
|
try {
|
|
26
26
|
const raw = await promises_1.default.readFile(file, "utf-8");
|
|
27
|
-
const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
|
|
27
|
+
const { content, virtualFile, deps } = (0, processFile_1.processFile)(file, raw);
|
|
28
28
|
engine.scanFile(virtualFile, content, config);
|
|
29
|
+
for (const dep of deps) {
|
|
30
|
+
try {
|
|
31
|
+
const depRaw = await promises_1.default.readFile(dep, "utf-8");
|
|
32
|
+
const { content: depContent, virtualFile: depVirtual, } = (0, processFile_1.processFile)(dep, depRaw);
|
|
33
|
+
engine.scanFile(depVirtual, depContent, config);
|
|
34
|
+
}
|
|
35
|
+
catch { }
|
|
36
|
+
}
|
|
29
37
|
}
|
|
30
38
|
catch (err) {
|
|
31
39
|
console.log(chalk_1.default.yellow(`Skipped: ${file}`));
|
|
32
|
-
if (err instanceof Error) {
|
|
33
|
-
console.log(chalk_1.default.gray(err.message));
|
|
34
|
-
}
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
const found = new Set(engine.getAllEvents());
|
package/dist/commands/sync.js
CHANGED
|
@@ -29,13 +29,21 @@ async function sync() {
|
|
|
29
29
|
for (const file of files) {
|
|
30
30
|
try {
|
|
31
31
|
const raw = await promises_1.default.readFile(file, "utf-8");
|
|
32
|
-
const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
|
|
32
|
+
const { content, virtualFile, deps } = (0, processFile_1.processFile)(file, raw);
|
|
33
33
|
engine["ts"].updateFile(virtualFile, content);
|
|
34
34
|
fileCache.push({ file: virtualFile, content });
|
|
35
|
+
// deps
|
|
36
|
+
for (const dep of deps) {
|
|
37
|
+
try {
|
|
38
|
+
const depRaw = await promises_1.default.readFile(dep, "utf-8");
|
|
39
|
+
const { content: depContent, virtualFile: depVirtual, } = (0, processFile_1.processFile)(dep, depRaw);
|
|
40
|
+
engine["ts"].updateFile(depVirtual, depContent);
|
|
41
|
+
fileCache.push({ file: depVirtual, content: depContent });
|
|
42
|
+
}
|
|
43
|
+
catch { }
|
|
44
|
+
}
|
|
35
45
|
}
|
|
36
|
-
catch {
|
|
37
|
-
// ignore
|
|
38
|
-
}
|
|
46
|
+
catch { }
|
|
39
47
|
}
|
|
40
48
|
for (const { file, content } of fileCache) {
|
|
41
49
|
try {
|
package/dist/commands/watch.js
CHANGED
|
@@ -53,8 +53,17 @@ async function watch() {
|
|
|
53
53
|
for (const file of batch) {
|
|
54
54
|
try {
|
|
55
55
|
const raw = await promises_1.default.readFile(file, "utf-8");
|
|
56
|
-
const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
|
|
56
|
+
const { content, virtualFile, deps } = (0, processFile_1.processFile)(file, raw);
|
|
57
57
|
engine.updateFile(virtualFile, content, config);
|
|
58
|
+
// deps
|
|
59
|
+
for (const dep of deps) {
|
|
60
|
+
try {
|
|
61
|
+
const depRaw = await promises_1.default.readFile(dep, "utf-8");
|
|
62
|
+
const { content: depContent, virtualFile: depVirtual, } = (0, processFile_1.processFile)(dep, depRaw);
|
|
63
|
+
engine.updateFile(depVirtual, depContent, config);
|
|
64
|
+
}
|
|
65
|
+
catch { }
|
|
66
|
+
}
|
|
58
67
|
}
|
|
59
68
|
catch {
|
|
60
69
|
console.log(chalk_1.default.gray(`skip: ${file}`));
|
|
@@ -7,15 +7,18 @@ exports.parseAstro = parseAstro;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
function parseAstro(content, file) {
|
|
9
9
|
const parts = [];
|
|
10
|
+
const deps = [];
|
|
10
11
|
// frontmatter
|
|
11
12
|
const frontmatter = content.match(/^---([\s\S]*?)---/);
|
|
12
13
|
if (frontmatter?.[1]) {
|
|
13
14
|
parts.push(frontmatter[1]);
|
|
14
15
|
}
|
|
16
|
+
// scripts
|
|
15
17
|
const scripts = content.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g);
|
|
16
18
|
for (const m of scripts) {
|
|
17
19
|
const attrs = m[1];
|
|
18
20
|
const body = m[2];
|
|
21
|
+
// external script
|
|
19
22
|
if (attrs.includes("src")) {
|
|
20
23
|
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
21
24
|
if (!src)
|
|
@@ -23,11 +26,14 @@ function parseAstro(content, file) {
|
|
|
23
26
|
const resolved = src.startsWith("/")
|
|
24
27
|
? path_1.default.resolve(process.cwd(), src.slice(1))
|
|
25
28
|
: path_1.default.resolve(path_1.default.dirname(file), src);
|
|
26
|
-
|
|
29
|
+
deps.push(resolved);
|
|
27
30
|
}
|
|
28
31
|
else {
|
|
29
32
|
parts.push(body);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
|
-
return
|
|
35
|
+
return {
|
|
36
|
+
code: parts.join("\n"),
|
|
37
|
+
deps,
|
|
38
|
+
};
|
|
33
39
|
}
|
|
@@ -4,7 +4,10 @@ exports.detectParser = detectParser;
|
|
|
4
4
|
const vue_1 = require("./vue");
|
|
5
5
|
const svelte_1 = require("./svelte");
|
|
6
6
|
const astro_1 = require("./astro");
|
|
7
|
-
const fallback = (content) =>
|
|
7
|
+
const fallback = (content) => ({
|
|
8
|
+
code: content,
|
|
9
|
+
deps: [],
|
|
10
|
+
});
|
|
8
11
|
function detectParser(file) {
|
|
9
12
|
const f = file.toLowerCase();
|
|
10
13
|
if (f.endsWith(".vue"))
|
|
@@ -1,31 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.parseSvelte = parseSvelte;
|
|
7
|
-
|
|
8
|
-
function parseSvelte(content, file) {
|
|
4
|
+
function parseSvelte(content) {
|
|
9
5
|
const parts = [];
|
|
10
|
-
const
|
|
6
|
+
const deps = [];
|
|
7
|
+
// script
|
|
8
|
+
const scripts = content.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g);
|
|
11
9
|
for (const m of scripts) {
|
|
12
|
-
|
|
13
|
-
const body = m[2];
|
|
14
|
-
if (attrs.includes("src")) {
|
|
15
|
-
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
16
|
-
if (!src)
|
|
17
|
-
continue;
|
|
18
|
-
const resolved = src.startsWith("/")
|
|
19
|
-
? path_1.default.resolve(process.cwd(), src.slice(1))
|
|
20
|
-
: path_1.default.resolve(path_1.default.dirname(file), src);
|
|
21
|
-
parts.push(`import "${resolved}"`);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
parts.push(body);
|
|
10
|
+
parts.push(m[1]);
|
|
25
11
|
}
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
// on:click={...}
|
|
13
|
+
const handlers = content.matchAll(/on:\w+=\{([^}]+)\}/g);
|
|
14
|
+
for (const h of handlers) {
|
|
15
|
+
parts.push(h[1] + ";");
|
|
29
16
|
}
|
|
30
|
-
return
|
|
17
|
+
return {
|
|
18
|
+
code: parts.join("\n"),
|
|
19
|
+
deps,
|
|
20
|
+
};
|
|
31
21
|
}
|
|
@@ -7,11 +7,12 @@ exports.parseVue = parseVue;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
function parseVue(content, file) {
|
|
9
9
|
const parts = [];
|
|
10
|
+
const deps = [];
|
|
11
|
+
// SCRIPT
|
|
10
12
|
const scripts = content.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g);
|
|
11
13
|
for (const m of scripts) {
|
|
12
14
|
const attrs = m[1];
|
|
13
15
|
const body = m[2];
|
|
14
|
-
// src
|
|
15
16
|
if (attrs.includes("src")) {
|
|
16
17
|
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
17
18
|
if (!src)
|
|
@@ -19,10 +20,9 @@ function parseVue(content, file) {
|
|
|
19
20
|
const resolved = src.startsWith("/")
|
|
20
21
|
? path_1.default.resolve(process.cwd(), src.slice(1))
|
|
21
22
|
: path_1.default.resolve(path_1.default.dirname(file), src);
|
|
22
|
-
|
|
23
|
+
deps.push(resolved);
|
|
23
24
|
continue;
|
|
24
25
|
}
|
|
25
|
-
// script setup
|
|
26
26
|
parts.push(body);
|
|
27
27
|
}
|
|
28
28
|
// TEMPLATE
|
|
@@ -30,12 +30,22 @@ function parseVue(content, file) {
|
|
|
30
30
|
let template = templateMatch?.[1] ?? "";
|
|
31
31
|
template = template.replace(/<!--[\s\S]*?-->/g, "");
|
|
32
32
|
// @click
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const handlers = template.matchAll(/@[\w-]+="([^"]+)"/g);
|
|
34
|
+
for (const h of handlers) {
|
|
35
|
+
parts.push(h[1] + ";");
|
|
35
36
|
}
|
|
36
37
|
// v-on
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const vOn = template.matchAll(/v-on:[\w-]+="([^"]+)"/g);
|
|
39
|
+
for (const v of vOn) {
|
|
40
|
+
parts.push(v[1] + ";");
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
// :prop
|
|
43
|
+
const binds = template.matchAll(/:[\w-]+="([^"]+)"/g);
|
|
44
|
+
for (const b of binds) {
|
|
45
|
+
parts.push(b[1] + ";");
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
code: parts.join("\n"),
|
|
49
|
+
deps,
|
|
50
|
+
};
|
|
41
51
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.processFile = processFile;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
4
|
const router_1 = require("./parsers/router");
|
|
9
5
|
function processFile(file, content) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const isVirtual = file.endsWith(".vue") ||
|
|
6
|
+
const parser = (0, router_1.detectParser)(file);
|
|
7
|
+
const res = parser(content, file);
|
|
8
|
+
const virtualFile = file.endsWith(".vue") ||
|
|
14
9
|
file.endsWith(".svelte") ||
|
|
15
|
-
file.endsWith(".astro")
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
file.endsWith(".astro")
|
|
11
|
+
? file + ".tsx"
|
|
12
|
+
: file;
|
|
13
|
+
return {
|
|
14
|
+
content: res.code,
|
|
15
|
+
virtualFile,
|
|
16
|
+
deps: res.deps,
|
|
17
|
+
};
|
|
18
18
|
}
|
package/package.json
CHANGED
package/src/commands/check.ts
CHANGED
|
@@ -25,16 +25,26 @@ export async function check({ fix = false }: { fix?: boolean }) {
|
|
|
25
25
|
for (const file of files) {
|
|
26
26
|
try {
|
|
27
27
|
const raw = await fs.readFile(file, "utf-8");
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
const { content, virtualFile, deps } = processFile(file, raw);
|
|
29
30
|
|
|
30
31
|
engine.scanFile(virtualFile, content, config);
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
for (const dep of deps) {
|
|
34
|
+
try {
|
|
35
|
+
const depRaw = await fs.readFile(dep, "utf-8");
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
content: depContent,
|
|
39
|
+
virtualFile: depVirtual,
|
|
40
|
+
} = processFile(dep, depRaw);
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
engine.scanFile(depVirtual, depContent, config);
|
|
43
|
+
} catch {}
|
|
37
44
|
}
|
|
45
|
+
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.log(chalk.yellow(`Skipped: ${file}`));
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
50
|
|
package/src/commands/sync.ts
CHANGED
|
@@ -31,12 +31,29 @@ export async function sync() {
|
|
|
31
31
|
for (const file of files) {
|
|
32
32
|
try {
|
|
33
33
|
const raw = await fs.readFile(file, "utf-8");
|
|
34
|
-
|
|
34
|
+
|
|
35
|
+
const { content, virtualFile, deps } = processFile(file, raw);
|
|
36
|
+
|
|
35
37
|
engine["ts"].updateFile(virtualFile, content);
|
|
36
38
|
fileCache.push({ file: virtualFile, content });
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
39
|
+
|
|
40
|
+
// deps
|
|
41
|
+
for (const dep of deps) {
|
|
42
|
+
try {
|
|
43
|
+
const depRaw = await fs.readFile(dep, "utf-8");
|
|
44
|
+
|
|
45
|
+
const {
|
|
46
|
+
content: depContent,
|
|
47
|
+
virtualFile: depVirtual,
|
|
48
|
+
} = processFile(dep, depRaw);
|
|
49
|
+
|
|
50
|
+
engine["ts"].updateFile(depVirtual, depContent);
|
|
51
|
+
fileCache.push({ file: depVirtual, content: depContent });
|
|
52
|
+
|
|
53
|
+
} catch {}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
} catch {}
|
|
40
57
|
}
|
|
41
58
|
|
|
42
59
|
for (const { file, content } of fileCache) {
|
package/src/commands/watch.ts
CHANGED
|
@@ -60,10 +60,26 @@ export async function watch() {
|
|
|
60
60
|
for (const file of batch) {
|
|
61
61
|
try {
|
|
62
62
|
const raw = await fs.readFile(file, "utf-8");
|
|
63
|
-
|
|
63
|
+
|
|
64
|
+
const { content, virtualFile, deps } = processFile(file, raw);
|
|
64
65
|
|
|
65
66
|
engine.updateFile(virtualFile, content, config);
|
|
66
67
|
|
|
68
|
+
// deps
|
|
69
|
+
for (const dep of deps) {
|
|
70
|
+
try {
|
|
71
|
+
const depRaw = await fs.readFile(dep, "utf-8");
|
|
72
|
+
|
|
73
|
+
const {
|
|
74
|
+
content: depContent,
|
|
75
|
+
virtualFile: depVirtual,
|
|
76
|
+
} = processFile(dep, depRaw);
|
|
77
|
+
|
|
78
|
+
engine.updateFile(depVirtual, depContent, config);
|
|
79
|
+
|
|
80
|
+
} catch {}
|
|
81
|
+
}
|
|
82
|
+
|
|
67
83
|
} catch {
|
|
68
84
|
console.log(chalk.gray(`skip: ${file}`));
|
|
69
85
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export type ScanMode = "strict" | "hybrid" | "discovery";
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type ParseResult = {
|
|
4
|
+
code: string;
|
|
5
|
+
deps: string[];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type Parser = (content: string, file: string) => ParseResult;
|
|
9
|
+
|
|
4
10
|
|
|
5
11
|
export type ComponentWrapper = {
|
|
6
12
|
name: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { ParseResult } from "../../types";
|
|
2
3
|
|
|
3
|
-
export function parseAstro(content: string, file: string) {
|
|
4
|
+
export function parseAstro(content: string, file: string): ParseResult {
|
|
4
5
|
const parts: string[] = [];
|
|
6
|
+
const deps: string[] = [];
|
|
5
7
|
|
|
6
8
|
// frontmatter
|
|
7
9
|
const frontmatter = content.match(/^---([\s\S]*?)---/);
|
|
@@ -9,12 +11,14 @@ export function parseAstro(content: string, file: string) {
|
|
|
9
11
|
parts.push(frontmatter[1]);
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
// scripts
|
|
12
15
|
const scripts = content.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g);
|
|
13
16
|
|
|
14
17
|
for (const m of scripts) {
|
|
15
18
|
const attrs = m[1];
|
|
16
19
|
const body = m[2];
|
|
17
20
|
|
|
21
|
+
// external script
|
|
18
22
|
if (attrs.includes("src")) {
|
|
19
23
|
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
20
24
|
if (!src) continue;
|
|
@@ -23,11 +27,14 @@ export function parseAstro(content: string, file: string) {
|
|
|
23
27
|
? path.resolve(process.cwd(), src.slice(1))
|
|
24
28
|
: path.resolve(path.dirname(file), src);
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
deps.push(resolved);
|
|
27
31
|
} else {
|
|
28
32
|
parts.push(body);
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
return
|
|
36
|
+
return {
|
|
37
|
+
code: parts.join("\n"),
|
|
38
|
+
deps,
|
|
39
|
+
};
|
|
33
40
|
}
|
|
@@ -3,7 +3,10 @@ import { parseVue } from "./vue";
|
|
|
3
3
|
import { parseSvelte } from "./svelte";
|
|
4
4
|
import { parseAstro } from "./astro";
|
|
5
5
|
|
|
6
|
-
const fallback: Parser = (content) =>
|
|
6
|
+
const fallback: Parser = (content) => ({
|
|
7
|
+
code: content,
|
|
8
|
+
deps: [],
|
|
9
|
+
});
|
|
7
10
|
|
|
8
11
|
export function detectParser(file: string): Parser {
|
|
9
12
|
const f = file.toLowerCase();
|
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ParseResult } from "../../types";
|
|
2
2
|
|
|
3
|
-
export function parseSvelte(content: string
|
|
3
|
+
export function parseSvelte(content: string): ParseResult {
|
|
4
4
|
const parts: string[] = [];
|
|
5
|
+
const deps: string[] = [];
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
// script
|
|
8
|
+
const scripts = content.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g);
|
|
8
9
|
for (const m of scripts) {
|
|
9
|
-
|
|
10
|
-
const body = m[2];
|
|
11
|
-
|
|
12
|
-
if (attrs.includes("src")) {
|
|
13
|
-
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
14
|
-
if (!src) continue;
|
|
15
|
-
|
|
16
|
-
const resolved = src.startsWith("/")
|
|
17
|
-
? path.resolve(process.cwd(), src.slice(1))
|
|
18
|
-
: path.resolve(path.dirname(file), src);
|
|
19
|
-
|
|
20
|
-
parts.push(`import "${resolved}"`);
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
parts.push(body);
|
|
10
|
+
parts.push(m[1]);
|
|
25
11
|
}
|
|
26
12
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
// on:click={...}
|
|
14
|
+
const handlers = content.matchAll(/on:\w+=\{([^}]+)\}/g);
|
|
15
|
+
|
|
16
|
+
for (const h of handlers) {
|
|
17
|
+
parts.push(h[1] + ";");
|
|
30
18
|
}
|
|
31
19
|
|
|
32
|
-
return
|
|
20
|
+
return {
|
|
21
|
+
code: parts.join("\n"),
|
|
22
|
+
deps,
|
|
23
|
+
};
|
|
33
24
|
}
|
package/src/utils/parsers/vue.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { ParseResult } from "../../types";
|
|
2
3
|
|
|
3
|
-
export function parseVue(content: string, file: string) {
|
|
4
|
+
export function parseVue(content: string, file: string): ParseResult {
|
|
4
5
|
const parts: string[] = [];
|
|
6
|
+
const deps: string[] = [];
|
|
5
7
|
|
|
8
|
+
// SCRIPT
|
|
6
9
|
const scripts = content.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g);
|
|
7
10
|
|
|
8
11
|
for (const m of scripts) {
|
|
9
12
|
const attrs = m[1];
|
|
10
13
|
const body = m[2];
|
|
11
14
|
|
|
12
|
-
// src
|
|
13
15
|
if (attrs.includes("src")) {
|
|
14
16
|
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
15
17
|
if (!src) continue;
|
|
@@ -18,11 +20,10 @@ export function parseVue(content: string, file: string) {
|
|
|
18
20
|
? path.resolve(process.cwd(), src.slice(1))
|
|
19
21
|
: path.resolve(path.dirname(file), src);
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
deps.push(resolved);
|
|
22
24
|
continue;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
// script setup
|
|
26
27
|
parts.push(body);
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -33,14 +34,25 @@ export function parseVue(content: string, file: string) {
|
|
|
33
34
|
template = template.replace(/<!--[\s\S]*?-->/g, "");
|
|
34
35
|
|
|
35
36
|
// @click
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
const handlers = template.matchAll(/@[\w-]+="([^"]+)"/g);
|
|
38
|
+
for (const h of handlers) {
|
|
39
|
+
parts.push(h[1] + ";");
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
// v-on
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
const vOn = template.matchAll(/v-on:[\w-]+="([^"]+)"/g);
|
|
44
|
+
for (const v of vOn) {
|
|
45
|
+
parts.push(v[1] + ";");
|
|
43
46
|
}
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
// :prop
|
|
49
|
+
const binds = template.matchAll(/:[\w-]+="([^"]+)"/g);
|
|
50
|
+
for (const b of binds) {
|
|
51
|
+
parts.push(b[1] + ";");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
code: parts.join("\n"),
|
|
56
|
+
deps,
|
|
57
|
+
};
|
|
46
58
|
}
|
package/src/utils/processFile.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import path from "path";
|
|
2
1
|
import { detectParser } from "./parsers/router";
|
|
3
2
|
|
|
4
3
|
export function processFile(file: string, content: string) {
|
|
5
|
-
const
|
|
4
|
+
const parser = detectParser(file);
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
content = parser(content, abs);
|
|
6
|
+
const res = parser(content, file);
|
|
9
7
|
|
|
10
|
-
const
|
|
8
|
+
const virtualFile =
|
|
11
9
|
file.endsWith(".vue") ||
|
|
12
10
|
file.endsWith(".svelte") ||
|
|
13
|
-
file.endsWith(".astro")
|
|
11
|
+
file.endsWith(".astro")
|
|
12
|
+
? file + ".tsx"
|
|
13
|
+
: file;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
return {
|
|
16
|
+
content: res.code,
|
|
17
|
+
virtualFile,
|
|
18
|
+
deps: res.deps,
|
|
19
|
+
};
|
|
18
20
|
}
|