@angular-devkit/core
Version:
Angular DevKit - Core Utility Library
45 lines • 1.59 kB
JavaScript
;
/**
* @license
* Copyright Google LLC 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.dev/license
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWorkspaceHost = createWorkspaceHost;
const rxjs_1 = require("rxjs");
const virtual_fs_1 = require("../virtual-fs");
function createWorkspaceHost(host) {
const decoder = new TextDecoder();
const encoder = new TextEncoder();
const workspaceHost = {
async readFile(path) {
const data = await (0, rxjs_1.lastValueFrom)(host.read((0, virtual_fs_1.normalize)(path)));
return decoder.decode(data);
},
async writeFile(path, data) {
return (0, rxjs_1.lastValueFrom)(host.write((0, virtual_fs_1.normalize)(path), encoder.encode(data).buffer));
},
async isDirectory(path) {
try {
return await (0, rxjs_1.lastValueFrom)(host.isDirectory((0, virtual_fs_1.normalize)(path)));
}
catch {
// some hosts throw if path does not exist
return false;
}
},
async isFile(path) {
try {
return await (0, rxjs_1.lastValueFrom)(host.isFile((0, virtual_fs_1.normalize)(path)));
}
catch {
// some hosts throw if path does not exist
return false;
}
},
};
return workspaceHost;
}
//# sourceMappingURL=host.js.map