diff --git a/README.md b/README.md index e76a026f..8e8f8553 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # Error Codes -[![NPM Version](https://img.shields.io/npm/v/%40atoska21k%2Ferror-codes)](https://www.npmjs.com/package/@atoska21/error-codes) Translated JSON files for known error codes used by the Wii U and 3DS @@ -75,9 +74,3 @@ Each file starts with 1 or 2 objects, each with 1 key each. The first object key | `long_solution` | A longer, more detailed, solution for the error. Intended to be used by the website. Markdown | | `support_link` | Link to a relevant support page for the error. Typically the website, but does not have to be | -### Utility functions -The main purpose of this repository is to maintain the JSON translation files. However 2 utility functions are also included for JavaScript/TypeScript projects. - -- `getModuleInfo(sysmodule, locale)` - Returns the module information for the locale, or `null` if not found -- `getErrorInfo(sysmodule, code, locale)` - Returns the error information (including the module information) for the locale. Returns null if either the module or error code is not found -- `getAllErrors()` - Returns an array of all error codes for all modules in the form `MODULE-CODE` diff --git a/format.sh b/format.sh deleted file mode 100644 index 8ed2ab0d..00000000 --- a/format.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# This script processes all files in the data directory using jq to: -# - Ensure all JSON files are formatted correctly with tabs -# - Catch any JSON files with syntax errors and log them to error.log for fixing - -# Remove any existing error log -rm -f error.log - -# Enable recursive globbing -shopt -s globstar - -# Process files in parallel using xargs -find data -type f -name "*.json" | xargs -n 1 -P "$(nproc)" -I {} bash -c ' - file="{}" - echo "Processing file: $file" - jq --tab -j . <"$file" >"$file.out" 2>"$file.err" - if [ $? -eq 0 ]; then - mv "$file.out" "$file" - rm "$file.err" - else - echo "$file.err" >> error.log - rm "$file.out" - fi -' - -# Print any files that failed to process -if [ -f error.log ] && [ "$(cat error.log | wc -l)" -gt 0 ]; then - echo "The following files failed to process:" - cat error.log | sed 's/^/ - /' -else - echo "All files processed successfully." -fi diff --git a/index.js b/index.js deleted file mode 100644 index 34262a1b..00000000 --- a/index.js +++ /dev/null @@ -1,78 +0,0 @@ -const path = require('node:path'); -const fs = require('node:fs'); - -function getModuleInfo(sysmodule, locale) { - const localePath = path.join(__dirname, 'data', sysmodule, `${locale.replace('-', '_')}.json`); - const defaultPath = path.join(__dirname, 'data', sysmodule, 'en_US.json'); - let content; - - if (fs.existsSync(localePath)) { - content = fs.readFileSync(localePath, { - encoding: 'utf8' - }); - } else if (fs.existsSync(defaultPath)) { - content = fs.readFileSync(defaultPath, { - encoding: 'utf8' - }); - } else { - return null; - } - - return JSON.parse(content); -} - -function getErrorInfo(sysmodule, code, locale) { - const moduleInfo = getModuleInfo(sysmodule, locale); - - if (!moduleInfo) { - return null; - } - - const localePath = path.join(__dirname, 'data', sysmodule, code, `${locale.replace('-', '_')}.json`); - const defaultPath = path.join(__dirname, 'data', sysmodule, code, 'en_US.json'); - let content; - - if (fs.existsSync(localePath)) { - content = fs.readFileSync(localePath, { - encoding: 'utf8' - }); - } else if (fs.existsSync(defaultPath)) { - content = fs.readFileSync(defaultPath, { - encoding: 'utf8' - }); - } else { - return null; - } - - const errorInfo = JSON.parse(content)[sysmodule][code]; - - errorInfo.module = moduleInfo[sysmodule]; - - return errorInfo; -} - -function getAllErrors() { - const errors = []; - - const modules = fs.readdirSync(path.join(__dirname, 'data'), { withFileTypes: true }); - - for (const moduleDirent of modules) { - if (moduleDirent.isDirectory()) { - const errorCodes = fs.readdirSync(path.join(__dirname, 'data', moduleDirent.name), { withFileTypes: true }); - - for (const errorDirent of errorCodes) { - if (errorDirent.isDirectory()) { - errors.push(`${moduleDirent.name}-${errorDirent.name}`); - } - } - } - } - - return errors; -} - -module.exports = { - getModuleInfo, - getErrorInfo, - getAllErrors -}; \ No newline at end of file diff --git a/json-file-fix.mjs b/json-file-fix.mjs deleted file mode 100644 index 12351043..00000000 --- a/json-file-fix.mjs +++ /dev/null @@ -1,71 +0,0 @@ -import fs from 'fs'; -import path from 'path'; - -// This script does a number of things: -// - Normalises the descriptions and solutions to be "Unknown cause." and "Unknown solution." rather than "N/A" -// - If one of the descriptions or solutions is "Unknown cause." or "Unknown solution.", the other will be copied to it -// - Ensures all descriptions and solutions end with a full stop if they do not already and if the last character is a letter -// - Writes the changes back to the file in place - -const arg = process.argv[2]; -if (!arg || !fs.existsSync(arg) || !fs.lstatSync(arg).isDirectory()) { - console.log("Please provide a valid directory path."); - process.exit(1); -} - -fs.readdirSync(arg, { recursive: true, withFileTypes: true }).forEach(file => { - if (!file.isFile() && !file.name.endsWith(".json")) return; - - const fullPath = path.join(file.parentPath, file.name); - - console.log(`Processing ${fullPath}`); - - const data = fs.readFileSync(fullPath, 'utf8'); - const json = JSON.parse(data); - - const key1 = Object.keys(json)[0]; - const key2 = Object.keys(json[key1])[0]; - - const errorObject = json[key1][key2]; - if (!errorObject || typeof errorObject !== "object") { - console.log(`No error object found in ${fullPath}`); - return; - } - - if (!errorObject["short_description"] || !errorObject["long_description"] || !errorObject["short_solution"] || !errorObject["long_solution"]) { - console.log(`Missing fields in ${fullPath}`); - return; - } - - const { - short_description, - long_description, - short_solution, - long_solution, - } = errorObject; - - if (short_description === "Unknown cause." && long_description !== "Unknown cause.") { - errorObject["short_description"] = long_description; - } else if (short_description !== "Unknown cause." && long_description === "Unknown cause.") { - errorObject["long_description"] = short_description; - } - - if (short_solution === "Unknown solution." && long_solution !== "Unknown solution.") { - errorObject["short_solution"] = long_solution; - } else if (short_solution !== "Unknown solution." && long_solution === "Unknown solution.") { - errorObject["long_solution"] = short_solution; - } - - const keys = ["short_description", "long_description", "short_solution", "long_solution"]; - - // Ensure all end with a full stop - keys.forEach(key => { - const value = errorObject[key]; - // If the value does not end with a full stop and the last character is a letter, add a full stop - if (value && !value.endsWith(".") && /[A-Za-z]$/.test(value)) { - errorObject[key] = value + "."; - } - }); - - fs.writeFileSync(fullPath, JSON.stringify(json, null, "\t")); -}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 2faa9f36..00000000 --- a/package-lock.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "@atoska21/error-codes", - "version": "1.1.0", - "lockfileVersion": 2, - "requires": true, - "packages": { - "": { - "name": "@atoska21/error-codes", - "version": "1.1.0" - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index ef417b75..00000000 --- a/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "@atoska21/error-codes", - "version": "1.1.0", - "description": "Translated error code information for the Wii U and 3DS", - "main": "index.js", - "files": [ - "index.js", - "data" - ] -}