From f05e7dc4a08d067093c346ca3f6ea50241e356c6 Mon Sep 17 00:00:00 2001 From: octocorvus Date: Thu, 3 Aug 2023 08:37:56 +0000 Subject: [PATCH] build: hook viewer build tasks to gradle --- app/build.gradle.kts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0c5357dd..11132e25 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,3 +1,4 @@ +import org.apache.tools.ant.taskdefs.condition.Os import java.util.Properties import java.io.FileInputStream @@ -94,3 +95,30 @@ dependencies { implementation("androidx.appcompat:appcompat:1.6.1") implementation("com.google.android.material:material:1.9.0") } + +fun getCommand(command: String, winExt: String = "cmd"): String { + return if (Os.isFamily(Os.FAMILY_WINDOWS)) "$command.$winExt" else command +} + +val npmSetup = tasks.register("npmSetup", Exec::class) { + workingDir = rootDir + commandLine(getCommand("npm"), "ci", "--ignore-scripts") +} + +val processStatic = tasks.register("processStatic", Exec::class) { + workingDir = rootDir + dependsOn(npmSetup) + commandLine(getCommand("node", "exe"), "process_static.mjs") +} + +val cleanStatic = tasks.register("cleanStatic", Delete::class) { + delete("src/main/assets/viewer", "src/debug/assets/viewer") +} + +tasks.preBuild { + dependsOn(processStatic) +} + +tasks.clean { + dependsOn(cleanStatic) +}