Skip to content

Commit e727dbf

Browse files
committed
Support for readonly sketches
1 parent b165d0a commit e727dbf

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

app/src/processing/app/gradle/GradleService.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ class GradleService(
8484
private fun setupGradle(): MutableList<String> {
8585
val sketch = sketch ?: throw IllegalStateException("Sketch is not set")
8686

87-
// TODO: if sketch is read-only, copy it whole to the temporary working directory / sketch
87+
val sketchFolder = if(sketch.isReadOnly) workingDir.resolve("sketch").toFile() else sketch.folder
88+
if(sketch.isReadOnly){
89+
// If the sketch is read-only, we copy it to the working directory
90+
// This allows us to run the sketch without modifying the original files
91+
sketch.folder.copyRecursively(sketchFolder, overwrite = true)
92+
}
8893

8994
val unsaved = sketch.code
9095
.map { code ->
@@ -118,7 +123,7 @@ class GradleService(
118123
//"window.color" to "0xFF000000", // TODO: Implement
119124
//"stop.color" to "0xFF000000", // TODO: Implement
120125
"stop.hide" to false, // TODO: Implement
121-
"sketch.folder" to sketch.folder.absolutePath,
126+
"sketch.folder" to sketchFolder,
122127
)
123128
val repository = Platform.getContentFile("repository").absolutePath.replace("""\""", """\\""")
124129

@@ -144,7 +149,7 @@ class GradleService(
144149
}
145150

146151

147-
val buildGradle = sketch.folder.resolve("build.gradle.kts")
152+
val buildGradle = sketchFolder.resolve("build.gradle.kts")
148153
val generate = buildGradle.let {
149154
if(!it.exists()) return@let true
150155

@@ -179,13 +184,16 @@ class GradleService(
179184
val content = "${header}\n${instructions}\n${configuration}"
180185
buildGradle.writeText(content)
181186
}
182-
val settingsGradle = sketch.folder.resolve("settings.gradle.kts")
187+
val settingsGradle = sketchFolder.resolve("settings.gradle.kts")
183188
if (!settingsGradle.exists()) {
184189
settingsGradle.createNewFile()
185190
}
186191

187192
val arguments = mutableListOf("--init-script", initGradle.toAbsolutePath().toString())
188193
if (!Base.DEBUG) arguments.add("--quiet")
194+
if(sketch.isReadOnly){
195+
arguments += listOf("--project-dir", sketchFolder.absolutePath)
196+
}
189197
arguments.addAll(variables.entries
190198
.filter { it.value != null }
191199
.map { "-Pprocessing.${it.key}=${it.value}" }

0 commit comments

Comments
 (0)