From f9430b80a41f744f39c9edce8cfe120dfec30728 Mon Sep 17 00:00:00 2001 From: Yuuki Wesp Date: Mon, 27 Apr 2020 01:47:08 +0300 Subject: [PATCH] add detecting platform --- npm/getBinary.js | 16 +++++++++++++++- npm/run.js | 7 +++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/npm/getBinary.js b/npm/getBinary.js index fae5d53..b29af04 100644 --- a/npm/getBinary.js +++ b/npm/getBinary.js @@ -1,8 +1,22 @@ const Binary = require('./binary'); + +const os = require('os'); + +function getPlatform() { + const type = os.type(); + const arch = os.arch(); + + if (type === 'Windows_NT' && arch === 'x64') return 'win'; + if (type === 'Linux' && arch === 'x64') return 'linux'; + if (type === 'Darwin' && arch === 'x64') return 'macos'; + + throw new Error(`Unsupported platform: ${type} ${arch}`); +} + function getBinary() { const name = 'rune'; const version = require('../package.json').version; - const url = `https://github.com/ancientproject/cli/releases/download/v${version}/${name}-cli-win-64.zip`; + const url = `https://github.com/ancientproject/cli/releases/download/v${version}/${name}-cli-${getPlatform()}-64.zip`; return new Binary(url, { name }); } diff --git a/npm/run.js b/npm/run.js index 2cd7a21..c0b1705 100644 --- a/npm/run.js +++ b/npm/run.js @@ -2,7 +2,10 @@ const getBinary = require('./getBinary'); - if(!getBinary().exist()) +{ + console.log(">> installing binaries..."); getBinary().install(); -getBinary().run(); \ No newline at end of file +} +else + getBinary().run(); \ No newline at end of file