[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 928f873cfa
commit 2b39b616b3

114
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(); if [[ -f "$dest" ]]; then
echo "$dest já existe, pulando download."
return
fi
echo "Baixando $url → $dest"
if command -v curl >/dev/null 2>&1; then
curl -L "$url" -o "$dest"
elif command -v wget >/dev/null 2>&1; then
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
} }
console.log(`Baixando ${url} → ${dest}`); # Detecta plataforma
const file = fs.createWriteStream(dest); PLATFORM=""
const client = url.startsWith("https") ? https : http; case "$(uname -s)" in
Linux*) PLATFORM="linux";;
Darwin*) PLATFORM="mac";;
MINGW*|MSYS*|CYGWIN*) PLATFORM="win";;
*) PLATFORM="unknown";;
esac
client.get(url, (res) => { echo "Plataforma detectada: $PLATFORM"
if (res.statusCode >= 400) return reject(new Error(`Erro ao baixar ${url}: ${res.statusCode}`));
res.pipe(file);
file.on("finish", () => file.close(resolve));
}).on("error", (err) => {
fs.unlink(dest, () => reject(err));
});
});
}
async function main() { # Setup npm
// setup do npm run_cmd npm ci
await runCmd("npm ci");
// cria pasta para binários # Cria pasta bin
const binDir = path.resolve("bin"); mkdir -p bin
if (!fs.existsSync(binDir)) fs.mkdirSync(binDir, { recursive: true });
// downloads # Arquivos por plataforma
const files = [ files=()
["https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe", "yt-dlp.exe"], if [[ "$PLATFORM" == "win" ]]; then
["https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe", "yt-dlp"], files=(
["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 bin/yt-dlp.exe"
["https://github.com/synt-xerror/manybot/releases/download/dependencies/yt-dlp.exe", "ffmpeg"] "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
for (const [url, name] of files) { # Baixa todos os arquivos
await downloadFile(url, path.join(binDir, name)); for file in "${files[@]}"; do
} url="${file%% *}"
dest="${file##* }"
download_file "$url" "$dest"
done
console.log("Setup concluído."); echo "Setup concluído."42
}
main().catch(console.error);