1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const lint_1 = require("./lint");
|
7 | const output_1 = require("./output");
|
8 | const path_1 = __importDefault(require("path"));
|
9 | const fs_1 = require("fs");
|
10 | async function command(options) {
|
11 | var _a, _b, _c, _d, _e;
|
12 | const fix = (_a = options.fix) !== null && _a !== void 0 ? _a : false;
|
13 | const workspace = (_b = options.workspace) !== null && _b !== void 0 ? _b : process.cwd();
|
14 | const configFile = options.configFile ? path_1.default.join(process.cwd(), options.configFile) : options.configFile;
|
15 | const format = (_c = options.format) !== null && _c !== void 0 ? _c : 'standard';
|
16 | const color = (_d = options.color) !== null && _d !== void 0 ? _d : true;
|
17 | const problemOnly = (_e = options.problemOnly) !== null && _e !== void 0 ? _e : false;
|
18 | const reports = await lint_1.lint({
|
19 | files: options.files,
|
20 | sourceCodes: options.codes,
|
21 | workspace,
|
22 | config: configFile,
|
23 | fix,
|
24 | rulesAutoResolve: true,
|
25 | });
|
26 | if (fix) {
|
27 | for (const report of reports) {
|
28 | fs_1.writeFile(report.filePath, report.fixedCode, { encoding: 'utf8' }, err => {
|
29 | if (err) {
|
30 | throw err;
|
31 | }
|
32 | process.stdout.write(`markuplint: Fix "${report.filePath}"\n`);
|
33 | });
|
34 | }
|
35 | }
|
36 | else {
|
37 | for (const result of reports) {
|
38 | await output_1.output({
|
39 | filePath: result.filePath,
|
40 | reports: result.results,
|
41 | html: result.sourceCode,
|
42 | format,
|
43 | color,
|
44 | problemOnly,
|
45 | });
|
46 | }
|
47 | }
|
48 | }
|
49 | exports.command = command;
|