gale/scaffold.ts

19 lines
649 B
TypeScript

const hostedRoot = import.meta.resolve("../").slice(0, -1);
async function Download(file:string, processor = (text:string)=>text)
{
const pathHosted = hostedRoot + "/scaffold/" + file;
try
{
const fileContents = await fetch(pathHosted).then(resp=>resp.text());
await Deno.writeTextFile(file, processor(fileContents));
console.log(`Successfully downloaded ${file}`);
}
catch (error)
{
console.error(`Error downloading ${file}:`, error);
}
}
Download("deno.json", t=>t.replaceAll(`{HOSTED}`, hostedRoot));
Download("index.html", t=>t.replaceAll(`{HOSTED}`, hostedRoot));
Download("app.js");