rigjs 2.1.22 → 2.1.25
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/built/index.js +74 -74
- package/lib/publish/index.ts +190 -160
- package/package.json +1 -1
package/lib/publish/index.ts
CHANGED
|
@@ -3,181 +3,211 @@ import CICDCmd from '@/classes/cicd/CICDCmd';
|
|
|
3
3
|
import CDN from '@/classes/cicd/Deploy/CDN';
|
|
4
4
|
|
|
5
5
|
const delay = async (ms: number) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
await new Promise((resolve) => {
|
|
7
|
+
setTimeout(resolve, ms);
|
|
8
|
+
});
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const setRewriteUri = async (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
domain: string,
|
|
13
|
+
original: string,
|
|
14
|
+
deployDir: string,
|
|
15
|
+
cdn: CDN
|
|
16
16
|
) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const rwriteResult = await cdn.setRewriteUri(
|
|
18
|
+
domain,
|
|
19
|
+
[original],
|
|
20
|
+
[deployDir],
|
|
21
|
+
['enhance_break']
|
|
22
|
+
);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
const configId = rwriteResult?.DomainConfigList.DomainConfigModel[0].ConfigId;
|
|
25
|
+
while (true) {
|
|
26
|
+
const configInfo = await cdn.describeCdnDomainConfigs(domain, configId);
|
|
27
|
+
if (configInfo.DomainConfigs.DomainConfig[0].Status === 'success') {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
if (configInfo.DomainConfigs.DomainConfig[0].Status === 'failed') {
|
|
31
|
+
throw new Error('cdn rewrite fail');
|
|
32
|
+
}
|
|
33
|
+
await delay(3000);
|
|
34
|
+
}
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const refreshCache = async (urls: string[], cdn: CDN) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
38
|
+
const refreshResult = await cdn.refreshCache(urls.join('\n'));
|
|
39
|
+
console.log('Please Wait For RefreshCache...');
|
|
40
|
+
while (true) {
|
|
41
|
+
const desResult = await cdn.describeRefreshTaskById(
|
|
42
|
+
refreshResult.RefreshTaskId
|
|
43
|
+
);
|
|
44
|
+
let successCount = 0;
|
|
45
|
+
for (const item of desResult.Tasks) {
|
|
46
|
+
if (item.Status === 'Complete') {
|
|
47
|
+
successCount++;
|
|
48
|
+
} else if (item.Status === 'Failed') {
|
|
49
|
+
throw new Error('RefreshCache Failed');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (successCount === desResult.Tasks.length) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
await delay(3000);
|
|
56
|
+
}
|
|
57
|
+
console.log('RefreshCache Done');
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
export default async (cmd: any) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
try {
|
|
62
|
+
//create cicd object
|
|
63
|
+
const cicd = CICD.createByDefault(cmd);
|
|
64
|
+
//construct cmd object
|
|
65
|
+
const cicdCmd = new CICDCmd(cmd, cicd);
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
console.log('Start Publish-----');
|
|
68
|
+
const target = Array.isArray(cicdCmd.cicd.target)
|
|
69
|
+
? cicdCmd.cicd.target[0]
|
|
70
|
+
: cicdCmd.cicd.target;
|
|
71
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
|
-
|
|
72
|
+
const cdn = new CDN(target);
|
|
73
|
+
const urls: string[] = [];
|
|
74
|
+
const setRewriteUriPromises: Promise<any>[] = [];
|
|
75
|
+
if (!cicdCmd.endpoints || cicdCmd.endpoints.length === 0) {
|
|
76
|
+
throw new Error('Endpoints.length Can Not Be 0!');
|
|
77
|
+
}
|
|
78
|
+
for (const endpoint of cicdCmd.endpoints) {
|
|
79
|
+
if (
|
|
80
|
+
!endpoint.uri_rewrite &&
|
|
81
|
+
(!target.uri_rewrite ||
|
|
82
|
+
!target.uri_rewrite.original ||
|
|
83
|
+
!target.uri_rewrite.original_regexp)
|
|
84
|
+
) {
|
|
85
|
+
let webEntryPath: string;
|
|
86
|
+
if (cicd.web_type === 'mpa') {
|
|
87
|
+
webEntryPath = '/';
|
|
88
|
+
} else if (cicd.web_type === 'history') {
|
|
89
|
+
webEntryPath = '/';
|
|
90
|
+
} else {
|
|
91
|
+
webEntryPath = endpoint.web_entry_path
|
|
92
|
+
? endpoint.web_entry_path
|
|
93
|
+
: target.web_entry_path || '/';
|
|
94
|
+
}
|
|
95
|
+
for (const domain of endpoint.domains) {
|
|
96
|
+
if (cicd.web_type === 'mpa') {
|
|
97
|
+
//mpa匹配非首页
|
|
98
|
+
setRewriteUriPromises.push(
|
|
99
|
+
setRewriteUri(
|
|
100
|
+
domain,
|
|
101
|
+
'^\\/([\\w-/]*\\w+)(?![^?]*\\.\\w+)',
|
|
102
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/$1.html`,
|
|
103
|
+
cdn
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
//mpa匹配文件
|
|
107
|
+
setRewriteUriPromises.push(
|
|
108
|
+
setRewriteUri(
|
|
109
|
+
domain,
|
|
110
|
+
`^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
|
|
111
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/$1`,
|
|
112
|
+
cdn
|
|
113
|
+
)
|
|
114
|
+
);
|
|
115
|
+
} else if (cicd.web_type === 'history') {
|
|
116
|
+
//spa/history匹配非首页
|
|
117
|
+
setRewriteUriPromises.push(
|
|
118
|
+
setRewriteUri(
|
|
119
|
+
domain,
|
|
120
|
+
'^\\/([\\w-/]*\\w+)(?![^?]*\\.\\w+)',
|
|
121
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
|
|
122
|
+
cdn
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
//spa-history匹配文件
|
|
126
|
+
setRewriteUriPromises.push(
|
|
127
|
+
setRewriteUri(
|
|
128
|
+
domain,
|
|
129
|
+
`^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
|
|
130
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/$1`,
|
|
131
|
+
cdn
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
}else{
|
|
135
|
+
//spa-hash匹配文件
|
|
136
|
+
//hash模式支持一个域名支持多个网页应用的入口路径,如/,/app1,/app2,都是不同的网页应用
|
|
137
|
+
//需要替换webpack中的publicPath为实际OSS的目录
|
|
138
|
+
setRewriteUriPromises.push(
|
|
139
|
+
setRewriteUri(
|
|
140
|
+
domain,
|
|
141
|
+
`^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
|
|
142
|
+
`/$1`,
|
|
143
|
+
cdn
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
//首页匹配正则,hash,history,mpa三个模式通用
|
|
148
|
+
setRewriteUriPromises.push(
|
|
149
|
+
setRewriteUri(
|
|
150
|
+
domain,
|
|
151
|
+
`^(${webEntryPath})($|\\?|#|\\/\\?|\\/$)`,
|
|
152
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
|
|
153
|
+
cdn
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
urls.push(`https://${domain}${webEntryPath}`);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
const uriRewrite = endpoint.uri_rewrite
|
|
160
|
+
? endpoint.uri_rewrite
|
|
161
|
+
: target.uri_rewrite;
|
|
140
162
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
163
|
+
if (!uriRewrite) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
144
166
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
167
|
+
for (const domain of endpoint.domains) {
|
|
168
|
+
setRewriteUriPromises.push(
|
|
169
|
+
setRewriteUri(
|
|
170
|
+
domain,
|
|
171
|
+
'^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)',
|
|
172
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/$1`,
|
|
173
|
+
cdn
|
|
174
|
+
)
|
|
175
|
+
);
|
|
176
|
+
setRewriteUriPromises.push(
|
|
177
|
+
setRewriteUri(
|
|
178
|
+
domain,
|
|
179
|
+
`${
|
|
180
|
+
uriRewrite.original_regexp
|
|
181
|
+
? uriRewrite.original_regexp
|
|
182
|
+
: uriRewrite.original
|
|
183
|
+
}`,
|
|
184
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
|
|
185
|
+
cdn
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
urls.push(`https://${domain}${uriRewrite.original}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
162
192
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
193
|
+
// 回源URI改写
|
|
194
|
+
console.log('Please Wait For Set RWrite URI...');
|
|
195
|
+
if (setRewriteUriPromises.length > 0) {
|
|
196
|
+
await Promise.all(setRewriteUriPromises);
|
|
197
|
+
} else {
|
|
198
|
+
console.log('Not Have To Set RWrite URI');
|
|
199
|
+
}
|
|
200
|
+
console.log('Set RWrite URI Done');
|
|
171
201
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
202
|
+
//刷新cdn
|
|
203
|
+
if (urls.length > 0) {
|
|
204
|
+
await refreshCache(urls, cdn);
|
|
205
|
+
} else {
|
|
206
|
+
console.log('Not Have To RefreshCache');
|
|
207
|
+
}
|
|
208
|
+
console.log('Publish Done-----');
|
|
209
|
+
} catch (e: any) {
|
|
210
|
+
console.error(e.message);
|
|
211
|
+
process.exit(1);
|
|
212
|
+
}
|
|
183
213
|
};
|
package/package.json
CHANGED