index.js 480 B

123456789101112131415161718
  1. 'use strict';
  2. var childProcess = require('child_process');
  3. var findVersions = require('find-versions');
  4. module.exports = function (bin, cb) {
  5. childProcess.exec(bin + ' --version', function (err, stdout, stderr) {
  6. if (err) {
  7. if (err.code === 'ENOENT') {
  8. err.message = 'Couldn\'t find the `' + bin + '` binary. Make sure it\'s installed and in your $PATH';
  9. }
  10. return cb(err);
  11. }
  12. cb(null, findVersions(stdout.trim() || stderr.trim(), {loose: true})[0]);
  13. });
  14. };