-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (35 loc) · 1.03 KB
/
index.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
const fs = require('fs');
const convert = require('xml-js');
const XML_STRINGS_CONTENT = fs.readFileSync('./strings.xml', 'utf8');
const CONTAINS_HTML_TAG_REGEX = /<[a-z][\s\S]*>/i
const result = convert.xml2js(XML_STRINGS_CONTENT);
const nextElements = result.elements[0].elements.map(element => {
const hasNestedHtml = element.elements && element.elements.length > 1;
return {
type: 'element',
name: 'string',
attributes: {
name: element.attributes.name
},
elements: [{
type: 'text',
text: hasNestedHtml ? `<![CDATA[${convert.js2xml(element)}]]>` : convert.js2xml(element)
}]
}
})
const nextXML = convert.js2xml(Object.assign(result, {}, {
elements: [{
type: 'element',
name: 'resources',
elements: nextElements
}]
}), {
spaces: 4
})
fs.writeFile('nextStrings.xml', nextXML, (err) => {
if (err) {
throw err
}
console.log('all done, homie');
console.log(`Open ${__dirname}/nextStrings.xml`)
});