vargai 0.4.0-alpha4 → 0.4.0-alpha6
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/package.json +1 -1
- package/src/cli/commands/render.tsx +44 -9
package/package.json
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
1
3
|
import { defineCommand } from "citty";
|
|
2
4
|
import { render } from "../../react/render";
|
|
3
5
|
import type { RenderMode, VargElement } from "../../react/types";
|
|
4
6
|
|
|
7
|
+
const AUTO_IMPORTS = `/** @jsxImportSource vargai */
|
|
8
|
+
import { Animate, Captions, Clip, Image, Music, Overlay, Packshot, Render, Slider, Speech, Split, Subtitle, Swipe, TalkingHead, Title, Video, Grid, SplitLayout } from "vargai/react";
|
|
9
|
+
import { fal, elevenlabs, replicate } from "vargai/ai";
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
async function loadComponent(filePath: string): Promise<VargElement> {
|
|
13
|
+
const resolvedPath = resolve(filePath);
|
|
14
|
+
const source = await Bun.file(resolvedPath).text();
|
|
15
|
+
|
|
16
|
+
const hasImports =
|
|
17
|
+
source.includes("from 'vargai") ||
|
|
18
|
+
source.includes('from "vargai') ||
|
|
19
|
+
source.includes("from '@vargai") ||
|
|
20
|
+
source.includes('from "@vargai');
|
|
21
|
+
|
|
22
|
+
if (hasImports) {
|
|
23
|
+
const mod = await import(resolvedPath);
|
|
24
|
+
return mod.default;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const tmpDir = ".cache/varg-render";
|
|
28
|
+
if (!existsSync(tmpDir)) {
|
|
29
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const tmpFile = `${tmpDir}/${Date.now()}.tsx`;
|
|
33
|
+
await Bun.write(tmpFile, AUTO_IMPORTS + source);
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const mod = await import(resolve(tmpFile));
|
|
37
|
+
return mod.default;
|
|
38
|
+
} finally {
|
|
39
|
+
(await Bun.file(tmpFile).exists()) && (await Bun.write(tmpFile, ""));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
5
43
|
export const renderCmd = defineCommand({
|
|
6
44
|
meta: {
|
|
7
45
|
name: "render",
|
|
@@ -49,21 +87,18 @@ export const renderCmd = defineCommand({
|
|
|
49
87
|
process.exit(1);
|
|
50
88
|
}
|
|
51
89
|
|
|
52
|
-
const
|
|
53
|
-
const mod = await import(resolvedPath);
|
|
54
|
-
const component: VargElement = mod.default;
|
|
90
|
+
const component = await loadComponent(file);
|
|
55
91
|
|
|
56
92
|
if (!component || component.type !== "render") {
|
|
57
93
|
console.error("error: default export must be a <Render> element");
|
|
58
94
|
process.exit(1);
|
|
59
95
|
}
|
|
60
96
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
.pop()}.mp4`;
|
|
97
|
+
const basename = file
|
|
98
|
+
.replace(/\.tsx?$/, "")
|
|
99
|
+
.split("/")
|
|
100
|
+
.pop();
|
|
101
|
+
const outputPath = args.output ?? `output/${basename}.mp4`;
|
|
67
102
|
|
|
68
103
|
const mode: RenderMode = args.strict
|
|
69
104
|
? "strict"
|