forked from NativeScript/nativescript-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource-loader.ts
More file actions
25 lines (22 loc) · 895 Bytes
/
resource-loader.ts
File metadata and controls
25 lines (22 loc) · 895 Bytes
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
import { path, knownFolders, File } from "file-system";
import { ResourceLoader } from "@angular/compiler";
export class FileSystemResourceLoader extends ResourceLoader {
resolve(url: string, baseUrl: string): string {
// Angular assembles absolute URL's and prefixes them with //
if (url.indexOf("/") !== 0) {
// Resolve relative URL's based on the app root.
return path.join(baseUrl, url);
} else {
return url;
}
}
get(url: string): Promise<string> {
const appDir = knownFolders.currentApp().path;
const templatePath = this.resolve(url, appDir);
if (!File.exists(templatePath)) {
throw new Error(`File ${templatePath} does not exist. Resolved from: ${url}.`);
}
let templateFile = File.fromPath(templatePath);
return templateFile.readText();
}
}