-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathcmd.ts
More file actions
74 lines (67 loc) · 2.01 KB
/
cmd.ts
File metadata and controls
74 lines (67 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* cmd.ts
*
* Copyright (C) 2025 Posit Software, PBC
*/
import { Command } from "cliffy/command/mod.ts";
import { quartoCacheDir } from "../../../core/appdirs.ts";
import { quartoConfig } from "../../../core/quarto.ts";
import {
ensureDir,
moveSync,
safeRemoveDirSync,
} from "../../../deno_ral/fs.ts";
import { basename, dirname, join } from "../../../deno_ral/path.ts";
import { copy } from "fs/copy";
import { resourcePath } from "../../../core/resources.ts";
import { execProcess } from "../../../core/process.ts";
const ensureTracingToolsCopied = async () => {
const cacheDir = quartoCacheDir();
const tracingDir = `${cacheDir}/ast-tracing`;
await ensureDir(tracingDir);
safeRemoveDirSync(join(tracingDir, "qmd"), cacheDir);
await copy(
resourcePath(join("tools", "ast-tracing")),
join(tracingDir, "qmd"),
);
return join(tracingDir, "qmd");
};
export const showAstTraceCommand = new Command()
.name("show-ast-trace")
.hidden()
.arguments("<arguments...>")
.description(
"Renders the document with AST tracing enabled and then shows the debugging output.\n\n",
)
.action(async (_options: unknown, input: string, ...args: string[]) => {
const toolsPath = await ensureTracingToolsCopied();
const dir = dirname(input);
const base = basename(input, ".qmd");
const traceName = join(dir, `${base}-quarto-ast-trace.json`);
const renderOpts = {
cmd: "quarto",
env: {
"QUARTO_TRACE_FILTERS": traceName,
},
args: [
"render",
input,
...args,
"--quiet",
],
};
const _renderResult = await execProcess(renderOpts);
// we don't check for errors here because we want to show the trace even if
// the render fails
moveSync(traceName, join(toolsPath, basename(traceName)));
const _previewResult = await execProcess({
cmd: "quarto",
cwd: toolsPath,
args: [
"preview",
"trace-viewer.qmd",
"-M",
`trace_1:${basename(traceName)}`,
],
});
});