aboutsummaryrefslogtreecommitdiff
path: root/web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenPlugin.groovy
diff options
context:
space:
mode:
Diffstat (limited to 'web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenPlugin.groovy')
-rw-r--r--web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenPlugin.groovy49
1 files changed, 49 insertions, 0 deletions
diff --git a/web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenPlugin.groovy b/web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenPlugin.groovy
new file mode 100644
index 00000000..90609607
--- /dev/null
+++ b/web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenPlugin.groovy
@@ -0,0 +1,49 @@
+import com.moowork.gradle.node.NodeExtension
+import com.pitchedapps.frost.gradle.WebGenInstallTask
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+import org.gradle.api.internal.file.FileResolver
+
+import javax.inject.Inject
+
+class WebGenPlugin implements Plugin<Project> {
+
+ private static final String NODE_VERSION = "12.4.0"
+ private Project project
+ private final FileResolver fileResolver
+
+ @Inject
+ WebGenPlugin(FileResolver fileResolver) {
+ this.fileResolver = fileResolver
+ }
+
+ /**
+ * Based on https://github.com/apollographql/apollo-android/blob/master/apollo-gradle-plugin/src/main/groovy/com/apollographql/apollo/gradle/ApolloPlugin.groovy
+ * @param target
+ */
+ @Override
+ void apply(Project target) {
+ this.project = project
+ project.plugins.withId("java-base") {
+ applyWebGenPlugin()
+ }
+ project.gradle.getTaskGraph().whenReady {
+ if (!project.plugins.hasPlugin("java-base")) {
+ throw new IllegalArgumentException(
+ "Frost Web Gen plugin can't be applied without Android or Java or Kotlin plugin.")
+ }
+ }
+ }
+
+ private void applyWebGenPlugin() {
+ setupNode()
+ project.tasks.create(WebGenInstallTask.NAME, WebGenInstallTask.class)
+ }
+
+ private void setupNode() {
+ project.plugins.apply NodePlugin
+ NodeExtension nodeConfig = project.extensions.findByName("node") as NodeExtension
+ nodeConfig.download = true
+ nodeConfig.version = NODE_VERSION
+ }
+} \ No newline at end of file