mirror of
https://github.com/Dadido3/go-typst.git
synced 2025-11-04 13:19:36 +00:00
Compare commits
No commits in common. "main" and "v0.4.0" have entirely different histories.
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -3,7 +3,6 @@
|
|||||||
"Dadido",
|
"Dadido",
|
||||||
"Foogaloo",
|
"Foogaloo",
|
||||||
"golangci",
|
"golangci",
|
||||||
"somepath",
|
|
||||||
"typst",
|
"typst",
|
||||||
"Vogel"
|
"Vogel"
|
||||||
]
|
]
|
||||||
|
|||||||
@ -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
|
package typst_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -20,10 +15,10 @@ func TestCliOptions(t *testing.T) {
|
|||||||
if len(args) != 2 {
|
if len(args) != 2 {
|
||||||
t.Errorf("wrong number of arguments, expected 2, got %d", len(args))
|
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])
|
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])
|
t.Error("wrong font path option, expected my two paths concatenated, got", args[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
cli.go
11
cli.go
@ -14,11 +14,8 @@ import (
|
|||||||
|
|
||||||
// TODO: Add docker support to CLI, by calling docker run instead
|
// 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 {
|
type CLI struct {
|
||||||
ExecutablePath string // The Typst executable path can be overridden here. Otherwise the default path will be used.
|
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
|
// 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 != "" {
|
if c.ExecutablePath != "" {
|
||||||
execPath = c.ExecutablePath
|
execPath = c.ExecutablePath
|
||||||
}
|
}
|
||||||
if execPath == "" {
|
|
||||||
return "", fmt.Errorf("go-typst doesn't support this platform")
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(execPath, "--version")
|
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
|
var output, errBuffer bytes.Buffer
|
||||||
cmd.Stdout = &output
|
cmd.Stdout = &output
|
||||||
@ -67,12 +60,8 @@ func (c CLI) Compile(input io.Reader, output io.Writer, options *CLIOptions) err
|
|||||||
if c.ExecutablePath != "" {
|
if c.ExecutablePath != "" {
|
||||||
execPath = c.ExecutablePath
|
execPath = c.ExecutablePath
|
||||||
}
|
}
|
||||||
if execPath == "" {
|
|
||||||
return fmt.Errorf("go-typst doesn't support this platform")
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := exec.Command(execPath, args...)
|
cmd := exec.Command(execPath, args...)
|
||||||
cmd.Dir = c.WorkingDirectory
|
|
||||||
cmd.Stdin = input
|
cmd.Stdin = input
|
||||||
cmd.Stdout = output
|
cmd.Stdout = output
|
||||||
|
|
||||||
|
|||||||
12
cli_js.go
12
cli_js.go
@ -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 = ""
|
|
||||||
22
cli_test.go
22
cli_test.go
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2024-2025 David Vogel
|
// Copyright (c) 2024 David Vogel
|
||||||
//
|
//
|
||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
@ -9,7 +9,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"image"
|
"image"
|
||||||
_ "image/png"
|
_ "image/png"
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -61,22 +60,3 @@ func TestCLI_Compile(t *testing.T) {
|
|||||||
t.Fatalf("Resulting image height is %d, expected %d.", imgConf.Height, inches*ppi)
|
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.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
12
cli_wasi.go
12
cli_wasi.go
@ -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 = ""
|
|
||||||
@ -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
|
package typst_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@ -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
|
package typst_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
#let template() = {
|
|
||||||
set page(width: auto, height: auto, margin: 5mm)
|
|
||||||
|
|
||||||
heading("Hello World!")
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
#set page(width: auto, height: auto, margin: 5mm)
|
|
||||||
|
|
||||||
#heading("Hello World!")
|
|
||||||
@ -1,8 +1,3 @@
|
|||||||
// Copyright (c) 2025 David Vogel
|
|
||||||
//
|
|
||||||
// This software is released under the MIT License.
|
|
||||||
// https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
package typst
|
package typst
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user