codacy-seed
Version:
Library to create Codacy Tools in Typescript
47 lines • 2.39 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const fileUtils_1 = require("./fileUtils");
const parseTimeoutSeconds_1 = require("./parseTimeoutSeconds");
const resultString_1 = require("./resultString");
const withDefaultParameters_1 = require("./withDefaultParameters");
function runImpl(engine) {
return __awaiter(this, void 0, void 0, function* () {
const jsonSpecification = yield (0, fileUtils_1.readJsonFile)("/docs/patterns.json");
const specificaiton = jsonSpecification
? (0, fileUtils_1.parseSpecification)(jsonSpecification)
: undefined;
const jsonCodacyrc = yield (0, fileUtils_1.readJsonFile)("/.codacyrc");
const codacyrc = jsonCodacyrc ? (0, fileUtils_1.parseCodacyrcFile)(jsonCodacyrc) : undefined;
// Creates a new configuration with default parameters when they are not present on the codacyrc
const codacyrcWithDefaults = codacyrc
? (0, withDefaultParameters_1.withDefaultParameters)(codacyrc, specificaiton)
: undefined;
const toolResults = yield engine(codacyrcWithDefaults);
const lines = (0, resultString_1.resultString)(toolResults);
console.log(lines);
});
}
function run(engine) {
const timeoutHandle = setTimeout(() => {
console.error("Timeout occurred. Exiting.");
process.exit(2);
}, (0, parseTimeoutSeconds_1.parseTimeoutSeconds)(process.env.TIMEOUT_SECONDS) * 1000);
runImpl(engine)
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => clearTimeout(timeoutHandle));
}
exports.run = run;
//# sourceMappingURL=run.js.map