Skip to content

Commit d8cd383

Browse files
committed
♻️ (project) Improve processCSS task
1 parent 5862545 commit d8cd383

1 file changed

Lines changed: 30 additions & 33 deletions

File tree

gradle/processCSS.gradle

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import groovy.transform.Field
22
import org.apache.tools.ant.taskdefs.condition.Os
33

4+
import java.nio.file.Files
5+
46
// Special handling for Windows. Fuck. This. Shit.
57
@Field var isWindows = (Os.isFamily(Os.FAMILY_WINDOWS))
68

79
tasks.register("processCSS") {
810
doLast {
911
def rootDir = rootProject.projectDir.absolutePath
1012
def resDir = new File("$rootDir/modules/resources/src/main/resources/io/github/palexdev/mfxresources/sass/themes")
11-
def dirs = resDir.listFiles()
12-
if (dirs == null || dirs.length == 0) return
13-
List<File> themesDirs = Arrays.stream(dirs)
14-
.filter(File::isDirectory)
15-
.toList()
13+
def files = Files.walk(resDir.toPath())
14+
.filter(p -> {
15+
def name = p.getFileName().toString()
16+
return !Files.isDirectory(p) && name.endsWith(".css") && !name.startsWith("tmp") && !name.contains("preset")
17+
}).toList()
18+
if (files.isEmpty()) return
1619

1720
// Check if npm, cleancss-cli and cssbeautify-cli are installed on the host
1821
if (!execute(["npm", "-v"])) {
@@ -29,36 +32,30 @@ tasks.register("processCSS") {
2932
}
3033
logger.info("All dependencies have been found")
3134

32-
themesDirs.each { dir ->
33-
dir.eachFileRecurse {
34-
def name = it.name
35-
def path = it.absolutePath
36-
if (!name.startsWith("tmp") &&
37-
!name.contains("preset") &&
38-
name.endsWith(".css")) {
39-
// Unfortunately, doesn't run very well on SCSS files
40-
def tmp = new File("${dir}/tmp.css")
41-
logger.warn("Optimizing: $name")
42-
execute([
43-
"cleancss",
44-
"-O2", "specialComments:all",
45-
"--format", "beautify",
46-
"--inline", "none",
47-
"${path}" as String,
48-
"-o", "${tmp}" as String
49-
], new File(path).parentFile)
35+
files.each {
36+
def name = it.getFileName().toString()
37+
def parent = it.getParent().toAbsolutePath()
38+
def tmp = new File("${parent}/tmp.css")
39+
40+
logger.lifecycle("Optimizing: $name")
41+
execute([
42+
"cleancss",
43+
"-O2", "specialComments:all",
44+
"--format", "beautify",
45+
"--inline", "none",
46+
"${it}" as String,
47+
"-o", "${tmp}" as String
48+
], parent.toFile())
5049

51-
logger.warn("Beautifying: $name")
52-
execute([
53-
"cssbeautify-cli",
54-
"-i2",
55-
"-f", "${tmp}" as String,
56-
"-w", "${path}" as String
57-
], new File(path).parentFile)
50+
logger.lifecycle("Beautifying: $name")
51+
execute([
52+
"cssbeautify-cli",
53+
"-i2",
54+
"-f", "${tmp}" as String,
55+
"-w", "${it}" as String
56+
], parent.toFile())
5857

59-
delete(tmp)
60-
}
61-
}
58+
delete(tmp)
6259
}
6360
}
6461
}

0 commit comments

Comments
 (0)