Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/package/src/common/dependencies/typst.ts
6451 views
1
2
import { join, dirname, basename } from "../../../../src/deno_ral/path.ts"
3
import { ensureDirSync, existsSync } from "../../../../src/deno_ral/fs.ts"
4
5
import { Configuration } from "../config.ts";
6
import { Dependency } from "./dependencies.ts";
7
import { which } from "../../../../src/core/path.ts";
8
import { unTar } from "../../util/tar.ts";
9
10
export function typst(version: string ): Dependency {
11
const typst_release = (filename: string ) => {
12
return {
13
filename,
14
url: `https://github.com/typst/typst/releases/download/v${version}/${filename}`,
15
configure: async(config: Configuration, path: string) => {
16
const file = config.os === "windows" ? "typst.exe" : "typst";
17
const archiveExt = config.os === "windows" ? ".zip" : ".tar.xz";
18
const vendor = Deno.env.get("QUARTO_VENDOR_BINARIES");
19
if (vendor === undefined || vendor === "true") {
20
// establish archive expand dir and remove existing if necessary
21
const dir = dirname(path);
22
23
const targetDir = join(dir, config.arch);
24
ensureDirSync(targetDir);
25
26
27
const archiveDir = basename(path, archiveExt);
28
const typstDir = join(dir, archiveDir);
29
const cleanup = () => {
30
if (existsSync(typstDir)) {
31
Deno.removeSync(typstDir, { recursive: true });
32
}
33
}
34
cleanup();
35
36
// expand
37
await unTar(path);
38
39
// move the file and cleanup
40
try {
41
const extractedPath = join(typstDir, file);
42
Deno.renameSync(extractedPath, join(targetDir, file));
43
} finally {
44
cleanup();
45
}
46
} else {
47
// verify that the binary is on PATH, but otherwise don't do anything
48
if (which(file) === undefined) {
49
throw new Error(
50
`${file} is not on PATH. Please install it and add it to PATH.`,
51
);
52
}
53
}
54
}
55
}
56
}
57
58
return {
59
name: "Typst",
60
bucket: "typst",
61
version,
62
architectureDependencies: {
63
"x86_64": {
64
"windows": typst_release("typst-x86_64-pc-windows-msvc.zip"),
65
"linux": typst_release("typst-x86_64-unknown-linux-musl.tar.xz"),
66
"darwin": typst_release("typst-x86_64-apple-darwin.tar.xz"),
67
},
68
"aarch64": {
69
"linux": typst_release("typst-aarch64-unknown-linux-musl.tar.xz"),
70
"darwin": typst_release("typst-aarch64-apple-darwin.tar.xz")
71
}
72
}
73
}
74
}
75
76
77
78