Path: blob/main/package/src/common/dependencies/pandoc.ts
6456 views
/*1* pandoc.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*5*/6import { ensureDirSync, existsSync } from "../../../../src/deno_ral/fs.ts";7import { dirname, join } from "../../../../src/deno_ral/path.ts";89import { unTar } from "../../util/tar.ts";10import { unzip } from "../../util/utils.ts";11import { Dependency } from "./dependencies.ts";12import { which } from "../../../../src/core/path.ts";13import { Configuration } from "../config.ts";1415export function pandoc(version: string): Dependency {16// Maps the file name and pandoc executable file name to a repo and expand17// to create a pandocRelease18const pandocRelease = (19filename: string,20pandocBinary: string,21) => {22return {23filename,24url:25`https://github.com/jgm/pandoc/releases/download/${version}/${filename}`,26configure: async (config: Configuration, path: string) => {27const dir = dirname(path);28// Mac subdirectories include architecture29const pandocSuffix = config.os !== "darwin" ? "" : config.arch === "aarch64" ? "-arm64" : "-" + config.arch;3031const pandocSubdir = join(dir, `pandoc-${version}${pandocSuffix}`);32const targetDir = config.os === "windows" ? dir : join(dir, config.arch);33ensureDirSync(targetDir);3435const vendor = Deno.env.get("QUARTO_VENDOR_BINARIES");36if (vendor === undefined || vendor === "true") {37// Clean pandoc interim dir38if (existsSync(pandocSubdir)) {39Deno.removeSync(pandocSubdir, { recursive: true });40}4142// Extract pandoc43if (config.os !== "windows") {4445await unTar(path);4647// move the binary48Deno.renameSync(49join(pandocSubdir, "bin", pandocBinary),50join(targetDir, pandocBinary),51);5253// TODO: If this is darwin, we need to emit a bash script54// that is executable at tools/pandoc5556} else {57await unzip(path, dir);5859// move the binary60Deno.renameSync(61join(pandocSubdir, pandocBinary),62join(targetDir, pandocBinary),63);64}6566// cleanup67if (existsSync(pandocSubdir)) {68Deno.removeSync(pandocSubdir, { recursive: true });69}70} else {71// verify that the binary is on PATH, but otherwise don't do anything72if (which(pandocBinary) === undefined) {73throw new Error(74`${pandocBinary} is not on PATH. Please install it and add it to PATH.`,75);76}77}78},79};80};8182// The pandocRelease83return {84name: "Pandoc",85bucket: "pandoc",86version,87architectureDependencies: {88"x86_64": {89"windows": pandocRelease(90`pandoc-${version}-windows-x86_64.zip`,91"pandoc.exe",92),93"linux": pandocRelease(94`pandoc-${version}-linux-amd64.tar.gz`,95"pandoc",96),97"darwin": pandocRelease(98`pandoc-${version}-x86_64-macOS.zip`,99"pandoc",100),101},102"aarch64": {103"linux": pandocRelease(104`pandoc-${version}-linux-arm64.tar.gz`,105"pandoc",106),107"darwin" : pandocRelease(108`pandoc-${version}-arm64-macOS.zip`,109"pandoc",110)111},112},113};114}115116117