UNPKG

makemcserver

Version:

A cli tool to easily create a new Minecraft server

23 lines (21 loc) 674 B
#!/usr/bin/env node import fs from "node:fs"; import path from "node:path"; import { Readable } from "node:stream"; import { finished } from "node:stream/promises"; export async function fetchJson(input) { return await ( await fetch(input, { headers: { "User-Agent": "shock59/makemcserver", }, }) ).json(); } export async function downloadFile(url, mainDirectory, relativeDestination) { const res = await fetch(url); const destination = path.resolve(mainDirectory, relativeDestination); const fileStream = fs.createWriteStream(destination); const readable = Readable.fromWeb(res.body); await finished(readable.pipe(fileStream)); }