forked from udos86/ng-dynamic-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
systemjs-angular-loader.js
59 lines (41 loc) · 1.84 KB
/
systemjs-angular-loader.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
var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*)/gm,
stylesUrlsRegex = /styleUrls *:(\s*\[[^\]]*?\])/g,
stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;
module.exports.translate = function (load) {
var url, basePathParts, basePath, baseHref;
if (load.source.indexOf("moduleId") !== -1) {
return load;
}
url = document.createElement("a");
url.href = load.address;
basePathParts = url.pathname.split("/");
basePathParts.pop();
basePath = basePathParts.join("/");
baseHref = document.createElement("a");
baseHref.href = this.baseURL;
baseHref = baseHref.pathname;
if (!baseHref.startsWith("/base/")) { // Non-Karma context
basePath = basePath.replace(baseHref, "");
}
load.source = load.source
.replace(templateUrlRegex, function (match, quote, url) {
var templateUrl = url;
if (url.startsWith(".")) {
templateUrl = basePath + url.substr(1);
}
return 'templateUrl: "' + templateUrl + '"';
})
.replace(stylesUrlsRegex, function (match, urls) {
var styleUrls = [];
while ((match = stringRegex.exec(urls)) !== null) {
var urlString = match[2];
if (urlString.startsWith(".")) {
styleUrls.push('"' + basePath + urlString.substr(1) + '"');
} else {
styleUrls.push('"' + urlString + '"');
}
}
return "styleUrls: [" + styleUrls.join(", ") + "]";
});
return load;
};