-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: project, modules and source sets
- Loading branch information
1 parent
ebb191d
commit f5239b2
Showing
17 changed files
with
207 additions
and
72 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
kode-kotlin/src/commonMain/kotlin/software/guimauve/kode/usecases/GenerateKotlinUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...are/guimauve/kode/kotlin/KotlinVisitor.kt → ...e/guimauve/kode/visitors/KotlinVisitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
kode-kotlin/src/commonTest/kotlin/software/guimauve/kode/kotlin/KotlinVisitorTest.kt
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
kode-kotlin/src/commonTest/kotlin/software/guimauve/kode/visitors/KotlinVisitorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package software.guimauve.kode.visitors | ||
|
||
import software.guimauve.kode.dsl.project | ||
import software.guimauve.kode.dsl.type | ||
import software.guimauve.kode.dsl.unaryPlus | ||
import software.guimauve.kode.usecases.GenerateFolderUseCase | ||
import software.guimauve.kode.usecases.GenerateKotlinUseCase | ||
import kotlin.test.Test | ||
|
||
class KotlinVisitorTest { | ||
|
||
@Test | ||
fun testModule() { | ||
val basePackage = "com.example" | ||
|
||
val proj = project { | ||
module("shared") { | ||
sourceSet("commonMain") { | ||
directorySet("kotlin") { | ||
`package`(basePackage) { | ||
file("Application.kt") { | ||
import("$basePackage.plugins") | ||
import("io.ktor.server.application.*") | ||
import("io.ktor.server.netty.*") | ||
|
||
function("main") { | ||
argument("args", type("Array") { | ||
parameter(type("String")) | ||
}) | ||
call("EngineMain.main") { | ||
parameters(+"args") | ||
} | ||
} | ||
|
||
function("Application.module") { | ||
call("configureI18n") | ||
// ... | ||
} | ||
} | ||
`package`("plugins") { | ||
file("I18n.kt") { | ||
import("dev.kaccelero.plugins.I18n") | ||
import("io.ktor.server.application.*") | ||
import("java.util.*") | ||
|
||
function("Application.configureI18n") { | ||
call("install") { | ||
parameter(+"I18n") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
val folder = GenerateFolderUseCase(GenerateKotlinUseCase()).invoke(proj) | ||
println(folder) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
kode/src/commonMain/kotlin/software/guimauve/kode/dsl/FileOrDirectory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package software.guimauve.kode.dsl | ||
|
||
sealed interface FileOrDirectory |
5 changes: 5 additions & 0 deletions
5
kode/src/commonMain/kotlin/software/guimauve/kode/dsl/Folder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package software.guimauve.kode.dsl | ||
|
||
data class Folder( | ||
val content: Map<String, FolderContent>, | ||
) : FolderContent |
3 changes: 3 additions & 0 deletions
3
kode/src/commonMain/kotlin/software/guimauve/kode/dsl/FolderContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package software.guimauve.kode.dsl | ||
|
||
sealed interface FolderContent |
14 changes: 14 additions & 0 deletions
14
kode/src/commonMain/kotlin/software/guimauve/kode/dsl/Module.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package software.guimauve.kode.dsl | ||
|
||
@KodeDsl | ||
class Module internal constructor( | ||
val name: String, | ||
) : FileOrDirectory { | ||
|
||
val sourceSets = mutableListOf<SourceSet>() | ||
|
||
fun sourceSet(name: String, block: SourceSet.() -> Unit = {}) { | ||
sourceSets.add(SourceSet(name).apply(block)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
kode/src/commonMain/kotlin/software/guimauve/kode/dsl/Project.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package software.guimauve.kode.dsl | ||
|
||
@KodeDsl | ||
class Project : FileOrDirectory { | ||
|
||
val modules = mutableListOf<Module>() | ||
val textFiles = mutableMapOf<String, TextFile>() | ||
|
||
fun module(name: String, block: Module.() -> Unit = {}) { | ||
modules.add(Module(name).apply(block)) | ||
} | ||
|
||
fun textFile(name: String, content: String) { | ||
textFiles[name] = TextFile(content) | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
kode/src/commonMain/kotlin/software/guimauve/kode/dsl/SourceDirectorySet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package software.guimauve.kode.dsl | ||
|
||
@KodeDsl | ||
class SourceDirectorySet internal constructor( | ||
val name: String, | ||
) : FileOrDirectory { | ||
|
||
val packages = mutableListOf<Package>() | ||
val files = mutableMapOf<String, File>() | ||
val textFiles = mutableMapOf<String, TextFile>() | ||
|
||
fun `package`(name: String, init: Package.() -> Unit = {}) { | ||
packages.add(Package(name).apply(init)) | ||
} | ||
|
||
fun file(name: String, init: File.() -> Unit = {}) { | ||
files[name] = File().apply(init) | ||
} | ||
|
||
fun textFile(name: String, content: String) { | ||
textFiles[name] = TextFile(content) | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
kode/src/commonMain/kotlin/software/guimauve/kode/dsl/SourceSet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package software.guimauve.kode.dsl | ||
|
||
@KodeDsl | ||
class SourceSet internal constructor( | ||
val name: String, | ||
) : FileOrDirectory { | ||
|
||
val directorySets = mutableListOf<SourceDirectorySet>() | ||
|
||
fun directorySet(name: String, block: SourceDirectorySet.() -> Unit = {}) { | ||
directorySets.add(SourceDirectorySet(name).apply(block)) | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
kode/src/commonMain/kotlin/software/guimauve/kode/dsl/TextFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package software.guimauve.kode.dsl | ||
|
||
@KodeDsl | ||
data class TextFile internal constructor( | ||
val content: String, | ||
) : FolderContent, FileOrDirectory |
28 changes: 28 additions & 0 deletions
28
kode/src/commonMain/kotlin/software/guimauve/kode/usecases/GenerateFolderUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package software.guimauve.kode.usecases | ||
|
||
import software.guimauve.kode.dsl.* | ||
|
||
class GenerateFolderUseCase( | ||
private val generateCodeUseCase: IGenerateCodeUseCase, | ||
) : IGenerateFolderUseCase { | ||
|
||
override fun invoke(input: FileOrDirectory): FolderContent = when (input) { | ||
is Project -> Folder(input.modules.associate { it.name to invoke(it) } + | ||
input.textFiles.map { it.key to invoke(it.value) }.associate { it }) | ||
|
||
is Module -> Folder(input.sourceSets.associate { it.name to invoke(it) }) | ||
is SourceSet -> Folder(input.directorySets.associate { it.name to invoke(it) }) | ||
is SourceDirectorySet -> folderFor(input.packages, input.files, input.textFiles) | ||
is Package -> folderFor(input.packages, input.files, input.textFiles) | ||
is File -> TextFile(generateCodeUseCase(input)) | ||
is TextFile -> input | ||
} | ||
|
||
// TODO: Fix recursive package names | ||
private fun folderFor(packages: List<Package>, files: Map<String, File>, textFiles: Map<String, TextFile>) = Folder( | ||
packages.associate { it.name to invoke(it) } | ||
+ files.map { it.key to invoke(it.value) }.associate { it } | ||
+ textFiles.map { it.key to it.value }.associate { it } | ||
) | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
kode/src/commonMain/kotlin/software/guimauve/kode/usecases/IGenerateFolderUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package software.guimauve.kode.usecases | ||
|
||
import dev.kaccelero.usecases.IUseCase | ||
import software.guimauve.kode.dsl.FileOrDirectory | ||
import software.guimauve.kode.dsl.FolderContent | ||
|
||
interface IGenerateFolderUseCase : IUseCase<FileOrDirectory, FolderContent> |