UNPKG

@billy-briggs-dev/sonar

Version:

Created by Billy Briggs

50 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const child_process_1 = require("child_process"); const util_1 = require("util"); function sonarExecutor(options, _context) { var _a, _b, _c, _d; return tslib_1.__awaiter(this, void 0, void 0, function* () { if (!((_a = options === null || options === void 0 ? void 0 : options.project) === null || _a === void 0 ? void 0 : _a.settings)) { if (!((_b = options === null || options === void 0 ? void 0 : options.sonar) === null || _b === void 0 ? void 0 : _b.projectKey)) { throw new Error('Project Key is required! Please provide a project key in the sonar properties file or in the project.json.'); } if (!((_d = (_c = options === null || options === void 0 ? void 0 : options.sonar) === null || _c === void 0 ? void 0 : _c.host) === null || _d === void 0 ? void 0 : _d.url)) { throw new Error('Host Url is required! Please provide a host url in the sonar properties file or in the project.json.'); } } const args = []; getPathsAsStringArray(options).map((path) => { args.push(`-D${path.join('.')}=${getValueByPath(options, path)}`); }); console.info(`Executing "sonar-scanner"...`); console.info(`Options: ${JSON.stringify(options, null, 2)}`); const { stdout, stderr } = yield (0, util_1.promisify)(child_process_1.exec)(`sonar-scanner ${args.join(' ')}`); console.log(stdout); console.error(stderr); const success = !stderr; return { success }; }); } exports.default = sonarExecutor; // Get all paths as a string array in a nested object function getPathsAsStringArray(obj) { const paths = []; Object.keys(obj).map((key) => { if (typeof obj[key] === 'string') { paths.push([key]); } else if (typeof obj[key] === 'object') { getPathsAsStringArray(obj[key]).map((p) => { paths.push([key, ...p]); }); } }); return paths; } // Get nested value from object function getValueByPath(obj, path) { return path.reduce((o, k) => o[k], obj); } //# sourceMappingURL=executor.js.map