index.html
8.75 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
<!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">
<a class="navbar-brand" href="">happy~happy~happy~</a>
<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" rows="2"></textarea>
</div>
</div>
<!--表格-->
<table class="table table-striped" v-if="serviceList.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>
<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();
},
},
data: {
source: '', //复制过来的
sourceArr: [], //按行分割的
serviceList: [], //服务列表
},
created: function () {
},
mounted() {
//等一会儿再执行
setTimeout(() => {
let sysPayload = window.sysPayload;
if (sysPayload) {
let source = ""
if (sysPayload.indexOf("node") == -1) {
source = "请手动粘贴吧"
}else{
source = sysPayload;
}
this.source = source;
this.analyseSource();
}else{
this.source = "请手动粘贴吧";
}
}, 500);
},
methods: {
//分析source
analyseSource: function () {
let serviceMap = {};
let serviceList = [];
let source = this.source;
console.log(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') {") {
console.log("uploadStartRow:" + i)
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;
}
}
let uploadRow = 0;
sourceArr.slice(uploadStartRow, uploadEndRow).forEach((item, index) => {
uploadRow = uploadStartRow + index;
let row = item.trim();
if (!row) {
return;
}
let isOpen = !!(row && !row.startsWith("//"));
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) {
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;
}
}
}
})
//serviceMap转为数组
for (let key in serviceMap) {
serviceList.push(serviceMap[key]);
}
this.sourceArr = sourceArr;
this.serviceList = serviceList;
},
//复制出来
copyNew: function () {
let {serviceList, sourceArr} = this;
if (!serviceList.length) {
alert("你输入的内容不对");
} else {
serviceList.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];
}
} else {
//如果是关闭的 还没有注释的话,就注释掉
if (!uploadRow.startsWith("//")) {
uploadRow = "//" + uploadRow;
}
if (!buildRow.startsWith("//")) {
buildRow = "//" + buildRow;
}
}
//格式
sourceArr[item.uploadRowNo] = "\t\t" + uploadRow;
sourceArr[item.buildRowNo] = "\t\t" + buildRow;
});
//组合成原来的字符串
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("复制成功");
}
}
}
})
</script>
</html>