From 1e16e2bd041e55b3003c370b7f94a75f87493cdd Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Mon, 25 May 2020 17:21:56 -0400 Subject: [PATCH] Switch To Kotlin Build Scripts --- Jenkinsfile | 12 ++ build.gradle | 82 ------------- build.gradle.kts | 111 ++++++++++++++++++ buildSrc/build.gradle.kts | 7 ++ buildSrc/src/main/kotlin/jni.gradle.kts | 80 +++++++++++++ .../src/main/kotlin/typescript.gradle.kts | 101 ++++++++++++++++ examples/javascript/build.gradle | 67 ----------- examples/javascript/build.gradle.kts | 66 +++++++++++ examples/javascript/settings.gradle | 1 - examples/javascript/settings.gradle.kts | 1 + examples/typescript/README.md | 11 +- examples/typescript/build.gradle | 71 ----------- examples/typescript/build.gradle.kts | 69 +++++++++++ examples/typescript/settings.gradle | 1 - examples/typescript/settings.gradle.kts | 1 + examples/typescript/src/main/ts/tsconfig.json | 24 +--- examples/typescript/typescript.build.gradle | 73 ------------ jni.build.gradle | 74 ------------ settings.gradle => settings.gradle.kts | 6 +- src/main/ts/tsconfig.json | 5 +- typescript.build.gradle | 93 --------------- 21 files changed, 463 insertions(+), 493 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/jni.gradle.kts create mode 100644 buildSrc/src/main/kotlin/typescript.gradle.kts delete mode 100644 examples/javascript/build.gradle create mode 100644 examples/javascript/build.gradle.kts delete mode 120000 examples/javascript/settings.gradle create mode 120000 examples/javascript/settings.gradle.kts delete mode 100644 examples/typescript/build.gradle create mode 100644 examples/typescript/build.gradle.kts delete mode 120000 examples/typescript/settings.gradle create mode 120000 examples/typescript/settings.gradle.kts mode change 100644 => 120000 examples/typescript/src/main/ts/tsconfig.json delete mode 100644 examples/typescript/typescript.build.gradle delete mode 100644 jni.build.gradle rename settings.gradle => settings.gradle.kts (51%) delete mode 100644 typescript.build.gradle diff --git a/Jenkinsfile b/Jenkinsfile index 37bcf33..76635b1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,5 +27,17 @@ pipeline { } } } + stage('Build Examples') { + steps { + sh 'cd examples/typescript; ./gradlew build' + sh 'cd examples/javascript; ./gradlew build' + } + post { + success { + archiveArtifacts artifacts: 'examples/typescript/build/libs/*', fingerprint: true + archiveArtifacts artifacts: 'examples/javascript/build/libs/*', fingerprint: true + } + } + } } } diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 513b120..0000000 --- a/build.gradle +++ /dev/null @@ -1,82 +0,0 @@ -plugins { - id 'fabric-loom' version '0.2.7-SNAPSHOT' - id 'maven-publish' -} - -compileJava { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -archivesBaseName = project.archives_base_name -version = project.minecraft_version as Object -group = project.maven_group as Object - -minecraft { -} - -dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" -} - -apply from: './typescript.build.gradle' -apply from: './jni.build.gradle' - -processResources { - inputs.property 'name', rootProject.name - - from(sourceSets.main.resources.srcDirs) { - include 'fabric.mod.json' - expand 'name': rootProject.name - } - - from(sourceSets.main.resources.srcDirs) { - exclude 'fabric.mod.json' - } -} - -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' -} - -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier 'sources' - from sourceSets.main.allSource -} - -artifacts { - archives sourcesJar -} - -jar { - from 'LICENSE' -} - -publishing { - publications { - mavenJava(MavenPublication) { - artifactId archivesBaseName - - artifact(remapJar) { - builtBy remapJar - } - artifact(apiJar) { - builtBy apiJar - } - } - } - repositories { - maven { - url '/data/maven' - } - } -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..0e3beb5 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,111 @@ +plugins { + id("fabric-loom") version "0.2.7-SNAPSHOT" + id("jni") + id("typescript") + `maven-publish` +} + +minecraft { +} + +base.archivesBaseName = project.property("archives_base_name") as String +version = project.property("minecraft_version")!! +group = project.property("maven_group")!! + +dependencies { + minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") + mappings("net.fabricmc:yarn:${project.property("minecraft_version")}+build.${project.property("yarn_build")}:v2") + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader_version")}") + modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_api_version")}") +} + +tasks.register("eslint") { + group = "verification" + + workingDir(project.extra.get("typescriptRoot") as File) + + executable("npm") + + args("run", "eslint") + + dependsOn(tasks["npmInstall"]) +} + +tasks.register("typedoc") { + group = "documentation" + + val typedocOut = File(project.extra.get("typescriptRoot") as File, "build/typedoc") + + inputs.dir(project.extra.get("typescriptRoot") as File) + outputs.dir(typedocOut) + + workingDir(project.extra.get("typescriptRoot") as File) + + executable("npm") + + args("run", "typedoc") + + doFirst { + project.delete { + delete(typedocOut) + } + } + + dependsOn(tasks["npmInstall"]) +} + +tasks.named("processResources") { + inputs.property("name", rootProject.name) + + from(sourceSets["main"].resources.srcDirs) { + include("fabric.mod.json") + expand("name" to rootProject.name) + } + + from(sourceSets["main"].resources.srcDirs) { + exclude("fabric.mod.json") + } +} + +// ensure that the encoding is set to UTF-8, no matter what the system default is +// this fixes some edge cases with special characters not displaying correctly +// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html +tasks.withType { + options.encoding = "UTF-8" +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task +// if it is present. +// If you remove this task, sources will not be generated. +tasks.register("sourcesJar") { + archiveClassifier.set("sources") + from(sourceSets["main"].allSource) +} +artifacts { + add("archives", tasks["sourcesJar"]) +} + +tasks.named("jar") { + from("LICENSE") +} + +publishing { + publications { + create("mavenJava") { + artifactId = project.property("archives_base_name") as String + + artifact(tasks["remapJar"]) + artifact(tasks["apiJar"]) + } + } + repositories { + maven { + url = uri("/data/maven") + } + } +} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..f01e2c3 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +repositories { + gradlePluginPortal() +} + +plugins { + `kotlin-dsl` +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/jni.gradle.kts b/buildSrc/src/main/kotlin/jni.gradle.kts new file mode 100644 index 0000000..21fe6f3 --- /dev/null +++ b/buildSrc/src/main/kotlin/jni.gradle.kts @@ -0,0 +1,80 @@ +val cDir = File(rootProject.projectDir.absolutePath, "src/main/c") + +class JNIPlatform(val name: String, val libExtension: String, rootDir: File) { + val cmakeArgs: Array = arrayOf("-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake") +} + +val jniPlatforms = arrayOf( + JNIPlatform("linux-x86_64", ".so", rootDir), + JNIPlatform("linux-x86", ".so", rootDir), + JNIPlatform("linux-armhf", ".so", rootDir), + JNIPlatform("linux-arm64", ".so", rootDir), + JNIPlatform("windows-x86_64", ".dll", rootDir), + JNIPlatform("windows-x86", ".dll", rootDir) +) + +tasks.register("cleanJNI") { + group = "jni" +} +tasks.register("compileJNI") { + group = "jni" +} + +jniPlatforms.forEach { + val buildDir = File(cDir, "build-${it.name}") + if (!buildDir.exists()) { + buildDir.mkdir() + } + + tasks.register("cmake-${it.name}") { + group = "jni" + workingDir(buildDir) + + executable("cmake") + args(it.cmakeArgs, "..") + } + + tasks.register("compileJNI-${it.name}") { + group = "jni" + workingDir(buildDir) + + executable("make") + + dependsOn(tasks["cmake-${it.name}"]) + } + + tasks.named("compileJNI") { + dependsOn(tasks["compileJNI-${it.name}"]) + } + + tasks.register("cleanJNI-${it.name}") { + group = "jni" + delete(buildDir) + } + + tasks.named("cleanJNI") { + dependsOn(tasks["cleanJNI-${it.name}"]) + } +} + +tasks.named("clean") { + dependsOn(tasks["cleanJNI"]) +} + +tasks.named("processResources") { + dependsOn(tasks["compileJNI"]) + + jniPlatforms.forEach { + val buildDir = File(cDir, "build-${it.name}") + if (!buildDir.exists()) { + buildDir.mkdir() + } + + val file = File(buildDir, "libscriptcraft${it.libExtension}") + inputs.files(file) + + from(file.absolutePath) { + into(File("natives", it.name).path) + } + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/typescript.gradle.kts b/buildSrc/src/main/kotlin/typescript.gradle.kts new file mode 100644 index 0000000..1b27344 --- /dev/null +++ b/buildSrc/src/main/kotlin/typescript.gradle.kts @@ -0,0 +1,101 @@ +val typescriptRoot = File(rootDir.absolutePath, "src/main/ts") + +extra.set("typescriptRoot", typescriptRoot) + +val typescriptOut = File(typescriptRoot, "build/ts") + +val nodeModules = File(typescriptRoot, "node_modules") + +val typescriptDependencies = File(typescriptRoot, "build/dependencies") + +configurations { + create("typescript") { + isTransitive = false + } +} + +tasks.register("extractTypescriptDependencies") { + group = "typescript" + + dependsOn(configurations["typescript"]) + + from(Callable { + configurations["typescript"].map { + zipTree(it).matching { + exclude("META-INF", "META-INF/**") + } + } + }) + + into(typescriptDependencies) +} + +tasks.register("npmInstall") { + group = "typescript" + + inputs.file(File(typescriptRoot, "package.json")) + outputs.dir(nodeModules) + + workingDir(typescriptRoot) + + executable("npm") + + args("install") + + doFirst { + project.delete { + delete(nodeModules) + } + } + + dependsOn(tasks["extractTypescriptDependencies"]) +} + +tasks.register("typescript") { + group = "typescript" + + inputs.dir(typescriptRoot) + outputs.dirs(typescriptOut) + + workingDir(typescriptRoot) + + executable("npm") + + args("run", "build") + + doFirst { + project.delete { + delete(typescriptOut) + } + } + + dependsOn(tasks["npmInstall"]) +} + +tasks.register("apiJar") { + group = "typescript" + + val dtsOut = File(typescriptRoot, "build/dts") + + into("/types") { + from(File(typescriptRoot, "types")) + } + into("/src") { + from(dtsOut) + } + + archiveClassifier.set("api") + + dependsOn(tasks["typescript"]) +} +artifacts { + add("archives", tasks["apiJar"]) +} + +tasks.named("processResources") { + dependsOn(tasks["typescript"]) + + from(typescriptOut.absolutePath) { + into("scriptcraft") + } +} \ No newline at end of file diff --git a/examples/javascript/build.gradle b/examples/javascript/build.gradle deleted file mode 100644 index 7c1e0c8..0000000 --- a/examples/javascript/build.gradle +++ /dev/null @@ -1,67 +0,0 @@ -plugins { - id 'fabric-loom' version '0.2.7-SNAPSHOT' -} - -compileJava { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -archivesBaseName = project.archives_base_name -def mod_version = project.mod_version as Object -version = "${mod_version}+${project.minecraft_version}" -group = project.maven_group as Object - -minecraft { -} - -repositories { - maven { - url 'https://maven.thebrokenrail.com/' - } -} - -dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" - - modImplementation "com.thebrokenrail:scriptcraft:${project.minecraft_version}" - include "com.thebrokenrail:scriptcraft:${project.minecraft_version}" -} - -processResources { - inputs.property 'version', mod_version - - from(sourceSets.main.resources.srcDirs) { - include 'fabric.mod.json' - expand 'version': mod_version - } - - from(sourceSets.main.resources.srcDirs) { - exclude 'fabric.mod.json' - } -} - -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' -} - -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier 'sources' - from sourceSets.main.allSource -} - -artifacts { - archives sourcesJar -} - -jar { - from 'LICENSE' -} diff --git a/examples/javascript/build.gradle.kts b/examples/javascript/build.gradle.kts new file mode 100644 index 0000000..6f32955 --- /dev/null +++ b/examples/javascript/build.gradle.kts @@ -0,0 +1,66 @@ +plugins { + id("fabric-loom") version "0.2.7-SNAPSHOT" +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +base.archivesBaseName = project.property("archives_base_name") as String +val modVersion = project.property("mod_version") +version = "${modVersion}+${project.property("minecraft_version")}" +group = project.property("maven_group")!! + +minecraft { +} + +repositories { + maven { + url = uri("https://maven.thebrokenrail.com/") + } +} + +dependencies { + minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") + mappings("net.fabricmc:yarn:${project.property("minecraft_version")}+build.${project.property("yarn_build")}:v2") + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader_version")}") + + modImplementation("com.thebrokenrail:scriptcraft:${project.property("minecraft_version")}") + include("com.thebrokenrail:scriptcraft:${project.property("minecraft_version")}") +} + +tasks.named("processResources") { + inputs.property("version", modVersion) + + from(sourceSets["main"].resources.srcDirs) { + include("fabric.mod.json") + expand("version" to modVersion) + } + + from(sourceSets["main"].resources.srcDirs) { + exclude("fabric.mod.json") + } +} + +// ensure that the encoding is set to UTF-8, no matter what the system default is +// this fixes some edge cases with special characters not displaying correctly +// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html +tasks.withType { + options.encoding = "UTF-8" +} + +// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task +// if it is present. +// If you remove this task, sources will not be generated. +tasks.register("sourcesJar") { + archiveClassifier.set("sources") + from(sourceSets["main"].allSource) +} +artifacts { + add("archives", tasks["sourcesJar"]) +} + +tasks.named("jar") { + from("LICENSE") +} diff --git a/examples/javascript/settings.gradle b/examples/javascript/settings.gradle deleted file mode 120000 index 19fe1e9..0000000 --- a/examples/javascript/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -../../settings.gradle \ No newline at end of file diff --git a/examples/javascript/settings.gradle.kts b/examples/javascript/settings.gradle.kts new file mode 120000 index 0000000..976ab1c --- /dev/null +++ b/examples/javascript/settings.gradle.kts @@ -0,0 +1 @@ +../../settings.gradle.kts \ No newline at end of file diff --git a/examples/typescript/README.md b/examples/typescript/README.md index 9da5ef0..503d1d7 100644 --- a/examples/typescript/README.md +++ b/examples/typescript/README.md @@ -1,19 +1,22 @@ # TypeScript Example This is an example of a Minecraft mod made in TypeScript using ScriptCraft. -#### Files +## Files - ```src/main/ts```: Contains TypeScript Code - ```src/main/java```: Contains Bootstrap Java Code -#### Notes +## Notes - This will also work with JavaScript if you set ```compilerOptions.allowJs``` and optionally ```compilerOptions.checkJs``` in ```src/main/ts/tsconfig.json``` to ```true``` - NPM dependencies are not bundled - API JARs are not bundled -#### ```typescript``` Gradle Configuration +## ```typescript``` Gradle Configuration The ```typescript``` gradle configuration will extract the specified API JAR into ```src/main/ts/build/dependencies```. -#### API JAR Format +## API JARs +An API JAR can be built with ```./gradlew apiJar```. + +### File Structure ``` - API JAR Root - src/ diff --git a/examples/typescript/build.gradle b/examples/typescript/build.gradle deleted file mode 100644 index 0db5e48..0000000 --- a/examples/typescript/build.gradle +++ /dev/null @@ -1,71 +0,0 @@ -plugins { - id 'fabric-loom' version '0.2.7-SNAPSHOT' -} - -compileJava { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -archivesBaseName = project.archives_base_name -def mod_version = project.mod_version as Object -version = "${mod_version}+${project.minecraft_version}" -group = project.maven_group as Object - -minecraft { -} - -repositories { - maven { - url 'https://maven.thebrokenrail.com/' - } -} - -apply from: './typescript.build.gradle' - -dependencies { - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.minecraft_version}+build.${project.yarn_build}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.fabric_loader_version}" - - modImplementation "com.thebrokenrail:scriptcraft:${project.minecraft_version}" - include "com.thebrokenrail:scriptcraft:${project.minecraft_version}" - - typescript "com.thebrokenrail:scriptcraft:${project.minecraft_version}:api" -} - -processResources { - inputs.property 'version', mod_version - - from(sourceSets.main.resources.srcDirs) { - include 'fabric.mod.json' - expand 'version': mod_version - } - - from(sourceSets.main.resources.srcDirs) { - exclude 'fabric.mod.json' - } -} - -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' -} - -// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task -// if it is present. -// If you remove this task, sources will not be generated. -task sourcesJar(type: Jar, dependsOn: classes) { - classifier 'sources' - from sourceSets.main.allSource -} - -artifacts { - archives sourcesJar -} - -jar { - from 'LICENSE' -} diff --git a/examples/typescript/build.gradle.kts b/examples/typescript/build.gradle.kts new file mode 100644 index 0000000..82f6c8f --- /dev/null +++ b/examples/typescript/build.gradle.kts @@ -0,0 +1,69 @@ +plugins { + id("fabric-loom") version "0.2.7-SNAPSHOT" + id("typescript") +} + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +base.archivesBaseName = project.property("archives_base_name") as String +val modVersion = project.property("mod_version") +version = "${modVersion}+${project.property("minecraft_version")}" +group = project.property("maven_group")!! + +minecraft { +} + +repositories { + maven { + url = uri("https://maven.thebrokenrail.com/") + } +} + +dependencies { + minecraft("com.mojang:minecraft:${project.property("minecraft_version")}") + mappings("net.fabricmc:yarn:${project.property("minecraft_version")}+build.${project.property("yarn_build")}:v2") + modImplementation("net.fabricmc:fabric-loader:${project.property("fabric_loader_version")}") + + modImplementation("com.thebrokenrail:scriptcraft:${project.property("minecraft_version")}") + include("com.thebrokenrail:scriptcraft:${project.property("minecraft_version")}") + + typescript("com.thebrokenrail:scriptcraft:${project.property("minecraft_version")}:api") +} + +tasks.named("processResources") { + inputs.property("version", modVersion) + + from(sourceSets["main"].resources.srcDirs) { + include("fabric.mod.json") + expand("version" to modVersion) + } + + from(sourceSets["main"].resources.srcDirs) { + exclude("fabric.mod.json") + } +} + +// ensure that the encoding is set to UTF-8, no matter what the system default is +// this fixes some edge cases with special characters not displaying correctly +// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html +tasks.withType { + options.encoding = "UTF-8" +} + +// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task +// if it is present. +// If you remove this task, sources will not be generated. +tasks.register("sourcesJar") { + archiveClassifier.set("sources") + from(sourceSets["main"].allSource) +} +artifacts { + add("archives", tasks["sourcesJar"]) +} + +tasks.named("jar") { + from("LICENSE") +} diff --git a/examples/typescript/settings.gradle b/examples/typescript/settings.gradle deleted file mode 120000 index 19fe1e9..0000000 --- a/examples/typescript/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -../../settings.gradle \ No newline at end of file diff --git a/examples/typescript/settings.gradle.kts b/examples/typescript/settings.gradle.kts new file mode 120000 index 0000000..976ab1c --- /dev/null +++ b/examples/typescript/settings.gradle.kts @@ -0,0 +1 @@ +../../settings.gradle.kts \ No newline at end of file diff --git a/examples/typescript/src/main/ts/tsconfig.json b/examples/typescript/src/main/ts/tsconfig.json deleted file mode 100644 index 673bfd0..0000000 --- a/examples/typescript/src/main/ts/tsconfig.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "noImplicitAny": true, - "noImplicitReturns": true, - "noImplicitThis": true, - "noUnusedLocals": true, - "lib": ["es2020"], - "module": "es2020", - "target": "es2020", - "removeComments": true, - "typeRoots": ["build/dependencies/types"], - "paths": { - "*": ["*", "../build/dependencies/src/*"] - }, - "baseUrl": "src", - "outDir": "build/ts", - "moduleResolution": "node", - "resolveJsonModule": true - }, - "include": [ - "src/**/*" - ] -} \ No newline at end of file diff --git a/examples/typescript/src/main/ts/tsconfig.json b/examples/typescript/src/main/ts/tsconfig.json new file mode 120000 index 0000000..e754f88 --- /dev/null +++ b/examples/typescript/src/main/ts/tsconfig.json @@ -0,0 +1 @@ +../../../../../src/main/ts/tsconfig.json \ No newline at end of file diff --git a/examples/typescript/typescript.build.gradle b/examples/typescript/typescript.build.gradle deleted file mode 100644 index 138ef8e..0000000 --- a/examples/typescript/typescript.build.gradle +++ /dev/null @@ -1,73 +0,0 @@ -def typescriptRoot = 'src/main/ts' -def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot) - -def typescriptOut = new File(typescriptRootFile, 'build/ts') - -def nodeModules = new File(typescriptRootFile, 'node_modules') - -task npmInstall(group: 'typescript', type: Exec) { - inputs.file new File(typescriptRootFile, 'package.json') - outputs.dir nodeModules - - workingDir typescriptRootFile - - executable 'npm' - - args 'install' - - doFirst { - project.delete { - delete nodeModules - } - } -} - -def typescriptDependencies = new File(typescriptRootFile, 'build/dependencies') - -configurations { - typescript { - transitive false - } -} - -task extractTypescriptDependencies(type: Sync, group: 'typescript') { - dependsOn configurations.typescript - - from { - configurations.typescript.collect { - zipTree(it).matching { - exclude 'META-INF', 'META-INF/**' - } - } - } - - into typescriptDependencies -} - -task typescript(group: 'typescript', type: Exec) { - inputs.dir typescriptRootFile - outputs.dirs typescriptOut - - workingDir typescriptRootFile - - executable 'npm' - - args 'run', 'build' - - doFirst { - project.delete { - delete typescriptOut - } - } -} - -typescript.dependsOn npmInstall -typescript.dependsOn extractTypescriptDependencies - -processResources.dependsOn typescript - -processResources { - from(typescriptOut.absolutePath) { - into 'scriptcraft' - } -} \ No newline at end of file diff --git a/jni.build.gradle b/jni.build.gradle deleted file mode 100644 index 4483aa1..0000000 --- a/jni.build.gradle +++ /dev/null @@ -1,74 +0,0 @@ -def cDir = new File(rootProject.projectDir.absolutePath, 'src/main/c') - -class JNIPlatform { - String name - String[] cmakeArgs - String libExtension - - JNIPlatform(String name, String libExtension, File rootDir) { - this.name = name - this.cmakeArgs = ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake"] as String[] - this.libExtension = libExtension - } -} - -JNIPlatform[] jniPlatforms = [ - new JNIPlatform("linux-x86_64", ".so", rootDir), - new JNIPlatform("linux-x86", ".so", rootDir), - new JNIPlatform("linux-armhf", ".so", rootDir), - new JNIPlatform("linux-arm64", ".so", rootDir), - new JNIPlatform("windows-x86_64", ".dll", rootDir), - new JNIPlatform("windows-x86", ".dll", rootDir) -] - -task cleanJNI {} -task compileJNI {} - -for (JNIPlatform platform : jniPlatforms) { - def buildDir = new File(cDir, "build-${platform.name}") - if (!buildDir.exists()) { - buildDir.mkdir() - } - - tasks.create(name: "cmake-${platform.name}", group: 'jni', type: Exec) { - workingDir buildDir - - executable 'cmake' - args platform.cmakeArgs + ['..'] - } - - tasks.create(name: "compileJNI-${platform.name}", group: 'jni', type: Exec) { - workingDir buildDir - - executable 'make' - - dependsOn tasks.getByName("cmake-${platform.name}") - } - - compileJNI.dependsOn tasks.getByName("compileJNI-${platform.name}") - - tasks.create(name: "cleanJNI-${platform.name}", group: 'jni', type: Delete) { - delete buildDir.absolutePath - } - - cleanJNI.dependsOn tasks.getByName("cleanJNI-${platform.name}") -} - -clean.dependsOn cleanJNI -processResources.dependsOn compileJNI - -processResources { - for (JNIPlatform platform : jniPlatforms) { - def buildDir = new File(cDir, "build-${platform.name}") - if (!buildDir.exists()) { - buildDir.mkdir() - } - - def file = new File(buildDir, 'libscriptcraft' + platform.libExtension) - inputs.files file - - from(file.absolutePath) { - into new File('natives', platform.name).path - } - } -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle.kts similarity index 51% rename from settings.gradle rename to settings.gradle.kts index ef88f39..4b7168c 100644 --- a/settings.gradle +++ b/settings.gradle.kts @@ -2,11 +2,11 @@ pluginManagement { repositories { jcenter() maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' + name = "Fabric" + url = uri("https://maven.fabricmc.net/") } gradlePluginPortal() } } -rootProject.name = 'ScriptCraft' +rootProject.name = "ScriptCraft" diff --git a/src/main/ts/tsconfig.json b/src/main/ts/tsconfig.json index 1079dad..a0a6a09 100644 --- a/src/main/ts/tsconfig.json +++ b/src/main/ts/tsconfig.json @@ -8,10 +8,13 @@ "module": "es2020", "target": "es2020", "removeComments": true, - "typeRoots": ["types"], "rootDir": "src", "baseUrl": "src", "outDir": "build/ts", + "typeRoots": ["types", "build/dependencies/types"], + "paths": { + "*": ["*", "../build/dependencies/src/*"] + }, "declaration": true, "declarationDir": "build/dts", "moduleResolution": "node", diff --git a/typescript.build.gradle b/typescript.build.gradle deleted file mode 100644 index 1bdef03..0000000 --- a/typescript.build.gradle +++ /dev/null @@ -1,93 +0,0 @@ -def typescriptRoot = 'src/main/ts' -def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot) - -def nodeModules = new File(typescriptRootFile, 'node_modules') - -task npmInstall(group: 'typescript', type: Exec) { - inputs.file new File(typescriptRootFile, 'package.json') - outputs.dir nodeModules - - workingDir typescriptRootFile - - executable 'npm' - - args 'install' -} - -def typescriptOut = new File(typescriptRootFile, 'build/ts') -def dtsOut = new File(typescriptRootFile, 'build/dts') - -task typescript(group: 'typescript', type: Exec) { - inputs.dir typescriptRootFile - outputs.dirs typescriptOut, dtsOut - - workingDir typescriptRootFile - - executable 'npm' - - args 'run', 'build' - - doFirst { - project.delete { - delete typescriptOut, dtsOut - } - } -} - -typescript.dependsOn npmInstall - -task apiJar(group: 'typescript', type: Jar) { - into('/types') { - from new File(typescriptRootFile as File, 'types') - } - into('/src') { - from dtsOut - } - - classifier 'api' -} - -apiJar.dependsOn typescript - -artifacts { - archives apiJar -} - -task eslint(group: 'typescript', type: Exec) { - workingDir typescriptRootFile - - executable 'npm' - - args 'run', 'eslint' -} - -eslint.dependsOn npmInstall - -processResources.dependsOn typescript - -def typedocOut = new File(typescriptRootFile, 'build/typedoc') - -task typedoc(group: 'typescript', type: Exec) { - inputs.dir typescriptRootFile - outputs.dir typedocOut - - workingDir typescriptRootFile - - executable 'npm' - - args 'run', 'typedoc' - - doFirst { - project.delete { - delete typedocOut - } - } -} - -typedoc.dependsOn npmInstall - -processResources { - from(typescriptOut.absolutePath) { - into 'scriptcraft' - } -} \ No newline at end of file