Skip to content

Commit 8ea4c20

Browse files
committed
修复无法创建多级目录问题
1 parent f5996b4 commit 8ea4c20

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

src/com/dengzii/plugin/template/model/FileTreeDsl.kt

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@ class FileTreeDsl() : FileTreeNode() {
1111
return this
1212
}
1313

14-
operator fun FileTreeNode.invoke(block: FileTreeDsl.() -> Unit): FileTreeNode {
15-
block()
16-
return this
17-
}
18-
19-
constructor(parent: FileTreeDsl?, name: String, isDir: Boolean) : this() {
20-
this.name = name
21-
this.parent = parent
22-
this.isDir = isDir
14+
operator fun FileTreeNode.invoke(block: FileTreeNode.() -> Unit){
15+
block(this)
2316
}
2417

2518
/**
@@ -28,7 +21,7 @@ class FileTreeDsl() : FileTreeNode() {
2821
* @param path The dir path
2922
* @param block The child node domain
3023
*/
31-
fun dir(path: String, block: FileTreeDsl.() -> Unit = {}) {
24+
fun FileTreeNode.dir(path: String, block: FileTreeNode.() -> Unit = {}) {
3225
if (!isDir) {
3326
this(block)
3427
return
@@ -37,30 +30,29 @@ class FileTreeDsl() : FileTreeNode() {
3730
path.contains(".") -> path.split(".")
3831
path.contains("/") -> path.split("/")
3932
else -> {
40-
val newNode = FileTreeDsl(this, path, true)
33+
val newNode = FileTreeNode(this, path, true)
4134
if (addChild(newNode)) {
4235
newNode(block)
4336
}
4437
return
4538
}
4639
}
47-
dirs = dirs
48-
.filter {
40+
dirs = dirs.filter {
4941
it.isNotBlank()
5042
}.toMutableList()
51-
createDirs(dirs, this)(block)
43+
val domain = createDirs(dirs, this)
44+
domain.invoke(block)
5245
}
5346

54-
fun file(name: String) {
47+
fun FileTreeNode.file(name: String) {
5548
if (!isDir) return
5649
addChild(FileTreeNode(this, name, false))
5750
}
5851

59-
fun fileTemplate(fileName: String, template: String) {
52+
fun FileTreeNode.fileTemplate(fileName: String, template: String) {
6053
if (this.fileTemplates == null) {
6154
this.fileTemplates = mutableMapOf()
6255
}
6356
fileTemplates!![fileName] = template
6457
}
65-
6658
}

src/com/dengzii/plugin/template/template/AndroidModuleTempateExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ typealias AucFrame = FileTreeNode
2020

2121
typealias ChildNodeBlock = (parent: Node) -> Unit
2222

23-
typealias Node = FileTreeDsl
23+
typealias Node = FileTreeNode
2424

2525
val Node.test: Node get() = dirNode("")
2626
val Node.main: Node get() = dirNode("main")

test/FileTreeDslTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ class FileTreeDslTest {
5050
placeholder("FILE_1", "first_file")
5151
placeholder("FILE_2", "second_file")
5252
file("\${FILE_1}.java")
53-
file("\${FILE_2}.java")
54-
dir("com/exmpale")
53+
dir("com/example"){
54+
println(name)
55+
file("\${FILE_2}.java")
56+
}
5557
}
58+
println(tree.getTreeGraph())
5659
}
5760
}

0 commit comments

Comments
 (0)