Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/project/types.ts
6450 views
1
/*
2
* types.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { RenderServices } from "../command/render/types.ts";
8
import { Metadata, PandocFlags } from "../config/types.ts";
9
import { Format, FormatExtras } from "../config/types.ts";
10
import {
11
Brand,
12
LightDarkBrand,
13
LightDarkBrandDarkFlag,
14
} from "../core/brand/brand.ts";
15
import { MappedString } from "../core/mapped-text.ts";
16
import { PartitionedMarkdown } from "../core/pandoc/types.ts";
17
import {
18
ExecutionEngineDiscovery,
19
ExecutionEngineInstance,
20
ExecutionTarget,
21
} from "../execute/types.ts";
22
import { InspectedMdCell } from "../inspect/inspect-types.ts";
23
import { NotebookContext } from "../render/notebook/notebook-types.ts";
24
import {
25
LogoLightDarkSpecifier,
26
NavigationItem as NavItem,
27
NavigationItemObject,
28
NavigationItemObject as SidebarTool,
29
ProjectConfig as ProjectConfig_Project,
30
} from "../resources/types/schema-types.ts";
31
import { ProjectEnvironment } from "./project-environment-types.ts";
32
import { ProjectCache } from "../core/cache/cache-types.ts";
33
import { TempContext } from "../core/temp-types.ts";
34
import { Cloneable } from "../core/safe-clone-deep.ts";
35
36
export {
37
type NavigationItem as NavItem,
38
type NavigationItemObject,
39
type NavigationItemObject as SidebarTool,
40
type PageFooter as NavigationFooter,
41
type ProjectPreview,
42
} from "../resources/types/schema-types.ts";
43
44
export const kProjectType = "type";
45
export const kProjectTitle = "title";
46
export const kProjectRender = "render";
47
export const kProjectPreRender = "pre-render";
48
export const kProjectPostRender = "post-render";
49
export const kProjectExecuteDir = "execute-dir";
50
export const kProjectOutputDir = "output-dir";
51
export const kProjectLibDir = "lib-dir";
52
export const kProjectResources = "resources";
53
54
export const kProjectWatchInputs = "watch-inputs";
55
56
export type FileInclusion = {
57
source: string;
58
target: string;
59
};
60
61
export type FileInformation = {
62
fullMarkdown?: MappedString;
63
includeMap?: FileInclusion[];
64
codeCells?: InspectedMdCell[];
65
engine?: ExecutionEngineInstance;
66
target?: ExecutionTarget;
67
metadata?: Metadata;
68
brand?: LightDarkBrandDarkFlag;
69
};
70
71
export interface ProjectContext extends Cloneable<ProjectContext> {
72
dir: string;
73
engines: string[];
74
files: ProjectFiles;
75
config?: ProjectConfig;
76
notebookContext: NotebookContext;
77
outputNameIndex?: Map<string, { file: string; format: Format } | undefined>;
78
79
fileInformationCache: Map<string, FileInformation>;
80
81
// This is a cache of _brand.yml for a project
82
brandCache?: { brand?: LightDarkBrandDarkFlag };
83
resolveBrand: (
84
fileName?: string,
85
) => Promise<
86
undefined | LightDarkBrandDarkFlag
87
>;
88
89
// expands markdown for a file
90
// input file doesn't have to be markdown; it can be, for example, a knitr spin file
91
// output file is always markdown, though, and it is cached in the project
92
93
resolveFullMarkdownForFile: (
94
engine: ExecutionEngineInstance | undefined,
95
file: string,
96
markdown?: MappedString,
97
force?: boolean,
98
) => Promise<MappedString>;
99
100
fileExecutionEngineAndTarget: (
101
file: string,
102
force?: boolean,
103
) => Promise<{ engine: ExecutionEngineInstance; target: ExecutionTarget }>;
104
105
fileMetadata: (
106
file: string,
107
force?: boolean,
108
) => Promise<Metadata>;
109
110
formatExtras?: (
111
source: string,
112
flags: PandocFlags,
113
format: Format,
114
services: RenderServices,
115
) => Promise<FormatExtras>;
116
117
// declaring renderFormats here is a relatively ugly hack to avoid a circular import chain
118
// that causes a deno bundler bug
119
renderFormats: (
120
file: string,
121
services: RenderServices,
122
to: string | undefined,
123
project: ProjectContext,
124
) => Promise<Record<string, Format>>;
125
126
environment: () => Promise<ProjectEnvironment>;
127
128
isSingleFile: boolean;
129
previewServer?: boolean;
130
131
diskCache: ProjectCache;
132
temp: TempContext;
133
134
cleanup: () => void;
135
}
136
137
export interface ProjectFiles {
138
input: string[];
139
resources?: string[];
140
config?: string[];
141
configResources?: string[];
142
}
143
144
export interface ProjectConfig {
145
project: ProjectConfig_Project;
146
[key: string]: unknown;
147
}
148
149
export const kProject404File = "404.html";
150
151
export type LayoutBreak = "" | "sm" | "md" | "lg" | "xl" | "xxl";
152
153
/**
154
* A restricted version of ProjectContext that only exposes
155
* functionality needed by execution engines.
156
*/
157
export interface EngineProjectContext {
158
/**
159
* Base directory of the project
160
*/
161
dir: string;
162
163
/**
164
* Flag indicating if project consists of a single file
165
*/
166
isSingleFile: boolean;
167
168
/**
169
* Config object containing project configuration
170
* Used primarily for config?.engines access
171
* Can contain arbitrary configuration properties
172
*/
173
config?: {
174
engines?: string[];
175
project?: {
176
[kProjectOutputDir]?: string;
177
};
178
[key: string]: unknown;
179
};
180
181
/**
182
* For file information cache management
183
* Used for the transient notebook tracking in Jupyter
184
*/
185
fileInformationCache: Map<string, FileInformation>;
186
187
/**
188
* Get the output directory for the project
189
*
190
* @returns Path to output directory
191
*/
192
getOutputDirectory: () => string;
193
194
/**
195
* Resolves full markdown content for a file, including expanding includes
196
*
197
* @param engine - The execution engine
198
* @param file - Path to the file
199
* @param markdown - Optional existing markdown content
200
* @param force - Whether to force re-resolution even if cached
201
* @returns Promise resolving to mapped markdown string
202
*/
203
resolveFullMarkdownForFile: (
204
engine: ExecutionEngineInstance | undefined,
205
file: string,
206
markdown?: MappedString,
207
force?: boolean,
208
) => Promise<MappedString>;
209
}
210
211
export const kAriaLabel = "aria-label";
212
export const kCollapseLevel = "collapse-level";
213
export const kCollapseBelow = "collapse-below";
214
export const kToolsCollapse = "tools-collapse";
215
export const kLogoAlt = "logo-alt";
216
export const kLogoHref = "logo-href";
217
218
export const kSidebarMenus = "sidebar-menus";
219
220
export interface Navbar {
221
title?: string | false;
222
logo?: LogoLightDarkSpecifier;
223
[kLogoAlt]?: string;
224
[kLogoHref]?: string;
225
background:
226
| "primary"
227
| "secondary"
228
| "success"
229
| "danger"
230
| "warning"
231
| "info"
232
| "light"
233
| "dark";
234
search?: boolean | string;
235
left?: NavItem[];
236
right?: NavItem[];
237
collapse?: boolean;
238
tools?: SidebarTool[];
239
pinned?: boolean;
240
[kCollapseBelow]?: LayoutBreak;
241
[kSidebarMenus]?: boolean;
242
darkToggle?: boolean;
243
readerToggle?: boolean;
244
[kToolsCollapse]?: boolean;
245
}
246
247
/* export interface NavItem {
248
// href + more readable/understndable aliases
249
icon?: string;
250
href?: string;
251
file?: string;
252
text?: string;
253
url?: string;
254
[kAriaLabel]?: string;
255
256
// core identification
257
id?: string;
258
259
// more
260
menu?: NavItem[];
261
}
262
*/
263
264
export interface Sidebar {
265
id?: string;
266
title?: string;
267
subtitle?: string;
268
logo?: LogoLightDarkSpecifier;
269
[kLogoAlt]?: string;
270
[kLogoHref]?: string;
271
alignment?: "left" | "right" | "center";
272
align?: "left" | "right" | "center"; // This is here only because older versions of Quarto used to use it even though it wasn't documented
273
background?:
274
| "none"
275
| "primary"
276
| "secondary"
277
| "success"
278
| "danger"
279
| "warning"
280
| "info"
281
| "light"
282
| "dark"
283
| "white";
284
search?: boolean | string;
285
[kCollapseLevel]?: number;
286
contents: SidebarItem[];
287
tools: SidebarTool[];
288
style: "docked" | "floating";
289
pinned?: boolean;
290
header?: Array<string> | string;
291
footer?: Array<string> | string;
292
}
293
294
export type SidebarItem = NavigationItemObject & {
295
// core structure/contents
296
section?: string;
297
sectionId?: string;
298
contents?: SidebarItem[];
299
300
// more
301
expanded?: boolean;
302
active?: boolean;
303
304
// transient properties used for expanding 'auto'
305
auto?: boolean | string | string[];
306
};
307
308
export interface InputTargetIndex extends Metadata {
309
title?: string;
310
markdown: PartitionedMarkdown;
311
formats: Record<string, Format>;
312
draft?: boolean;
313
}
314
315
export interface InputTarget {
316
input: string;
317
title?: string;
318
outputHref: string;
319
draft: boolean;
320
}
321
322
/*export interface SidebarTool {
323
// label/contents
324
icon?: string;
325
text?: string;
326
menu?: NavItem[];
327
328
// href + more readable/understndable aliases
329
href?: string;
330
file?: string;
331
url?: string;
332
}*/
333
334