2020-09-23 13:47:24 +00:00
|
|
|
import { chainsPath } from "../generic/repo-structure";
|
|
|
|
import { findFiles } from "../generic/filesystem";
|
|
|
|
import { ActionInterface, CheckStepInterface } from "../generic/interface";
|
2021-03-08 10:38:22 +00:00
|
|
|
import { formatJsonFile, isValidJSON } from "../generic/json";
|
2020-08-06 19:17:38 +00:00
|
|
|
import * as bluebird from "bluebird";
|
|
|
|
|
2021-03-08 10:38:22 +00:00
|
|
|
async function formatInfos(): Promise<void> {
|
|
|
|
console.log(`Formatting json files...`);
|
|
|
|
|
|
|
|
const files = [
|
|
|
|
...findFiles(chainsPath, 'json'),
|
|
|
|
];
|
|
|
|
let count1 = 0;
|
|
|
|
let count2 = 0;
|
|
|
|
await bluebird.each(files, async (file) => {
|
|
|
|
if (formatJsonFile(file)) {
|
|
|
|
++count2;
|
|
|
|
}
|
|
|
|
++count1;
|
|
|
|
});
|
|
|
|
console.log(`Formatted ${count2} json files (total ${count1})`);
|
|
|
|
}
|
|
|
|
|
2020-08-06 19:17:38 +00:00
|
|
|
export class JsonAction implements ActionInterface {
|
|
|
|
getName(): string { return "Json files"; }
|
|
|
|
|
2020-08-10 08:56:41 +00:00
|
|
|
getSanityChecks(): CheckStepInterface[] {
|
2020-08-06 19:17:38 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
getName: () => { return "Check all JSON files to have valid content"},
|
|
|
|
check: async () => {
|
2020-09-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
const files = [
|
|
|
|
...findFiles(chainsPath, 'json'),
|
|
|
|
];
|
|
|
|
|
|
|
|
await bluebird.each(files, async file => {
|
|
|
|
if (!isValidJSON(file)) {
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.push(`${file} path contains invalid JSON`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
2020-09-16 12:52:10 +00:00
|
|
|
return [errors, []];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
2021-03-08 10:38:22 +00:00
|
|
|
|
|
|
|
async sanityFix(): Promise<void> {
|
|
|
|
await formatInfos();
|
|
|
|
}
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|