index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use strict';
  2. const pkgInfo = require('../package.json');
  3. const helper = require('./helper');
  4. const Releases = require('./releases');
  5. const install = require('./install');
  6. /**
  7. * Interface to and wrapper around the `sentry-cli` executable.
  8. *
  9. * Commands are grouped into namespaces. See the respective namespaces for more
  10. * documentation. To use this wrapper, simply create an instance and call methods:
  11. *
  12. * @example
  13. * const cli = new SentryCli();
  14. * console.log(SentryCli.getVersion());
  15. *
  16. * @example
  17. * const cli = new SentryCli('path/to/custom/sentry.properties');
  18. * const release = await cli.releases.proposeVersion());
  19. * console.log(release);
  20. */
  21. class SentryCli {
  22. /**
  23. * Creates a new `SentryCli` instance.
  24. *
  25. * If the `configFile` parameter is specified, configuration located in the default
  26. * location and the value specified in the `SENTRY_PROPERTIES` environment variable is
  27. * overridden.
  28. *
  29. * @param {string} [configFile] Relative or absolute path to the configuration file.
  30. * @param {Object} [options] More options to pass to the CLI
  31. */
  32. constructor(configFile, options) {
  33. if (typeof configFile === 'string') {
  34. this.configFile = configFile;
  35. }
  36. this.options = options || { silent: false };
  37. this.releases = new Releases({ ...this.options, configFile });
  38. }
  39. /**
  40. * Returns the version of the installed `sentry-cli` binary.
  41. * @returns {string}
  42. */
  43. static getVersion() {
  44. return pkgInfo.version;
  45. }
  46. /**
  47. * Returns an absolute path to the `sentry-cli` binary.
  48. * @returns {string}
  49. */
  50. static getPath() {
  51. return helper.getPath();
  52. }
  53. /**
  54. * Downloads the CLI binary.
  55. * @param {any} [configFile] Optional logger to log installation information. Defaults to printing to the terminal.
  56. * @returns {Promise<void>}
  57. */
  58. static downloadBinary(logger) {
  59. return install.downloadBinary(logger);
  60. }
  61. /**
  62. * See {helper.execute} docs.
  63. * @param {string[]} args Command line arguments passed to `sentry-cli`.
  64. * @param {boolean} live We inherit stdio to display `sentry-cli` output directly.
  65. * @returns {Promise.<string>} A promise that resolves to the standard output.
  66. */
  67. execute(args, live) {
  68. return helper.execute(args, live, this.options.silent, this.configFile, this.options);
  69. }
  70. }
  71. module.exports = SentryCli;