2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-10 15:55:18 -07:00
|
|
|
import {BaseException, Injectable} from '@angular/core';
|
2016-01-06 14:13:44 -08:00
|
|
|
|
2016-08-05 09:50:49 -07:00
|
|
|
import {Math, isBlank, isPresent} from '../facade/lang';
|
2016-06-08 16:38:52 -07:00
|
|
|
|
|
|
|
|
|
2016-01-06 14:13:44 -08:00
|
|
|
// asset:<package-name>/<realm>/<path-to-module>
|
2016-08-05 09:50:49 -07:00
|
|
|
var _ASSET_URL_RE = /asset:([^\/]+)\/([^\/]+)\/(.+)/;
|
2016-01-06 14:13:44 -08:00
|
|
|
|
|
|
|
|
/**
|
2016-05-02 09:38:46 -07:00
|
|
|
* Interface that defines how import statements should be generated.
|
2016-01-06 14:13:44 -08:00
|
|
|
*/
|
2016-05-02 09:38:46 -07:00
|
|
|
export abstract class ImportGenerator {
|
|
|
|
|
static parseAssetUrl(url: string): AssetUrl { return AssetUrl.parse(url); }
|
2016-01-06 14:13:44 -08:00
|
|
|
|
2016-05-02 09:38:46 -07:00
|
|
|
abstract getImportPath(moduleUrlStr: string, importedUrlStr: string): string;
|
2016-01-06 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
|
2016-05-02 09:38:46 -07:00
|
|
|
export class AssetUrl {
|
|
|
|
|
static parse(url: string, allowNonMatching: boolean = true): AssetUrl {
|
2016-08-05 09:50:49 -07:00
|
|
|
const match = url.match(_ASSET_URL_RE);
|
|
|
|
|
if (match !== null) {
|
2016-05-02 09:38:46 -07:00
|
|
|
return new AssetUrl(match[1], match[2], match[3]);
|
2016-01-06 14:13:44 -08:00
|
|
|
}
|
|
|
|
|
if (allowNonMatching) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
throw new BaseException(`Url ${url} is not a valid asset: url`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(public packageName: string, public firstLevelDir: string, public modulePath: string) {
|
|
|
|
|
}
|
|
|
|
|
}
|