UNPKG

3.06 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var __metadata = (this && this.__metadata) || function (k, v) {
9 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10};
11var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13 return new (P || (P = Promise))(function (resolve, reject) {
14 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17 step((generator = generator.apply(thisArg, _arguments || [])).next());
18 });
19};
20Object.defineProperty(exports, "__esModule", { value: true });
21exports.CommitmsgCommand = void 0;
22const clipanion_1 = require("clipanion");
23const code_commitlint_1 = require("@monstrs/code-commitlint");
24class CommitmsgCommand extends clipanion_1.Command {
25 execute() {
26 return __awaiter(this, void 0, void 0, function* () {
27 const messages = yield code_commitlint_1.read({ edit: true });
28 const results = yield Promise.all(messages.map(code_commitlint_1.lint));
29 const report = results.reduce((info, result) => ({
30 valid: result.valid ? info.valid : false,
31 errorCount: info.errorCount + result.errors.length,
32 warningCount: info.warningCount + result.warnings.length,
33 results: [...info.results, result],
34 }), {
35 valid: true,
36 errorCount: 0,
37 warningCount: 0,
38 results: [],
39 });
40 const output = code_commitlint_1.format(report, {
41 helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
42 });
43 if (output !== '') {
44 this.context.stdout.write(output);
45 }
46 if (!report.valid) {
47 process.exit(1);
48 }
49 });
50 }
51}
52__decorate([
53 clipanion_1.Command.Path(`commitmsg`),
54 __metadata("design:type", Function),
55 __metadata("design:paramtypes", []),
56 __metadata("design:returntype", Promise)
57], CommitmsgCommand.prototype, "execute", null);
58exports.CommitmsgCommand = CommitmsgCommand;