From eaa5b46b1f496e2380037a2f47329e5f72dbf4aa Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Thu, 30 May 2024 11:47:00 -0300 Subject: [PATCH] update build and postinstall for mac --- .github/workflows/build.yml | 6 +++++- postinstall.cjs | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 791a9c01..a5d24504 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ jobs: build: strategy: matrix: - os: [windows-latest, ubuntu-latest, macos-11] + os: [macos-11] runs-on: ${{ matrix.os }} @@ -19,6 +19,10 @@ jobs: with: node-version: 20.11.1 + - name: Install aria2 on Mac + if: matrix.os == 'macos-11' + run: brew install aria2 + - name: Install dependencies run: yarn diff --git a/postinstall.cjs b/postinstall.cjs index 2b793257..94ad23a4 100644 --- a/postinstall.cjs +++ b/postinstall.cjs @@ -1,10 +1,11 @@ const { default: axios } = require("axios"); const util = require("node:util"); const fs = require("node:fs"); +const { spawnSync } = require("node:child_process"); const exec = util.promisify(require("node:child_process").exec); -const downloadAria2 = async () => { +const downloadAria2WindowsAndLinux = async () => { if (fs.existsSync("aria2")) { console.log("Aria2 already exists, skipping download..."); return; @@ -47,6 +48,19 @@ const downloadAria2 = async () => { }); }; +const copyAria2Macos = async () => { + const isAria2Installed = spawnSync("which", ["aria2c"]).status; + + if (isAria2Installed != 0) { + console.log("Please install aria2"); + console.log("brew install aria2"); + return; + } + + fs.mkdirSync("aria2"); + await exec(`cp $(which aria2c) aria2/aria2c`); +}; + if (process.platform === "win32") { fs.copyFileSync( "node_modules/ps-list/vendor/fastlist-0.3.0-x64.exe", @@ -54,4 +68,8 @@ if (process.platform === "win32") { ); } -downloadAria2(); +if (process.platform == "darwin") { + copyAria2Macos(); +} else { + downloadAria2WindowsAndLinux(); +}