Skip to content

Commit

Permalink
Merge pull request #4 from jcbhmr/sweep/add_more_options_to_the_typst…
Browse files Browse the repository at this point in the history
…compile_com
  • Loading branch information
jcbhmr authored Dec 17, 2023
2 parents 2fcbf85 + 18c343b commit 0347c94
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ import { toPath, typstPath } from "./utils.js";
import { $ } from "execa";

export interface TypstCompileOptions {
root?: PathLike;
fontPath?: PathLike;
diagnosticFormat?: 'human' | 'short';
format?: 'pdf' | 'png' | 'svg';
open?: boolean;
ppi?: number;
flamegraph?: PathLike;
}
export default async function compile(
inputRaw: PathLike,
outputRaw: PathLike | undefined = undefined,
options: TypstCompileOptions = {},
) {
const inputPath = toPath(inputRaw);
const outputPath = outputRaw === undefined ? undefined : toPath(outputRaw);
const opts = [
...(options.fontPath == null
? []
: ["--font-path", toPath(options.fontPath)]),
];
const outputPath = outputRaw == null ? undefined : toPath(outputRaw);
const opts = [];
if (options.root != null) opts.push("--root", toPath(options.root));
if (options.fontPath != null) opts.push("--font-path", toPath(options.fontPath));
if (options.diagnosticFormat != null) opts.push("--diagnostic-format", options.diagnosticFormat);
if (options.format != null) opts.push("-f", options.format);
if (options.open != null) opts.push("--open");
if (options.ppi != null) opts.push("--ppi", options.ppi.toString());
if (options.flamegraph != null) opts.push("--flamegraph", options.flamegraph ? toPath(options.flamegraph) : undefined);
if (outputPath === undefined) {
await $`${typstPath} compile ${opts} ${inputPath}`;
} else {
Expand Down

0 comments on commit 0347c94

Please sign in to comment.