-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
59 lines (44 loc) · 1.75 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
"use strict";
const
parser = require('xml2json'),
jsesc = require('jsesc'),
path = require('path'),
fs = require('fs'),
util = require('util'),
APNconfig = require('./package.json').apns;
module.exports = (function(global, undefined) {
function APNs() {
let apns = Object.create(Object);
apns.version = APNconfig.version;
apns.apn = [];
let files = fs.readdirSync(path.join(__dirname, 'src'));
for (let i = 0, len = files.length; i < len; i++) {
let file = path.join(__dirname, "src", files[i]);
let part_apns = JSON.parse(fs.readFileSync(file)).apns;
if (parseInt(part_apns.version) === parseInt(APNconfig.version)) {
apns.apn = apns.apn.concat(part_apns.apn);
}
}
apns.prototype.toXML = function toXML() {
let LICENSE = fs.readFileSync(path.join(__dirname, 'LICENSE'));
let XMLdata = parser.toXml({ apns: this }, { sanitize: false });
return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
`<!--\n${LICENSE}\n-->\n` +
'<!-- use empty string to specify no proxy or port -->\n' +
'<!-- This version must agree with that in apps/common/res/apns.xml -->\n' +
`${XMLdata}\n`
.replace(/(<apn .+?)><\/apn>/g, " $1 />")
.replace(/>(\s*)</g, ">\n$1<");
}
apns.prototype.toJSON = function toJSON(indt) {
return jsesc(this, {
quotes: 'double',
minimal: true,
compact: !indt && true || false,
indent: indt || ' '
});
}
return apns;
}
return new APNs();
})(global);