generated from DanySK/template-for-gradle-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
246 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/io/github/zuccherosintattico/gradle/NpmDependenciesTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.zuccherosintattico.gradle | ||
|
||
import com.lordcodes.turtle.shellRun | ||
import io.github.zuccherosintattico.utils.NpmCommandsExtension.npmInstall | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
/** | ||
* A task to install NPM dependencies. | ||
*/ | ||
open class NpmDependenciesTask : DefaultTask() { | ||
init { | ||
group = "Node" | ||
description = "Install NPM dependencies" | ||
} | ||
|
||
/** | ||
The action to install NPM dependencies. | ||
*/ | ||
@TaskAction | ||
fun installNpmDependencies() { | ||
logger.quiet("Installing NPM dependencies") | ||
val out = shellRun(project.projectDir) { npmInstall() } | ||
logger.quiet(out) | ||
} | ||
} |
64 changes: 11 additions & 53 deletions
64
src/main/kotlin/io/github/zuccherosintattico/gradle/Typescript.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,30 @@ | ||
package io.github.zuccherosintattico.gradle | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.Task | ||
import org.gradle.kotlin.dsl.create | ||
import org.gradle.kotlin.dsl.property | ||
import org.gradle.kotlin.dsl.register | ||
import java.io.Serializable | ||
|
||
/** | ||
* Just a template. | ||
* A plugin to compile TypeScript files. | ||
*/ | ||
open class Typescript : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
val extension = project.extensions.create<TypescriptExtension>("typescript") | ||
|
||
val checkNodeTask = project.tasks.register<CheckNodeTask>("checkNode") | ||
|
||
project.tasks.register<TypescriptTask>("compileTypescript") { | ||
val checkNodeTask = project.registerTask<CheckNodeTask>("checkNode") | ||
val npmDependenciesTask = project.registerTask<NpmDependenciesTask>("npmDependencies") { | ||
dependsOn(checkNodeTask) | ||
sourceSet.set(extension.sourceSet) | ||
} | ||
project.registerTask<TypescriptTask>("compileTypescript") { | ||
dependsOn(npmDependenciesTask) | ||
entrypoint.set(extension.entrypoint) | ||
buildDir.set(extension.outputDir) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Just a template. | ||
*/ | ||
open class TypescriptTask : DefaultTask() { | ||
|
||
/** | ||
* Just a template. | ||
*/ | ||
@Input | ||
val sourceSet: Property<String> = project.objects.property() | ||
|
||
/** | ||
* Read-only property calculated from the greeting. | ||
*/ | ||
@Internal | ||
val message: Provider<String> = sourceSet.map { "Hello from $it" } | ||
|
||
/** | ||
* Just a template. | ||
*/ | ||
@TaskAction | ||
fun printMessage() { | ||
logger.quiet(message.get()) | ||
} | ||
} | ||
|
||
/** | ||
* Just a template. | ||
*/ | ||
open class TypescriptExtension(objects: ObjectFactory) : Serializable { | ||
|
||
/** | ||
* Just a template. | ||
*/ | ||
val sourceSet: Property<String> = objects.property<String>().convention("src/main/typescript") | ||
|
||
companion object { | ||
private const val serialVersionUID = 1L | ||
private inline fun <reified T : Task> Project.registerTask(name: String, noinline action: T.() -> Unit = {}) = | ||
tasks.register<T>(name, action) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/io/github/zuccherosintattico/gradle/TypescriptExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.zuccherosintattico.gradle | ||
|
||
import org.gradle.api.model.ObjectFactory | ||
import org.gradle.api.provider.Property | ||
import org.gradle.kotlin.dsl.property | ||
import java.io.Serializable | ||
|
||
/** | ||
* The extension for configuring TypeScript plugin. | ||
*/ | ||
open class TypescriptExtension(objects: ObjectFactory) : Serializable { | ||
|
||
/** | ||
* The path to the TypeScript source set. | ||
*/ | ||
val entrypoint: Property<String> = objects.propertyWithDefault("src/main/typescript/index.ts") | ||
|
||
/** | ||
* The path to the TypeScript output directory. | ||
*/ | ||
val outputDir: Property<String> = objects.propertyWithDefault("build/dist") | ||
|
||
companion object { | ||
private const val serialVersionUID = 1L | ||
|
||
private inline fun <reified T> ObjectFactory.propertyWithDefault(value: T): Property<T> = | ||
property<T>().convention(value) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/io/github/zuccherosintattico/gradle/TypescriptTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.github.zuccherosintattico.gradle | ||
|
||
import com.lordcodes.turtle.shellRun | ||
import io.github.zuccherosintattico.utils.NpmCommandsExtension.npxCommand | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
/** | ||
* Typescript task. | ||
*/ | ||
abstract class TypescriptTask : DefaultTask() { | ||
|
||
/** | ||
* The source set to compile. | ||
*/ | ||
@get:Input | ||
abstract val entrypoint: Property<String> | ||
|
||
/** | ||
* The build directory. | ||
*/ | ||
@get:OutputFile | ||
abstract val buildDir: Property<String> | ||
|
||
/** | ||
* The task action. | ||
*/ | ||
@TaskAction | ||
fun compileTypescript() { | ||
logger.quiet("Compiling TypeScript files in ${entrypoint.get()}") | ||
shellRun(project.projectDir) { | ||
npxCommand("tsc", "--outDir", buildDir.get(), entrypoint.get()) | ||
}.also { logger.quiet("Compiled: $it") } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/io/github/zuccherosintattico/utils/NodeCommandsExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.zuccherosintattico.utils | ||
|
||
import com.lordcodes.turtle.ShellScript | ||
|
||
/** | ||
* The extension for Node commands for [ShellScript]. | ||
*/ | ||
object NodeCommandsExtension { | ||
|
||
/** | ||
* Get the version of installed Node. | ||
*/ | ||
fun ShellScript.nodeVersion(): String = nodeCommand(listOf("--version")) | ||
|
||
private fun ShellScript.nodeCommand(arguments: List<String>): String = command("node", arguments) | ||
} |
Oops, something went wrong.