forked from trustwallet/assets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-format.ts
More file actions
51 lines (45 loc) · 1.54 KB
/
json-format.ts
File metadata and controls
51 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { chainsPath } from "../generic/repo-structure";
import { findFiles } from "../generic/filesystem";
import { ActionInterface, CheckStepInterface } from "../generic/interface";
import { formatJsonFile, isValidJSON } from "../generic/json";
import * as bluebird from "bluebird";
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})`);
}
export class JsonAction implements ActionInterface {
getName(): string { return "Json files"; }
getSanityChecks(): CheckStepInterface[] {
return [
{
getName: () => { return "Check all JSON files to have valid content"},
check: async () => {
const errors: string[] = [];
const files = [
...findFiles(chainsPath, 'json'),
];
await bluebird.each(files, async file => {
if (!isValidJSON(file)) {
errors.push(`${file} path contains invalid JSON`);
}
});
return [errors, []];
}
},
];
}
async sanityFix(): Promise<void> {
await formatInfos();
}
}