forked from mui/base-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonlint.mjs
47 lines (40 loc) · 1.36 KB
/
jsonlint.mjs
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
/* eslint-disable no-console */
import chalk from 'chalk';
import fse from 'fs-extra';
import { globby } from 'globby';
import path from 'path';
import { getWorkspaceRoot } from './utils.mjs';
const passMessage = (message) => `✓ ${chalk.gray(message)}`;
const failMessage = (message) => `✗ ${chalk.whiteBright(message)}`;
async function run() {
const workspaceRoot = getWorkspaceRoot();
const eslintignoreContent = await fse.readFile(path.join(workspaceRoot, '.eslintignore'), {
encoding: 'utf8',
});
const eslintignore = eslintignoreContent.split(/\r?\n/).filter(Boolean);
const filenames = await globby('**/*.json', {
cwd: workspaceRoot,
gitignore: true,
ignore: [...eslintignore, '**/tsconfig*.json'],
followSymbolicLinks: false,
});
let passed = true;
const checks = filenames.map(async (filename) => {
const content = await fse.readFile(path.join(workspaceRoot, filename), { encoding: 'utf8' });
try {
JSON.parse(content);
console.log(passMessage(filename));
} catch (error) {
passed = false;
console.error(failMessage(`Error parsing ${filename}:\n\n${String(error)}`));
}
});
await Promise.allSettled(checks);
if (passed === false) {
throw new Error('At least one file did not pass. Check the console output');
}
}
run().catch((error) => {
console.error(error);
process.exit(1);
});