Skip to content

Commit

Permalink
Fix crashing with not existing package path and add package cache path
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaracha committed Oct 22, 2024
1 parent 1080c61 commit 9ebb2e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@ class GradleTypstPlugin : Plugin<Project> {
task.target.convention(project.layout.buildDirectory.dir("tools/typst"))
}
extension.compiler.convention(extractTask.flatMap { it.target })
val appDataDir = if (currentOs.isMacOsX) {
val dataDir = if (currentOs.isMacOsX) {
project.layout.projectDirectory.dir(project.providers.systemProperty("user.home")).map { it.dir("Library/Application Support") }
} else if (currentOs.isLinux) {
project.layout.projectDirectory.dir(project.providers.environmentVariable("XDG_DATA_HOME"))
} else {
project.layout.projectDirectory.dir(project.providers.environmentVariable("APPDATA"))
}
extension.localPackages.convention(appDataDir.map { it.dir("typst/packages") })
val cacheDir = if (currentOs.isMacOsX) {
project.layout.projectDirectory.dir(project.providers.systemProperty("user.home")).map { it.dir("Library/Caches") }
} else if (currentOs.isLinux) {
project.layout.projectDirectory.dir(project.providers.environmentVariable("XDG_CACHE_HOME"))
} else {
project.layout.projectDirectory.dir(project.providers.environmentVariable("LOCALAPPDATA"))
}
val packagePath = dataDir.map { it.dir("typst/packages") }
val packageCachePath = cacheDir.map { it.dir("typst/packages") }
if (packagePath.get().asFile.exists()) extension.localPackages.convention(packagePath)
extension.sourceSets.configureEach { s ->
s.format.pdf.enabled.convention(true)
s.format.png.enabled.convention(false)
Expand All @@ -54,6 +63,7 @@ class GradleTypstPlugin : Plugin<Project> {
project.tasks.withType(TypstCompileTask::class.java).configureEach { task ->
task.compiler.convention(extension.compiler)
task.packagePath.set(extension.localPackages)
task.packageCachePath.set(packageCachePath.get().asFile.absolutePath)
task.root.convention(project.layout.projectDirectory.asFile.absolutePath)
task.creationTimestamp.convention(extension.creationTimestamp)
task.useSystemFonts.convention(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ abstract class TypstCompileTask @Inject constructor(private val executor: Worker
interface Params : WorkParameters {
val executable: Property<String>
val packagePath: DirectoryProperty
val packageCachePath: Property<String>
val document: RegularFileProperty
val root: Property<String>
val variables: MapProperty<String, String>
Expand All @@ -47,6 +48,7 @@ abstract class TypstCompileTask @Inject constructor(private val executor: Worker
parameters.variables.get().forEach { (k, v) -> action.args("--input", "$k=$v") }
if (parameters.creationTimestamp.isPresent) action.args("--creation-timestamp", parameters.creationTimestamp.get())
if (parameters.packagePath.isPresent) action.args("--package-path", parameters.packagePath.asFile.get().absolutePath)
if (parameters.packageCachePath.isPresent) action.args("--package-cache-path", parameters.packageCachePath.get())
if (parameters.ppi.isPresent) action.args("--ppi", parameters.ppi.get().toString())
action.args(parameters.document.get().asFile.absolutePath)
.args(parameters.target.asFile.get().absolutePath)
Expand All @@ -59,6 +61,9 @@ abstract class TypstCompileTask @Inject constructor(private val executor: Worker
@get:Optional
@get:InputDirectory
abstract val packagePath: DirectoryProperty
@get:Optional
@get:Input
abstract val packageCachePath: Property<String>
@get:InputFiles
abstract val documents: ListProperty<RegularFile>
@get:Input
Expand Down Expand Up @@ -90,6 +95,7 @@ abstract class TypstCompileTask @Inject constructor(private val executor: Worker
queue.submit(TypstAction::class.java) { params ->
params.executable.set(executable)
params.packagePath.set(packagePath)
params.packageCachePath.set(packageCachePath)
params.document.set(document)
params.root.set(root)
params.variables.set(variables)
Expand Down

0 comments on commit 9ebb2e4

Please sign in to comment.