diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 9f9261e..be65ffb 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -7,7 +7,15 @@ Inside the JAR, JS source files are in ```/scriptcraft```, and inside An external libraries API can be accessed using an ```import``` statement. ## TypeScript -TypeScript-based projects use thw ```com.thebrokenrail.scriptcraft.plugin``` Gradle plugin, this plugin will handle installing TypeScript and download any API type declarations. The TypeScript root using this Gradle plugin is at ```src/main/ts```. +TypeScript-based projects use the ```com.thebrokenrail.scriptcraft.plugin``` Gradle plugin, this plugin will handle installing TypeScript and download any API type declarations. The TypeScript root using this Gradle plugin is at ```src/main/ts```. + +### Custom TypeScript Root +The root for the TypeScript sub-project can be changed with: +```groovy +scriptcraft { + root = new File(project.rootDir, "a/b/c") +} +``` ### External Libraries To access an external libraries' API in addition to an ```import``` statement, the TypeScript compiler must have access to the external libraries' type declarations. The ScriptCraft Gradle plugin generates and downloads these using JAR files called API JARs. diff --git a/docs/MODULE_RESOLUTION.md b/docs/MODULE_RESOLUTION.md index 5f58323..b15c18c 100644 --- a/docs/MODULE_RESOLUTION.md +++ b/docs/MODULE_RESOLUTION.md @@ -1,11 +1,50 @@ # Module Resolution All ScriptCraft mods have a folder called ```scriptcraft``` in the root of their JAR file, when ScriptCraft is loaded all of these are combined to form a single "virtual" root. It is recommended to use namespaces to avoid conflicts with other mods. -## Supported File Types -- ```.js``` -- ```.mjs``` -- ```.json``` +## Examples -## Extra Details -- If the import path is a folder, ScriptCraft will load the ```index``` file, and if it doesn't exist it will try to load ```/index```. -- If the specified import does not exist, it will try to load the import appended with each supported file type. \ No newline at end of file +### Relative +Test Code: +```javascript +import '../path'; +``` + +Test Code Path: +``` +/some/thing/index.js +``` + +Module Resolution trace: +``` +/some/path +/some/path.js +/some/path.json +/some/path.mjs +/some/path/index +/some/path/index.js +/some/path/index.json +/some/path/index.mjs +``` + +### Non-Relative +Test Code: +```javascript +import 'path'; +``` + +Test Code Path: +``` +/some/thing/index.js +``` + +Module Resolution trace: +``` +/path +/path.js +/path.json +/path.mjs +/path/index +/path/index.js +/path/index.json +/path/index.mjs +``` \ No newline at end of file diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index e97e492..d59a75f 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -9,26 +9,18 @@ plugins { } group = "com.thebrokenrail.scriptcraft" -base.archivesBaseName = "plugin" version = "1.0.0" gradlePlugin { plugins { register("scriptcraft-plugin") { - id = "${group}.${base.archivesBaseName}" + id = "${group}.${project.name}" implementationClass = "ScriptCraftPlugin" } } } publishing { - project.afterEvaluate { - publications { - named("pluginMaven") { - artifactId = base.archivesBaseName - } - } - } repositories { maven { url = uri("/data/maven") diff --git a/plugin/src/main/kotlin/ScriptCraftPlugin.kt b/plugin/src/main/kotlin/ScriptCraftPlugin.kt index 757ff0e..2235510 100644 --- a/plugin/src/main/kotlin/ScriptCraftPlugin.kt +++ b/plugin/src/main/kotlin/ScriptCraftPlugin.kt @@ -8,7 +8,7 @@ import java.io.File import java.util.concurrent.Callable class ScriptCraftPlugin : Plugin { - open class TypeScriptConfig(rootDir: File) { + open class Config(rootDir: File) { var root: File = File(rootDir, "src/main/ts") } @@ -36,7 +36,7 @@ class ScriptCraftPlugin : Plugin { @InputDirectory fun getInput(): Callable { return Callable { - project.the().root + project.the().root } } @@ -49,7 +49,7 @@ class ScriptCraftPlugin : Plugin { if (File(dir).isAbsolute) { File(dir) } else { - File(project.the().root, dir) + File(project.the().root, dir) } } } else { @@ -66,7 +66,7 @@ class ScriptCraftPlugin : Plugin { } project.exec { workingDir(Callable { - project.the().root + project.the().root }) executable("npm") @@ -78,20 +78,20 @@ class ScriptCraftPlugin : Plugin { @InputFile fun getInput(): Callable { return Callable { - File(project.the().root, "package.json") + File(project.the().root, "package.json") } } @OutputDirectory fun getOutput(): Callable { return Callable { - File(project.the().root, "node_modules") + File(project.the().root, "node_modules") } } } override fun apply(project: Project): Unit = project.run { - val extension = project.extensions.create("typescript", projectDir) + val extension = project.extensions.create("scriptcraft", projectDir) val typescript = configurations.create("typescript") { isTransitive = false diff --git a/scriptcraft/build.gradle.kts b/scriptcraft/build.gradle.kts index 23f77c0..5da0d28 100644 --- a/scriptcraft/build.gradle.kts +++ b/scriptcraft/build.gradle.kts @@ -8,7 +8,7 @@ plugins { minecraft { } -base.archivesBaseName = project.property("archives_base_name") as String +val displayName = project.property("display_name") version = project.property("minecraft_version")!! group = project.property("maven_group")!! @@ -42,11 +42,11 @@ tasks.register("typedoc") { } tasks.named("processResources") { - inputs.property("name", rootProject.name) + inputs.property("name", displayName) from(sourceSets["main"].resources.srcDirs) { include("fabric.mod.json") - expand("name" to rootProject.name) + expand("name" to displayName) } from(sourceSets["main"].resources.srcDirs) { @@ -66,6 +66,10 @@ java { targetCompatibility = JavaVersion.VERSION_1_8 } +tasks.named("javadoc") { + title = "ScriptCraft" +} + // 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. @@ -84,8 +88,6 @@ tasks.named("jar") { publishing { publications { create("mavenJava") { - artifactId = project.property("archives_base_name") as String - artifact(tasks["remapJar"]) artifact(tasks["apiJar"]) } diff --git a/scriptcraft/buildSrc/src/main/kotlin/JNIPlugin.kt b/scriptcraft/buildSrc/src/main/kotlin/JNIPlugin.kt index 4b1454c..1c23888 100644 --- a/scriptcraft/buildSrc/src/main/kotlin/JNIPlugin.kt +++ b/scriptcraft/buildSrc/src/main/kotlin/JNIPlugin.kt @@ -8,7 +8,7 @@ import java.io.File import java.util.concurrent.Callable class JNIPlugin : Plugin { - open class JNIConfig(private val project: Project) { + open class Config(private val project: Project) { var root: File = File(project.rootDir, "src/main/c") fun addPlatform(name: String, libExtension: String) = project.run { @@ -76,6 +76,6 @@ class JNIPlugin : Plugin { dependsOn(tasks["compileJNI"]) } - project.extensions.create("jni", project) + project.extensions.create("jni", project) } } \ No newline at end of file diff --git a/scriptcraft/gradle.properties b/scriptcraft/gradle.properties index 35fbfb6..66ffe51 100644 --- a/scriptcraft/gradle.properties +++ b/scriptcraft/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs = -Xmx1G # Mod Properties maven_group = com.thebrokenrail - archives_base_name = scriptcraft + display_name = ScriptCraft # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api diff --git a/scriptcraft/settings.gradle.kts b/scriptcraft/settings.gradle.kts index 562c178..ac96046 100644 --- a/scriptcraft/settings.gradle.kts +++ b/scriptcraft/settings.gradle.kts @@ -12,6 +12,4 @@ pluginManagement { } } -rootProject.name = "ScriptCraft" - includeBuild("../plugin")