mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 21:59:05 +00:00
fix: convert gradle-plugins from directory to submodule
Matches dev branch's submodule reference so branch switching works seamlessly. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
1 parent
0b0dcdc58d
commit
9fcda980ee
9 files changed
+1
-1700
No files matched your search
Submodule
+1
Submodule gradle-plugins added at f1c82c10c8.
@@ -1,9 +0,0 @@
|
||||
/.gradle
|
||||
/build
|
||||
/out
|
||||
/bin
|
||||
/.idea
|
||||
/.vscode
|
||||
/.settings
|
||||
.project
|
||||
.classpath
|
||||
@@ -1,94 +0,0 @@
|
||||
# dts-gradle-plugin
|
||||
|
||||
This repo contains the Gradle plugin for generating TypeScript `.d.ts` files for the CustomNPC-Plus API.
|
||||
|
||||
These files are used for the generation of auto-completion suggestions and type/interface documentation when scripting
|
||||
in the Script Editor in-game.
|
||||
|
||||
### Implementation using JitPack
|
||||
|
||||
Add JitPack to the buildscript and depend on the plugin JAR. Using `main-SNAPSHOT` will build the latest `main` commit;
|
||||
for reproducible builds use a tag or commit hash instead.
|
||||
|
||||
`settings.gradle`
|
||||
```gradle
|
||||
pluginManagement {
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if(requested.id.toString() == "dts.typescript-generator") {
|
||||
useModule("com.github.bigguy345:dts-gradle-plugin:main-SNAPSHOT")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
repositories {
|
||||
maven { url "https://jitpack.io" }
|
||||
gradlePluginPortal()
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
`build.gradle`:
|
||||
|
||||
```gradle
|
||||
plugins {
|
||||
id 'dts.typescript-generator'
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// TypeScript Definition Generation Task
|
||||
// Generates .d.ts files from Java API sources for scripting IDE support
|
||||
// ============================================================================
|
||||
// TypeScript plugin is applied above in the main plugins block
|
||||
|
||||
tasks.named("generateTypeScriptDefinitions").configure {
|
||||
// Source directories containing the Java API code
|
||||
sourceDirectories = ['src/main/java']
|
||||
|
||||
// Packages in source directories to generate .d.ts files for
|
||||
apiPackages = ['noppes.npcs.api'] as Set
|
||||
|
||||
// Output directory for the generated .d.ts files
|
||||
// Must be within resources/assets/${modId}/api to be detected by CNPC+
|
||||
outputDirectory = "src/main/resources/assets/${modId}/api"
|
||||
|
||||
// Whether to clean old generated files before regenerating
|
||||
cleanOutputFirst = true
|
||||
|
||||
// Optional: copy external patch .d.ts files into assets/<modid>/api/patches
|
||||
patchesDirectory = "dts-patches"
|
||||
}
|
||||
|
||||
|
||||
// Optional: To ensure definitions are generated on processing resources on jar build
|
||||
// But in most cases, you may want to run the task manually when needed
|
||||
// processResources.dependsOn generateTypeScriptDefinitions
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Patches (optional overrides)
|
||||
|
||||
Use `dts-patches/` to override or refine generated types. Files in this folder are copied to
|
||||
`assets/<modid>/api/patches` after generation.
|
||||
|
||||
### Example: override `IPlayer.getDBCPlayer()` to return `IDBCAddon` instead of `IDBCPlayer`
|
||||
|
||||
File: `dts-patches/IPlayer.d.ts`
|
||||
|
||||
```ts
|
||||
/**
|
||||
* DBC Addon patch for IPlayer
|
||||
* @javaFqn noppes.npcs.api.entity.IPlayer
|
||||
*/
|
||||
export interface IPlayer<T> {
|
||||
getDBCPlayer(): IDBCAddon;
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
plugins {
|
||||
id 'groovy-gradle-plugin'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
group = 'dts'
|
||||
version = '1.0.0'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation gradleApi()
|
||||
implementation localGroovy()
|
||||
}
|
||||
|
||||
// Configure source sets if building as standalone
|
||||
sourceSets {
|
||||
main {
|
||||
groovy {
|
||||
srcDirs = ['src/main/groovy']
|
||||
}
|
||||
resources {
|
||||
srcDirs = ['src/main/resources']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
typescriptGenerator {
|
||||
id = 'dts.typescript-generator'
|
||||
implementationClass = 'dts.TypeScriptGeneratorPlugin'
|
||||
displayName = 'TypeScript Definition Generator'
|
||||
description = 'Generates TypeScript definition files from Java API sources'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
}
|
||||
}
|
||||
|
||||
// Handle duplicate resources
|
||||
tasks.processResources {
|
||||
duplicatesStrategy = 'include'
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
rootProject.name = 'dts-gradle-plugin'
|
||||
@@ -1,175 +0,0 @@
|
||||
package dts
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.Optional
|
||||
|
||||
/**
|
||||
* Gradle task that generates TypeScript definition (.d.ts) files from Java API sources.
|
||||
*
|
||||
* Usage in build.gradle:
|
||||
*
|
||||
* tasks.withType(GenerateTypeScriptTask).configureEach {
|
||||
* sourceDirectories = ['src/api/java'] // Strings are converted to Files
|
||||
* outputDirectory = 'src/main/resources/${modid}/api' // String converted to File
|
||||
* apiPackages = ['noppes.npcs.api', 'kamkeel.npcdbc.api']
|
||||
* }
|
||||
*/
|
||||
abstract class GenerateTypeScriptTask extends DefaultTask {
|
||||
|
||||
// Accept Object types (String or File) with @Internal annotation
|
||||
@Internal
|
||||
List<Object> sourceDirectories = []
|
||||
|
||||
@Internal
|
||||
Object outputDirectory
|
||||
|
||||
@Input
|
||||
Set<String> apiPackages = []
|
||||
|
||||
@Input
|
||||
Boolean cleanOutputFirst = false
|
||||
|
||||
@Input
|
||||
List<String> excludePatterns = []
|
||||
|
||||
@Internal
|
||||
Object patchesDirectory
|
||||
|
||||
// Provide task input/output properties that Gradle can validate
|
||||
@InputFiles
|
||||
protected List<File> getResolvedSourceDirectories() {
|
||||
return sourceDirectories.collect { obj ->
|
||||
if (obj instanceof File) return obj
|
||||
String pathStr = obj.toString()
|
||||
if (pathStr.contains('${modid}')) {
|
||||
String modid = project.archivesBaseName ?: 'mod'
|
||||
pathStr = pathStr.replace('${modid}', modid)
|
||||
}
|
||||
File f = new File(pathStr)
|
||||
if (!f.isAbsolute()) {
|
||||
f = new File(project.projectDir, pathStr)
|
||||
}
|
||||
return f
|
||||
}
|
||||
}
|
||||
|
||||
@OutputDirectory
|
||||
protected File getResolvedOutputDirectory() {
|
||||
def obj = outputDirectory
|
||||
if (obj instanceof File) return obj
|
||||
String pathStr = obj.toString()
|
||||
if (pathStr.contains('${modid}')) {
|
||||
String modid = project.archivesBaseName ?: 'mod'
|
||||
pathStr = pathStr.replace('${modid}', modid)
|
||||
}
|
||||
File f = new File(pathStr)
|
||||
if (!f.isAbsolute()) {
|
||||
f = new File(project.projectDir, pathStr)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
@Optional
|
||||
@InputDirectory
|
||||
protected File getResolvedDtsPatchesDirectory() {
|
||||
if (patchesDirectory == null) return null
|
||||
def obj = patchesDirectory
|
||||
if (obj instanceof File) return obj
|
||||
String pathStr = obj.toString()
|
||||
if (pathStr.contains('${modid}')) {
|
||||
String modid = project.archivesBaseName ?: 'mod'
|
||||
pathStr = pathStr.replace('${modid}', modid)
|
||||
}
|
||||
File f = new File(pathStr)
|
||||
if (!f.isAbsolute()) {
|
||||
f = new File(project.projectDir, pathStr)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a value (String or File) to a File object.
|
||||
* Supports special tokens like ${modid}.
|
||||
*/
|
||||
// conversion logic inlined into getters to avoid calling private helper at configuration time
|
||||
|
||||
GenerateTypeScriptTask() {
|
||||
group = 'api'
|
||||
description = 'Generates TypeScript definition files from Java API sources'
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
void generate() {
|
||||
List<File> srcDirs = getResolvedSourceDirectories()
|
||||
File outDir = getResolvedOutputDirectory()
|
||||
File patchesDir = getResolvedDtsPatchesDirectory()
|
||||
|
||||
logger.lifecycle("=".multiply(60))
|
||||
logger.lifecycle("Generating TypeScript definitions...")
|
||||
logger.lifecycle("=".multiply(60))
|
||||
|
||||
if (srcDirs.isEmpty()) {
|
||||
logger.warn("No source directories specified!")
|
||||
return
|
||||
}
|
||||
|
||||
// Validate directories
|
||||
srcDirs.each { dir ->
|
||||
if (!dir.exists()) {
|
||||
logger.warn("Source directory does not exist: ${dir}")
|
||||
} else {
|
||||
logger.lifecycle("Source: ${dir}")
|
||||
}
|
||||
}
|
||||
|
||||
logger.lifecycle("Output: ${outDir}")
|
||||
logger.lifecycle("API Packages: ${apiPackages}")
|
||||
|
||||
// Clean output if requested
|
||||
if (cleanOutputFirst && outDir.exists()) {
|
||||
logger.lifecycle("Cleaning output directory...")
|
||||
outDir.eachFileRecurse { file ->
|
||||
if (file.name.endsWith('.d.ts') && !file.name.equals('minecraft-raw.d.ts') && !file.name.equals('forge-events-raw.d.ts')) {
|
||||
file.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create converter and process
|
||||
JavaToTypeScriptConverter converter = new JavaToTypeScriptConverter(outDir, apiPackages)
|
||||
|
||||
List<File> validDirs = srcDirs.findAll { it.exists() }
|
||||
if (validDirs.isEmpty()) {
|
||||
logger.error("No valid source directories found!")
|
||||
return
|
||||
}
|
||||
|
||||
converter.processDirectories(validDirs, logger)
|
||||
|
||||
if (patchesDir != null) {
|
||||
if (!patchesDir.exists()) {
|
||||
logger.lifecycle("Patches directory does not exist: ${patchesDir}")
|
||||
} else {
|
||||
File patchOutputDir = new File(outDir, "patches")
|
||||
if (patchOutputDir.exists()) {
|
||||
patchOutputDir.deleteDir()
|
||||
}
|
||||
project.copy {
|
||||
from patchesDir
|
||||
into patchOutputDir
|
||||
}
|
||||
logger.lifecycle("Copied .d.ts patches to: ${patchOutputDir}")
|
||||
}
|
||||
}
|
||||
|
||||
logger.lifecycle("=".multiply(60))
|
||||
logger.lifecycle("TypeScript definition generation complete!")
|
||||
logger.lifecycle("=".multiply(60))
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,17 +0,0 @@
|
||||
package dts
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
/**
|
||||
* Gradle plugin for generating TypeScript definition files from Java API sources.
|
||||
*/
|
||||
class TypeScriptGeneratorPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
if (project.tasks.findByName('generateTypeScriptDefinitions') == null) {
|
||||
project.tasks.register('generateTypeScriptDefinitions', GenerateTypeScriptTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
implementation-class=dts.TypeScriptGeneratorPlugin
|
||||
Reference in new issue
Block a user