Skip to content

Commit

Permalink
use uniform paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Zweig committed Dec 22, 2023
1 parent c7c036d commit d5062e2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions scripts/downloadStockfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import cpuFeatures from "cpu-features";
import fd from "follow-redirects";
import fs from "fs";
import path from "path";
import tar from "tar";
import unzipper from "unzipper";

Expand Down Expand Up @@ -36,16 +37,17 @@ const STOCKFISH_FILE_EXTENSION = STOCKFISH_PLATFORM === "windows" ? ".exe" : "";
const STOCKFISH_FILENAME = `stockfish-${STOCKFISH_PLATFORM}-x86-64-${STOCKFISH_CPU_ARCHITECTURE}`;
const STOCKFISH_DOWNLOAD_BASE_URL = `https://github.com/official-stockfish/Stockfish/releases/download/sf_${STOCKFISH_VERSION}`;
const STOCKFISH_DOWNLOAD_URL = `${STOCKFISH_DOWNLOAD_BASE_URL}/${STOCKFISH_FILENAME}${STOCKFISH_ARCHIVE_EXTENSION}`;
const STOCKFISH_DOWNLOAD_PATH = `external/stockfish${STOCKFISH_ARCHIVE_EXTENSION}`;
const STOCKFISH_DOWNLOAD_PATH = path.join("external", `stockfish${STOCKFISH_ARCHIVE_EXTENSION}`);
const STOCKFISH_BINARY_PATH = path.join("external", `stockfish${STOCKFISH_FILE_EXTENSION}`);

const stockfishBinaryFilter = (path) => path.includes(`${STOCKFISH_FILENAME}${STOCKFISH_FILE_EXTENSION}`);

function renameAndCleanup() {
console.log("Cleaning up");
if (fs.existsSync("external/stockfish")) {
if (fs.existsSync(STOCKFISH_BINARY_PATH)) {
const stockfishBinary = fs.readdirSync("external/stockfish")[0];
fs.copyFileSync(`external/stockfish/${stockfishBinary}`, `external/${stockfishBinary}`);
fs.rmSync("external/stockfish", { recursive: true, force: true });
fs.rmSync(STOCKFISH_BINARY_PATH, { recursive: true, force: true });
fs.renameSync(`external/${stockfishBinary}`, `external/stockfish${STOCKFISH_FILE_EXTENSION}`);
}
if (fs.existsSync(STOCKFISH_DOWNLOAD_PATH)) {
Expand Down Expand Up @@ -87,9 +89,9 @@ function parseArchive(readStream) {
}

async function main() {
if (fs.existsSync("external/stockfish")) {
if (fs.existsSync(STOCKFISH_BINARY_PATH)) {
console.log("Deleting old stockfish binary");
fs.unlinkSync("external/stockfish");
fs.unlinkSync(STOCKFISH_BINARY_PATH);
}

const writeStream = fs.createWriteStream(STOCKFISH_DOWNLOAD_PATH);
Expand Down

0 comments on commit d5062e2

Please sign in to comment.