fs#rm TypeScript Examples

The following examples show how to use fs#rm. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.ts    From obsidian-jupyter with MIT License 5 votes vote down vote up
onLoadFile(file: TFile): Promise<void> {
		// Get the base path of the vault.
		let adapter = file.vault.adapter;
		if (!(adapter instanceof FileSystemAdapter)) {
			this.contentEl.innerHTML = 'Could not determine notebook path.';
			return null;
		}
		// Convert the file by writing it to a temporary location. Piping unfortunately leads to
		// problems for long lines due to buffer overflows.
		let basePath = adapter.getBasePath();
		let filename = `${basePath}/${file.path}`;
		let htmlPath = `${tmpdir()}/${uuid()}.html`;
		let args = ['-m', 'nbconvert', `--output=${htmlPath}`, '--to=html', filename];
		let child = spawn(this.interpreter, args);

		// Process the output and delete the temporary file.
		child.on('close', (code: number) => {
			if (code) {
				this.contentEl.innerHTML = 'Failed to convert notebook to HTML.';
			} else {
				// Create the frame for rendering.
				let frame = document.createElement('iframe');
				frame.addClass('notebookPreview')
				const html = readFileSync(htmlPath).toString();
				const blob = new Blob([html], {type: 'text/html'});
				frame.src = window.URL.createObjectURL(blob);

				// Insert the frame and hook up to resize events.
				this.contentEl.innerHTML = '';
				this.contentEl.addClass('notebookPreview');
				this.contentEl.appendChild(frame);
				new ResizeObserver((entries) => {
					for (let entry of entries) {
						frame.height = `${entry.contentRect.height - 6}px`;
					}
				}).observe(this.contentEl);
			}
			rm(htmlPath, () => null);
		})
		return null;
	}