aboutsummaryrefslogtreecommitdiff
path: root/web-gen
diff options
context:
space:
mode:
Diffstat (limited to 'web-gen')
-rw-r--r--web-gen/build.gradle16
-rw-r--r--web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenInstallTask.groovy57
-rw-r--r--web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenPlugin.groovy49
-rw-r--r--web-gen/src/main/resources/META-INF/gradle-plugins/com.pitchedapps.frost.gradle.properties1
4 files changed, 123 insertions, 0 deletions
diff --git a/web-gen/build.gradle b/web-gen/build.gradle
new file mode 100644
index 00000000..3f23b8b9
--- /dev/null
+++ b/web-gen/build.gradle
@@ -0,0 +1,16 @@
+apply plugin: 'groovy'
+apply plugin: 'idea'
+apply plugin: 'java-gradle-plugin'
+
+sourceSets.main.java.srcDirs = []
+sourceSets.main.groovy.srcDirs = ["src/main/java", "src/main/groovy"]
+
+repositories {
+ jcenter()
+}
+
+dependencies {
+ compileOnly gradleApi()
+ implementation localGroovy()
+ implementation "com.moowork.gradle:gradle-node-plugin:${Versions.nodeGradle}"
+}
diff --git a/web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenInstallTask.groovy b/web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenInstallTask.groovy
new file mode 100644
index 00000000..55b8aab8
--- /dev/null
+++ b/web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenInstallTask.groovy
@@ -0,0 +1,57 @@
+package com.pitchedapps.frost.gradle
+
+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"
+ 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/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
diff --git a/web-gen/src/main/resources/META-INF/gradle-plugins/com.pitchedapps.frost.gradle.properties b/web-gen/src/main/resources/META-INF/gradle-plugins/com.pitchedapps.frost.gradle.properties
new file mode 100644
index 00000000..b6435604
--- /dev/null
+++ b/web-gen/src/main/resources/META-INF/gradle-plugins/com.pitchedapps.frost.gradle.properties
@@ -0,0 +1 @@
+implementation-class=com.pitchedapps.frost.gradle.WebGenPlugin