/
index.js
45 lines (38 loc) · 1.01 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
42
43
44
45
'use strict';
/**
* Add raw xml to the config.xml file.
*
* @author Sam Verschueren <sam.verschueren@gmail.com>
* @since 12 June 2015
*/
// module dependencies
var path = require('path');
var through = require('through2');
var gutil = require('gulp-util');
var Config = require('cordova-config');
// export the module
module.exports = function (xml) {
return through.obj(function (file, enc, cb) {
// Pipe the file to the next step
this.push(file);
// Make sure it is an array so we can iterate
xml = [].concat(xml);
try {
// Load the config.xml file
var config = new Config(path.join(file.path, 'config.xml'));
// Iterate over the xml tags
xml.forEach(function (tag) {
// Add the tag to the config.xml file
config.addRawXML(tag);
});
// Write the config file
config.write(function () {
// Call the callback
cb();
});
} catch (err) {
// Return an error if something went wrong while parsing
cb(new gutil.PluginError('gulp-cordova-xml', err.message));
}
});
};