@winner-fed/winner-deploy 3.3.4 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/see.js +131 -29
- package/src/utils.js +101 -1
- package/templates/see/bash/deploy.xml +0 -1
- package/templates/see/docker/deploy.xml +2 -2
- package/templates/see/python/deploy.xml +1 -1
- package/templates/see/bash/.DS_Store +0 -0
package/package.json
CHANGED
package/src/see.js
CHANGED
|
@@ -3,10 +3,73 @@ const path = require('path')
|
|
|
3
3
|
const tpl = require('lodash.template')
|
|
4
4
|
const xml = require('xml')
|
|
5
5
|
const babel = require('@babel/core')
|
|
6
|
-
const { unEscapeForXML } = require('./utils')
|
|
6
|
+
const { unEscapeForXML, genComplexSelectXml, findTemplateVariableItem } = require('./utils')
|
|
7
7
|
|
|
8
|
+
// 支持的类型
|
|
9
|
+
// input - 普通文本输入框。
|
|
10
|
+
// select - 单选下拉框。
|
|
11
|
+
// switch - 开关组件。
|
|
12
|
+
// smallfile - 文件上传控件,仅支持小于 2M 的文件,文件内容以 base64 转码后的字符串存储。
|
|
13
|
+
// switchForm - 开关表单,通过控件 switch 控制下面表单的显示
|
|
14
|
+
// complexSelect - 复杂单选框,通过控件 select 控制下面显示哪个表单
|
|
15
|
+
// table - 表格控件,table 类型的模板配置目前只支持 Array<Object> 类型配置项,比如 APPS。
|
|
16
|
+
// division - 分栏折叠控件。 division分栏组件将界面上众多的组件分栏并给出每一栏目的标头该控件仅用于界面展示控制由于其不具有name属性故其子元素取值方式保持原有不变,举例division包含子控件b其取值变量为b),分区组件,用于界面控制,作为分栏使用,对参数使用没意义
|
|
17
|
+
const typeSupported = ['input', 'select', 'switch', 'smallfile', 'table', 'mselect', 'switchForm', 'complexSelect', 'division']
|
|
8
18
|
const resolveFile = (file) => path.resolve(__dirname, `../templates/see/${file}`)
|
|
9
19
|
|
|
20
|
+
// 生成 filed 属性解析
|
|
21
|
+
const generateField = (attr) => {
|
|
22
|
+
const type = attr.type
|
|
23
|
+
if (!typeSupported.includes(type)) return ''
|
|
24
|
+
const {
|
|
25
|
+
label,
|
|
26
|
+
name,
|
|
27
|
+
tooltip = '',
|
|
28
|
+
// 配置界面开启是否默认显示该参数,用于隐藏不常修改的配置参数。可选值:true、false
|
|
29
|
+
visible = 'true',
|
|
30
|
+
required = 'false',
|
|
31
|
+
// 冻结表行,表格配置默认值,配置不允许用户增加或者修改行
|
|
32
|
+
fixed = 'false',
|
|
33
|
+
// 控件是否默认折叠,操控控件默认展示时是否占用最小空间,选填字段;可选值:true、false。
|
|
34
|
+
fold = 'false',
|
|
35
|
+
// 选择项,select、mselect、linkageform控件必填。示例:“true:是;false:否“
|
|
36
|
+
options = ''
|
|
37
|
+
} = attr
|
|
38
|
+
let defaultValue = attr.default
|
|
39
|
+
|
|
40
|
+
if (type === 'table') {
|
|
41
|
+
const keys = attr.keys || []
|
|
42
|
+
const columns = attr.columns || keys
|
|
43
|
+
|
|
44
|
+
defaultValue = columns.map(attr => generateField(attr)).join('\n ')
|
|
45
|
+
} else if (type === 'switchForm' || type === 'division') {
|
|
46
|
+
const children = attr.children
|
|
47
|
+
defaultValue = children.map(attr => generateField(attr)).join('\n ')
|
|
48
|
+
} else if (type === 'complexSelect') {
|
|
49
|
+
return genComplexSelectXml(attr)
|
|
50
|
+
} else {
|
|
51
|
+
defaultValue = [defaultValue]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const xmlVariable = xml({
|
|
55
|
+
field: [{
|
|
56
|
+
_attr: {
|
|
57
|
+
type,
|
|
58
|
+
label,
|
|
59
|
+
name,
|
|
60
|
+
tooltip,
|
|
61
|
+
visible,
|
|
62
|
+
required,
|
|
63
|
+
fixed,
|
|
64
|
+
fold,
|
|
65
|
+
options
|
|
66
|
+
}
|
|
67
|
+
}, defaultValue].concat(defaultValue)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
return unEscapeForXML(`${xmlVariable}`)
|
|
71
|
+
}
|
|
72
|
+
|
|
10
73
|
exports.genDeployXml = function genDeployXml ({
|
|
11
74
|
system,
|
|
12
75
|
type,
|
|
@@ -29,14 +92,9 @@ exports.genDeployXml = function genDeployXml ({
|
|
|
29
92
|
version,
|
|
30
93
|
configFileName,
|
|
31
94
|
variables: (() => {
|
|
32
|
-
return variables
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
delete attr.default
|
|
36
|
-
const xmlVariable = xml({ field: [{ _attr: attr }, defaultValue] })
|
|
37
|
-
return unEscapeForXML(`${xmlVariable}`)
|
|
38
|
-
})
|
|
39
|
-
.join('\n ')
|
|
95
|
+
return variables.map((attr) => {
|
|
96
|
+
return generateField(attr)
|
|
97
|
+
}).join('\n ')
|
|
40
98
|
})(),
|
|
41
99
|
description
|
|
42
100
|
})
|
|
@@ -86,18 +144,72 @@ exports.genTemplate = function genTemplate (file, variables = []) {
|
|
|
86
144
|
visitor: {
|
|
87
145
|
Literal (path) {
|
|
88
146
|
if (path.parentPath.isProperty()) {
|
|
89
|
-
const _match = variables
|
|
147
|
+
const _match = findTemplateVariableItem(variables, (variable) => path.parentPath.get('key').node.name === variable.name)
|
|
148
|
+
|
|
90
149
|
if (_match) {
|
|
150
|
+
if (_match.fullPath.includes('complexSelect')) {
|
|
151
|
+
_match.name = _match.fullName
|
|
152
|
+
}
|
|
153
|
+
|
|
91
154
|
if (path.isStringLiteral()) {
|
|
92
|
-
path.node.value =
|
|
155
|
+
path.node.value = `$!\{${_match.name}\}`
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (path.isNumericLiteral()) {
|
|
160
|
+
path.node.value = `$!\{${match.name}\}`
|
|
93
161
|
return
|
|
94
162
|
}
|
|
163
|
+
|
|
95
164
|
if (path.isBooleanLiteral()) {
|
|
96
165
|
path.node.type = 'StringLiteral'
|
|
166
|
+
|
|
167
|
+
if (_match.fullPath.includes('complexSelect')) {
|
|
168
|
+
path.node.value = `$!\{${_match.fullName}\}`
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
|
|
97
172
|
path.node.value = `[NO_QUOTATION_MARKS]$\{${_match.name}\}[NO_QUOTATION_MARKS]`
|
|
98
173
|
}
|
|
99
174
|
}
|
|
100
175
|
}
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
ArrayExpression (path) {
|
|
179
|
+
if (path.parentPath.isProperty()) {
|
|
180
|
+
const _match = findTemplateVariableItem(variables, variable => path.parentPath.get('key').node.name === variable.name)
|
|
181
|
+
|
|
182
|
+
if (_match) {
|
|
183
|
+
if (_match.fullPath.includes('complexSelect')) {
|
|
184
|
+
_match.name = _match.fullName
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let value = ''
|
|
188
|
+
|
|
189
|
+
// 目前只支持 [{}, {}] 这种形式的 table
|
|
190
|
+
// keys 表示 Object 元素的 key,value 目前只支持 String 类型
|
|
191
|
+
const keys = _match.keys || []
|
|
192
|
+
// 原来这个字段是 keys,不太好理解,换成 columns,需要处理兼容问题
|
|
193
|
+
const columns = _match.columns || keys
|
|
194
|
+
const options = _match.options
|
|
195
|
+
|
|
196
|
+
if (options) {
|
|
197
|
+
value = `[NO_QUOTATION_MARKS][#foreach($row in $${_match.name}) '$row' , #end][NO_QUOTATION_MARKS]`
|
|
198
|
+
path.node.type = 'StringLiteral'
|
|
199
|
+
path.node.value = value
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (columns && columns.length) {
|
|
204
|
+
columns.forEach(item => {
|
|
205
|
+
value += `${item.name}: '$\!{row.${item.name}}',` // 双引号会被转义
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
path.node.type = 'StringLiteral'
|
|
210
|
+
path.node.value = `[NO_QUOTATION_MARKS][#foreach($row in $${_match.name}) {${value}}, #end][NO_QUOTATION_MARKS]`
|
|
211
|
+
}
|
|
212
|
+
}
|
|
101
213
|
}
|
|
102
214
|
}
|
|
103
215
|
}
|
|
@@ -135,14 +247,9 @@ exports.genDockerDeployXml = function genDockerDeployXml ({
|
|
|
135
247
|
version,
|
|
136
248
|
configFileName,
|
|
137
249
|
variables: (() => {
|
|
138
|
-
return variables
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
delete attr.default
|
|
142
|
-
const xmlVariable = xml({ field: [{ _attr: attr }, defaultValue] })
|
|
143
|
-
return unEscapeForXML(`${xmlVariable}`)
|
|
144
|
-
})
|
|
145
|
-
.join('\n ')
|
|
250
|
+
return variables.map((attr) => {
|
|
251
|
+
return generateField(attr)
|
|
252
|
+
}).join('\n ')
|
|
146
253
|
})(),
|
|
147
254
|
description,
|
|
148
255
|
web_app_web_service_name,
|
|
@@ -151,7 +258,7 @@ exports.genDockerDeployXml = function genDockerDeployXml ({
|
|
|
151
258
|
}
|
|
152
259
|
|
|
153
260
|
exports.genK8sDeployRes = function genK8sDeployResYaml (options) {
|
|
154
|
-
const template = fs.readFileSync(resolveFile(`docker/k8s-deploy-res.yaml`))
|
|
261
|
+
const template = fs.readFileSync(resolveFile(`docker/k8s-deploy-res.yaml`))
|
|
155
262
|
|
|
156
263
|
return tpl(template, {
|
|
157
264
|
interpolate: /{{([\s\S]+?)}}/g
|
|
@@ -175,7 +282,7 @@ exports.genDeployXmlBySh = function genDeployXmlBySh ({
|
|
|
175
282
|
variables = [],
|
|
176
283
|
description
|
|
177
284
|
}) {
|
|
178
|
-
const template = fs.readFileSync(resolveFile(`bash/deploy.xml`))
|
|
285
|
+
const template = fs.readFileSync(resolveFile(`bash/deploy.xml`))
|
|
179
286
|
|
|
180
287
|
return tpl(template, {
|
|
181
288
|
interpolate: /{{([\s\S]+?)}}/g
|
|
@@ -187,14 +294,9 @@ exports.genDeployXmlBySh = function genDeployXmlBySh ({
|
|
|
187
294
|
version,
|
|
188
295
|
configFileName,
|
|
189
296
|
variables: (() => {
|
|
190
|
-
return variables
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
delete attr.default
|
|
194
|
-
const xmlVariable = xml({ field: [{ _attr: attr }, defaultValue] })
|
|
195
|
-
return unEscapeForXML(`${xmlVariable}`)
|
|
196
|
-
})
|
|
197
|
-
.join('\n ')
|
|
297
|
+
return variables.map((attr) => {
|
|
298
|
+
return generateField(attr)
|
|
299
|
+
}).join('\n ')
|
|
198
300
|
})(),
|
|
199
301
|
description
|
|
200
302
|
})
|
package/src/utils.js
CHANGED
|
@@ -3,6 +3,7 @@ const chalk = require('chalk')
|
|
|
3
3
|
const ora = require('ora')
|
|
4
4
|
const fs = require('fs-extra')
|
|
5
5
|
const archiver = require('archiver')
|
|
6
|
+
const xml = require('xml')
|
|
6
7
|
|
|
7
8
|
const context = process.cwd()
|
|
8
9
|
|
|
@@ -35,7 +36,7 @@ exports.unEscapeForXML = function unEscapeForXML (string) {
|
|
|
35
36
|
*/
|
|
36
37
|
// 1,项目包名为 dist
|
|
37
38
|
exports.isProProject = function isProProject (subPath) {
|
|
38
|
-
const newSubPath = subPath || ''
|
|
39
|
+
const newSubPath = subPath || ''
|
|
39
40
|
const sysconfigJS = path.resolve(context, 'dist', newSubPath, 'sysconfig.js')
|
|
40
41
|
return fs.pathExistsSync(sysconfigJS)
|
|
41
42
|
}
|
|
@@ -80,3 +81,102 @@ exports.genZipPackage = function genZipPackage (zipPackageName, tmp, cb) {
|
|
|
80
81
|
archive.directory(tmp, false)
|
|
81
82
|
archive.finalize()
|
|
82
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 生成通用的 field 字段
|
|
87
|
+
* @param attr 属性
|
|
88
|
+
* @param children 子集
|
|
89
|
+
* @param t 字段类型
|
|
90
|
+
* @return {*}
|
|
91
|
+
*/
|
|
92
|
+
exports.formatCommonField = function formatCommonField (attr, children = [], t) {
|
|
93
|
+
const {
|
|
94
|
+
type,
|
|
95
|
+
label,
|
|
96
|
+
name,
|
|
97
|
+
tooltip = '',
|
|
98
|
+
visible = 'true',
|
|
99
|
+
required = 'false',
|
|
100
|
+
fixed = 'false',
|
|
101
|
+
fold = 'false',
|
|
102
|
+
options = ''
|
|
103
|
+
} = attr
|
|
104
|
+
const defaultValue = attr.default
|
|
105
|
+
|
|
106
|
+
if (t === 'form') {
|
|
107
|
+
const xmlVariable = xml({
|
|
108
|
+
form: [{
|
|
109
|
+
_attr: {
|
|
110
|
+
name,
|
|
111
|
+
tooltip,
|
|
112
|
+
visible,
|
|
113
|
+
required,
|
|
114
|
+
fixed,
|
|
115
|
+
fold,
|
|
116
|
+
options
|
|
117
|
+
}
|
|
118
|
+
}, children]
|
|
119
|
+
})
|
|
120
|
+
return exports.unEscapeForXML(xmlVariable)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const xmlVariable = xml({
|
|
124
|
+
field: [{
|
|
125
|
+
_attr: {
|
|
126
|
+
type,
|
|
127
|
+
label,
|
|
128
|
+
name,
|
|
129
|
+
tooltip,
|
|
130
|
+
visible,
|
|
131
|
+
required,
|
|
132
|
+
fixed,
|
|
133
|
+
fold,
|
|
134
|
+
options
|
|
135
|
+
}
|
|
136
|
+
}, defaultValue ? defaultValue : children]
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
return exports.unEscapeForXML(xmlVariable)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 复杂选择器解析
|
|
144
|
+
* @param attr
|
|
145
|
+
* @return {*}
|
|
146
|
+
*/
|
|
147
|
+
exports.formatComplexSelectXml = function formatComplexSelectXml (attr) {
|
|
148
|
+
const children = attr.children
|
|
149
|
+
const formsXmlVariable = children.map((form) => {
|
|
150
|
+
const children = form.children
|
|
151
|
+
const formItemsValue = children.map(formItem => exports.formatCommonField(formItem)).join('')
|
|
152
|
+
return exports.formatCommonField(form, formItemsValue, 'form')
|
|
153
|
+
}).join('')
|
|
154
|
+
|
|
155
|
+
return exports.formatCommonField(attr, formsXmlVariable)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 解析模板变量
|
|
160
|
+
*
|
|
161
|
+
* @param {Array} variables 模板变量数组
|
|
162
|
+
* @param {Function} cb 回调函数
|
|
163
|
+
* @param prefix
|
|
164
|
+
* @param path
|
|
165
|
+
* @returns 查询对象,若没有找到则返回 null
|
|
166
|
+
*/
|
|
167
|
+
exports.findTemplateVariableItem = function findTemplateVariableItem (variables, cb, prefix = '', path = '') {
|
|
168
|
+
for (let i = 0; i < variables.length; i++) {
|
|
169
|
+
let item = variables[i]
|
|
170
|
+
item.fullName = `${prefix === '' ? '' : prefix + '.'}${item.name}`
|
|
171
|
+
item.fullPath = `${path === '' ? '' : path + '-'}${item.type}`
|
|
172
|
+
|
|
173
|
+
if (cb(item)) {
|
|
174
|
+
return item
|
|
175
|
+
} else if (item.children && item.children.length > 0) {
|
|
176
|
+
let result = exports.findTemplateVariableItem(item.children, cb, item.fullName, item.fullPath)
|
|
177
|
+
if (result) return result
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return null
|
|
182
|
+
}
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
<% } else { %>
|
|
35
35
|
<field name="webAppName" label="前端应用名" type="hidden" tooltip="前端部署完成后访问的站点名称;需要与IAR中的location前端目录名称保持一致">{{ name }}</field>
|
|
36
36
|
<% } %>
|
|
37
|
-
|
|
38
37
|
{{ variables }}
|
|
39
38
|
</variables>
|
|
40
39
|
<config path="./${webAppName}/{{ configFileName }}.js" encoding="UTF-8"/>
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
<system id="{{ name }}" type="" name="{{ name }}" mode="cluster" front="">
|
|
16
16
|
<variables describe="集群基本参数">
|
|
17
17
|
<field name="user" label="安装用户" type="input">root</field>
|
|
18
|
-
<field name="workspace" label="前端安装目录"
|
|
18
|
+
<field name="workspace" label="前端安装目录" tooltip="IAR上存放前端目录" type="input">/html</field>
|
|
19
19
|
|
|
20
20
|
<!-- K8S部署配置 -->
|
|
21
21
|
<field name="division_k8s" label="K8S部署配置" type="division" fold="false">
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
</field>
|
|
37
37
|
<field name="liveness_probe_enable" label="存活检查探针开启" type="switch" options="true:ON;false:OFF">false</field>
|
|
38
38
|
</field>
|
|
39
|
-
|
|
40
39
|
{{ variables }}
|
|
40
|
+
|
|
41
41
|
</variables>
|
|
42
42
|
<config path="./{{ name }}/{{ configFileName }}.js" encoding="UTF-8"/>
|
|
43
43
|
<config reference="" encoding="utf-8" path="./k8s-deploy-res.yaml" />
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
<% } else { %>
|
|
35
35
|
<field name="webAppName" label="前端应用名" type="hidden" tooltip="前端部署完成后访问的站点名称;需要与IAR中的location前端目录名称保持一致">{{ name }}</field>
|
|
36
36
|
<% } %>
|
|
37
|
-
|
|
38
37
|
{{ variables }}
|
|
38
|
+
|
|
39
39
|
</variables>
|
|
40
40
|
<config path="./${webAppName}/{{ configFileName }}.js" encoding="UTF-8"/>
|
|
41
41
|
<config path="./scripts/{{ name }}/install.py" encoding="UTF-8"/>
|
|
Binary file
|