From 8f4da4ea838c52d857a12398967da2a99967a14e Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 2 Jul 2019 19:59:59 -0700 Subject: Sample gradle npm test --- app/src/main/play/en-US/whatsnew | 3 +- app/src/main/res/xml/frost_changelog.xml | 2 +- buildSrc/build.gradle.kts | 27 +++++++++- buildSrc/src/main/kotlin/FrostPlugin.kt | 38 +++++++++++++++ buildSrc/src/main/kotlin/Versions.kt | 2 + buildSrc/src/main/kotlin/WebGenInstallTask.groovy | 55 +++++++++++++++++++++ docs/Changelog.md | 1 + settings.gradle.kts | 2 +- web-gen/build.gradle | 16 ++++++ .../frost/gradle/WebGenInstallTask.groovy | 57 ++++++++++++++++++++++ .../pitchedapps/frost/gradle/WebGenPlugin.groovy | 49 +++++++++++++++++++ .../com.pitchedapps.frost.gradle.properties | 1 + 12 files changed, 248 insertions(+), 5 deletions(-) create mode 100644 buildSrc/src/main/kotlin/FrostPlugin.kt create mode 100644 buildSrc/src/main/kotlin/WebGenInstallTask.groovy create mode 100644 web-gen/build.gradle create mode 100644 web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenInstallTask.groovy create mode 100644 web-gen/src/main/groovy/com/pitchedapps/frost/gradle/WebGenPlugin.groovy create mode 100644 web-gen/src/main/resources/META-INF/gradle-plugins/com.pitchedapps.frost.gradle.properties diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index 9ae7372d..ec5e33e9 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -2,4 +2,5 @@ v2.3.1 * Hide all story panels if enabled * Prevent swipe to refresh if not at the very top -* Add vertical swipe to dismiss when viewing images \ No newline at end of file +* Add vertical swipe to dismiss when viewing images +* Add horizontal scroll support for webviews \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 32fc108b..3562c5c9 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -10,7 +10,7 @@ - + diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 0c518118..aded2979 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,5 +1,9 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { `kotlin-dsl` + groovy + idea } group = "com.pitchedapps" @@ -12,13 +16,32 @@ repositories { // Currently can't read properties from root project // Reading it manually since it's simple val rootProps = - File(project.rootDir.let { if (it.name == "buildSrc") it.parent else it.absolutePath }, "gradle.properties") + File( + project.rootDir.let { if (it.name == "buildSrc") it.parent else it.absolutePath }, + "gradle.properties" + ) val kau = rootProps.useLines { it.first { s -> s.startsWith("KAU=") } }.substring(4).trim() println("Using kau $kau") +sourceSets { + main { + withConvention(GroovySourceSet::class) { + groovy.srcDir("src/main/groovy") + } + } +} + dependencies { implementation("ca.allanwang.kau:gradle-plugin:$kau") -} \ No newline at end of file + implementation("com.moowork.gradle:gradle-node-plugin:1.3.1") +} + +val compileGroovy = tasks.withType().first() +val compileKotlin = tasks.withType().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 new file mode 100644 index 00000000..8e640f04 --- /dev/null +++ b/buildSrc/src/main/kotlin/FrostPlugin.kt @@ -0,0 +1,38 @@ +import com.moowork.gradle.node.NodeExtension +import com.moowork.gradle.node.NodePlugin +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.create + +class FrostPlugin : Plugin { + + companion object { + private const val NODE_VERSION = "12.4.0" + } + + override fun apply(project: Project) { + project.plugins.withId("java-base") { + project.applyWebGenPlugin() + } + 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." + ) + } + } + } + + private fun Project.applyWebGenPlugin() { + setupNode() +// tasks.create(WebGenInstallTask.NAME, WebGenInstallTask::class) + } + + private fun Project.setupNode() { + plugins.apply(NodePlugin::class) + val nodeConfig = extensions.findByName("node") as NodeExtension + nodeConfig.download = true + nodeConfig.version = NODE_VERSION + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 7eaa9a4a..5d93dbfa 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -34,4 +34,6 @@ object Versions { const val scaleImageView = "3.10.0" // https://github.com/umano/AndroidSlidingUpPanel#importing-the-library const val slidingPanel = "3.4.0" + // https://github.com/srs/gradle-node-plugin/releases + const val nodeGradle = "1.3.1" } \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/WebGenInstallTask.groovy b/buildSrc/src/main/kotlin/WebGenInstallTask.groovy new file mode 100644 index 00000000..a70effee --- /dev/null +++ b/buildSrc/src/main/kotlin/WebGenInstallTask.groovy @@ -0,0 +1,55 @@ +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/docs/Changelog.md b/docs/Changelog.md index bfcfaf47..4ebca7e8 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -4,6 +4,7 @@ * Hide all story panels if enabled * Prevent swipe to refresh if not at the very top * Add vertical swipe to dismiss when viewing images +* Add horizontal scroll support for webviews ## v2.3.0 * Converted internals of Facebook data storage; auto migration will only work from 2.2.x to 2.3.x diff --git a/settings.gradle.kts b/settings.gradle.kts index 270f7597..291a3447 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,3 @@ -include(":app", ":gradle-plugin") +include(":app", ":gradle-plugin", ":web-gen") project(":gradle-plugin").projectDir = file("buildSrc") \ No newline at end of file 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 { + + 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 -- cgit v1.2.3