index.html
13.8 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>happy~happy~happy~</title>
<script src="./static/js/jquery-3.6.1.min.js"></script>
<script src="./static/js/vue-2.6.10.min.js"></script>
<script src="./static/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./static/css/bootstrap.min.css">
<link rel="stylesheet" href="./static/css/bootstrap-theme.min.css">
</head>
<style>
</style>
<body>
<h1 style="text-align: center"></h1>
<div id="app" class="main container">
<!-- 导航栏 -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="btn btn-danger navbar-btn" @click="cleanInput">清除输入</button>
<a class="navbar-brand" href="">happy~happy~happy~</a>
<div class="btn-group navbar-btn" role="group" aria-label="...">
<button type="button" class="btn btn-default" @click="selectAll(1)">全选</button>
<button type="button" class="btn btn-default" @click="selectAll(2)">全不选</button>
</div>
<button type="button" class="btn btn-default navbar-btn" @click="copyNew">复制出来</button>
</div>
</div>
</nav>
<!-- 文本输入框 -->
<div>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">把配置贴到这</span>
<textarea v-model="source" class="form-control" placeholder="请手动输入..." rows="2"></textarea>
</div>
</div>
<!--搜索-->
<div class="row navbar-btn" v-if="allServiceList.length">
<div class="col-lg-6">
<div class="input-group">
<input type="text" class="form-control" v-model="searchText" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-danger" type="button" @click="cleanSearchText">clean</button>
</span>
</div>
</div>
</div>
<!--表格-->
<table class="table table-striped" v-if="allServiceList.length">
<thead class="thead-dark">
<tr>
<th>No.</th>
<th>服务名</th>
<th>是否需要部署</th>
</tr>
</thead>
<tbody>
<tr v-for="(item,i) in serviceList">
<td>{{i+1}}</td>
<td @click="selectService(i)">
<h3 v-if="!item.isWebService">{{item.serviceName}}</h3>
<h4 v-else>{{item.serviceName}}</h4>
</td>
<td><input class="form-check-input" type="checkbox" v-model="item.isOpen"/></td>
</tr>
</tbody>
</table>
</div>
</body>
<script type="text/javascript">
new Vue({
el: '#app',
//监听source变动
watch: {
source: function (val) {
this.source = val;
this.analyseSource();
},
searchText: function (val) {
//在allServiceList中找到包含val的
let serviceList = [];
this.allServiceList.forEach((item) => {
console.log(item)
if (item.serviceName.indexOf(val) != -1) {
serviceList.push(item);
}
});
this.serviceList = serviceList;
}
},
data: {
source: '', //复制过来的
sourceArr: [], //按行分割的
serviceList: [], //服务列表
allServiceList: [], //服务列表
sleepList: [], //sleep列表
searchText: "", //搜索框的值
},
created: function () {
},
mounted() {
//等一会儿再执行
setTimeout(() => {
let sysPayload = window.sysPayload;
if (sysPayload) {
let source = ""
if (sysPayload.indexOf("node") !== -1) {
source = sysPayload;
}
this.source = source;
this.analyseSource();
}
}, 500);
},
methods: {
//清除搜索框
cleanSearchText: function () {
this.searchText = "";
},
//清除输入
cleanInput: function () {
this.source = "";
},
//选择服务
selectService: function (index) {
this.serviceList[index].isOpen = !this.serviceList[index].isOpen;
},
//全选
selectAll: function (type) {
let serviceList = this.serviceList;
let isOpen = true;
if (type == 2) {
isOpen = false;
}
serviceList.forEach((item) => {
item.isOpen = isOpen;
});
this.serviceList = serviceList;
},
//分析source
analyseSource: function () {
let serviceMap = {};
let serviceList = [];
let sleepList = [];
let source = this.source;
//将source按行分割
let sourceArr = source.split("\n");
//upload的开始行
let uploadStartRow = 0;
//upload的结束行
let uploadEndRow = 0;
//imageBuild的开始行
let imageBuildStart = 0;
//imageBuild的结束行
let imageBuildEnd = 0;
//找出关键行的行号
for (let i = 0; i < sourceArr.length; i++) {
let row = sourceArr[i].trim();
let nextRow = "";
if (i != sourceArr.length - 1) {
nextRow = sourceArr[i + 1].trim();
}
//upload的开始行
if (row == "stage('upload') {") {
uploadStartRow = i + 1;
}
//upload的结束行和imageBuild的开始行
if (row == "}" && nextRow == "stage('image build') {") {
uploadEndRow = i;
imageBuildStart = i + 2;
}
//imageBuild的结束行
if (row == "}" && uploadEndRow != 0 && imageBuildEnd == 0 && i != uploadEndRow) {
imageBuildEnd = i;
}
if (row.indexOf("sleep") != -1) {
let sleepRow = "sleep";
let strings = row.split("sleep");
strings.forEach((str,index)=>{
if (index>0){
sleepRow+=str;
}
});
row = sleepRow;
row = this.dealStr(row);
let rowObj = {
rowNo: i,
row: row,
}
sleepList.push(rowObj);
}
}
let uploadRow = 0;
sourceArr.slice(uploadStartRow, uploadEndRow).forEach((item, index) => {
uploadRow = uploadStartRow + index;
let row = item.trim();
if (!row) {
return;
}
//过滤可能是注释的行
if (escape(row).indexOf("%u") !== -1 || item.indexOf("sh") === -1) {
return;
}
let isOpen = !!(row && !row.startsWith("//"));
if (!isOpen) {
row = this.dealStr(row);
}
let strings = item.split("*.jar")[0].split("/");
let serviceName = strings[strings.length - 1].substring(0, strings[strings.length - 1].length - 1);
let service = {
isOpen: isOpen,
uploadRowNo: uploadRow,
uploadRow: row,
serviceName: serviceName,
isWebService: serviceName.indexOf("web") > -1,
}
serviceMap[service.serviceName] = service;
})
let buildRowNo = 0;
sourceArr.slice(imageBuildStart, imageBuildEnd).forEach((item, index) => {
buildRowNo = imageBuildStart + index;
let trimItem = item.trim();
if (item.indexOf("sleep") === -1 && trimItem) {
//过滤可能是注释的行
if (escape(trimItem).indexOf("%u") !== -1 || item.indexOf(".sh") === -1) {
return;
}
let serviceName = item.split(".sh ")[1].split(" ")[0];
let service = serviceMap[serviceName];
if (!service) {
return;
}
service.buildRowNo = buildRowNo;
service.buildRow = trimItem;
if (service.isOpen) {
if (trimItem.startsWith("//")) {
service.buildRow = trimItem.substring(2);
}
} else {
if (!trimItem.startsWith("//")) {
service.buildRow = "//" + trimItem;
}
}
if (!service.isOpen) {
service.buildRow = this.dealStr(service.buildRow);
}
}
});
//serviceMap转为数组
for (let key in serviceMap) {
serviceList.push(serviceMap[key]);
}
this.sourceArr = sourceArr;
this.allServiceList = serviceList;
this.serviceList = serviceList;
this.sleepList = sleepList;
},
//复制出来
copyNew: function () {
let {serviceList, allServiceList, sourceArr, sleepList} = this;
if (!allServiceList.length) {
alert("你输入的内容不对");
} else {
allServiceList.forEach((item) => {
let uploadRow = item.uploadRow;
let buildRow = item.buildRow;
sourceArr[item.uploadRowNo] = uploadRow;
sourceArr[item.buildRowNo] = buildRow;
if (item.isOpen) {
if (uploadRow.startsWith("//")) {
uploadRow = uploadRow.split("//")[1];
}
if (buildRow.startsWith("//")) {
buildRow = buildRow.split("//")[1];
}
let sleepRow = item.buildRowNo + 1;
sleepList.forEach(item => {
if (item.rowNo == sleepRow) {
if (item.row.startsWith("//")) {
item.row = item.row.split("//")[1];
}
}
});
} else {
//如果是关闭的 还没有注释的话,就注释掉
if (!uploadRow.startsWith("//")) {
uploadRow = "//" + uploadRow;
}
if (!buildRow.startsWith("//")) {
buildRow = "//" + buildRow;
}
let sleepRow = item.buildRowNo + 1;
sleepList.forEach(item => {
if (item.rowNo == sleepRow) {
if (!item.row.startsWith("//")) {
item.row = "//" + item.row;
}
}
});
}
//格式
sourceArr[item.uploadRowNo] = "\t\t" + uploadRow;
sourceArr[item.buildRowNo] = "\t\t" + buildRow;
});
sleepList.forEach(item => {
item.row = "\t\t" + item.row;
sourceArr[item.rowNo] = item.row;
})
//去掉sourceArr的空行
sourceArr = sourceArr.filter(item => {
return item.trim();
})
//组合成原来的字符串
let newSource = "";
sourceArr.forEach(item => {
newSource += item + "\n";
})
//复制到剪切板
let txa = document.createElement('textarea')
txa.value = newSource
document.body.appendChild(txa)
txa.select()
document.execCommand('copy')
document.body.removeChild(txa)
alert("复制成功");
}
},
//dealStr
dealStr: function (str) {
//如果是注释的
if (str.startsWith("//")) {
if (str[2] === " ") {
//去除第三位的空格
str = str.substring(0, 2) + str.substring(3).trim();
return this.dealStr(str);
} else {
return str;
}
} else {
return str;
}
}
}
})
</script>
</html>