Skip to content

Commit 93917f3

Browse files
author
dengzi
committed
module preview
1 parent f5d184b commit 93917f3

17 files changed

Lines changed: 645 additions & 228 deletions

resources/META-INF/plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
<actions>
3131
<!-- Add your actions here -->
3232
<action id="com.dengzii.plugin.template.gen" class="com.dengzii.plugin.template.CreateModuleAction"
33-
text="AucFrameGenerator"
34-
description="AucFrameGenerator">
33+
text="Template Module Generator"
34+
description="Create module from template">
3535
<add-to-group group-id="ProjectViewPopupMenu" anchor="first"/>
3636
</action>
3737
</actions>

resources/fileTemplates/Template Application.java.ft

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
${PACKAGE_NAME}
1+
package ${PACKAGE_NAME};
22

3-
import ${BASE_APPLICATION}
3+
import ${BASE_APPLICATION};
44

5-
public class App extends BaseApplication{
5+
public class ${APPLICATION_NAME} extends BaseApplication{
66

77
public void onCreate(){
88

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ${PACKAGE_NAME}
2+
3+
import ${BASE_APPLICATION}
4+
5+
public class App extends BaseApplication{
6+
7+
public void onCreate(){
8+
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
Auc Application File
4+
</body>
5+
</html>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.dengzii.plugin.template
2+
3+
import com.dengzii.plugin.template.model.ModuleConfig
4+
import com.dengzii.plugin.template.template.AucTemplate
5+
import com.intellij.ide.util.PropertiesComponent
6+
7+
/**
8+
* <pre>
9+
* author : dengzi
10+
* e-mail : denua@foxmail.com
11+
* github : https://github.com/dengzii
12+
* time : 2020/1/3
13+
* desc :
14+
* </pre>
15+
*/
16+
17+
object Config {
18+
19+
private const val KEY_TEMPLATES = "KEY_TEMPLATES"
20+
21+
val DEFAULT_TEMPLATE = listOf(
22+
ModuleConfig.create(AucTemplate.MODULE, "feature", "com.example.feature", "Java", "Auc Feature Module"),
23+
ModuleConfig.create(AucTemplate.APP, "app", "com.example.feature", "Java", "Auc App Module"),
24+
ModuleConfig.create(AucTemplate.PKG, "pkg", "com.example.feature", "Java", "Auc Pkg Module"),
25+
ModuleConfig.create(AucTemplate.EXPORT, "export", "com.example.feature", "Java", "Auc Export Module")
26+
)
27+
28+
fun clear() {
29+
PropertiesComponent.getInstance().unsetValue(KEY_TEMPLATES)
30+
}
31+
32+
fun loadTemplates(): List<ModuleConfig> {
33+
return DEFAULT_TEMPLATE
34+
}
35+
36+
fun saveTemplates() {
37+
38+
}
39+
}

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.dengzii.plugin.template
22

33
import com.dengzii.plugin.template.model.FileTreeNode
44
import com.dengzii.plugin.template.model.ModuleConfig
5-
import com.dengzii.plugin.template.template.AucTemplate
6-
import com.dengzii.plugin.template.template.Placeholder
75
import com.dengzii.plugin.template.utils.Logger
86
import com.dengzii.plugin.template.utils.PluginKit
97
import com.intellij.openapi.command.UndoConfirmationPolicy
@@ -39,15 +37,9 @@ class FileWriteCommand(private var kit: PluginKit, private var moduleConfig: Mod
3937
Logger.i(TAG, "Current target is not directory.")
4038
return
4139
}
42-
val app = moduleConfig.template
43-
if (app.placeHolderMap == null) {
44-
app.placeHolderMap = AucTemplate.DEFAULT_PLACEHOLDER.toMutableMap()
45-
}
46-
app.placeHolderMap?.set(Placeholder.PACKAGE_NAME, moduleConfig.packageName)
47-
app.placeHolderMap?.set(Placeholder.MODULE_NAME, moduleConfig.name)
48-
49-
Logger.d(TAG, app.placeHolderMap.toString())
50-
app.children.forEach {
40+
val fileTreeNode = moduleConfig.template
41+
Logger.d(TAG, fileTreeNode.placeHolderMap.toString())
42+
fileTreeNode.children.forEach {
5143
createFileTree(it, current)
5244
}
5345
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.dengzii.plugin.template.model
22

3-
import com.dengzii.plugin.template.utils.Logger
43
import com.dengzii.plugin.template.template.Placeholder
54
import com.dengzii.plugin.template.template.replacePlaceholder
5+
import com.dengzii.plugin.template.utils.Logger
66
import java.io.File
77

88
/**
@@ -30,7 +30,6 @@ open class FileTreeNode private constructor() {
3030
private var realName: String = ""
3131
private var parent: FileTreeNode? = null
3232

33-
3433
companion object {
3534
private val TAG = FileTreeNode::class.java.simpleName
3635

@@ -61,6 +60,13 @@ open class FileTreeNode private constructor() {
6160
return this
6261
}
6362

63+
fun placeholder(placeholder: Placeholder, value: String) {
64+
if (this.placeHolderMap == null) {
65+
this.placeHolderMap = kotlin.collections.mutableMapOf()
66+
}
67+
placeHolderMap!![placeholder] = value
68+
}
69+
6470
/**
6571
* set current node as root.
6672
* the file of specified path must be a directory and exist.
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
package com.dengzii.plugin.template.model
22

3-
import com.dengzii.plugin.template.template.AucFrame
4-
5-
data class ModuleConfig(
6-
var template: AucFrame,
3+
class ModuleConfig(
4+
var template: FileTreeNode,
75
var name: String,
86
var packageName: String,
9-
var language: String
10-
)
7+
var language: String,
8+
var templateName: String
9+
) {
10+
11+
enum class Language {
12+
JAVA, KOTLIN;
13+
14+
15+
}
16+
17+
companion object {
18+
fun create(template: FileTreeNode, moduleName: String,
19+
packageName: String, language: String, templateName: String): ModuleConfig {
20+
return ModuleConfig(template, moduleName, packageName, language, templateName)
21+
}
22+
23+
fun getLangList() = Language.values().map { it.name.toLowerCase() }.toTypedArray()
24+
}
25+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ val Node.values: Node get() = dirNode("values")
3636
val Node.drawable: Node get() = dirNode("drawable")
3737
val Node.mipmap: Node get() = dirNode("mipmap")
3838

39-
val Node.AndroidManifest: FileNode get() = fileNode("MainActivity")
39+
val Node.AndroidManifest: FileNode get() = fileNode("AndroidManifest")
4040
val Node.proguard_rules: FileNode get() = fileNode("proguard-rules")
4141
val Node.gitignore: FileNode get() = fileNode(".gitignore")
4242
val Node.build: FileNode get() = fileNode("build")

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ package com.dengzii.plugin.template.template
99
* desc :
1010
</pre> */
1111

12-
fun main() {
13-
AucTemplate.MODULE.traversal({ i, d ->
14-
println(i.getPath())
15-
})
16-
}
17-
1812
object AucTemplate {
1913

2014
private val res = AucFrame {
@@ -25,14 +19,9 @@ object AucTemplate {
2519
}
2620
}
2721

28-
val DEFAULT_PLACEHOLDER = mapOf(
29-
Pair(Placeholder.APPLICATION_NAME, "App"),
30-
Pair(Placeholder.MODULE_NAME, "module"),
31-
Pair(Placeholder.PACKAGE_NAME, "com.example.app"),
32-
Pair(Placeholder.PROJECT_NAME, "Example")
33-
)
34-
3522
val APP = AucFrame {
23+
placeholder(Placeholder.MODULE_NAME, "app")
24+
placeholder(Placeholder.PACKAGE_NAME, "com.example")
3625
app {
3726
src {
3827
main {
@@ -57,6 +46,8 @@ object AucTemplate {
5746
}
5847

5948
val PKG = AucFrame {
49+
placeholder(Placeholder.MODULE_NAME, "pkg")
50+
placeholder(Placeholder.PACKAGE_NAME, "com.example")
6051
pkg {
6152
src {
6253
main {
@@ -82,6 +73,8 @@ object AucTemplate {
8273
}
8374

8475
val EXPORT = AucFrame {
76+
placeholder(Placeholder.MODULE_NAME, "export")
77+
placeholder(Placeholder.PACKAGE_NAME, "com.example")
8578
export {
8679
src { main {
8780
java { pkg_name { module_name { export {
@@ -100,6 +93,8 @@ object AucTemplate {
10093

10194
val MODULE = AucFrame {
10295
module_name {
96+
placeholder(Placeholder.MODULE_NAME, "feature")
97+
placeholder(Placeholder.PACKAGE_NAME, "com.example")
10398
include(APP)
10499
include(PKG)
105100
include(EXPORT)

0 commit comments

Comments
 (0)