-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-xml-cli.ts
33 lines (29 loc) · 916 Bytes
/
parse-xml-cli.ts
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
import {parseString} from "npm:xml2js";
const decoder = new TextDecoder("utf-8");
const data = decoder.decode(await Deno.readFile(Deno.args[0]));
/**
* {
* "downloadUrl": "",
* "id": "",
* }
*/
parseString(data, (err, result) => {
if (err) {
console.error(err);
return;
}
const baseUrl = result["DependencyManifest"]["$"]["BaseUrl"];
const packs = result["DependencyManifest"]["Packs"][0]["Pack"].reduce((shaMap, pack) => {
shaMap[pack["$"]["Hash"]] = {
downloadUrl: `${baseUrl}/${pack["$"]["RemotePath"]}/${pack["$"]["Hash"]}`,
id: pack["$"]["Hash"]
};
return shaMap;
}, {})
try {
// Deno.writeTextFileSync(Deno.args[1], JSON.stringify(result, null, 4));
Deno.writeTextFileSync(Deno.args[1], JSON.stringify(packs, null));
} catch (writeErr) {
console.error(writeErr);
}
});