Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/package/src/common/dependencies/pandoc.ts
6456 views
1
/*
2
* pandoc.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { ensureDirSync, existsSync } from "../../../../src/deno_ral/fs.ts";
8
import { dirname, join } from "../../../../src/deno_ral/path.ts";
9
10
import { unTar } from "../../util/tar.ts";
11
import { unzip } from "../../util/utils.ts";
12
import { Dependency } from "./dependencies.ts";
13
import { which } from "../../../../src/core/path.ts";
14
import { Configuration } from "../config.ts";
15
16
export function pandoc(version: string): Dependency {
17
// Maps the file name and pandoc executable file name to a repo and expand
18
// to create a pandocRelease
19
const pandocRelease = (
20
filename: string,
21
pandocBinary: string,
22
) => {
23
return {
24
filename,
25
url:
26
`https://github.com/jgm/pandoc/releases/download/${version}/${filename}`,
27
configure: async (config: Configuration, path: string) => {
28
const dir = dirname(path);
29
// Mac subdirectories include architecture
30
const pandocSuffix = config.os !== "darwin" ? "" : config.arch === "aarch64" ? "-arm64" : "-" + config.arch;
31
32
const pandocSubdir = join(dir, `pandoc-${version}${pandocSuffix}`);
33
const targetDir = config.os === "windows" ? dir : join(dir, config.arch);
34
ensureDirSync(targetDir);
35
36
const vendor = Deno.env.get("QUARTO_VENDOR_BINARIES");
37
if (vendor === undefined || vendor === "true") {
38
// Clean pandoc interim dir
39
if (existsSync(pandocSubdir)) {
40
Deno.removeSync(pandocSubdir, { recursive: true });
41
}
42
43
// Extract pandoc
44
if (config.os !== "windows") {
45
46
await unTar(path);
47
48
// move the binary
49
Deno.renameSync(
50
join(pandocSubdir, "bin", pandocBinary),
51
join(targetDir, pandocBinary),
52
);
53
54
// TODO: If this is darwin, we need to emit a bash script
55
// that is executable at tools/pandoc
56
57
} else {
58
await unzip(path, dir);
59
60
// move the binary
61
Deno.renameSync(
62
join(pandocSubdir, pandocBinary),
63
join(targetDir, pandocBinary),
64
);
65
}
66
67
// cleanup
68
if (existsSync(pandocSubdir)) {
69
Deno.removeSync(pandocSubdir, { recursive: true });
70
}
71
} else {
72
// verify that the binary is on PATH, but otherwise don't do anything
73
if (which(pandocBinary) === undefined) {
74
throw new Error(
75
`${pandocBinary} is not on PATH. Please install it and add it to PATH.`,
76
);
77
}
78
}
79
},
80
};
81
};
82
83
// The pandocRelease
84
return {
85
name: "Pandoc",
86
bucket: "pandoc",
87
version,
88
architectureDependencies: {
89
"x86_64": {
90
"windows": pandocRelease(
91
`pandoc-${version}-windows-x86_64.zip`,
92
"pandoc.exe",
93
),
94
"linux": pandocRelease(
95
`pandoc-${version}-linux-amd64.tar.gz`,
96
"pandoc",
97
),
98
"darwin": pandocRelease(
99
`pandoc-${version}-x86_64-macOS.zip`,
100
"pandoc",
101
),
102
},
103
"aarch64": {
104
"linux": pandocRelease(
105
`pandoc-${version}-linux-arm64.tar.gz`,
106
"pandoc",
107
),
108
"darwin" : pandocRelease(
109
`pandoc-${version}-arm64-macOS.zip`,
110
"pandoc",
111
)
112
},
113
},
114
};
115
}
116
117