Allow Specifying Custom TypeScript Root
Some checks failed
ScriptCraft/pipeline/head There was a failure building this commit
Some checks failed
ScriptCraft/pipeline/head There was a failure building this commit
This commit is contained in:
parent
9f68375dc6
commit
d8b0a1ddbe
@ -28,39 +28,17 @@ jni {
|
|||||||
addPlatform("windows-x86", ".dll")
|
addPlatform("windows-x86", ".dll")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Exec>("eslint") {
|
tasks.register<TypeScriptPlugin.NPMTask>("eslint") {
|
||||||
group = "verification"
|
group = "verification"
|
||||||
|
|
||||||
workingDir(typescript.root)
|
taskName = "eslint"
|
||||||
|
|
||||||
executable("npm")
|
|
||||||
|
|
||||||
args("run", "eslint")
|
|
||||||
|
|
||||||
dependsOn(tasks["npmInstall"])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Exec>("typedoc") {
|
tasks.register<TypeScriptPlugin.NPMTask>("typedoc") {
|
||||||
group = "documentation"
|
group = "documentation"
|
||||||
|
|
||||||
val typedocOut = File(typescript.root, "build/typedoc")
|
taskName = "typedoc"
|
||||||
|
outputDir = "build/typedoc"
|
||||||
inputs.dir(typescript.root)
|
|
||||||
outputs.dir(typedocOut)
|
|
||||||
|
|
||||||
workingDir(typescript.root)
|
|
||||||
|
|
||||||
executable("npm")
|
|
||||||
|
|
||||||
args("run", "typedoc")
|
|
||||||
|
|
||||||
doFirst {
|
|
||||||
project.delete {
|
|
||||||
delete(typedocOut)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependsOn(tasks["npmInstall"])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named<Copy>("processResources") {
|
tasks.named<Copy>("processResources") {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.tasks.Copy
|
import org.gradle.api.tasks.*
|
||||||
import org.gradle.api.tasks.Exec
|
|
||||||
import org.gradle.api.tasks.Sync
|
|
||||||
import org.gradle.api.tasks.bundling.Jar
|
import org.gradle.api.tasks.bundling.Jar
|
||||||
import org.gradle.kotlin.dsl.*
|
import org.gradle.kotlin.dsl.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -10,113 +9,158 @@ import java.util.concurrent.Callable
|
|||||||
|
|
||||||
class TypeScriptPlugin : Plugin<Project> {
|
class TypeScriptPlugin : Plugin<Project> {
|
||||||
open class TypeScriptConfig(rootDir: File) {
|
open class TypeScriptConfig(rootDir: File) {
|
||||||
val root: File = File(rootDir, "src/main/ts")
|
var root: File = File(rootDir, "src/main/ts")
|
||||||
|
}
|
||||||
|
|
||||||
fun getOutDir(): File {
|
open class NPMTask : DefaultTask() {
|
||||||
return File(root, "build/ts")
|
@get:Input
|
||||||
|
lateinit var taskName: String
|
||||||
|
@get:Input
|
||||||
|
lateinit var outputDir: String
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
fun exec() {
|
||||||
|
project.delete {
|
||||||
|
delete(getOutput())
|
||||||
|
}
|
||||||
|
project.exec {
|
||||||
|
workingDir(getInput())
|
||||||
|
|
||||||
|
executable("npm")
|
||||||
|
|
||||||
|
args("run", taskName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDeclarationDir(): File {
|
@InputDirectory
|
||||||
return File(root, "build/dts")
|
fun getInput(): Callable<File> {
|
||||||
|
return Callable {
|
||||||
|
project.the<TypeScriptConfig>().root
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDependenciesDir(): File {
|
@OutputDirectory
|
||||||
return File(root, "build/dependencies")
|
fun getOutput(): Callable<File>? {
|
||||||
|
return if (this::outputDir.isInitialized) {
|
||||||
|
Callable {
|
||||||
|
if (File(outputDir).isAbsolute) {
|
||||||
|
File(outputDir)
|
||||||
|
} else {
|
||||||
|
File(project.the<TypeScriptConfig>().root, outputDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class NPMInstallTask : DefaultTask() {
|
||||||
|
@TaskAction
|
||||||
|
fun exec() {
|
||||||
|
project.delete {
|
||||||
|
delete(getOutput())
|
||||||
|
}
|
||||||
|
project.exec {
|
||||||
|
workingDir(Callable {
|
||||||
|
project.the<TypeScriptConfig>().root
|
||||||
|
})
|
||||||
|
|
||||||
|
executable("npm")
|
||||||
|
|
||||||
|
args("install")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@InputFile
|
||||||
|
fun getInput(): Callable<File> {
|
||||||
|
return Callable {
|
||||||
|
File(project.the<TypeScriptConfig>().root, "package.json")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OutputDirectory
|
||||||
|
fun getOutput(): Callable<File> {
|
||||||
|
return Callable {
|
||||||
|
File(project.the<TypeScriptConfig>().root, "node_modules")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun apply(project: Project): Unit = project.run {
|
override fun apply(project: Project): Unit = project.run {
|
||||||
val extension = project.extensions.create<TypeScriptConfig>("typescript", projectDir)
|
val extension = project.extensions.create<TypeScriptConfig>("typescript", projectDir)
|
||||||
|
|
||||||
configurations {
|
val typescript = configurations.create("typescript") {
|
||||||
create("typescript") {
|
isTransitive = false
|
||||||
isTransitive = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Sync>("extractTypescriptDependencies") {
|
val npmInstallTask = tasks.register<NPMInstallTask>("npmInstall") {
|
||||||
|
group = "typescript"
|
||||||
|
}
|
||||||
|
|
||||||
|
val extractTypescriptDependenciesTask = tasks.register<Sync>("extractTypescriptDependencies") {
|
||||||
group = "typescript"
|
group = "typescript"
|
||||||
|
|
||||||
dependsOn(configurations["typescript"])
|
dependsOn(typescript)
|
||||||
|
|
||||||
from(Callable {
|
from(Callable {
|
||||||
configurations["typescript"].map {
|
typescript.map {
|
||||||
zipTree(it).matching {
|
zipTree(it).matching {
|
||||||
exclude("META-INF", "META-INF/**")
|
exclude("META-INF", "META-INF/**")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
into(extension.getDependenciesDir())
|
into(File(extension.root, "build/dependencies/api"))
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Exec>("npmInstall") {
|
project.afterEvaluate {
|
||||||
group = "typescript"
|
tasks.forEach {
|
||||||
|
if (it is NPMTask) {
|
||||||
inputs.file(File(extension.root, "package.json"))
|
it.dependsOn(npmInstallTask)
|
||||||
outputs.dir(File(extension.root, "node_modules"))
|
it.dependsOn(extractTypescriptDependenciesTask)
|
||||||
|
|
||||||
workingDir(extension.root)
|
|
||||||
|
|
||||||
executable("npm")
|
|
||||||
|
|
||||||
args("install")
|
|
||||||
|
|
||||||
doFirst {
|
|
||||||
project.delete {
|
|
||||||
delete(File(extension.root, "node_modules"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependsOn(tasks["extractTypescriptDependencies"])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Exec>("typescript") {
|
val typescriptTask = tasks.register<NPMTask>("typescript") {
|
||||||
group = "typescript"
|
group = "typescript"
|
||||||
|
|
||||||
inputs.dir(extension.root)
|
taskName = "build"
|
||||||
outputs.dirs(extension.getOutDir())
|
outputDir = "build/ts"
|
||||||
|
|
||||||
workingDir(extension.root)
|
|
||||||
|
|
||||||
executable("npm")
|
|
||||||
|
|
||||||
args("run", "build")
|
|
||||||
|
|
||||||
doFirst {
|
|
||||||
project.delete {
|
|
||||||
delete(extension.getOutDir())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependsOn(tasks["npmInstall"])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register<Jar>("apiJar") {
|
val apiJarTask = tasks.register<Jar>("apiJar") {
|
||||||
group = "typescript"
|
group = "typescript"
|
||||||
|
|
||||||
into("/types") {
|
into("/types") {
|
||||||
from(File(extension.root, "types"))
|
from(Callable {
|
||||||
|
File(extension.root, "types")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
into("/src") {
|
into("/src") {
|
||||||
from(extension.getDeclarationDir())
|
from(Callable {
|
||||||
|
File(extension.root, "build/dts")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
archiveClassifier.set("api")
|
archiveClassifier.set("api")
|
||||||
|
|
||||||
dependsOn(tasks["typescript"])
|
dependsOn(typescriptTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts {
|
artifacts {
|
||||||
add("archives", tasks["apiJar"])
|
add("archives", apiJarTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named<Copy>("processResources") {
|
tasks.named<Copy>("processResources") {
|
||||||
dependsOn(tasks["typescript"])
|
dependsOn(typescriptTask)
|
||||||
|
|
||||||
from(extension.getOutDir()) {
|
from(Callable {
|
||||||
into("scriptcraft")
|
File(extension.root, "build/ts")
|
||||||
}
|
})
|
||||||
|
|
||||||
|
into("scriptcraft")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,12 +10,12 @@ This is an example of a Minecraft mod made in TypeScript using ScriptCraft.
|
|||||||
- NPM dependencies are not bundled
|
- NPM dependencies are not bundled
|
||||||
- API JARs are not bundled
|
- API JARs are not bundled
|
||||||
|
|
||||||
## ```typescript``` Gradle Configuration
|
|
||||||
The ```typescript``` gradle configuration will extract the specified API JAR into ```src/main/ts/build/dependencies```.
|
|
||||||
|
|
||||||
## API JARs
|
## API JARs
|
||||||
An API JAR can be built with ```./gradlew apiJar```.
|
An API JAR can be built with ```./gradlew apiJar```.
|
||||||
|
|
||||||
|
### ```typescript``` Gradle Configuration
|
||||||
|
The ```typescript``` gradle configuration will extract the specified API JAR into ```src/main/ts/build/dependencies```. It will not be bundled with the mod.
|
||||||
|
|
||||||
### File Structure
|
### File Structure
|
||||||
```
|
```
|
||||||
- API JAR Root
|
- API JAR Root
|
||||||
|
Reference in New Issue
Block a user