utils.js
1.45 KB
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
"use strict";
var U = module.exports;
// because not all file systems like '*' in a name (and they're scary)
U._tameWild = function tameWild(pathname, wild) {
if (!wild) {
return pathname;
}
var tame = wild.replace(/\*/g, "_");
return pathname.replace(wild, tame);
};
U._tpl = function tpl(store, opts, str) {
var server = ["directoryUrl", "serverDir", "server"];
var env = ["env", "directoryUrl"];
[
["basePath", "configDir"],
server,
["subject", "hostname", "domain"],
env
].forEach(function(group) {
group.forEach(function(tmpl) {
group.forEach(function(key) {
var item = opts[key] || store.options[key];
if ("string" !== typeof item) {
return;
}
if ("directoryUrl" === key) {
item = item.replace(/^https?:\/\//i, "");
}
if ("env" === tmpl) {
if (/staging/.test(item)) {
item = "staging";
} else if (/acme-v02/.test(item)) {
item = "live";
} else {
// item = item;
}
}
if (-1 === str.indexOf(":" + tmpl)) {
return;
}
str = str.replace(":" + tmpl, item);
});
});
});
return str;
};