Move postcss purge config to gradle
This commit is contained in:
parent
95ec674eb8
commit
fdc8d34f82
@ -2,9 +2,8 @@ package be.simplenotes
|
|||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.GradleException
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.tasks.InputDirectory
|
import org.gradle.api.tasks.*
|
||||||
import org.gradle.api.tasks.OutputDirectory
|
import org.gradle.kotlin.dsl.getByType
|
||||||
import org.gradle.api.tasks.TaskAction
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.ProcessBuilder.Redirect.PIPE
|
import java.lang.ProcessBuilder.Redirect.PIPE
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@ -12,31 +11,57 @@ import kotlin.concurrent.thread
|
|||||||
|
|
||||||
open class CssTask : DefaultTask() {
|
open class CssTask : DefaultTask() {
|
||||||
|
|
||||||
private val root = project.file(".").parent
|
private val root = project.parent!!.rootDir
|
||||||
|
|
||||||
|
private val viewsProject = project
|
||||||
|
.parent
|
||||||
|
?.project(":simplenotes-views")
|
||||||
|
?: error("Missing :simplenotes-views")
|
||||||
|
|
||||||
@get:InputDirectory
|
@get:InputDirectory
|
||||||
val templatesDir = File(root, "simplenotes-views/src/main/kotlin/be/simplenotes/views")
|
val templatesDir = viewsProject.extensions
|
||||||
|
.getByType<SourceSetContainer>()
|
||||||
|
.asMap.getOrElse("main") { error("main sources not found") }
|
||||||
|
.allSource.srcDirs
|
||||||
|
.find { it.endsWith("kotlin") }
|
||||||
|
?: error("kotlin sources not found")
|
||||||
|
|
||||||
|
private val yarnRoot = File(project.rootDir, "css")
|
||||||
|
|
||||||
@get:InputDirectory
|
@get:InputDirectory
|
||||||
val postCssDir = File(project.rootDir, "css/src")
|
val postCssDir = File(project.rootDir, "css/src")
|
||||||
|
|
||||||
|
@get:InputFiles
|
||||||
|
val postCssConfig = listOf(
|
||||||
|
"tailwind.config.js",
|
||||||
|
"postcss.config.js",
|
||||||
|
"package.json"
|
||||||
|
).map { File(yarnRoot, it) }
|
||||||
|
|
||||||
@get:OutputDirectory
|
@get:OutputDirectory
|
||||||
val outputRootDir = File(project.buildDir, "generated-resources/css")
|
val outputRootDir = File(project.buildDir, "generated-resources/css")
|
||||||
|
|
||||||
private val yarnRoot = File(project.rootDir, "css")
|
|
||||||
private val cssIndex = File(postCssDir, "styles.pcss")
|
private val cssIndex = File(postCssDir, "styles.pcss")
|
||||||
|
|
||||||
private val cssOutput = File(outputRootDir, "static/styles.css")
|
private val cssOutput = File(outputRootDir, "static/styles.css")
|
||||||
private val manifestOutput = File(outputRootDir, "css-manifest.json")
|
private val manifestOutput = File(outputRootDir, "css-manifest.json")
|
||||||
|
|
||||||
|
private val purgeGlob = "$templatesDir/**/*.kt"
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun generateCss() {
|
fun generateCss() {
|
||||||
// TODO: auto yarn install ?
|
// TODO: auto yarn install ?
|
||||||
|
|
||||||
outputRootDir.listFiles()?.let { it.forEach { it.delete() } }
|
outputRootDir.deleteRecursively()
|
||||||
|
|
||||||
ProcessBuilder("yarn", "run", "postcss", "build", "$cssIndex", "--output", "$cssOutput")
|
ProcessBuilder("yarn", "run", "postcss", "build", "$cssIndex", "--output", "$cssOutput")
|
||||||
.apply { environment()["MANIFEST"] = "$manifestOutput" }
|
.apply {
|
||||||
|
environment().let {
|
||||||
|
it["MANIFEST"] = "$manifestOutput"
|
||||||
|
it["NODE_ENV"] = "production"
|
||||||
|
it["PURGE"] = purgeGlob
|
||||||
|
}
|
||||||
|
}
|
||||||
.redirectOutput(PIPE)
|
.redirectOutput(PIPE)
|
||||||
.redirectError(PIPE)
|
.redirectError(PIPE)
|
||||||
.directory(yarnRoot)
|
.directory(yarnRoot)
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
purge: {
|
purge: {
|
||||||
content: [
|
content: [
|
||||||
'../simplenotes-app/src/main/kotlin/be/simplenotes/app/views/**/*.kt'
|
process.env.PURGE
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
|
|||||||
@ -184,7 +184,7 @@ class NoteView(styles: String) : View(styles) {
|
|||||||
type = ButtonType.submit,
|
type = ButtonType.submit,
|
||||||
name = if (note.public) "private" else "public",
|
name = if (note.public) "private" else "public",
|
||||||
classes = "font-semibold border-b-4 " +
|
classes = "font-semibold border-b-4 " +
|
||||||
if (!note.public) "border-teal-200" else "border-green-500" +
|
(if (!note.public) "border-teal-200" else "border-green-500") +
|
||||||
" p-2 rounded-r bg-teal-200 text-gray-800"
|
" p-2 rounded-r bg-teal-200 text-gray-800"
|
||||||
) {
|
) {
|
||||||
+"Public"
|
+"Public"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user