install.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const download = require('download');
  2. const ora = require('ora');
  3. const pkg = require('../package.json');
  4. const PLATFORM = {
  5. 'darwin': 'darwin',
  6. 'freebsd': 'freebsd',
  7. 'linux': 'linux',
  8. 'openbsd': 'openbsd',
  9. 'win32': 'windows'
  10. };
  11. const ARCH = {
  12. 'ia32': '386',
  13. 'x64': 'amd64',
  14. 'x32': '386'
  15. };
  16. function install() {
  17. if (!(process.arch in ARCH)) {
  18. console.error('Installation is not supported for this architecture: ' + process.arch);
  19. return;
  20. }
  21. if (!(process.platform in PLATFORM)) {
  22. console.error('Installation is not supported for this platform: ' + process.platform);
  23. return;
  24. }
  25. const platform = PLATFORM[process.platform];
  26. const arch = ARCH[process.arch];
  27. const ghURL = `https://github.com/jsmartx/giter/releases/download/v${pkg.version}/`;
  28. const url = `${ghURL}${pkg.name}_${pkg.version}_${platform}_${arch}.tar.gz`;
  29. const spinner = ora(`Downloading ${url}`).start();
  30. download(url, 'bin', {
  31. extract: true
  32. }).then(() => {
  33. spinner.succeed();
  34. }).catch(() => {
  35. spinner.fail();
  36. });
  37. }
  38. install();