github.com/getgauge/gauge@v1.6.9/build/npm/src/install.js (about) 1 #!/usr/bin/env node 2 3 "use strict" 4 5 const fs = require('fs'); 6 7 const BASE_URL="https://github.com/getgauge/gauge/releases/download/", 8 ARCH_MAPPING = { 9 "ia32": "x86", 10 "x64": "x86_64", 11 "arm64": "arm64" 12 }, 13 PLATFORM_MAPPING = { 14 "darwin": "darwin", 15 "linux": "linux", 16 "win32": "windows" 17 }; 18 19 var getVersion = function(p) { 20 return new Promise( (resolve, reject) => { 21 if (!fs.existsSync(p)) { 22 reject("Unable to find package.json."); 23 } 24 fs.readFile(p, (err, data) => { 25 if(err) { 26 reject(err); 27 } 28 const pkg = JSON.parse(data); 29 if (pkg.version) { 30 resolve(pkg.version); 31 } else { 32 reject(new Error("Unable to find version in package.json.")); 33 } 34 }) 35 }); 36 } 37 38 var getBinaryUrl = function(version) { 39 let os = PLATFORM_MAPPING[process.platform]; 40 let arch = ARCH_MAPPING[process.arch]; 41 return `${BASE_URL}v${version}/gauge-${version}-${os}.${arch}.zip`; 42 } 43 44 module.exports = { 45 getVersion: getVersion, 46 getBinaryUrl: getBinaryUrl 47 }