cloudflare/Azure-Sentinel
Publicmirrored fromhttps://github.com/cloudflare/Azure-Sentinel
.script/jsonFileValidator.ts
24lines · modecode
| 1 | import { runCheckOverChangedFiles } from "./utils/changedFilesValidator"; |
| 2 | import { ExitCode } from "./utils/exitCode"; |
| 3 | import fs from "fs"; |
| 4 | import * as logger from "./utils/logger"; |
| 5 | |
| 6 | export async function IsValidJsonFile(filePath: string): Promise<ExitCode> { |
| 7 | JSON.parse(fs.readFileSync(filePath, "utf8")); |
| 8 | return ExitCode.SUCCESS; |
| 9 | } |
| 10 | |
| 11 | let fileTypeSuffixes = ["json"]; |
| 12 | let CheckOptions = { |
| 13 | onCheckFile: (filePath: string) => { |
| 14 | return IsValidJsonFile(filePath); |
| 15 | }, |
| 16 | onExecError: async (e: any, filePath: string) => { |
| 17 | console.log(`Incorrect Json file. File path: ${filePath}. Error message: ${e.message}`); |
| 18 | }, |
| 19 | onFinalFailed: async () => { |
| 20 | logger.logError("An error occurred, please open an issue"); |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | runCheckOverChangedFiles(CheckOptions, fileTypeSuffixes); |