readFile(fileName) { const filePath = this.resolve(fileName); try { if (this._memoryHost.isFile(filePath)) { return core_1.virtualFs.fileBufferToString(this._memoryHost.read(filePath)); } else { const content = this._syncHost.read(filePath); return core_1.virtualFs.fileBufferToString(content); } } catch (_a) { return undefined; } }
readJsonSync(path) { if (!this._syncHost) { this._syncHost = new core_1.virtualFs.SyncDelegateHost(this._host); } const data = this._syncHost.read(core_1.normalize('/' + path)); return JSON.parse(core_1.virtualFs.fileBufferToString(data)); }
Object.keys(files).forEach(fileName => { let content = files[fileName]; if (typeof content == 'string') { content = core_1.virtualFs.stringToFileBuffer(content); } else if (content instanceof Buffer) { content = content.buffer.slice(content.byteOffset, content.byteOffset + content.byteLength); } this.scopedSync().write(core_1.normalize(fileName), content); });
return (fileName, data, _writeByteOrderMark, onError, _sourceFiles) => { const p = this.resolve(fileName); try { this._memoryHost.write(p, core_1.virtualFs.stringToFileBuffer(data)); } catch (e) { if (onError) { onError(e.message); } } };
readFile(fileName) { const p = this.resolve(fileName); const stats = this._files[p]; if (!stats) { try { const result = core_1.virtualFs.fileBufferToString(this._syncHost.read(p)); if (result !== undefined) { if (this._cache) { this._setFileContent(p, result); } } return result; } catch (e) { return undefined; } } return stats.content; }
})), this.getServerModuleBundlePath(options)).pipe(operators_1.switchMap(([[browserIndexOutputPath, indexContent], serverBundlePath]) => { const root = this.context.workspace.root; require_project_module_1.requireProjectModule(core_1.getSystemPath(root), 'zone.js/dist/zone-node'); const renderModuleFactory = require_project_module_1.requireProjectModule(core_1.getSystemPath(root), '@angular/platform-server').renderModuleFactory; const AppServerModuleNgFactory = require(core_1.getSystemPath(serverBundlePath)).AppServerModuleNgFactory; const indexHtml = core_1.virtualFs.fileBufferToString(indexContent); const outputPath = core_1.join(root, options.outputIndexPath || browserIndexOutputPath); // Render to HTML and overwrite the client index file. return rxjs_1.from(renderModuleFactory(AppServerModuleNgFactory, { document: indexHtml, url: options.route, }) .then((html) => { return this.context.host .write(outputPath, core_1.virtualFs.stringToFileBuffer(html)) .toPromise(); }) .then(() => ({ success: true }))); }));
.then((html) => { return this.context.host .write(outputIndexPath, core_1.virtualFs.stringToFileBuffer(html)) .toPromise(); })
return this._workspace.host.read(core_1.normalize(path)).pipe(operators_1.map(buffer => core_1.virtualFs.fileBufferToString(buffer)), operators_1.map(str => core_1.parseJson(str, core_1.JsonParseMode.Loose)));
const o = this._host.read(core_1.normalize('/' + path)).pipe(operators_1.map(content => JSON.parse(core_1.virtualFs.fileBufferToString(content))));
appendToFile(path, str) { const content = core_1.virtualFs.fileBufferToString(this.scopedSync().read(core_1.normalize(path))); this.scopedSync().write(core_1.normalize(path), core_1.virtualFs.stringToFileBuffer(content.concat(str))); }
replaceInFile(path, match, replacement) { const content = core_1.virtualFs.fileBufferToString(this.scopedSync().read(core_1.normalize(path))); this.scopedSync().write(core_1.normalize(path), core_1.virtualFs.stringToFileBuffer(content.replace(match, replacement))); }
.subscribe(data => content = core_1.virtualFs.fileBufferToString(data));
get bufferContent() { if (!this._bufferContent && this._content) { this._bufferContent = core_1.virtualFs.stringToFileBuffer(this._content); } return this._bufferContent || core_1.virtualFs.stringToFileBuffer(''); }
get content() { if (!this._content && this.bufferContent) { this._content = core_1.virtualFs.fileBufferToString(this.bufferContent); } return this._content || ''; }