Skip to content

Commit a8fbb00

Browse files
committed
Refine p5js example import path handling
Improves the processing of example file paths by removing leading digits and underscores from sketch folder names during extraction.
1 parent 420310e commit a8fbb00

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

p5js/build.gradle.kts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.jetbrains.compose.internal.de.undercouch.gradle.tasks.download.Download
2+
import org.jetbrains.kotlin.konan.properties.suffix
23
import kotlin.text.replace
34

45
plugins {
@@ -44,7 +45,9 @@ tasks.register<Download>("includeP5jsExamples"){
4445
from(zipTree(examples)){ // remove top level directory
4546
include("*/src/content/examples/en/**/*")
4647
exclude("**/description.mdx")
47-
eachFile { relativePath = RelativePath(true, *relativePath.segments.drop(5).toTypedArray()) }
48+
eachFile{
49+
relativePath = RelativePath(true, *relativePath.segments.drop(5).toTypedArray())
50+
}
4851
eachFile{
4952
if(name != "code.js"){ return@eachFile }
5053

@@ -58,6 +61,16 @@ tasks.register<Download>("includeP5jsExamples"){
5861
if(parentName == name.removeSuffix(".js")){ return@eachFile }
5962
relativePath = RelativePath(true, *relativePath.segments.dropLast(1).toTypedArray(), name.removeSuffix(".js"), name)
6063
}
64+
// if a sketch folder starts with a digit, remove that digit and the following dash
65+
eachFile {
66+
val parent = this.file.parentFile
67+
val parentName = parent.name
68+
val regex = Regex("^\\d+_")
69+
if(regex.containsMatchIn(parentName)){
70+
val newParentName = parentName.replace(regex, "")
71+
relativePath = RelativePath(true, *relativePath.segments.dropLast(2).toTypedArray(), newParentName, newParentName.suffix("js"))
72+
}
73+
}
6174
}
6275
into(layout.buildDirectory.dir("mode/examples/Basics"))
6376
}

0 commit comments

Comments
 (0)