Skip to content

Instantly share code, notes, and snippets.

@azazellj
Created May 27, 2024 21:06
Show Gist options
  • Save azazellj/0e300ea7320ce9d916bf8cc0818727a4 to your computer and use it in GitHub Desktop.
Save azazellj/0e300ea7320ce9d916bf8cc0818727a4 to your computer and use it in GitHub Desktop.
@TaskAction
fun taskAction() {
val typeMap = mutableMapOf<String, T>()
// read file
val jsonObject = JSONObject(dsmFile.get().asFile.readText())
// find all type tokens
searchTypeTokens(jsonObject.getJSONObject(rootDSMKey), rootDSMKey, typeMap)
val fileBuilder = FileSpec.builder(
packageName = `package`.get(),
fileName = generatedFileName,
)
val objectBuilder = TypeSpec
.objectBuilder(
name = generatedFileName,
)
.addModifiers(KModifier.INTERNAL)
// write all properties
for ((key, type) in typeMap) {
objectBuilder.addProperty(
PropertySpec.builder(
// some keys have dots in name as opacity
name = key.replace(".", "_"),
type = componentClassName,
modifiers = arrayOf(KModifier.INTERNAL),
)
.initializer(writeTypeToken(key, type))
.build(),
)
}
fileBuilder.addType(objectBuilder.build())
fileBuilder.build().writeTo(flavorDirectory.get().asFile)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment