forked from quizlet/ts-migration
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathignoreFileErrorsRunner.js
55 lines (55 loc) · 2.88 KB
/
ignoreFileErrorsRunner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"use strict";
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ERROR_COMMENT = void 0;
const lodash_1 = require("lodash");
const fs_1 = require("fs");
const commitAll_1 = __importDefault(require("./commitAll"));
const tsCompilerHelpers_1 = require("./tsCompilerHelpers");
exports.ERROR_COMMENT = "// @quizlet-ts-ignore-errors:";
const successFiles = [];
const errorFiles = [];
function run(paths, shouldCommit) {
return __awaiter(this, void 0, void 0, function* () {
const diagnostics = yield (0, tsCompilerHelpers_1.getDiagnostics)(paths);
const diagnosticsWithFile = diagnostics.filter(d => !!d.file);
const diagnosticsGroupedByFile = (0, lodash_1.groupBy)(diagnosticsWithFile, d => d.file.fileName);
Object.keys(diagnosticsGroupedByFile).forEach((fileName, i, arr) => __awaiter(this, void 0, void 0, function* () {
const fileDiagnostics = diagnosticsGroupedByFile[fileName];
console.log(`${i} of ${arr.length - 1}: Ignoring ${fileDiagnostics.length} ts-error(s) in ${fileName}`);
try {
const filePath = (0, tsCompilerHelpers_1.getFilePath)(paths, fileDiagnostics[0]);
let codeSplitByLine = (0, fs_1.readFileSync)(filePath, "utf8").split("\n");
codeSplitByLine.unshift(`${exports.ERROR_COMMENT}${fileDiagnostics.length}`);
const fileData = codeSplitByLine.join("\n");
(0, fs_1.writeFileSync)(filePath, fileData);
successFiles.push(fileName);
}
catch (e) {
console.log(e);
errorFiles.push(fileName);
}
}));
if (shouldCommit) {
yield (0, commitAll_1.default)("Ignore File Errors", paths);
}
console.log(`${successFiles.length} files with errors ignored successfully.`);
if (errorFiles.length) {
console.log(`Error checking for ignored type errors in ${errorFiles.length} files:`);
console.log(errorFiles);
}
});
}
exports.default = run;
//# sourceMappingURL=ignoreFileErrorsRunner.js.map