diff options
author | Allan Wang <me@allanwang.ca> | 2019-07-02 19:59:59 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-07-02 19:59:59 -0700 |
commit | 8f4da4ea838c52d857a12398967da2a99967a14e (patch) | |
tree | d57ba1b8b2cc6d31c764cef481082bd198a86b1f /buildSrc/src | |
parent | 19ad91cec0c2964f666e8b22ae5e583df04cba56 (diff) | |
download | frost-8f4da4ea838c52d857a12398967da2a99967a14e.tar.gz frost-8f4da4ea838c52d857a12398967da2a99967a14e.tar.bz2 frost-8f4da4ea838c52d857a12398967da2a99967a14e.zip |
Sample gradle npm test
Diffstat (limited to 'buildSrc/src')
-rw-r--r-- | buildSrc/src/main/kotlin/FrostPlugin.kt | 38 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/Versions.kt | 2 | ||||
-rw-r--r-- | buildSrc/src/main/kotlin/WebGenInstallTask.groovy | 55 |
3 files changed, 95 insertions, 0 deletions
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<Project> { + + 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 |