1 | ;
|
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 | */
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | exports.createWorkspaceHost = void 0;
|
11 | const rxjs_1 = require("rxjs");
|
12 | const virtual_fs_1 = require("../virtual-fs");
|
13 | function createWorkspaceHost(host) {
|
14 | const workspaceHost = {
|
15 | async readFile(path) {
|
16 | const data = await (0, rxjs_1.lastValueFrom)(host.read((0, virtual_fs_1.normalize)(path)));
|
17 | return virtual_fs_1.virtualFs.fileBufferToString(data);
|
18 | },
|
19 | async writeFile(path, data) {
|
20 | return (0, rxjs_1.lastValueFrom)(host.write((0, virtual_fs_1.normalize)(path), virtual_fs_1.virtualFs.stringToFileBuffer(data)));
|
21 | },
|
22 | async isDirectory(path) {
|
23 | try {
|
24 | return await (0, rxjs_1.lastValueFrom)(host.isDirectory((0, virtual_fs_1.normalize)(path)));
|
25 | }
|
26 | catch {
|
27 | // some hosts throw if path does not exist
|
28 | return false;
|
29 | }
|
30 | },
|
31 | async isFile(path) {
|
32 | try {
|
33 | return await (0, rxjs_1.lastValueFrom)(host.isFile((0, virtual_fs_1.normalize)(path)));
|
34 | }
|
35 | catch {
|
36 | // some hosts throw if path does not exist
|
37 | return false;
|
38 | }
|
39 | },
|
40 | };
|
41 | return workspaceHost;
|
42 | }
|
43 | exports.createWorkspaceHost = createWorkspaceHost;
|
44 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaG9zdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2FuZ3VsYXJfZGV2a2l0L2NvcmUvc3JjL3dvcmtzcGFjZS9ob3N0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs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