aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-07-02 23:22:11 -0700
committerAllan Wang <me@allanwang.ca>2019-07-02 23:22:11 -0700
commit5a107bcb768fa1e7fb110ba65e22e49b3b004eed (patch)
tree08d2214e1d1801ce2b731e7db00112c6015e8550
parent648a89d79fd26e717cde0ea58dff8a1a90d89475 (diff)
downloadfrost-5a107bcb768fa1e7fb110ba65e22e49b3b004eed.tar.gz
frost-5a107bcb768fa1e7fb110ba65e22e49b3b004eed.tar.bz2
frost-5a107bcb768fa1e7fb110ba65e22e49b3b004eed.zip
Convert install task to kotlin using delegation
-rw-r--r--buildSrc/build.gradle.kts30
-rw-r--r--buildSrc/src/main/kotlin/FrostPlugin.kt6
-rw-r--r--buildSrc/src/main/kotlin/WebGenInstallTask.groovy55
-rw-r--r--buildSrc/src/main/kotlin/WebGenInstallTask.kt68
4 files changed, 85 insertions, 74 deletions
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
index aded2979..efb7a7dd 100644
--- a/buildSrc/build.gradle.kts
+++ b/buildSrc/build.gradle.kts
@@ -2,8 +2,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`kotlin-dsl`
- groovy
- idea
+// groovy
+// idea
}
group = "com.pitchedapps"
@@ -26,22 +26,22 @@ val kau = rootProps.useLines {
println("Using kau $kau")
-sourceSets {
- main {
- withConvention(GroovySourceSet::class) {
- groovy.srcDir("src/main/groovy")
- }
- }
-}
+//sourceSets {
+// main {
+// withConvention(GroovySourceSet::class) {
+// groovy.srcDir("src/main/groovy")
+// }
+// }
+//}
dependencies {
implementation("ca.allanwang.kau:gradle-plugin:$kau")
implementation("com.moowork.gradle:gradle-node-plugin:1.3.1")
}
-val compileGroovy = tasks.withType<GroovyCompile>().first()
-val compileKotlin = tasks.withType<KotlinCompile>().first()
-
-compileGroovy.dependsOn.remove(compileKotlin)
-compileKotlin.dependsOn(compileGroovy)
-compileKotlin.classpath += files(compileGroovy.destinationDir)
+//val compileGroovy = tasks.withType<GroovyCompile>().first()
+//val compileKotlin = tasks.withType<KotlinCompile>().first()
+//
+//compileGroovy.dependsOn.remove(compileKotlin)
+//compileKotlin.dependsOn(compileGroovy)
+//compileKotlin.classpath += files(compileGroovy.destinationDir)
diff --git a/buildSrc/src/main/kotlin/FrostPlugin.kt b/buildSrc/src/main/kotlin/FrostPlugin.kt
index 8e640f04..0fd4ea9d 100644
--- a/buildSrc/src/main/kotlin/FrostPlugin.kt
+++ b/buildSrc/src/main/kotlin/FrostPlugin.kt
@@ -17,16 +17,14 @@ class FrostPlugin : Plugin<Project> {
}
project.gradle.taskGraph.whenReady {
if (!project.plugins.hasPlugin("java-base")) {
- throw IllegalArgumentException(
- "Frost plugin can't be applied without Android or Java or Kotlin plugin."
- )
+ throw IllegalArgumentException("Frost plugin can't be applied without Android or Java or Kotlin plugin.")
}
}
}
private fun Project.applyWebGenPlugin() {
setupNode()
-// tasks.create(WebGenInstallTask.NAME, WebGenInstallTask::class)
+ tasks.create(WebGenInstallTask.NAME, WebGenInstallTask::class)
}
private fun Project.setupNode() {
diff --git a/buildSrc/src/main/kotlin/WebGenInstallTask.groovy b/buildSrc/src/main/kotlin/WebGenInstallTask.groovy
deleted file mode 100644
index a70effee..00000000
--- a/buildSrc/src/main/kotlin/WebGenInstallTask.groovy
+++ /dev/null
@@ -1,55 +0,0 @@
-import com.moowork.gradle.node.npm.NpmTask
-import org.gradle.api.file.DirectoryProperty
-import org.gradle.api.file.RegularFileProperty
-import org.gradle.api.model.ObjectFactory
-import org.gradle.api.tasks.OutputDirectory
-import org.gradle.api.tasks.OutputFile
-
-/**
- * Based on https://github.com/apollographql/apollo-android/blob/master/apollo-gradle-plugin/src/main/groovy/com/apollographql/apollo/gradle/ApolloCodegenInstallTask.groovy
- */
-class WebGenInstallTask extends NpmTask {
-
- static final String TAG = "frost-web-gen"
- public static final String NAME = "installWebGen"
- static final String INSTALLATION_PATH = TAG + File.separator + "node_modules"
- static final String PACKAGE_FILE_PATH = TAG + File.separator + "package.json"
-
- static final String TYPESCRIPT_VERSION = "3.3.1"
- static final String SASS_VERSION = "1.19.0"
-
- @OutputDirectory
- final DirectoryProperty installDir = ObjectFactory.directoryProperty()
- @OutputFile
- final RegularFileProperty packageFile = ObjectFactory.fileProperty()
-
- WebGenInstallTask() {
- setGroup("frost")
- setDescription("Runs npm install for $TAG")
- installDir.set(project.file(new File(project.buildDir, INSTALLATION_PATH)))
- packageFile.set(project.file(new File(project.buildDir, PACKAGE_FILE_PATH)))
- }
-
- @Override
- void exec() {
- installDir.get().getAsFile().deleteDir()
- writePackageFile(packageFile.get().getAsFile())
-
- setArgs(Lists.newArrayList("install", "typescript@" + TYPESCRIPT_VERSION, "sass@" + SASS_VERSION, "--save", "--save-exact"))
- getLogging().captureStandardOutput(LogLevel.INFO)
-
- super.exec()
- }
-
- /**
- * Generates a dummy package.json file to silence npm warnings
- */
- private static void writePackageFile(File apolloPackageFile) {
- apolloPackageFile.write(
- '''{
- "name": "frost-web-gen"
-}
-'''
- )
- }
-} \ No newline at end of file
diff --git a/buildSrc/src/main/kotlin/WebGenInstallTask.kt b/buildSrc/src/main/kotlin/WebGenInstallTask.kt
new file mode 100644
index 00000000..2076ee84
--- /dev/null
+++ b/buildSrc/src/main/kotlin/WebGenInstallTask.kt
@@ -0,0 +1,68 @@
+import com.moowork.gradle.node.npm.NpmTask
+import org.gradle.api.DefaultTask
+import org.gradle.api.logging.LogLevel
+import org.gradle.api.tasks.OutputDirectory
+import org.gradle.api.tasks.OutputFile
+import org.gradle.api.tasks.TaskAction
+import java.io.File
+
+/**
+ * Based on https://github.com/apollographql/apollo-android/blob/master/apollo-gradle-plugin/src/main/groovy/com/apollographql/apollo/gradle/ApolloCodegenInstallTask.groovy
+ */
+class WebGenInstallTask : DefaultTask() {
+
+ companion object {
+ const val TAG = "frost-web-gen"
+ const val NAME = "installWebGen"
+ val INSTALLATION_PATH = TAG + File.separator + "node_modules"
+ val PACKAGE_FILE_PATH = TAG + File.separator + "package.json"
+
+ const val TYPESCRIPT_VERSION = "3.3.1"
+ const val SASS_VERSION = "1.19.0"
+ }
+
+ @OutputDirectory
+ val installDir = project.layout.directoryProperty()
+ @OutputFile
+ val packageFile = project.layout.fileProperty()
+
+ val npmTask = NpmTask()
+
+ init {
+ group = "frost"
+ description = "Runs npm install for $TAG"
+
+ installDir.set(project.file(File(project.buildDir, INSTALLATION_PATH)))
+ packageFile.set(project.file(File(project.buildDir, PACKAGE_FILE_PATH)))
+
+ npmTask.setWorkingDir(File(project.buildDir, TAG))
+ }
+
+ @TaskAction
+ fun exec() {
+ installDir.get().asFile.takeIf { it.isDirectory }?.deleteRecursively()
+ writePackageFile(packageFile.get().asFile)
+ npmTask.setArgs(
+ listOf(
+ "install",
+ "typescript@$TYPESCRIPT_VERSION",
+ "sass@$SASS_VERSION",
+ "--save",
+ "--save-exact"
+ )
+ )
+ npmTask.logging.captureStandardOutput(LogLevel.INFO)
+ npmTask.exec()
+ }
+
+ private fun writePackageFile(packageFile: File) {
+ packageFile.writeText(
+ """
+ {
+ "name": "$TAG",
+ "version": "1.0"
+ }
+ """.trimIndent()
+ )
+ }
+} \ No newline at end of file