UNPKG

textlint

Version:

The pluggable linting tool for text and markdown.

58 lines (56 loc) 2.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.printResults = exports.showEmptyRuleWarning = void 0; const logger_1 = require("./util/logger"); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const showEmptyRuleWarning = () => { logger_1.Logger.log(` == No rules found, textlint hasn’t done anything == Possible reasons: * Your textlint config file has no rules. * You have no config file and you aren’t passing rules via command line. * Your textlint config has a syntax error. => How to set up rules? https://github.com/textlint/textlint/blob/master/docs/configuring.md `); }; exports.showEmptyRuleWarning = showEmptyRuleWarning; /** * Print results of lining text. * @param {string} output the output text which is formatted by {@link TextLintEngine.formatResults} * @param {object} options cli option object {@lint ./options.js} * @returns {boolean} does print result success? */ function printResults(output, options) { if (!output) { return true; } const outputFile = options.outputFile; if (outputFile) { const filePath = path_1.default.resolve(process.cwd(), outputFile); if (fs_1.default.existsSync(filePath) && fs_1.default.statSync(filePath).isDirectory()) { logger_1.Logger.error("Cannot write to output file path, it is a directory: %s", outputFile); return false; } try { fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true }); fs_1.default.writeFileSync(filePath, output); } catch (ex) { logger_1.Logger.error("There was a problem writing the output file:\n%s", ex); return false; } } else { logger_1.Logger.log(output); } return true; } exports.printResults = printResults; //# sourceMappingURL=cli-util.js.map