rigjs 2.1.27 → 2.1.28

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.
@@ -87,6 +87,7 @@ export default async (cmd: any) => {
87
87
  ep.defines['__DEPLOY_DIR__'] = ep.publicPath;
88
88
  ep.defines['__RIG_PUBLIC_PATH__'] = ep.publicPath;
89
89
  ep.defines['__RIG_DEPLOY_DIR__'] = ep.publicPath;
90
+ ep.defines['__RIG_ENTRY_PATH__'] = ep.web_entry_path!;
90
91
  replaceDefine(path.join(cicd.source.root_path, ep.publicPath), ep.defines);
91
92
  }
92
93
  } catch (e) {
@@ -101,7 +101,7 @@ class CDN {
101
101
  },
102
102
  {
103
103
  argName: 'flag',
104
- argValue: flags[index] || null,
104
+ argValue: flags[index] || 'enhance_break',
105
105
  },
106
106
  ],
107
107
  functionName: 'back_to_origin_url_rewrite',
@@ -3,31 +3,38 @@ 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
- await new Promise((resolve) => {
7
- setTimeout(resolve, ms);
8
- });
6
+ await new Promise((resolve) => {
7
+ setTimeout(resolve, ms);
8
+ });
9
9
  };
10
10
 
11
11
  const setRewriteUri = async (
12
- domain: string,
13
- original: string,
14
- deployDir: string,
15
- cdn: CDN
12
+ domain: string,
13
+ original: string | string[],
14
+ deployDir: string | string[],
15
+ cdn: CDN
16
16
  ) => {
17
- const rwriteResult = await cdn.setRewriteUri(
18
- domain,
19
- [original],
20
- [deployDir],
21
- ['enhance_break']
22
- );
17
+ const rwriteResult = await cdn.setRewriteUri(
18
+ domain,
19
+ Array.isArray(original) ? original : [original],
20
+ Array.isArray(deployDir) ? deployDir : [deployDir],
21
+ ['enhance_break']
22
+ );
23
23
 
24
24
  const configId = rwriteResult?.DomainConfigList.DomainConfigModel[0].ConfigId;
25
25
  for (let i = 0; i <= 200; i++) {
26
26
  const configInfo = await cdn.describeCdnDomainConfigs(domain, configId);
27
- if (configInfo.DomainConfigs.DomainConfig[0].Status === 'success') {
27
+ const domainConfigs = configInfo.DomainConfigs.DomainConfig;
28
+ let successCount = 0;
29
+ for (const domainConfig of domainConfigs) {
30
+ if (domainConfig.Status === 'success') {
31
+ successCount++;
32
+ } else if (domainConfig.Status === 'failed') {
33
+ throw new Error('cdn rewrite fail');
34
+ }
35
+ }
36
+ if (successCount === domainConfigs.length) {
28
37
  break;
29
- } else if (configInfo.DomainConfigs.DomainConfig[0].Status === 'failed') {
30
- throw new Error('cdn rewrite fail');
31
38
  }
32
39
  if (i === 200) {
33
40
  throw new Error('cdn rewrite timeout 10min');
@@ -63,167 +70,170 @@ const refreshCache = async (urls: string[], cdn: CDN) => {
63
70
  };
64
71
 
65
72
  export default async (cmd: any) => {
66
- try {
67
- //create cicd object
68
- const cicd = CICD.createByDefault(cmd);
69
- //construct cmd object
70
- const cicdCmd = new CICDCmd(cmd, cicd);
73
+ try {
74
+ const rewriteConfigs: {
75
+ [domain: string]: { original: string[]; deployDir: string[] };
76
+ } = {};
77
+ const setRewriteConfig = (
78
+ domain: string,
79
+ originalItem: string,
80
+ deployDirItem: string
81
+ ) => {
82
+ if (rewriteConfigs[domain]) {
83
+ rewriteConfigs[domain].original.push(originalItem);
84
+ rewriteConfigs[domain].deployDir.push(deployDirItem);
85
+ } else {
86
+ rewriteConfigs[domain] = {
87
+ original: [originalItem],
88
+ deployDir: [deployDirItem],
89
+ };
90
+ }
91
+ };
92
+ //create cicd object
93
+ const cicd = CICD.createByDefault(cmd);
94
+ //construct cmd object
95
+ const cicdCmd = new CICDCmd(cmd, cicd);
71
96
 
72
- console.log('Start Publish-----');
73
- const target = Array.isArray(cicdCmd.cicd.target)
74
- ? cicdCmd.cicd.target[0]
75
- : cicdCmd.cicd.target;
97
+ console.log('Start Publish-----');
98
+ const target = Array.isArray(cicdCmd.cicd.target)
99
+ ? cicdCmd.cicd.target[0]
100
+ : cicdCmd.cicd.target;
76
101
 
77
- const cdn = new CDN(target);
78
- const urls: string[] = [];
79
- const setRewriteUriPromises: Promise<any>[] = [];
80
- if (!cicdCmd.endpoints || cicdCmd.endpoints.length === 0) {
81
- throw new Error('Endpoints.length Can Not Be 0!');
82
- }
83
- for (const endpoint of cicdCmd.endpoints) {
84
- if (
85
- !endpoint.uri_rewrite &&
86
- (!target.uri_rewrite ||
87
- !target.uri_rewrite.original ||
88
- !target.uri_rewrite.original_regexp)
89
- ) {
90
- let webEntryPath: string;
91
- if (cicd.web_type === 'mpa') {
92
- webEntryPath = '/';
93
- } else if (cicd.web_type === 'history') {
94
- webEntryPath = '/';
95
- } else {
96
- webEntryPath = endpoint.web_entry_path
97
- ? endpoint.web_entry_path
98
- : target.web_entry_path || '/';
99
- }
100
- for (const domain of endpoint.domains) {
101
- if (cicd.web_type === 'mpa') {
102
- //mpa匹配非首页
103
- setRewriteUriPromises.push(
104
- setRewriteUri(
105
- domain,
106
- '^\\/([\\w-/]*\\w+)(?![^?]*\\.\\w+)',
107
- `/${endpoint.deployDir.replace(/\\/g, '/')}/$1.html`,
108
- cdn
109
- )
110
- );
111
- //mpa匹配文件
112
- setRewriteUriPromises.push(
113
- setRewriteUri(
114
- domain,
115
- `^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
116
- `/${endpoint.deployDir.replace(/\\/g, '/')}/$1`,
117
- cdn
118
- )
119
- );
120
- } else if (cicd.web_type === 'history') {
121
- //spa/history匹配非首页
122
- setRewriteUriPromises.push(
123
- setRewriteUri(
124
- domain,
125
- '^\\/([\\w-/]*\\w+)(?![^?]*\\.\\w+)',
126
- `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
127
- cdn
128
- )
129
- );
130
- //spa-history匹配文件
131
- setRewriteUriPromises.push(
132
- setRewriteUri(
133
- domain,
134
- `^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
135
- `/${endpoint.deployDir.replace(/\\/g, '/')}/$1`,
136
- cdn
137
- )
138
- );
139
- }else{
140
- //spa-hash匹配文件
141
- //hash模式支持一个域名支持多个网页应用的入口路径,如/,/app1,/app2,都是不同的网页应用
142
- //需要替换webpack中的publicPath为实际OSS的目录
143
- setRewriteUriPromises.push(
144
- setRewriteUri(
145
- domain,
146
- `^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
147
- `/$1`,
148
- cdn
149
- )
150
- );
151
- }
152
- //首页匹配正则,hash,history,mpa三个模式通用
153
- setRewriteUriPromises.push(
154
- setRewriteUri(
155
- domain,
156
- `^(${webEntryPath})($|\\?|#|\\/\\?|\\/$)`,
157
- `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
158
- cdn
159
- )
160
- );
161
- urls.push(`https://${domain}${webEntryPath}`);
162
- }
163
- } else {
164
- const uriRewrite = endpoint.uri_rewrite
165
- ? endpoint.uri_rewrite
166
- : target.uri_rewrite;
102
+ const cdn = new CDN(target);
103
+ const urls: string[] = [];
104
+ if (!cicdCmd.endpoints || cicdCmd.endpoints.length === 0) {
105
+ throw new Error('Endpoints.length Can Not Be 0!');
106
+ }
107
+ for (const endpoint of cicdCmd.endpoints) {
108
+ if (
109
+ !endpoint.uri_rewrite &&
110
+ (!target.uri_rewrite ||
111
+ !target.uri_rewrite.original ||
112
+ !target.uri_rewrite.original_regexp)
113
+ ) {
114
+ let webEntryPath: string;
115
+ if (cicd.web_type === 'mpa') {
116
+ webEntryPath = '/';
117
+ } else if (cicd.web_type === 'history') {
118
+ webEntryPath = '/';
119
+ } else {
120
+ webEntryPath = endpoint.web_entry_path
121
+ ? endpoint.web_entry_path
122
+ : target.web_entry_path || '/';
123
+ }
124
+ for (const domain of endpoint.domains) {
125
+ if (cicd.web_type === 'mpa') {
126
+ //mpa匹配非首页
127
+ setRewriteConfig(
128
+ domain,
129
+ '^\\/([\\w-/]*\\w+)(?![^?]*\\.\\w+)',
130
+ `/${endpoint.deployDir.replace(/\\/g, '/')}/$1.html`
131
+ );
132
+ //mpa匹配文件
133
+ setRewriteConfig(
134
+ domain,
135
+ `^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
136
+ `/${endpoint.deployDir.replace(/\\/g, '/')}/$1`
137
+ );
138
+ } else if (cicd.web_type === 'history') {
139
+ //spa/history匹配非首页
140
+ setRewriteConfig(
141
+ domain,
142
+ '^\\/([\\w-/]*\\w+)(?![^?]*\\.\\w+)',
143
+ `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`
144
+ );
145
+ //spa-history匹配文件
146
+ setRewriteConfig(
147
+ domain,
148
+ `^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
149
+ `/${endpoint.deployDir.replace(/\\/g, '/')}/$1`
150
+ );
151
+ } else {
152
+ //spa-hash匹配文件
153
+ //hash模式支持一个域名支持多个网页应用的入口路径,如/,/app1,/app2,都是不同的网页应用
154
+ //需要替换webpack中的publicPath为实际OSS的目录
155
+ setRewriteConfig(
156
+ domain,
157
+ `^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
158
+ `/$1`
159
+ );
160
+ }
161
+ //首页匹配正则,hash,history,mpa三个模式通用
162
+ setRewriteConfig(
163
+ domain,
164
+ `^(${webEntryPath})($|\\?|#|\\/\\?|\\/$)`,
165
+ `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`
166
+ );
167
+ urls.push(`https://${domain}${webEntryPath}`);
168
+ }
169
+ } else {
170
+ const uriRewrite = endpoint.uri_rewrite
171
+ ? endpoint.uri_rewrite
172
+ : target.uri_rewrite;
167
173
 
168
- if (!uriRewrite) {
169
- continue;
170
- }
174
+ if (!uriRewrite) {
175
+ continue;
176
+ }
171
177
 
172
- for (const domain of endpoint.domains) {
173
- if (cicd.web_type !== 'hash'){
174
- setRewriteUriPromises.push(
175
- setRewriteUri(
176
- domain,
177
- '^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)',
178
- `/${endpoint.deployDir.replace(/\\/g, '/')}/$1`,
179
- cdn
180
- )
181
- );
182
- }else{
183
- setRewriteUriPromises.push(
184
- setRewriteUri(
185
- domain,
186
- '^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)',
187
- `/$1`,
188
- cdn
189
- )
190
- );
191
- }
192
- setRewriteUriPromises.push(
193
- setRewriteUri(
194
- domain,
195
- `${
196
- uriRewrite.original_regexp
197
- ? uriRewrite.original_regexp
198
- : uriRewrite.original
199
- }`,
200
- `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
201
- cdn
202
- )
203
- );
204
- urls.push(`https://${domain}${uriRewrite.original}`);
205
- }
206
- }
207
- }
178
+ for (const domain of endpoint.domains) {
179
+ if (cicd.web_type !== 'hash') {
180
+ setRewriteConfig(
181
+ domain,
182
+ '^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)',
183
+ `/${endpoint.deployDir.replace(/\\/g, '/')}/$1`
184
+ );
185
+ } else {
186
+ setRewriteConfig(
187
+ domain,
188
+ '^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)',
189
+ `/$1`
190
+ );
191
+ }
192
+ setRewriteConfig(
193
+ domain,
194
+ `${
195
+ uriRewrite.original_regexp
196
+ ? uriRewrite.original_regexp
197
+ : uriRewrite.original
198
+ }`,
199
+ `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`
200
+ );
201
+ urls.push(`https://${domain}${uriRewrite.original}`);
202
+ }
203
+ }
204
+ }
208
205
 
209
- // 回源URI改写
210
- console.log('Please Wait For Set RWrite URI...');
211
- if (setRewriteUriPromises.length > 0) {
212
- await Promise.all(setRewriteUriPromises);
213
- } else {
214
- console.log('Not Have To Set RWrite URI');
215
- }
216
- console.log('Set RWrite URI Done');
206
+ // 回源URI改写
207
+ console.log('Please Wait For Set RWrite URI...');
208
+ const setRewriteUriPromises: Promise<any>[] = [];
209
+ console.log('rewriteConfigs: ', rewriteConfigs);
210
+ Object.keys(rewriteConfigs).forEach((domain) => {
211
+ const rewriteConfig = rewriteConfigs[domain];
212
+ setRewriteUriPromises.push(
213
+ setRewriteUri(
214
+ domain,
215
+ rewriteConfig.original,
216
+ rewriteConfig.deployDir,
217
+ cdn
218
+ )
219
+ );
220
+ });
221
+ if (setRewriteUriPromises.length > 0) {
222
+ await Promise.all(setRewriteUriPromises);
223
+ } else {
224
+ console.log('Not Have To Set RWrite URI');
225
+ }
226
+ console.log('Set RWrite URI Done');
217
227
 
218
- //刷新cdn
219
- if (urls.length > 0) {
220
- await refreshCache(urls, cdn);
221
- } else {
222
- console.log('Not Have To RefreshCache');
223
- }
224
- console.log('Publish Done-----');
225
- } catch (e: any) {
226
- console.error(e.message);
227
- process.exit(1);
228
- }
228
+ //刷新cdn
229
+ if (urls.length > 0) {
230
+ await refreshCache(urls, cdn);
231
+ } else {
232
+ console.log('Not Have To RefreshCache');
233
+ }
234
+ console.log('Publish Done-----');
235
+ } catch (e: any) {
236
+ console.error(e.message);
237
+ process.exit(1);
238
+ }
229
239
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.1.27",
3
+ "version": "2.1.28",
4
4
  "description": "A multi-repos dev tool based on yarn and git.Rig is inspired by cocoapods. Not like those monorepo solutions,rig is a tool for organizing multi-repos.",
5
5
  "keywords": [
6
6
  "modular",