@eventra_dev/eventra-cli 0.1.16 → 0.1.17
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/watch.js +2 -8
- package/dist/utils/parsers/astro.js +27 -8
- package/dist/utils/parsers/svelte.js +12 -4
- package/dist/utils/parsers/vue.js +34 -24
- package/package.json +1 -1
- package/src/commands/watch.ts +2 -10
- package/src/utils/parsers/astro.ts +31 -8
- package/src/utils/parsers/svelte.ts +14 -4
- package/src/utils/parsers/vue.ts +40 -26
package/dist/commands/watch.js
CHANGED
|
@@ -12,13 +12,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
12
12
|
const config_1 = require("../utils/config");
|
|
13
13
|
const engine_1 = require("../engine/engine");
|
|
14
14
|
const processFile_1 = require("../utils/processFile");
|
|
15
|
-
const toVirtual = async (file) => {
|
|
16
|
-
const abs = path_1.default.resolve(file);
|
|
17
|
-
const raw = await promises_1.default.readFile(abs, "utf-8");
|
|
18
|
-
return (0, processFile_1.processFile)(abs, raw);
|
|
19
|
-
};
|
|
20
15
|
async function watch() {
|
|
21
|
-
process.env.EVENTRA_WATCH = "1";
|
|
22
16
|
const config = await (0, config_1.loadConfig)();
|
|
23
17
|
if (!config)
|
|
24
18
|
return;
|
|
@@ -34,7 +28,6 @@ async function watch() {
|
|
|
34
28
|
const abs = path_1.default.resolve(file);
|
|
35
29
|
const raw = await promises_1.default.readFile(abs, "utf-8");
|
|
36
30
|
const { content, virtualFile } = (0, processFile_1.processFile)(abs, raw);
|
|
37
|
-
engine["ts"].updateFile(virtualFile, content);
|
|
38
31
|
fileCache.push({ file: virtualFile, content });
|
|
39
32
|
}
|
|
40
33
|
catch {
|
|
@@ -59,7 +52,8 @@ async function watch() {
|
|
|
59
52
|
queued.clear();
|
|
60
53
|
for (const file of batch) {
|
|
61
54
|
try {
|
|
62
|
-
const
|
|
55
|
+
const raw = await promises_1.default.readFile(file, "utf-8");
|
|
56
|
+
const { content, virtualFile } = (0, processFile_1.processFile)(file, raw);
|
|
63
57
|
engine.updateFile(virtualFile, content, config);
|
|
64
58
|
}
|
|
65
59
|
catch {
|
|
@@ -2,12 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseAstro = parseAstro;
|
|
4
4
|
function parseAstro(content) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const parts = [];
|
|
6
|
+
// frontmatter
|
|
7
|
+
const frontmatter = content.match(/^---([\s\S]*?)---/);
|
|
8
|
+
if (frontmatter?.[1]) {
|
|
9
|
+
parts.push(frontmatter[1]);
|
|
10
|
+
}
|
|
11
|
+
// scripts
|
|
12
|
+
const scripts = content.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g);
|
|
13
|
+
for (const m of scripts) {
|
|
14
|
+
const attrs = m[1];
|
|
15
|
+
const body = m[2];
|
|
16
|
+
if (attrs.includes("src")) {
|
|
17
|
+
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
18
|
+
if (src) {
|
|
19
|
+
parts.push(`import "${src}"`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
parts.push(body);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// inline handlers
|
|
27
|
+
const inlineJS = content.matchAll(/on\w+="([^"]+)"/g);
|
|
28
|
+
for (const m of inlineJS) {
|
|
29
|
+
parts.push(m[1] + ";");
|
|
30
|
+
}
|
|
31
|
+
return parts.join("\n");
|
|
13
32
|
}
|
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseSvelte = parseSvelte;
|
|
4
4
|
function parseSvelte(content) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
];
|
|
8
|
-
|
|
5
|
+
const parts = [];
|
|
6
|
+
// scripts
|
|
7
|
+
const scripts = content.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g);
|
|
8
|
+
for (const m of scripts) {
|
|
9
|
+
parts.push(m[1]);
|
|
10
|
+
}
|
|
11
|
+
// on:click / on:*
|
|
12
|
+
const handlers = content.matchAll(/on:\w+=\{([^}]+)\}/g);
|
|
13
|
+
for (const h of handlers) {
|
|
14
|
+
parts.push(h[1] + ";");
|
|
15
|
+
}
|
|
16
|
+
return parts.join("\n");
|
|
9
17
|
}
|
|
@@ -2,30 +2,40 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseVue = parseVue;
|
|
4
4
|
function parseVue(content) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
];
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
const parts = [];
|
|
6
|
+
// --- SCRIPT ---
|
|
7
|
+
const scripts = content.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g);
|
|
8
|
+
for (const m of scripts) {
|
|
9
|
+
const attrs = m[1];
|
|
10
|
+
const body = m[2];
|
|
11
|
+
if (attrs.includes("src")) {
|
|
12
|
+
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
13
|
+
if (src) {
|
|
14
|
+
parts.push(`import "${src}"`);
|
|
15
|
+
}
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
parts.push(body);
|
|
19
|
+
}
|
|
20
|
+
// --- TEMPLATE ---
|
|
21
|
+
const templateMatch = content.match(/<template[^>]*>([\s\S]*?)<\/template>/);
|
|
11
22
|
let template = templateMatch?.[1] ?? "";
|
|
23
|
+
// remove comments
|
|
12
24
|
template = template.replace(/<!--[\s\S]*?-->/g, "");
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
);
|
|
29
|
-
`;
|
|
30
|
-
return script + "\n" + jsx;
|
|
25
|
+
// --- event handlers (@click)
|
|
26
|
+
const handlers = template.matchAll(/@[\w-]+="([^"]+)"/g);
|
|
27
|
+
for (const h of handlers) {
|
|
28
|
+
parts.push(h[1] + ";");
|
|
29
|
+
}
|
|
30
|
+
// --- v-on
|
|
31
|
+
const vOn = template.matchAll(/v-on:[\w-]+="([^"]+)"/g);
|
|
32
|
+
for (const v of vOn) {
|
|
33
|
+
parts.push(v[1] + ";");
|
|
34
|
+
}
|
|
35
|
+
// --- :prop bindings
|
|
36
|
+
const binds = template.matchAll(/:[\w-]+="([^"]+)"/g);
|
|
37
|
+
for (const b of binds) {
|
|
38
|
+
parts.push(b[1] + ";");
|
|
39
|
+
}
|
|
40
|
+
return parts.join("\n");
|
|
31
41
|
}
|
package/package.json
CHANGED
package/src/commands/watch.ts
CHANGED
|
@@ -8,15 +8,7 @@ import { loadConfig, saveConfig } from "../utils/config";
|
|
|
8
8
|
import { EventraEngine } from "../engine/engine";
|
|
9
9
|
import { processFile } from "../utils/processFile";
|
|
10
10
|
|
|
11
|
-
const toVirtual = async (file: string) => {
|
|
12
|
-
const abs = path.resolve(file);
|
|
13
|
-
const raw = await fs.readFile(abs, "utf-8");
|
|
14
|
-
return processFile(abs, raw);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
11
|
export async function watch() {
|
|
18
|
-
process.env.EVENTRA_WATCH = "1";
|
|
19
|
-
|
|
20
12
|
const config = await loadConfig();
|
|
21
13
|
if (!config) return;
|
|
22
14
|
|
|
@@ -36,7 +28,6 @@ export async function watch() {
|
|
|
36
28
|
const abs = path.resolve(file);
|
|
37
29
|
const raw = await fs.readFile(abs, "utf-8");
|
|
38
30
|
const { content, virtualFile } = processFile(abs, raw);
|
|
39
|
-
engine["ts"].updateFile(virtualFile, content);
|
|
40
31
|
fileCache.push({ file: virtualFile, content });
|
|
41
32
|
} catch {
|
|
42
33
|
console.log(chalk.gray(`skip: ${file}`));
|
|
@@ -68,7 +59,8 @@ export async function watch() {
|
|
|
68
59
|
|
|
69
60
|
for (const file of batch) {
|
|
70
61
|
try {
|
|
71
|
-
const
|
|
62
|
+
const raw = await fs.readFile(file, "utf-8");
|
|
63
|
+
const { content, virtualFile } = processFile(file, raw);
|
|
72
64
|
|
|
73
65
|
engine.updateFile(virtualFile, content, config);
|
|
74
66
|
|
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
export function parseAstro(content: string) {
|
|
2
|
-
const
|
|
2
|
+
const parts: string[] = [];
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
]
|
|
4
|
+
// frontmatter
|
|
5
|
+
const frontmatter = content.match(/^---([\s\S]*?)---/);
|
|
6
|
+
if (frontmatter?.[1]) {
|
|
7
|
+
parts.push(frontmatter[1]);
|
|
8
|
+
}
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// scripts
|
|
11
|
+
const scripts = content.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g);
|
|
12
|
+
|
|
13
|
+
for (const m of scripts) {
|
|
14
|
+
const attrs = m[1];
|
|
15
|
+
const body = m[2];
|
|
16
|
+
|
|
17
|
+
if (attrs.includes("src")) {
|
|
18
|
+
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
19
|
+
if (src) {
|
|
20
|
+
parts.push(`import "${src}"`);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
parts.push(body);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// inline handlers
|
|
28
|
+
const inlineJS = content.matchAll(/on\w+="([^"]+)"/g);
|
|
29
|
+
|
|
30
|
+
for (const m of inlineJS) {
|
|
31
|
+
parts.push(m[1] + ";");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return parts.join("\n");
|
|
12
35
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
export function parseSvelte(content: string) {
|
|
2
|
-
const
|
|
3
|
-
...content.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g)
|
|
4
|
-
];
|
|
2
|
+
const parts: string[] = [];
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
// scripts
|
|
5
|
+
const scripts = content.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g);
|
|
6
|
+
for (const m of scripts) {
|
|
7
|
+
parts.push(m[1]);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// on:click / on:*
|
|
11
|
+
const handlers = content.matchAll(/on:\w+=\{([^}]+)\}/g);
|
|
12
|
+
for (const h of handlers) {
|
|
13
|
+
parts.push(h[1] + ";");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return parts.join("\n");
|
|
7
17
|
}
|
package/src/utils/parsers/vue.ts
CHANGED
|
@@ -1,34 +1,48 @@
|
|
|
1
1
|
export function parseVue(content: string) {
|
|
2
|
-
const
|
|
3
|
-
...content.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/g)
|
|
4
|
-
];
|
|
2
|
+
const parts: string[] = [];
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
// --- SCRIPT ---
|
|
5
|
+
const scripts = content.matchAll(/<script([^>]*)>([\s\S]*?)<\/script>/g);
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
for (const m of scripts) {
|
|
8
|
+
const attrs = m[1];
|
|
9
|
+
const body = m[2];
|
|
10
|
+
|
|
11
|
+
if (attrs.includes("src")) {
|
|
12
|
+
const src = attrs.match(/src=["'](.+?)["']/)?.[1];
|
|
13
|
+
if (src) {
|
|
14
|
+
parts.push(`import "${src}"`);
|
|
15
|
+
}
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
parts.push(body);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// --- TEMPLATE ---
|
|
23
|
+
const templateMatch = content.match(/<template[^>]*>([\s\S]*?)<\/template>/);
|
|
10
24
|
let template = templateMatch?.[1] ?? "";
|
|
11
25
|
|
|
26
|
+
// remove comments
|
|
12
27
|
template = template.replace(/<!--[\s\S]*?-->/g, "");
|
|
13
28
|
|
|
14
|
-
//
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return script + "\n" + jsx;
|
|
29
|
+
// --- event handlers (@click)
|
|
30
|
+
const handlers = template.matchAll(/@[\w-]+="([^"]+)"/g);
|
|
31
|
+
for (const h of handlers) {
|
|
32
|
+
parts.push(h[1] + ";");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// --- v-on
|
|
36
|
+
const vOn = template.matchAll(/v-on:[\w-]+="([^"]+)"/g);
|
|
37
|
+
for (const v of vOn) {
|
|
38
|
+
parts.push(v[1] + ";");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// --- :prop bindings
|
|
42
|
+
const binds = template.matchAll(/:[\w-]+="([^"]+)"/g);
|
|
43
|
+
for (const b of binds) {
|
|
44
|
+
parts.push(b[1] + ";");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return parts.join("\n");
|
|
34
48
|
}
|