difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
 
source "scripts/foundations.sh"
# ============================ Function Region ===============================
 
g_new_mod()
{
    modName=`echo "$2" | tr A-Z a-z`
    if [ -d "./assets/Scripts/mod/$modName" ]
    then
        echo "\"$modName\"已经存在"
        exit 1
    fi
 
    echo "生成模块结构"
    modPath="./assets/Scripts/mod/$modName"
    mkdir $modPath
    mkdir "$modPath/view"
    forNow=`_getDateNowByFormat`
 
    camelCaseModName=`_converFirstChar $2`
 
    # echo "创建事件文件"
    # echo ${camelCaseModName}Event = ${camelCaseModName}Event or {} > "$modPath/${modName}_event.js"
 
    echo "创建模块控制器"
    cp "scripts/tpl/controller_tpl.js" "$modPath/${modName}_controller.js"
    sed -i "s/{MOD_CLASS_NAME}/${camelCaseModName}/g" "$modPath/${modName}_controller.js"
    sed -i "s/{MOD_NAME}/${modName}/g" "$modPath/${modName}_controller.js"
    sed -i "s/{DATE}/$forNow/g" "$modPath/${modName}_controller.js"
 
    echo "创建模块数据储存"
    cp "scripts/tpl/model_tpl.js" "$modPath/${modName}_model.js"
    sed -i "s/{MOD_CLASS_NAME}/${camelCaseModName}/g" "$modPath/${modName}_model.js"
    sed -i "s/{DATE}/$forNow/g" "$modPath/${modName}_model.js"
}
 
g_n_mod()
{
    modName=`echo "$2" | tr A-Z a-z`
    if [ -d "./assets/Scripts/mod/$modName" ]
    then
        echo "\"$modName\"已经存在"
        exit 1
    fi
 
    echo "生成模块结构"
    modPath="./assets/Scripts/mod/$modName"
    mkdir $modPath
    mkdir "$modPath/view"
    forNow=`_getDateNowByFormat`
 
    camelCaseModName=`_converFirstChar $2`
 
    # echo "创建事件文件"
    # echo ${camelCaseModName}Event = ${camelCaseModName}Event or {} > "$modPath/${modName}_event.js"
 
    echo "创建模块控制器"
    cp "scripts/tpl/controller_tpl.js" "$modPath/${modName}_controller.js"
    sed -i "" "s/{MOD_CLASS_NAME}/${camelCaseModName}/g" "$modPath/${modName}_controller.js"
    sed -i "" "s/{MOD_NAME}/${modName}/g" "$modPath/${modName}_controller.js"
    sed -i "" "s/{DATE}/$forNow/g" "$modPath/${modName}_controller.js"
 
    echo "创建模块数据储存"
    cp "scripts/tpl/model_tpl.js" "$modPath/${modName}_model.js"
    sed -i "" "s/{MOD_CLASS_NAME}/${camelCaseModName}/g" "$modPath/${modName}_model.js"
    sed -i "" "s/{DATE}/$forNow/g" "$modPath/${modName}_model.js"
}
 
g_n_view()
{
    modName=$(check_empty "请输入模块名: " $2)
    fileName=$(check_empty "请输入文件名: " $3)
    platform=$(check_empty "请输入平台标识1:pc2:mac: " $4)
 
    modPath="./assets/Scripts/mod/$modName"
 
    if [ ! -d "${modPath}" ]
    then
        echo "\"$modName\"模块不存在"
        exit 1
    fi
 
    winPath="${modPath}/view/${fileName}_window.js"
    if [ -f "${winPath}" ]
    then
        echo "\"$winName\"窗体已存在"
        exit 1
    fi
    
    forNow=`_getDateNowByFormat`
    camelCaseModName=`_converFirstChar ${fileName}`
 
    echo "创建模块窗体"
    cp "scripts/tpl/view_tpl.js" "${winPath}"
    if [ "$platform" == "1" ]; then
        sed -i "s/{WINDOW_NAME}/${camelCaseModName}Window/g" "${winPath}"
        sed -i "s/{DATE}/$forNow/g" "${winPath}"
    else
        sed -i "" "s/{WINDOW_NAME}/${camelCaseModName}Window/g" "${winPath}"
        sed -i "" "s/{DATE}/$forNow/g" "${winPath}"
    fi
}
 
g_n_panel()
{
    modName=$(check_empty "请输入模块名: " $2)
    fileName=$(check_empty "请输入文件名: " $3)
    platform=$(check_empty "请输入平台标识1:pc2:mac: " $4)
 
    modPath="./assets/Scripts/mod/$modName"
 
    if [ ! -d "${modPath}" ]
    then
        echo "\"$modName\"模块不存在"
        exit 1
    fi
 
    winPath="${modPath}/view/${fileName}_panel.js"
    if [ -f "${winPath}" ]
    then
        echo "\"$winName\"面板已存在"
        exit 1
    fi
    
    forNow=`_getDateNowByFormat`
    camelCaseModName=`_converFirstChar ${fileName}`
 
    echo "创建模块窗体"
    cp "scripts/tpl/panel_tpl.js" "${winPath}"
    if [ "$platform" == "1" ]; then
        sed -i "s/{PANEL_NAME}/${camelCaseModName}Panel/g" "${winPath}"
        sed -i "s/{DATE}/$forNow/g" "${winPath}"
    else
        sed -i "" "s/{PANEL_NAME}/${camelCaseModName}Panel/g" "${winPath}"
        sed -i "" "s/{DATE}/$forNow/g" "${winPath}"
    fi
}
 
# 判断是否为空值 空值则要求输入
check_empty(){
    if [ "$2" == "" ]; then
        read -p $1 input
        echo $input
    fi
    echo $2
}
 
g_help()
{
    echo "Help:
    new_mod            创建模块:  new_mod [模块名称]
    n_mod              创建模块: mac端下的操作 
    n_view             创建窗体:  模块名 文件名 平台
    n_panel            创建面板:  模块名 文件名 平台"
}
 
if [ "n_mod" = $1 ]
then
    g_n_mod $@
    exit 0
fi
 
if [ "new_mod" = $1 ]
then
    g_new_mod $@
    exit 0
fi
 
if [ "n_view" = $1 ]
then
    g_n_view $@
    exit 0
fi
 
if [ "n_panel" = $1 ]
then
    g_n_panel $@
    exit 0
fi