standard-commit
Version:
conventional commit
39 lines (38 loc) • 1.48 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const os_1 = require("os");
const ansi_colors_1 = __importDefault(require("ansi-colors"));
const lib_1 = require("../lib");
async function hook() {
try {
const edit = process.env.GIT_PARAMS || '.git/COMMIT_EDITMSG';
const load = (0, lib_1.loadConfig)();
const read = (0, lib_1.commitRead)({ edit });
const config = await load;
const commitmsg = await read;
const report = await (0, lib_1.commitLint)(commitmsg[0], config);
const header = commitmsg[0].split('\n')[0].trim();
if (report.errors.length > 0) {
process.stdout.write(ansi_colors_1.default.red(header));
}
else if (report.warnings.length > 0) {
process.stdout.write(ansi_colors_1.default.yellow(header));
}
else {
process.stdout.write(ansi_colors_1.default.blue(header));
}
const output = await (0, lib_1.commitFormatReport)(report);
process.stdout.write(output);
process.stdout.write(ansi_colors_1.default.reset(os_1.EOL));
process.exitCode = report.errors.length > 0 ? -1 : 0;
}
catch (err) {
// tslint:disable-next-line:no-console
console.error(err);
process.exitCode = -1;
}
}
hook();