UNPKG

typescript-assistant

Version:

Combines and integrates professional Typescript tools into your project

52 lines 2.42 kB
"use strict"; // pre-commit makes sure the changed code is formatted and linted. // // Rationale: // - Fixing formatting and linting errors are always fast and easy to fix. // - This prevents over-complicated merge conflicts // - This prevents small formatting/linting fix commits 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.createPreCommitCommand = createPreCommitCommand; const util_1 = require("../util"); function createPreCommitCommand(deps) { const { logger, linter, git, formatter } = deps; return { execute() { return __awaiter(this, arguments, void 0, function* (options = {}) { let { format = true } = options; let files = (yield git.findChangedFiles()).filter(util_1.isTypescriptFile); let lintFiles = () => { return linter.lintOnce(false, files); }; if (format) { if (!(yield formatter.verifyFiles(files))) { logger.log("hooks", "Not all files were formatted, Hint: run `npm run fix`"); process.exit(1); } else { logger.log("hooks", "All files were formatted"); } } let result = yield lintFiles(); if (result) { logger.log("hooks", `All ${files.length} files were linted`); process.exit(0); } else { logger.log("hooks", "There were linting errors"); process.exit(1); } }); }, }; } //# sourceMappingURL=pre-commit.js.map