-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
74 lines (55 loc) · 1.89 KB
/
app.js
File metadata and controls
74 lines (55 loc) · 1.89 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import fs from 'fs';
import path from 'path';
import xml2js from 'xml2js';
const metaPath = './metas';
async function processMetaFiles() {
const itemsMap = new Map();
try {
const files = await fs.promises.readdir(metaPath);
for (const file of files) {
if (path.extname(file) === '.xml') continue;
const filePath = path.join(metaPath, file);
const data = await fs.promises.readFile(filePath, 'utf8');
const result = await xml2js.parseStringPromise(data);
const handlingData = result.CHandlingDataMgr.HandlingData;
if (handlingData && handlingData.length > 0) {
for (const item of handlingData[0].Item) {
const handlingName = item.handlingName && item.handlingName[0];
if (handlingName) {
if (itemsMap.has(handlingName)) {
console.warn(`Duplicate found for handlingName: ${handlingName}`);
continue;
}
itemsMap.set(handlingName, item);
} else {
console.warn(`Item without handlingName in file: ${file}`);
}
}
} else {
console.warn(`No HandlingData found in file: ${file}`);
}
}
const items = Array.from(itemsMap.values());
items.sort((a, b) => {
const handlingNameA = a.handlingName[0];
const handlingNameB = b.handlingName[0];
return handlingNameA.localeCompare(handlingNameB);
});
const mergedData = {
CHandlingDataMgr: {
HandlingData: {
Item: items.map(item => ({
...item,
$: { type: "CHandlingData" } // Add the type attribute to each Item
}))
}
}
};
const builder = new xml2js.Builder();
const xml = builder.buildObject(mergedData);
await fs.promises.writeFile('handling.meta', xml);
} catch (err) {
console.error('Error processing meta files:', err);
}
}
processMetaFiles();