forked from sscots/ionic-white-label
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (53 loc) · 1.79 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let fs = require('fs'),
xml2js = require('xml2js'),
commandLineArgs = require('command-line-args');
const { exec } = require('child_process');
let parser = new xml2js.Parser(),
xmlBuilder = new xml2js.Builder();
const optionDefinitions = [
{ name: 'config', alias: 'c', type: String, defaultValue: './config.xml' },
{ name: 'id', type: String },
{ name: 'name', alias: 'n', type: String },
{ name: 'version', alias: 'v', type: String },
{ name: 'icon', alias: 'i', type: String, defaultValue: './resources/icon.png' },
{ name: 'splash', alias: 's', type: String, defaultValue: './resources/splash.png' }
];
const options = commandLineArgs(optionDefinitions);
fs.readFile(options.config, function(err, data) {
if(err) console.log(err);
parser.parseString(data, function (err, result) {
if(err) console.log(err);
if(result.widget) {
if(options.id) {
result.widget.$.id = options.id;
console.log('New confix.xml id: '+options.id);
}
if(options.name) {
result.widget.name = options.name;
console.log('New config.xml name: '+options.name);
}
if(options.version) {
result.widget.$.version = options.version;
console.log('New config.xml version: '+options.version);
}
let xml = xmlBuilder.buildObject(result);
fs.writeFile(options.config, xml, () => {
console.log('config.xml Updated');
createResource(options);
});
} else {
console.log('Invalid config.xml file');
}
});
});
let createResource = (options) => {
exec('cp '+options.splash+' resources/; cp '+options.icon+' resources/; ionic cordova resources --force --splash; ionic cordova resources --force --icon', (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
console.log(err);
return;
}
if(stdout) console.log(stdout);
console.log(stderr);
});
}