Compare commits

..

No commits in common. "main" and "v0.4.0" have entirely different histories.
main ... v0.4.0

11 changed files with 4 additions and 88 deletions

View File

@ -3,7 +3,6 @@
"Dadido",
"Foogaloo",
"golangci",
"somepath",
"typst",
"Vogel"
]

View File

@ -1,8 +1,3 @@
// Copyright (c) 2025 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package typst_test
import (
@ -20,10 +15,10 @@ func TestCliOptions(t *testing.T) {
if len(args) != 2 {
t.Errorf("wrong number of arguments, expected 2, got %d", len(args))
}
if args[0] != "--font-path" {
if "--font-path" != args[0] {
t.Error("wrong font path option, expected --font-path, got", args[0])
}
if args[1] != "somepath/to/somewhere"+string(os.PathListSeparator)+"another/to/somewhere" {
if "somepath/to/somewhere"+string(os.PathListSeparator)+"another/to/somewhere" != args[1] {
t.Error("wrong font path option, expected my two paths concatenated, got", args[1])
}
}

11
cli.go
View File

@ -14,11 +14,8 @@ import (
// TODO: Add docker support to CLI, by calling docker run instead
// TODO: Add an interface for the Typst caller and let CLI (and later docker and WASM) be implementations of that
type CLI struct {
ExecutablePath string // The Typst executable path can be overridden here. Otherwise the default path will be used.
WorkingDirectory string // The path where the Typst executable is run in. When left empty, the Typst executable will be run in the process's current directory.
}
// TODO: Add method for querying the Typst version resulting in a semver object
@ -30,12 +27,8 @@ func (c CLI) VersionString() (string, error) {
if c.ExecutablePath != "" {
execPath = c.ExecutablePath
}
if execPath == "" {
return "", fmt.Errorf("go-typst doesn't support this platform")
}
cmd := exec.Command(execPath, "--version")
cmd.Dir = c.WorkingDirectory // This doesn't do anything, but we will do it anyways for consistency.
var output, errBuffer bytes.Buffer
cmd.Stdout = &output
@ -67,12 +60,8 @@ func (c CLI) Compile(input io.Reader, output io.Writer, options *CLIOptions) err
if c.ExecutablePath != "" {
execPath = c.ExecutablePath
}
if execPath == "" {
return fmt.Errorf("go-typst doesn't support this platform")
}
cmd := exec.Command(execPath, args...)
cmd.Dir = c.WorkingDirectory
cmd.Stdin = input
cmd.Stdout = output

View File

@ -1,12 +0,0 @@
// Copyright (c) 2025 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
//go:build js
package typst
// The path to the Typst executable.
// We leave that empty as we don't support this platform for now.
var ExecutablePath = ""

View File

@ -1,4 +1,4 @@
// Copyright (c) 2024-2025 David Vogel
// Copyright (c) 2024 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
@ -9,7 +9,6 @@ import (
"bytes"
"image"
_ "image/png"
"path/filepath"
"strconv"
"testing"
@ -61,22 +60,3 @@ func TestCLI_Compile(t *testing.T) {
t.Fatalf("Resulting image height is %d, expected %d.", imgConf.Height, inches*ppi)
}
}
// Test basic compile functionality with a given working directory.
func TestCLI_CompileWithWorkingDir(t *testing.T) {
cli := typst.CLI{
WorkingDirectory: filepath.Join(".", "test-files"),
}
r := bytes.NewBufferString(`#import "hello-world-template.typ": template
#show: doc => template()`)
var w bytes.Buffer
err := cli.Compile(r, &w, nil)
if err != nil {
t.Fatalf("Failed to compile document: %v.", err)
}
if w.Available() == 0 {
t.Errorf("No output was written.")
}
}

View File

@ -1,12 +0,0 @@
// Copyright (c) 2025 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
//go:build wasip1
package typst
// The path to the Typst executable.
// We leave that empty as we don't support this platform for now.
var ExecutablePath = ""

View File

@ -1,8 +1,3 @@
// Copyright (c) 2025 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package typst_test
import (

View File

@ -1,8 +1,3 @@
// Copyright (c) 2025 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package typst_test
import (

View File

@ -1,5 +0,0 @@
#let template() = {
set page(width: auto, height: auto, margin: 5mm)
heading("Hello World!")
}

View File

@ -1,3 +0,0 @@
#set page(width: auto, height: auto, margin: 5mm)
#heading("Hello World!")

View File

@ -1,8 +1,3 @@
// Copyright (c) 2025 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package typst
import (