CodeCommitsIssuesPull requestsActionsInsightsSecurity
19bbc8653b3f9467f062295411a42fee398a97b8

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.script/jsonFileValidator.ts

25lines · modecode

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