UNPKG

1.45 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.createWorkspaceHost = void 0;
11const virtual_fs_1 = require("../virtual-fs");
12function createWorkspaceHost(host) {
13 const workspaceHost = {
14 async readFile(path) {
15 const data = await host.read(virtual_fs_1.normalize(path)).toPromise();
16 return virtual_fs_1.virtualFs.fileBufferToString(data);
17 },
18 async writeFile(path, data) {
19 return host.write(virtual_fs_1.normalize(path), virtual_fs_1.virtualFs.stringToFileBuffer(data)).toPromise();
20 },
21 async isDirectory(path) {
22 try {
23 return await host.isDirectory(virtual_fs_1.normalize(path)).toPromise();
24 }
25 catch {
26 // some hosts throw if path does not exist
27 return false;
28 }
29 },
30 async isFile(path) {
31 try {
32 return await host.isFile(virtual_fs_1.normalize(path)).toPromise();
33 }
34 catch {
35 // some hosts throw if path does not exist
36 return false;
37 }
38 },
39 };
40 return workspaceHost;
41}
42exports.createWorkspaceHost = createWorkspaceHost;