31 lines
984 B
TypeScript
31 lines
984 B
TypeScript
|
import { resolve, basename } from "https://deno.land/std/path/mod.ts";
|
||
|
|
||
|
const hostDir = "./scaffold/";
|
||
|
|
||
|
const filePaths = [
|
||
|
"index.html",
|
||
|
"app.js",
|
||
|
];
|
||
|
|
||
|
|
||
|
for (const filePath of filePaths)
|
||
|
{
|
||
|
// Resolve the file path relative to the script's directory
|
||
|
const fileUrl = import.meta.resolve(hostDir + filePath);
|
||
|
|
||
|
// Determine the destination path in the current working directory
|
||
|
const destinationPath = resolve(Deno.cwd(), basename(filePath));
|
||
|
|
||
|
console.log(`Downloading ${fileUrl} to ${destinationPath}`);
|
||
|
try {
|
||
|
const response = await fetch(fileUrl);
|
||
|
if (!response.ok) {
|
||
|
throw new Error(`Failed to fetch ${fileUrl}: ${response.statusText}`);
|
||
|
}
|
||
|
const fileData = await response.arrayBuffer();
|
||
|
await Deno.writeFile(destinationPath, new Uint8Array(fileData));
|
||
|
console.log(`Successfully downloaded ${filePath}`);
|
||
|
} catch (error) {
|
||
|
console.error(`Error downloading ${filePath}:`, error);
|
||
|
}
|
||
|
}
|