Skip to content

Commit 5177ed7

Browse files
committed
Improve exporter code
1 parent f764ef1 commit 5177ed7

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

src/main/kotlin/net/theevilreaper/stelaris/cli/exporter/BaseExporter.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package net.theevilreaper.stelaris.cli.exporter
22

33
import org.yaml.snakeyaml.DumperOptions
44
import org.yaml.snakeyaml.Yaml
5-
import java.io.InputStream
65
import java.nio.file.Files
76
import java.nio.file.Path
8-
import java.nio.file.Paths
97
import java.nio.file.StandardCopyOption
108

119
/**
@@ -19,12 +17,7 @@ import java.nio.file.StandardCopyOption
1917
abstract class BaseExporter protected constructor() : ProjectExporter {
2018

2119
private val pubSpec: String = "pubspec.yaml"
22-
protected val templateDir = "template"
23-
protected val templateStream: InputStream
24-
25-
init {
26-
templateStream = javaClass.classLoader.getResourceAsStream(templateDir)
27-
}
20+
protected val templateDir = "flutter_template"
2821

2922
/**
3023
* Modify the pubspec.yaml file in the given source folder to the new version.

src/main/kotlin/net/theevilreaper/stelaris/cli/exporter/GitProjectExporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class GitProjectExporter(
3232
}
3333

3434
override fun export() {
35-
Files.copy(templateStream, generationFolder, StandardCopyOption.REPLACE_EXISTING)
35+
// Files.copy(templateStream, generationFolder, StandardCopyOption.REPLACE_EXISTING)
3636

3737
val gitRepo = Git.init().setDirectory(generationFolder.toFile()).call()
3838

src/main/kotlin/net/theevilreaper/stelaris/cli/exporter/LocalProjectExporter.kt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package net.theevilreaper.stelaris.cli.exporter
22

33
import net.theevilreaper.stelaris.cli.generator.Generator
4+
import java.io.IOException
45
import java.nio.file.Files
56
import java.nio.file.Path
67
import java.nio.file.StandardCopyOption
8+
import java.util.zip.ZipInputStream
79

810
class LocalProjectExporter(
911
private val exportPath: Path,
@@ -19,17 +21,33 @@ class LocalProjectExporter(
1921
println("Exporting to local path: $exportPath")
2022

2123
if (!Files.exists(exportPath)) {
22-
Files.createDirectories(exportPath)
24+
Files.createDirectory(exportPath)
2325
println("Created directory: $exportPath")
2426
}
2527

26-
Files.copy(templateStream, exportPath, StandardCopyOption.REPLACE_EXISTING)
28+
println("Exporting to: $exportPath")
29+
30+
val zipStream = javaClass.getClassLoader().getResourceAsStream("flutter_template.zip")
31+
ZipInputStream(zipStream).use { zis ->
32+
var entry = zis.nextEntry
33+
while (entry != null) {
34+
val newPath = exportPath.resolve(entry.name)
35+
36+
if (entry.isDirectory) {
37+
Files.createDirectories(newPath)
38+
} else {
39+
Files.createDirectories(newPath.parent)
40+
Files.copy(zis, newPath, StandardCopyOption.REPLACE_EXISTING)
41+
}
42+
43+
zis.closeEntry()
44+
entry = zis.nextEntry
45+
}
46+
}
2747

2848
val libPath: Path = exportPath.resolve("lib")
2949
if (!Files.exists(libPath)) Files.createDirectory(libPath)
3050
modifyPubSpecFile(exportPath, versionString)
31-
3251
generators.forEach { generator -> generator.generate(libPath) }
33-
3452
}
3553
}

0 commit comments

Comments
 (0)