urlResolver.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var ts = require("typescript");
  17. var config_1 = require("../config");
  18. var abstractResolver_1 = require("./abstractResolver");
  19. var path_1 = require("path");
  20. var UrlResolver = (function (_super) {
  21. __extends(UrlResolver, _super);
  22. function UrlResolver(pathResolver) {
  23. var _this = _super.call(this) || this;
  24. _this.pathResolver = pathResolver;
  25. return _this;
  26. }
  27. UrlResolver.prototype.resolve = function (d) {
  28. var _this = this;
  29. var templateUrl = this.getTemplateUrl(d);
  30. var styleUrls = this.getStyleUrls(d);
  31. var targetPath = this.getProgramFilePath(d);
  32. if (targetPath) {
  33. var componentPath_1 = path_1.dirname(targetPath);
  34. return {
  35. templateUrl: config_1.Config.resolveUrl(this.pathResolver.resolve(templateUrl, componentPath_1)),
  36. styleUrls: styleUrls.map(function (p) {
  37. return config_1.Config.resolveUrl(_this.pathResolver.resolve(p, componentPath_1));
  38. })
  39. };
  40. }
  41. return {
  42. templateUrl: config_1.Config.resolveUrl(null),
  43. styleUrls: []
  44. };
  45. };
  46. UrlResolver.prototype.getProgramFilePath = function (d) {
  47. var current = d;
  48. while (current) {
  49. if (current.kind === ts.SyntaxKind.SourceFile) {
  50. return current.path || current.fileName;
  51. }
  52. current = current.parent;
  53. }
  54. return undefined;
  55. };
  56. return UrlResolver;
  57. }(abstractResolver_1.AbstractResolver));
  58. exports.UrlResolver = UrlResolver;