CodeCommitsIssuesPull requestsActionsInsightsSecurity
19bbc8653b3f9467f062295411a42fee398a97b8

Branches

Tags

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

Clone

HTTPS

Download ZIP

.script/yamlFileValidator.ts

26lines · modecode

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