From 0db3c07b4352639154d8203fbbb5d3b5bcc31855 Mon Sep 17 00:00:00 2001 From: raub Date: Thu, 18 Jan 2018 12:29:32 +0300 Subject: [PATCH] fix paths --- index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 213903e..46cc3bf 100644 --- a/index.js +++ b/index.js @@ -3,24 +3,27 @@ const thisDir = __dirname.replace(/\\/g, '/'); -const allDirs = ['bin_win32', 'bin_win64', 'bin_linux32', 'bin_linux64', 'bin_mac64']; +const names = ['win32', 'win64', 'linux32', 'linux64', 'mac64']; -const platformDirs = { - get win32() { return process.arch === 'x64' ? 'bin_win64' : 'bin_win32'; }, - get linux() { return process.arch === 'x64' ? 'bin_linux64' : 'bin_linux32'; }, - get darwin() { return 'bin_mac64'; }, +const getPlatformDir = platform => { + switch (platform) { + case 'win32' : return process.arch === 'x64' ? 'win64' : 'win32'; + case 'linux' : return process.arch === 'x64' ? 'linux64' : 'linux32'; + case 'darwin' : return 'mac64'; + default : throw new Error(`Platform "${platform}" is not supported.`); + } }; -const binDir = platformDirs[process.platform]; +const currentDir = getPlatformDir(process.platform); -const remDirs = allDirs.splice(allDirs.indexOf(binDir), 1); +const remDirs = names.filter(n => n !== currentDir); const paths = dir => { dir = dir.replace(/\\/g, '/'); - const binPath = `${dir}/${binDir}`; + const binPath = `${dir}/${currentDir}`; if (process.platform === 'win32') { process.env.path = `${process.env.path ? `${process.env.path};` : ''}${binPath}`;