-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.js
38 lines (34 loc) · 1.09 KB
/
config.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
'use strict';
const fs = require('fs');
const path = require('path');
const replace = require('replace');
const et = require('elementtree');
const ENV = require('./env');
const src = {
android: (ENV === 'development' ? 'http://10.0.2.2:8080/' : '') + 'index.html',
ios: (ENV === 'development' ? 'http://localhost:8080/' : '') + 'index.html',
};
const config = path.resolve('./config.xml');
try {
var configXML = new et.ElementTree(
et.XML(
fs.readFileSync(config, 'utf-8')
)
);
configXML.getroot()._children.forEach(function(el) {
if (el.tag === 'platform') {
if (el.attrib.name === 'android' || el.attrib.name === 'ios') {
el._children.forEach(function(child) {
if (child.tag === 'content') {
console.log('Setting ' + el.attrib.name + ' src to ' + src[el.attrib.name])
child.attrib.src = src[el.attrib.name];
}
});
}
}
});
fs.writeFileSync(config, configXML.write({indent: 4}), 'utf-8');
} catch (err) {
console.error('ERROR: Could not replace content src in: ' + config, err);
process.exit(1);
}