Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/command/capabilities/capabilities.ts
3562 views
1
/*
2
* capabilities.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { basename, join } from "../../deno_ral/path.ts";
8
9
import * as ld from "../../core/lodash.ts";
10
import { formatResourcePath } from "../../core/resources.ts";
11
12
import { pandocListFormats } from "../../core/pandoc/pandoc-formats.ts";
13
import { JupyterCapabilitiesEx } from "../../core/jupyter/types.ts";
14
import { jupyterCapabilities } from "../../core/jupyter/capabilities.ts";
15
import { jupyterKernelspecs } from "../../core/jupyter/kernels.ts";
16
17
export interface Capabilities {
18
formats: string[];
19
themes: string[];
20
python?: JupyterCapabilitiesEx;
21
}
22
23
export async function capabilities(): Promise<Capabilities> {
24
const caps = {
25
formats: await formats(),
26
themes: await themes(),
27
python: await jupyterCapabilities(),
28
};
29
30
// provide extended capabilities
31
if (caps.python) {
32
const pythonEx = caps.python as JupyterCapabilitiesEx;
33
if (pythonEx.jupyter_core) {
34
pythonEx.kernels = Array.from((await jupyterKernelspecs()).values());
35
}
36
pythonEx.venv = !pythonEx.conda;
37
}
38
39
return caps;
40
}
41
42
async function formats() {
43
const formats = await pandocListFormats();
44
45
const commonFormats = [
46
"html",
47
"pdf",
48
"docx",
49
"odt",
50
"pptx",
51
"beamer",
52
"revealjs",
53
"gfm",
54
"epub",
55
"dashboard",
56
"email",
57
];
58
59
const excludedFormats = [
60
"bibtex",
61
"biblatex",
62
"csljson",
63
];
64
65
return ld.difference(
66
commonFormats.concat(ld.difference(formats, commonFormats)),
67
excludedFormats,
68
);
69
}
70
71
async function themes() {
72
const themesPath = formatResourcePath("html", join("bootstrap", "themes"));
73
const themes: string[] = ["default"];
74
const kScss = ".scss";
75
for await (const dirEntry of Deno.readDir(themesPath)) {
76
if (dirEntry.isFile && dirEntry.name.endsWith(kScss)) {
77
themes.push(basename(dirEntry.name, kScss));
78
}
79
}
80
return themes;
81
}
82
83