* Checks the line endings of the API extractor report. * Exits with status code 1 if the line endings don't match the * API Extractor config. * @param config {ExtractorConfig}
(config)
| 61 | * @param config {ExtractorConfig} |
| 62 | */ |
| 63 | function checkLineEndings(config) { |
| 64 | const report = fs.readFileSync(config.reportFilePath); |
| 65 | |
| 66 | const LF = '\n'; |
| 67 | const CRLF = '\r\n'; |
| 68 | |
| 69 | const containsLf = report.includes(LF); |
| 70 | const containsCrLf = report.includes(CRLF); |
| 71 | |
| 72 | const relativeReportPath = path.relative( |
| 73 | process.cwd(), |
| 74 | config.reportFilePath, |
| 75 | ); |
| 76 | |
| 77 | if (config.newlineKind === LF && containsCrLf) { |
| 78 | exit( |
| 79 | `${relativeReportPath} contains CRLF.`, |
| 80 | `Please convert its line endings to LF.`, |
| 81 | ); |
| 82 | } |
| 83 | if (config.newlineKind === CRLF && containsLf && !containsCrLf) { |
| 84 | exit( |
| 85 | `${relativeReportPath} contains LF.`, |
| 86 | `Please convert its line endings to CRLF.`, |
| 87 | ); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Finds and loads the API Extractor config relative to the |