forked from mapnik/mapnik-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index._
100 lines (88 loc) · 2.52 KB
/
index._
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
THIS FILE IS GENERATED PROGAMMATICALLY. DO NOT MODIFIY DIRECTLY.
Modify index._ instead and run node generate.js
*/
var path = require('path');
var semver = require('semver');
var versions = [
<% _.forEach(versions, function (value, key) {
print(" '" + value + "'");
if (key < versions.length - 1) {
print(",\n");
}
});
%>
];
// These older versions don't have the datasource info
var no_datasources = [
<% _.forEach(no_datasources, function (value, key) {
print(" '" + value + "'");
if (key < no_datasources.length - 1) {
print(",\n");
}
});
%>
];
module.exports.versions = versions;
module.exports.latest = versions[versions.length - 1];
var getSatisfyingVersion = function (wanted) {
var version = semver.maxSatisfying(versions, wanted), parsed;
if (!version) {
try {
parsed = semver.parse(wanted);
parsed.patch = 'x';
version = semver.maxSatisfying(versions, parsed.format());
} catch (err) {
version = null;
}
}
return version;
};
var loadBrowser = function (version) {
var versionRefs = {
<% _.forEach(versions, function (value, key) {
print(" '" + value + "': {\n");
print(" 'ref': require('./" + value + "/reference.json'),\n");
print(" 'datasources': ");
if (_.some(no_datasources, function (ds) { return value === ds; })) {
print("null\n");
}
else {
print("require('./" + value + "/datasources.json').datasources\n");
}
if (key < versions.length - 1) {
print(" },\n");
}
else {
print(" }");
}
});
%>
};
var ref = versionRefs[version].ref;
if (no_datasources.indexOf(version) <= -1) {
ref.datasources = versionRefs[version].datasources;
}
return ref;
};
var load = function (version) {
var ref = require(path.join(__dirname, version, 'reference.json'));
if (no_datasources.indexOf(version) <= -1) {
ref.datasources = require(path.join(__dirname, version, 'datasources.json')).datasources;
}
return ref;
};
module.exports.load = function(wanted) {
var version = getSatisfyingVersion(wanted),
ref;
if (!version) {
throw new Error("Unknown mapnik-reference version: '" + wanted + "'");
}
if (process.browser) {
ref = loadBrowser(version);
}
else {
ref = load(version);
}
return ref;
}