a reactive (signals based) hypermedia web framework (wip) stormlightlabs.github.io/volt/
hypermedia frontend signals
at main 1.6 kB view raw
1import { mkdir, writeFile } from "node:fs/promises"; 2import https from "node:https"; 3import path from "node:path"; 4 5/** 6 * Download a file from a URL and save it to the specified path. 7 */ 8export async function downloadFile(url: string, outputPath: string): Promise<void> { 9 const dir = path.dirname(outputPath); 10 await mkdir(dir, { recursive: true }); 11 12 return new Promise((resolve, reject) => { 13 https.get(url, (response) => { 14 if (response.statusCode === 302 || response.statusCode === 301) { 15 if (response.headers.location) { 16 downloadFile(response.headers.location, outputPath).then(resolve).catch(reject); 17 return; 18 } 19 } 20 21 if (response.statusCode !== 200) { 22 reject(new Error(`Failed to download: ${response.statusCode} ${response.statusMessage}`)); 23 return; 24 } 25 26 const chunks: Buffer[] = []; 27 28 response.on("data", (chunk) => { 29 chunks.push(chunk); 30 }); 31 32 response.on("end", async () => { 33 try { 34 const buffer = Buffer.concat(chunks); 35 await writeFile(outputPath, buffer); 36 resolve(); 37 } catch (error) { 38 reject(error); 39 } 40 }); 41 42 response.on("error", reject); 43 }).on("error", reject); 44 }); 45} 46 47/** 48 * Get the CDN URLs for VoltX.js assets. 49 */ 50export function getCDNUrls(version: string = "latest"): { js: string; css: string } { 51 const baseUrl = version === "latest" 52 ? "https://cdn.jsdelivr.net/npm/voltx.js@latest/dist" 53 : `https://cdn.jsdelivr.net/npm/voltx.js@${version}/dist`; 54 55 return { js: `${baseUrl}/voltx.min.js`, css: `${baseUrl}/voltx.min.css` }; 56}