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