@winner-fed/winner-deploy 3.4.2 → 4.0.6
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/README.md +3 -1
- package/dist/index.cjs +7 -0
- package/dist/index.d.ts +130 -0
- package/dist/index.js +7 -0
- package/package.json +34 -47
- package/templates/see/bash/deploy.xml +3 -1
- package/templates/see/docker/deploy.xml +3 -1
- package/templates/see/docker/k8s-deploy-res.yaml +9 -9
- package/templates/see/python/deploy.xml +3 -1
- package/LICENSE +0 -21
- package/src/genDockerPackage.js +0 -93
- package/src/genWebPackage.js +0 -102
- package/src/see.js +0 -334
- package/src/utils.js +0 -182
- package/src/winner-deploy.js +0 -212
package/src/see.js
DELETED
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
const fs = require('fs-extra')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const tpl = require('lodash.template')
|
|
4
|
-
const xml = require('xml')
|
|
5
|
-
const babel = require('@babel/core')
|
|
6
|
-
const { unEscapeForXML, formatComplexSelectXml, findTemplateVariableItem } = require('./utils')
|
|
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']
|
|
18
|
-
const resolveFile = (file) => path.resolve(__dirname, `../templates/see/${file}`)
|
|
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 formatComplexSelectXml(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
|
-
|
|
73
|
-
exports.genDeployXml = function genDeployXml ({
|
|
74
|
-
system,
|
|
75
|
-
type,
|
|
76
|
-
name,
|
|
77
|
-
appType,
|
|
78
|
-
version,
|
|
79
|
-
configFileName = 'config.local',
|
|
80
|
-
variables = [],
|
|
81
|
-
description
|
|
82
|
-
}) {
|
|
83
|
-
const template = fs.readFileSync(resolveFile(`python/deploy.xml`)).toString()
|
|
84
|
-
|
|
85
|
-
return tpl(template, {
|
|
86
|
-
interpolate: /{{([\s\S]+?)}}/g
|
|
87
|
-
})({
|
|
88
|
-
system,
|
|
89
|
-
type,
|
|
90
|
-
name,
|
|
91
|
-
appType,
|
|
92
|
-
version,
|
|
93
|
-
configFileName,
|
|
94
|
-
variables: (() => {
|
|
95
|
-
return variables.map((attr) => {
|
|
96
|
-
return generateField(attr)
|
|
97
|
-
}).join('\n ')
|
|
98
|
-
})(),
|
|
99
|
-
description
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
exports.genScripts = function genScripts (name, options) {
|
|
104
|
-
const template = fs.readFileSync(resolveFile(`python/scripts/${name}.py`)).toString()
|
|
105
|
-
return tpl(template, {
|
|
106
|
-
interpolate: /{{([\s\S]+?)}}/g
|
|
107
|
-
})(options)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
exports.genTemplate = function genTemplate (file, variables = []) {
|
|
111
|
-
// phase 1. parse
|
|
112
|
-
// const template = fs.readFileSync(file).toString();
|
|
113
|
-
// const ast = parse(template);
|
|
114
|
-
|
|
115
|
-
// phase 2. traverse
|
|
116
|
-
// traverse(ast, {
|
|
117
|
-
// enter(path) {
|
|
118
|
-
// if (path.isLiteral() && path.parentPath.isProperty()) {
|
|
119
|
-
// const _match = variables.find((variable) => path.parentPath.get("key").node.name === variable.name);
|
|
120
|
-
// if (_match) {
|
|
121
|
-
// console.log(_match.name);
|
|
122
|
-
// if (path.isStringLiteral()) {
|
|
123
|
-
// path.node.value = `$\{${_match.name}\}`;
|
|
124
|
-
// return;
|
|
125
|
-
// }
|
|
126
|
-
// if (path.isBooleanLiteral()) {
|
|
127
|
-
// path.node.type = "StringLiteral";
|
|
128
|
-
// path.node.value = `[NO_QUOTATION_MARKS]$\{${_match.name}\}[NO_QUOTATION_MARKS]`;
|
|
129
|
-
// return;
|
|
130
|
-
// }
|
|
131
|
-
// }
|
|
132
|
-
// }
|
|
133
|
-
// },
|
|
134
|
-
// });
|
|
135
|
-
|
|
136
|
-
// phase 3. traverse
|
|
137
|
-
// let { code } = generate(ast, template);
|
|
138
|
-
|
|
139
|
-
const { code } = babel.transformFileSync(file, {
|
|
140
|
-
babelrc: false,
|
|
141
|
-
plugins: [
|
|
142
|
-
function seeTemplatePlugin () {
|
|
143
|
-
return {
|
|
144
|
-
visitor: {
|
|
145
|
-
Literal (path) {
|
|
146
|
-
if (path.parentPath.isProperty()) {
|
|
147
|
-
const currentNode = path.parentPath.get('key').node
|
|
148
|
-
let currentNodeName = currentNode.name
|
|
149
|
-
// 当 key 为字符串的时候,会转换失败
|
|
150
|
-
// 解决方法,重置为标识符字面量节点
|
|
151
|
-
// 如
|
|
152
|
-
// window.LOCAL_CONFIG_whaleTest = {
|
|
153
|
-
// "API_HOME": 'https://api.github.com/',
|
|
154
|
-
// 'API_USER': "https://www.baidu.com",
|
|
155
|
-
// API_UPLOAD: 'https://api.github.com/upload',
|
|
156
|
-
// IS_OPEN_VCONSOLE: false
|
|
157
|
-
// }
|
|
158
|
-
// 转换之后的效果是有问题的,API_HOME 没有转换
|
|
159
|
-
// window.LOCAL_CONFIG_whaleTest = {
|
|
160
|
-
// "API_HOME": 'https://api.github.com/',
|
|
161
|
-
// 'API_USER': "https://www.baidu.com",
|
|
162
|
-
// API_UPLOAD: 'https://api.github.com/upload',
|
|
163
|
-
// IS_OPEN_VCONSOLE: ${IS_OPEN_VCONSOLE}
|
|
164
|
-
// }
|
|
165
|
-
if (currentNode.type === 'StringLiteral') {
|
|
166
|
-
currentNode.type = 'Identifier'
|
|
167
|
-
currentNode.name = currentNode.value
|
|
168
|
-
currentNodeName = currentNode.value
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const _match = findTemplateVariableItem(variables, (variable) => currentNodeName === variable.name)
|
|
172
|
-
if (_match) {
|
|
173
|
-
if (_match.fullPath.includes('complexSelect')) {
|
|
174
|
-
_match.name = _match.fullName
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// 是否为字符串字面量节点
|
|
178
|
-
if (path.isStringLiteral()) {
|
|
179
|
-
path.node.value = `$!\{${_match.name}\}`
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
// 是否为数字字面量节点
|
|
183
|
-
if (path.isNumericLiteral()) {
|
|
184
|
-
path.node.value = `$!\{${_match.name}\}`
|
|
185
|
-
return
|
|
186
|
-
}
|
|
187
|
-
// 是否为数布尔字面量节点
|
|
188
|
-
if (path.isBooleanLiteral()) {
|
|
189
|
-
path.node.type = 'StringLiteral'
|
|
190
|
-
|
|
191
|
-
if (_match.fullPath.includes('complexSelect')) {
|
|
192
|
-
path.node.value = `$!\{${_match.fullName}\}`
|
|
193
|
-
return
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
path.node.value = `[NO_QUOTATION_MARKS]$\{${_match.name}\}[NO_QUOTATION_MARKS]`
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
ArrayExpression (path) {
|
|
203
|
-
if (path.parentPath.isProperty()) {
|
|
204
|
-
const _match = findTemplateVariableItem(variables, variable => path.parentPath.get('key').node.name === variable.name)
|
|
205
|
-
|
|
206
|
-
if (_match) {
|
|
207
|
-
if (_match.fullPath.includes('complexSelect')) {
|
|
208
|
-
_match.name = _match.fullName
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
let value = ''
|
|
212
|
-
|
|
213
|
-
// 目前只支持 [{}, {}] 这种形式的 table
|
|
214
|
-
// keys 表示 Object 元素的 key,value 目前只支持 String 类型
|
|
215
|
-
const keys = _match.keys || []
|
|
216
|
-
// 原来这个字段是 keys,不太好理解,换成 columns,需要处理兼容问题
|
|
217
|
-
const columns = _match.columns || keys
|
|
218
|
-
const options = _match.options
|
|
219
|
-
|
|
220
|
-
if (options) {
|
|
221
|
-
value = `[NO_QUOTATION_MARKS][#foreach($row in $${_match.name}) '$row' , #end][NO_QUOTATION_MARKS]`
|
|
222
|
-
path.node.type = 'StringLiteral'
|
|
223
|
-
path.node.value = value
|
|
224
|
-
return
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (columns && columns.length) {
|
|
228
|
-
columns.forEach(item => {
|
|
229
|
-
value += `${item.name}: '$\!{row.${item.name}}',` // 双引号会被转义
|
|
230
|
-
})
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
path.node.type = 'StringLiteral'
|
|
234
|
-
path.node.value = `[NO_QUOTATION_MARKS][#foreach($row in $${_match.name}) {${value}}, #end][NO_QUOTATION_MARKS]`
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
],
|
|
242
|
-
retainLines: true
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
// BooleanLiteral 需要在模版中去掉引号
|
|
246
|
-
return code.replace(/"\[NO_QUOTATION_MARKS](.*)\[NO_QUOTATION_MARKS]"/g, '$1')
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// ---------------------------------------------------docker
|
|
250
|
-
exports.genDockerDeployXml = function genDockerDeployXml ({
|
|
251
|
-
system,
|
|
252
|
-
type,
|
|
253
|
-
name,
|
|
254
|
-
appType,
|
|
255
|
-
version,
|
|
256
|
-
configFileName = 'config.local',
|
|
257
|
-
variables = [],
|
|
258
|
-
description,
|
|
259
|
-
web_app_web_service_name,
|
|
260
|
-
dockerImage
|
|
261
|
-
}) {
|
|
262
|
-
const template = fs.readFileSync(resolveFile(`docker/deploy.xml`)).toString()
|
|
263
|
-
|
|
264
|
-
return tpl(template, {
|
|
265
|
-
interpolate: /{{([\s\S]+?)}}/g
|
|
266
|
-
})({
|
|
267
|
-
system,
|
|
268
|
-
type,
|
|
269
|
-
name,
|
|
270
|
-
appType,
|
|
271
|
-
version,
|
|
272
|
-
configFileName,
|
|
273
|
-
variables: (() => {
|
|
274
|
-
return variables.map((attr) => {
|
|
275
|
-
return generateField(attr)
|
|
276
|
-
}).join('\n ')
|
|
277
|
-
})(),
|
|
278
|
-
description,
|
|
279
|
-
web_app_web_service_name,
|
|
280
|
-
dockerImage
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
exports.genK8sDeployRes = function genK8sDeployResYaml (options) {
|
|
285
|
-
const template = fs.readFileSync(resolveFile(`docker/k8s-deploy-res.yaml`)).toString()
|
|
286
|
-
|
|
287
|
-
return tpl(template, {
|
|
288
|
-
interpolate: /{{([\s\S]+?)}}/g
|
|
289
|
-
})(options)
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
exports.genDockerfile = function genDockerfile (options) {
|
|
293
|
-
const template = fs.readFileSync(resolveFile(`docker/Dockerfile`)).toString()
|
|
294
|
-
|
|
295
|
-
return tpl(template)(options)
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// --------------------------------------------------- bash
|
|
299
|
-
exports.genDeployXmlBySh = function genDeployXmlBySh ({
|
|
300
|
-
system,
|
|
301
|
-
type,
|
|
302
|
-
name,
|
|
303
|
-
appType,
|
|
304
|
-
version,
|
|
305
|
-
configFileName = 'config.local',
|
|
306
|
-
variables = [],
|
|
307
|
-
description
|
|
308
|
-
}) {
|
|
309
|
-
const template = fs.readFileSync(resolveFile(`bash/deploy.xml`)).toString()
|
|
310
|
-
|
|
311
|
-
return tpl(template, {
|
|
312
|
-
interpolate: /{{([\s\S]+?)}}/g
|
|
313
|
-
})({
|
|
314
|
-
system,
|
|
315
|
-
type,
|
|
316
|
-
name,
|
|
317
|
-
appType,
|
|
318
|
-
version,
|
|
319
|
-
configFileName,
|
|
320
|
-
variables: (() => {
|
|
321
|
-
return variables.map((attr) => {
|
|
322
|
-
return generateField(attr)
|
|
323
|
-
}).join('\n ')
|
|
324
|
-
})(),
|
|
325
|
-
description
|
|
326
|
-
})
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
exports.genScriptsBySh = function genScriptsBySh (name, options) {
|
|
330
|
-
const template = fs.readFileSync(resolveFile(`bash/scripts/${name}.sh`)).toString()
|
|
331
|
-
return tpl(template, {
|
|
332
|
-
interpolate: /{{([\s\S]+?)}}/g
|
|
333
|
-
})(options)
|
|
334
|
-
}
|
package/src/utils.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const chalk = require('chalk')
|
|
3
|
-
const ora = require('ora')
|
|
4
|
-
const fs = require('fs-extra')
|
|
5
|
-
const archiver = require('archiver')
|
|
6
|
-
const xml = require('xml')
|
|
7
|
-
|
|
8
|
-
const context = process.cwd()
|
|
9
|
-
|
|
10
|
-
exports.spinner = function spinner (text) {
|
|
11
|
-
return ora({
|
|
12
|
-
text: `${chalk.white('[deploy] ')}${text}`
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// 还原特殊字符 /([&"<>'])/g
|
|
17
|
-
exports.unEscapeForXML = function unEscapeForXML (string) {
|
|
18
|
-
const XML_CHARACTER_MAP = {
|
|
19
|
-
'&': '&',
|
|
20
|
-
'"': '"',
|
|
21
|
-
''': '\'',
|
|
22
|
-
'<': '<',
|
|
23
|
-
'>': '>'
|
|
24
|
-
}
|
|
25
|
-
return string && string.replace
|
|
26
|
-
? string.replace(/(&)|(")|(')|(<)|(>)/g, function(str) {
|
|
27
|
-
return XML_CHARACTER_MAP[str]
|
|
28
|
-
})
|
|
29
|
-
: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @param subPath 子包路径
|
|
35
|
-
* @returns {*}
|
|
36
|
-
*/
|
|
37
|
-
// 1,项目包名为 dist
|
|
38
|
-
exports.isProProject = function isProProject (subPath) {
|
|
39
|
-
const newSubPath = subPath || ''
|
|
40
|
-
const sysconfigJS = path.resolve(context, 'dist', newSubPath, 'sysconfig.js')
|
|
41
|
-
return fs.pathExistsSync(sysconfigJS)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// winner项目特点
|
|
45
|
-
// 1,项目包名为 dist
|
|
46
|
-
// 2,配置文件名为 config.local
|
|
47
|
-
exports.isWinnerProject = function isWinnerProject () {
|
|
48
|
-
// 默认为 dist 目录
|
|
49
|
-
const configLocalJS = path.resolve(context, 'dist', 'config.local.js')
|
|
50
|
-
return fs.pathExistsSync(configLocalJS)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 生成 zip
|
|
55
|
-
* @param zipPackageName
|
|
56
|
-
* @param tmp
|
|
57
|
-
* @param cb
|
|
58
|
-
*/
|
|
59
|
-
exports.genZipPackage = function genZipPackage (zipPackageName, tmp, cb) {
|
|
60
|
-
// 包存放路径
|
|
61
|
-
const packagePath = 'package'
|
|
62
|
-
fs.ensureDirSync(packagePath)
|
|
63
|
-
|
|
64
|
-
const output = fs.createWriteStream(`${packagePath}/${zipPackageName}.zip`)
|
|
65
|
-
|
|
66
|
-
output.on('close', function() {
|
|
67
|
-
setTimeout(function() {
|
|
68
|
-
cb && cb()
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const archive = archiver('zip', { zlib: { level: 9 } }) // Sets the compression level.
|
|
73
|
-
|
|
74
|
-
archive.on('error', function(error) {
|
|
75
|
-
console.error()
|
|
76
|
-
console.error(error.stack || error)
|
|
77
|
-
error.details && console.error(error.details)
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
archive.pipe(output)
|
|
81
|
-
archive.directory(tmp, false)
|
|
82
|
-
archive.finalize()
|
|
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
|
-
}
|