Pop-up dictionary browser extension for language learning. Successor to Yomichan. (PERSONAL FORK)
1/*
2 * Copyright (C) 2023-2025 Yomitan Authors
3 * Copyright (C) 2020-2022 Yomichan Authors
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19import fs from 'fs';
20import {performance} from 'perf_hooks';
21import {parseJson} from '../../ext/js/core/json.js';
22import {createJsonSchema} from '../schema-validate.js';
23
24/** */
25function main() {
26 const args = process.argv.slice(2);
27 if (args.length < 2) {
28 console.log([
29 'Usage:',
30 ' node schema-validate [--ajv] <schema-file-name> <data-file-names>...',
31 ].join('\n'));
32 return;
33 }
34
35 /** @type {import('dev/schema-validate').ValidateMode} */
36 let mode = null;
37 if (args[0] === '--ajv') {
38 mode = 'ajv';
39 args.splice(0, 1);
40 }
41
42 const schemaSource = fs.readFileSync(args[0], {encoding: 'utf8'});
43 const schema = parseJson(schemaSource);
44
45 for (const dataFileName of args.slice(1)) {
46 // eslint-disable-next-line no-restricted-syntax
47 const start = performance.now();
48 try {
49 console.log(`Validating ${dataFileName}...`);
50 const dataSource = fs.readFileSync(dataFileName, {encoding: 'utf8'});
51 const data = parseJson(dataSource);
52 createJsonSchema(mode, schema).validate(data);
53 // eslint-disable-next-line no-restricted-syntax
54 const end = performance.now();
55 console.log(`No issues detected (${((end - start) / 1000).toFixed(2)}s)`);
56 } catch (e) {
57 // eslint-disable-next-line no-restricted-syntax
58 const end = performance.now();
59 console.log(`Encountered an error (${((end - start) / 1000).toFixed(2)}s)`);
60 console.warn(e);
61 }
62 }
63}
64
65
66main();