-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_xml.js
42 lines (36 loc) · 1.32 KB
/
update_xml.js
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
const parser = require('fast-xml-parser');
const yaml = require('yaml')
const fs = require('fs')
const path = require('path')
const template_path = "simulation/templates"
/*
fs.readdir(template_path,(err,res) => {
for (var i = 0; i < res.length; i++) {
var filename=res[i]
if
if (filename.endsWith(".xml") && filename.startsWith("template_unit")){
console.log(`reading file ${filename}`)
readFile(`${template_path}/${filename}`)
}
}
})
*/
var file_path = `${template_path}/units/infantry/melee_spearman.yml`
var filePath = file_path;
function readFile(filePath){
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (!err) {
var newLine2Array = function(val, parent) {
// val = val.replace(/ /g,'')
val = val.trim()
if(val.includes('\n')){
val = val.split("\n")
val = val.map(s => s.trim());
// val = val.trim()
}
return val
}
var array2NewLine = function(val, elementName, currentElementObject) {
return val
}
var options1 = { compact: true, textFn: newLine2Array, nativeType: true, ignoreDeclaration: true, ignoreText: false}