Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: total rehaul #15

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
blah
  • Loading branch information
brizzbuzz committed Aug 5, 2024
commit 826615bb9e18d74b46fc8d30d2fff7c0fd8bbd13
31 changes: 27 additions & 4 deletions playground/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,31 @@ sourceSets {
}

skribe {
specUrl.set(file("../codegen/src/test/resources/alpaca-broker.yml").absoluteFile.toString())
outputDir.set("$projectDir/src/main/gen")
basePackage.set("io.bkbn.sourdough.clients")
shouldCleanDir.set(true)
shouldCleanDir = true
outputDir = "$projectDir/src/main/gen"

api {
basePackage = "com.alpaca.broker.client"
specUrl = file("../codegen/src/test/resources/alpaca-broker.yml").absoluteFile.toString()
}

api {
basePackage = "com.factset.price.client"
specUrl = file("../codegen/src/test/resources/factset-prices.yml").absoluteFile.toString()
}
}
//skribe {
// specUrl.set(file("../codegen/src/test/resources/alpaca-broker.yml").absoluteFile.toString())
// outputDir.set("$projectDir/src/main/gen")
// basePackage.set("io.bkbn.sourdough.clients")
// shouldCleanDir.set(true)
//}
//skribe {
// shouldCleanDir = true
// outputDir = "$projectDir/src/main/gen"
//
// api("alpaca-broker") {
// specUrl = file("../codegen/src/test/resources/alpaca-broker.yml").absoluteFile.toString()
// basePackage = "io.bkbn.sourdough.clients"
// }
//}
26 changes: 21 additions & 5 deletions plugin/src/main/kotlin/io/bkbn/skribe/plugin/SkribeExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@ package io.bkbn.skribe.plugin

import org.gradle.api.provider.Property

interface SkribeExtension {
val specUrl: Property<String>
val basePackage: Property<String>
val outputDir: Property<String>
val shouldCleanDir: Property<Boolean>
//interface SkribeExtension {
// val specUrl: Property<String>
// val basePackage: Property<String>
// val outputDir: Property<String>
// val shouldCleanDir: Property<Boolean>
//}

abstract class SkribeExtension {
val apis: MutableList<ApiExtension> = mutableListOf()

var outputDir: String? = null
var shouldCleanDir: Boolean = false

fun api(configure: ApiExtension.() -> Unit) {
apis.add(ApiExtension().apply(configure))
}
}

class ApiExtension {
lateinit var specUrl: String
lateinit var basePackage: String
}
14 changes: 8 additions & 6 deletions plugin/src/main/kotlin/io/bkbn/skribe/plugin/SkribePlugin.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package io.bkbn.skribe.plugin

import io.bkbn.skribe.codegen.utils.StringUtils.capitalized
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.internal.cc.base.logger

class SkribePlugin : Plugin<Project> {
override fun apply(target: Project) {
val ext = target.extensions.create("skribe", SkribeExtension::class.java)
target.tasks.register("skribe", SkribeTask::class.java) {
it.specUrl.set(ext.specUrl)
it.outputDir.set(ext.outputDir)
it.basePackage.set(ext.basePackage)
it.shouldCleanDir.set(ext.shouldCleanDir)

target.tasks.register("skribe", SkribeTask::class.java) {
it.apis.set(ext.apis)
it.outputDir.set(ext.outputDir)
it.shouldCleanDir.set(ext.shouldCleanDir)
}
}
}
}
22 changes: 11 additions & 11 deletions plugin/src/main/kotlin/io/bkbn/skribe/plugin/SkribeTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.bkbn.skribe.plugin

import io.bkbn.skribe.codegen.Skribe
import org.gradle.api.DefaultTask
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
Expand All @@ -11,30 +12,29 @@ import java.nio.file.Path
abstract class SkribeTask : DefaultTask() {

@get:Input
abstract val specUrl: Property<String>
abstract val apis: ListProperty<ApiExtension>

@get:Input
abstract val outputDir: Property<String>

@get:Input
abstract val basePackage: Property<String>

@get:Input
@get:Optional
abstract val shouldCleanDir: Property<Boolean?>

@TaskAction
fun generate() {
logger.quiet("Generating client from ${specUrl.get()} to ${outputDir.get()}")
val outputDirPath = Path.of(outputDir.get())

if (shouldCleanDir.orNull == true) {
logger.quiet("Cleaning directory recursively ${outputDir.get()}")
outputDirPath.toFile().deleteRecursively()
// if (shouldCleanDir.orNull == true) {
// logger.quiet("Cleaning directory recursively ${outputDir.get()}")
// outputDirPath.toFile().deleteRecursively()
// }

apis.get().forEach { api ->
val fileSpecs = Skribe.generate(api.specUrl, api.basePackage)
logger.quiet("Writing files to ${outputDir.get()}")
fileSpecs.forEach { it.writeTo(outputDirPath) }
}

val fileSpecs = Skribe.generate(specUrl.get(), basePackage.get())
logger.quiet("Writing files to ${outputDir.get()}")
fileSpecs.forEach { it.writeTo(outputDirPath) }
}
}