| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c1c022f commit c7de568
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,6 @@ | |||
| 51 | 51 | "@types/node": "latest", | |
| 52 | 52 | "@types/source-map-support": "latest", | |
| 53 | 53 | "@types/which": "^2.0.1", | |
| 54 | - "@types/xml2js": "^0.4.11", | ||
| 55 | 54 | "@typescript-eslint/eslint-plugin": "^5.33.1", | |
| 56 | 55 | "@typescript-eslint/parser": "^5.33.1", | |
| 57 | 56 | "@typescript-eslint/utils": "^5.33.1", | |
@@ -67,10 +66,11 @@ | |||
| 67 | 66 | "eslint-plugin-jsdoc": "^39.3.6", | |
| 68 | 67 | "eslint-plugin-local": "^1.0.0", | |
| 69 | 68 | "eslint-plugin-no-null": "^1.0.2", | |
| 69 | + "fast-xml-parser": "^4.0.11", | ||
| 70 | 70 | "fs-extra": "^9.1.0", | |
| 71 | 71 | "glob": "latest", | |
| 72 | - "jsonc-parser": "^3.2.0", | ||
| 73 | 72 | "hereby": "^1.5.0", | |
| 73 | + "jsonc-parser": "^3.2.0", | ||
| 74 | 74 | "minimist": "latest", | |
| 75 | 75 | "mkdirp": "latest", | |
| 76 | 76 | "mocha": "latest", | |
@@ -79,8 +79,7 @@ | |||
| 79 | 79 | "node-fetch": "^3.2.10", | |
| 80 | 80 | "source-map-support": "latest", | |
| 81 | 81 | "typescript": "^4.8.4", | |
| 82 | - "which": "^2.0.2", | ||
| 83 | - "xml2js": "^0.4.23" | ||
| 82 | + "which": "^2.0.2" | ||
| 84 | 83 | }, | |
| 85 | 84 | "scripts": { | |
| 86 | 85 | "test": "hereby runtests-parallel --light=false", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,26 @@ | |||
| 1 | 1 | import fs from "fs"; | |
| 2 | 2 | import path from "path"; | |
| 3 | - import xml2js from "xml2js"; | ||
| 4 | - import util from "util"; | ||
| 5 | - | ||
| 6 | - const parseString = util.promisify(xml2js.parseString); | ||
| 3 | + import { XMLParser } from "fast-xml-parser" | ||
| 4 | + | ||
| 5 | + /** @typedef {{ | ||
| 6 | + LCX: { | ||
| 7 | + $_TgtCul: string; | ||
| 8 | + Item: { | ||
| 9 | + Item: { | ||
| 10 | + Item: { | ||
| 11 | + $_ItemId: string; | ||
| 12 | + Str: { | ||
| 13 | + Val: string; | ||
| 14 | + Tgt: { | ||
| 15 | + Val: string; | ||
| 16 | + }; | ||
| 17 | + }; | ||
| 18 | + }[]; | ||
| 19 | + }; | ||
| 20 | + }; | ||
| 21 | + } | ||
| 22 | + }} ParsedLCL */ | ||
| 23 | + void 0; | ||
| 7 | 24 | ||
| 8 | 25 | async function main() { | |
| 9 | 26 | const args = process.argv.slice(2); | |
@@ -31,15 +48,16 @@ async function main() { | |||
| 31 | 48 | */ | |
| 32 | 49 | async function visitDirectory(name) { | |
| 33 | 50 | const inputFilePath = path.join(inputPath, name, "diagnosticMessages", "diagnosticMessages.generated.json.lcl"); | |
| 34 | - const contents = await fs.promises.readFile(inputFilePath, "utf-8"); | ||
| 35 | - const result = await parseString(contents); | ||
| 36 | - if (!result || !result.LCX || !result.LCX.$ || !result.LCX.$.TgtCul) { | ||
| 37 | - console.error("Unexpected XML file structure. Expected to find result.LCX.$.TgtCul."); | ||
| 51 | + const contents = await fs.promises.readFile(inputFilePath); | ||
| 52 | + /** @type {ParsedLCL} */ | ||
| 53 | + const result = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "$_"}).parse(contents); | ||
| 54 | + if (!result || !result.LCX || !result.LCX.$_TgtCul) { | ||
| 55 | + console.error("Unexpected XML file structure. Expected to find result.LCX.$_TgtCul."); | ||
| 38 | 56 | process.exit(1); | |
| 39 | 57 | } | |
| 40 | - const outputDirectoryName = getPreferredLocaleName(result.LCX.$.TgtCul).toLowerCase(); | ||
| 58 | + const outputDirectoryName = getPreferredLocaleName(result.LCX.$_TgtCul).toLowerCase(); | ||
| 41 | 59 | if (!outputDirectoryName) { | |
| 42 | - console.error(`Invalid output locale name for '${result.LCX.$.TgtCul}'.`); | ||
| 60 | + console.error(`Invalid output locale name for '${result.LCX.$_TgtCul}'.`); | ||
| 43 | 61 | process.exit(1); | |
| 44 | 62 | } | |
| 45 | 63 | await writeFile(path.join(outputPath, outputDirectoryName, "diagnosticMessages.generated.json"), xmlObjectToString(result)); | |
@@ -77,14 +95,14 @@ async function main() { | |||
| 77 | 95 | } | |
| 78 | 96 | ||
| 79 | 97 | /** | |
| 80 | - * @param {any} o | ||
| 98 | + * @param {ParsedLCL} o | ||
| 81 | 99 | */ | |
| 82 | 100 | function xmlObjectToString(o) { | |
| 83 | 101 | /** @type {any} */ | |
| 84 | 102 | const out = {}; | |
| 85 | - for (const item of o.LCX.Item[0].Item[0].Item) { | ||
| 86 | - let ItemId = item.$.ItemId; | ||
| 87 | - let val = item.Str[0].Tgt ? item.Str[0].Tgt[0].Val[0] : item.Str[0].Val[0]; | ||
| 103 | + for (const item of o.LCX.Item.Item.Item) { | ||
| 104 | + let ItemId = item.$_ItemId; | ||
| 105 | + let val = item.Str.Tgt ? item.Str.Tgt.Val : item.Str.Val; | ||
| 88 | 106 | ||
| 89 | 107 | if (typeof ItemId !== "string" || typeof val !== "string") { | |
| 90 | 108 | console.error("Unexpected XML file structure"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments