forked from heygen-com/hyperframes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.producer.ts
More file actions
47 lines (40 loc) · 1.34 KB
/
Copy pathvite.producer.ts
File metadata and controls
47 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { execFileSync } from "node:child_process";
import { existsSync } from "node:fs";
import { resolve } from "node:path";
export function resolveProducerDistEntry(studioDir: string): string {
return resolve(studioDir, "../producer/dist/index.js");
}
export function resolveWorkspaceRoot(studioDir: string): string {
return resolve(studioDir, "../..");
}
export function ensureProducerDist(opts: {
studioDir: string;
existsSyncImpl?: (path: string) => boolean;
execFileSyncImpl?: typeof execFileSync;
env?: NodeJS.ProcessEnv;
}): { built: boolean; producerDistEntry: string } {
const producerDistEntry = resolveProducerDistEntry(opts.studioDir);
const exists = opts.existsSyncImpl ?? existsSync;
if (exists(producerDistEntry)) {
return { built: false, producerDistEntry };
}
const exec = opts.execFileSyncImpl ?? execFileSync;
exec("bun", ["run", "--filter", "@hyperframes/producer", "build"], {
cwd: resolveWorkspaceRoot(opts.studioDir),
stdio: "pipe",
env: opts.env,
});
return { built: true, producerDistEntry };
}
export function createRetryingModuleLoader<T>(load: () => Promise<T>): () => Promise<T> {
let promise: Promise<T> | null = null;
return async () => {
if (!promise) {
promise = load().catch((error) => {
promise = null;
throw error;
});
}
return promise;
};
}