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.GradleException
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import java.io.File
|
||||
import java.lang.ProcessBuilder.Redirect.PIPE
|
||||
import java.util.concurrent.TimeUnit
|
||||
@ -12,31 +11,57 @@ import kotlin.concurrent.thread
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
val outputRootDir = File(project.buildDir, "generated-resources/css")
|
||||
|
||||
private val yarnRoot = File(project.rootDir, "css")
|
||||
private val cssIndex = File(postCssDir, "styles.pcss")
|
||||
|
||||
private val cssOutput = File(outputRootDir, "static/styles.css")
|
||||
private val manifestOutput = File(outputRootDir, "css-manifest.json")
|
||||
|
||||
private val purgeGlob = "$templatesDir/**/*.kt"
|
||||
|
||||
@TaskAction
|
||||
fun generateCss() {
|
||||
// TODO: auto yarn install ?
|
||||
|
||||
outputRootDir.listFiles()?.let { it.forEach { it.delete() } }
|
||||
outputRootDir.deleteRecursively()
|
||||
|
||||
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)
|
||||
.redirectError(PIPE)
|
||||
.directory(yarnRoot)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
module.exports = {
|
||||
purge: {
|
||||
content: [
|
||||
'../simplenotes-app/src/main/kotlin/be/simplenotes/app/views/**/*.kt'
|
||||
process.env.PURGE
|
||||
]
|
||||
},
|
||||
theme: {
|
||||
|
||||
@ -184,8 +184,8 @@ class NoteView(styles: String) : View(styles) {
|
||||
type = ButtonType.submit,
|
||||
name = if (note.public) "private" else "public",
|
||||
classes = "font-semibold border-b-4 " +
|
||||
if (!note.public) "border-teal-200" else "border-green-500" +
|
||||
" p-2 rounded-r bg-teal-200 text-gray-800"
|
||||
(if (!note.public) "border-teal-200" else "border-green-500") +
|
||||
" p-2 rounded-r bg-teal-200 text-gray-800"
|
||||
) {
|
||||
+"Public"
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user