[setup] nodejs -> bash. adding suport to windows. binaries separated.

This commit is contained in:
synt-xerror
2026-03-13 16:33:37 -03:00
parent 70a85dde88
commit bf148ef154

112
setup Normal file → Executable file
View File

@@ -1,64 +1,72 @@
import { exec } from "child_process"; #!/bin/bash
import fs from "fs"; set -e
import path from "path";
import https from "https";
import http from "http";
// Função para rodar comandos de shell # Função para rodar comando mostrando saída
function runCmd(cmd) { run_cmd() {
return new Promise((resolve, reject) => { echo "+ $*"
const p = exec(cmd, (err, stdout, stderr) => { "$@"
if (err) return reject(err);
resolve({ stdout, stderr });
});
p.stdout.pipe(process.stdout);
p.stderr.pipe(process.stderr);
});
} }
// Função para baixar arquivo # Função para baixar arquivos se não existirem
function downloadFile(url, dest) { download_file() {
return new Promise((resolve, reject) => { local url="$1"
if (fs.existsSync(dest)) { local dest="$2"
console.log(`${dest} já existe, pulando download.`);
return resolve();
}
console.log(`Baixando ${url} → ${dest}`); if [[ -f "$dest" ]]; then
const file = fs.createWriteStream(dest); echo "$dest já existe, pulando download."
const client = url.startsWith("https") ? https : http; return
fi
client.get(url, (res) => { echo "Baixando $url → $dest"
if (res.statusCode >= 400) return reject(new Error(`Erro ao baixar ${url}: ${res.statusCode}`));
res.pipe(file); if command -v curl >/dev/null 2>&1; then
file.on("finish", () => file.close(resolve)); curl -L "$url" -o "$dest"
}).on("error", (err) => { elif command -v wget >/dev/null 2>&1; then
fs.unlink(dest, () => reject(err)); wget "$url" -O "$dest"
}); else
}); echo "Erro: curl ou wget são necessários para baixar arquivos."
exit 1
fi
chmod +x "$dest" 2>/dev/null || true
} }
async function main() { # Detecta plataforma
// setup do npm PLATFORM=""
await runCmd("npm ci"); case "$(uname -s)" in
Linux*) PLATFORM="linux";;
Darwin*) PLATFORM="mac";;
MINGW*|MSYS*|CYGWIN*) PLATFORM="win";;
*) PLATFORM="unknown";;
esac
// cria pasta para binários echo "Plataforma detectada: $PLATFORM"
const binDir = path.resolve("bin");
if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true });
// downloads # Setup npm
const files = [ run_cmd npm ci
["https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe", "yt-dlp.exe"],
["https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe", "yt-dlp"],
["https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe", "ffmpeg.exe"],
["https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe", "ffmpeg"]
];
for (const [url, name] of files) { # Cria pasta bin
await downloadFile(url, path.join(binDir, name)); mkdir -p bin
}
console.log("Setup concluído."); # Arquivos por plataforma
} files=()
if [[ "$PLATFORM" == "win" ]]; then
files=(
"https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe bin/yt-dlp.exe"
"https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg.exe bin/ffmpeg.exe"
)
else
files=(
"https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp bin/yt-dlp"
"https://github.com/synt-xerror/manybot/releases/download/dependencies/ffmpeg bin/ffmpeg"
)
fi
main().catch(console.error); # Baixa todos os arquivos
for file in "${files[@]}"; do
url="${file%% *}"
dest="${file##* }"
download_file "$url" "$dest"
done
echo "Setup concluído."42