|
| 1 | +const os = require('os'); |
| 2 | +const download = require('download'); |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | +const ora = require('ora'); |
| 6 | +const chalk = require('chalk'); |
| 7 | +const execa = require('execa'); |
| 8 | + |
| 9 | +module.exports = async (config, dest) => { |
| 10 | + let url; |
| 11 | + let fileName = 'nova-cluster'; |
| 12 | + const platform = os.platform(); |
| 13 | + if (platform === 'darwin') { |
| 14 | + url = 'https://github.com/ara-framework/nova-cluster/releases/download/1.2.0/nova-cluster-darwin-amd64'; |
| 15 | + } else if (platform === 'win32') { |
| 16 | + url = 'https://github.com/ara-framework/nova-cluster/releases/download/1.2.0/nova-cluster-windows-amd64.exe'; |
| 17 | + fileName = `${fileName}.exe`; |
| 18 | + } |
| 19 | + |
| 20 | + const executable = path.join(dest, fileName); |
| 21 | + |
| 22 | + if (!fs.existsSync(executable)) { |
| 23 | + if (url) { |
| 24 | + const spinner = ora('Downloading nova-cluster').start(); |
| 25 | + try { |
| 26 | + await download(url, dest, { filename: fileName }); |
| 27 | + fs.chmodSync(executable, 755); |
| 28 | + spinner.succeed('Downloaded nova-cluster'); |
| 29 | + } catch (error) { |
| 30 | + spinner.fail('Downloadind nova-cluster failed'); |
| 31 | + return null; |
| 32 | + } |
| 33 | + } else { |
| 34 | + return console.error(chalk.red(`run:cluster command is not supported in "${platform}"`)); |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + try { |
| 39 | + process.env.CONFIG_FILE = process.env.CONFIG_FILE || config; |
| 40 | + |
| 41 | + execa(executable).stdout.pipe(process.stdout); |
| 42 | + } catch (error) { |
| 43 | + console.error(chalk.red(error.stderr || 'Nova cluster failed when running')); |
| 44 | + } |
| 45 | + |
| 46 | + return null; |
| 47 | +}; |
0 commit comments