summaryrefslogtreecommitdiff
path: root/dev/dictionary-validate.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-11-08 03:11:35 +0900
committerDarius Jahandarie <djahandarie@gmail.com>2023-11-08 03:23:17 +0900
commit0f4d36938fd0d844f548aa5a7f7e7842df8dfb41 (patch)
tree5b6be3620a557d0b9177047003f6d742d9d2a32d /dev/dictionary-validate.js
parentef79eab44bfd000792c610b968b5ceefd41e76a0 (diff)
Switch to vitest for ESM support; other fixes
Diffstat (limited to 'dev/dictionary-validate.js')
-rw-r--r--dev/dictionary-validate.js49
1 files changed, 8 insertions, 41 deletions
diff --git a/dev/dictionary-validate.js b/dev/dictionary-validate.js
index 0c926acc..eb40beda 100644
--- a/dev/dictionary-validate.js
+++ b/dev/dictionary-validate.js
@@ -16,12 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-const fs = require('fs');
-const path = require('path');
-const {performance} = require('perf_hooks');
-const {JSZip} = require('./util');
-const {createJsonSchema} = require('./schema-validate');
-
+import fs from 'fs';
+import JSZip from 'jszip';
+import path from 'path';
+import {performance} from 'perf_hooks';
+import {createJsonSchema} from './schema-validate.js';
function readSchema(relativeFileName) {
const fileName = path.join(__dirname, relativeFileName);
@@ -29,7 +28,6 @@ function readSchema(relativeFileName) {
return JSON.parse(source);
}
-
async function validateDictionaryBanks(mode, zip, fileNameFormat, schema) {
let jsonSchema;
try {
@@ -57,7 +55,7 @@ async function validateDictionaryBanks(mode, zip, fileNameFormat, schema) {
}
}
-async function validateDictionary(mode, archive, schemas) {
+export async function validateDictionary(mode, archive, schemas) {
const fileName = 'index.json';
const indexFile = archive.files[fileName];
if (!indexFile) {
@@ -82,7 +80,7 @@ async function validateDictionary(mode, archive, schemas) {
await validateDictionaryBanks(mode, archive, 'tag_bank_?.json', schemas.tagBankV3);
}
-function getSchemas() {
+export function getSchemas() {
return {
index: readSchema('../ext/data/schemas/dictionary-index-schema.json'),
kanjiBankV1: readSchema('../ext/data/schemas/dictionary-kanji-bank-v1-schema.json'),
@@ -95,8 +93,7 @@ function getSchemas() {
};
}
-
-async function testDictionaryFiles(mode, dictionaryFileNames) {
+export async function testDictionaryFiles(mode, dictionaryFileNames) {
const schemas = getSchemas();
for (const dictionaryFileName of dictionaryFileNames) {
@@ -115,33 +112,3 @@ async function testDictionaryFiles(mode, dictionaryFileNames) {
}
}
}
-
-
-async function main() {
- const dictionaryFileNames = process.argv.slice(2);
- if (dictionaryFileNames.length === 0) {
- console.log([
- 'Usage:',
- ' node dictionary-validate [--ajv] <dictionary-file-names>...'
- ].join('\n'));
- return;
- }
-
- let mode = null;
- if (dictionaryFileNames[0] === '--ajv') {
- mode = 'ajv';
- dictionaryFileNames.splice(0, 1);
- }
-
- await testDictionaryFiles(mode, dictionaryFileNames);
-}
-
-
-if (require.main === module) { main(); }
-
-
-module.exports = {
- getSchemas,
- validateDictionary,
- testDictionaryFiles
-};