mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-02-14 12:13:49 +00:00
add TorqueScript transpiler and runtime
This commit is contained in:
parent
c8391a1056
commit
7d10fb7dee
49 changed files with 12324 additions and 2075 deletions
30
src/torqueScript/scriptLoader.browser.ts
Normal file
30
src/torqueScript/scriptLoader.browser.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import type { ScriptLoader } from "./types";
|
||||
import { getUrlForPath } from "../loaders";
|
||||
|
||||
/**
|
||||
* Creates a script loader for browser environments that fetches scripts
|
||||
* using the manifest-based URL resolution.
|
||||
*/
|
||||
export function createScriptLoader(): ScriptLoader {
|
||||
return async (path: string): Promise<string | null> => {
|
||||
let url: string;
|
||||
try {
|
||||
url = getUrlForPath(path);
|
||||
} catch (err) {
|
||||
console.warn(`Script not in manifest: ${path}`, err);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
console.warn(`Script fetch failed: ${path} (${response.status})`);
|
||||
return null;
|
||||
}
|
||||
return await response.text();
|
||||
} catch (err) {
|
||||
console.warn(`Script fetch error: ${path}`, err);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue