sonar-web-frontend-reporters
Version:
sreporter is a Command-Line Interface to generate Front-End linters reporters for the SonarQube plugin
75 lines (60 loc) • 2.61 kB
JavaScript
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/* eslint no-console:off */
var fs = require('fs'),
chalk = require('chalk'),
ReporterType = require('./reporter.enum'),
ReporterFactory = require('./reporter.factory');
var CLIEngine =
/*#__PURE__*/
function () {
/**
* Instantiate a new CLIEngine
*
* @param {string=} [config=./.sreporterrc] Use configuration from this file. Defaults to ./.sreporterrc.
*/
function CLIEngine() {
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : './.sreporterrc';
_classCallCheck(this, CLIEngine);
if (!fs.existsSync(config)) {
throw new Error("".concat(config, " file is missing"));
}
this.options = JSON.parse(fs.readFileSync(config, 'utf8'));
}
/**
* Launch the Sonar Web Front-End Reporters.
* It automatically launch reporters registered under `ReporterType`.
*/
_createClass(CLIEngine, [{
key: "launchReporters",
value: function launchReporters() {
var _this = this;
Object.keys(ReporterType).forEach(function (key) {
return _this.launch(ReporterType[key], _this.options);
});
}
/**
* Launch a reporter.
*
* @param {ReporterType} type Type of the reporter to be launched
* @param {Object} options `.sreporterrc` file content
*/
}, {
key: "launch",
value: function launch(type, options) {
var opts = options[type],
reporter = ReporterFactory.create(type, opts, options.projectName);
if (opts) {
reporter.launch(function () {
console.info(chalk.green("\u2714 ".concat(chalk.green.bold(reporter.linterName), " has been generated under ").concat(opts.report)));
});
} else {
console.info(chalk.gray("- ".concat(chalk.gray.bold(reporter.linterName), " has been ignored")));
}
}
}]);
return CLIEngine;
}();
module.exports = CLIEngine;
;