Path: blob/main/src/command/capabilities/capabilities.ts
3562 views
/*1* capabilities.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*/56import { basename, join } from "../../deno_ral/path.ts";78import * as ld from "../../core/lodash.ts";9import { formatResourcePath } from "../../core/resources.ts";1011import { pandocListFormats } from "../../core/pandoc/pandoc-formats.ts";12import { JupyterCapabilitiesEx } from "../../core/jupyter/types.ts";13import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts";14import { jupyterKernelspecs } from "../../core/jupyter/kernels.ts";1516export interface Capabilities {17formats: string[];18themes: string[];19python?: JupyterCapabilitiesEx;20}2122export async function capabilities(): Promise<Capabilities> {23const caps = {24formats: await formats(),25themes: await themes(),26python: await jupyterCapabilities(),27};2829// provide extended capabilities30if (caps.python) {31const pythonEx = caps.python as JupyterCapabilitiesEx;32if (pythonEx.jupyter_core) {33pythonEx.kernels = Array.from((await jupyterKernelspecs()).values());34}35pythonEx.venv = !pythonEx.conda;36}3738return caps;39}4041async function formats() {42const formats = await pandocListFormats();4344const commonFormats = [45"html",46"pdf",47"docx",48"odt",49"pptx",50"beamer",51"revealjs",52"gfm",53"epub",54"dashboard",55"email",56];5758const excludedFormats = [59"bibtex",60"biblatex",61"csljson",62];6364return ld.difference(65commonFormats.concat(ld.difference(formats, commonFormats)),66excludedFormats,67);68}6970async function themes() {71const themesPath = formatResourcePath("html", join("bootstrap", "themes"));72const themes: string[] = ["default"];73const kScss = ".scss";74for await (const dirEntry of Deno.readDir(themesPath)) {75if (dirEntry.isFile && dirEntry.name.endsWith(kScss)) {76themes.push(basename(dirEntry.name, kScss));77}78}79return themes;80}818283