rigjs 2.1.26 → 2.1.29

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.
@@ -72,7 +72,7 @@ export default async (cmd: any) => {
72
72
  case FrameworkType.vue: {
73
73
  vueEnv.useEnv(ep.vue_env!, ep.extra_env);
74
74
  //推测vue脚本
75
- if (!ep.build) ep.build = `npx vue-cli-service build --mode rig --dest ${ep.extra_env['OUTPUT_DIR']}`;
75
+ if (!ep.build) ep.build = `npx @vue/cli-service build --mode rig --dest ${ep.extra_env['OUTPUT_DIR']}`;
76
76
  }
77
77
  break;
78
78
  default:
@@ -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',
@@ -16,6 +16,8 @@ const traverseFolder = (url: string) => {
16
16
  filesList.push(curPath);
17
17
  }
18
18
  });
19
+ } else {
20
+ throw new Error(`Not Found FilePath: ${url}`);
19
21
  }
20
22
  };
21
23
 
@@ -3,222 +3,237 @@ 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
- 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
- }
24
+ const configId = rwriteResult?.DomainConfigList.DomainConfigModel[0].ConfigId;
25
+ for (let i = 0; i <= 200; i++) {
26
+ const configInfo = await cdn.describeCdnDomainConfigs(domain, configId);
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) {
37
+ break;
38
+ }
39
+ if (i === 200) {
40
+ throw new Error('cdn rewrite timeout 10min');
41
+ }
42
+ await delay(3000);
43
+ }
35
44
  };
36
45
 
37
46
  const refreshCache = async (urls: string[], cdn: CDN) => {
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');
47
+ const refreshResult = await cdn.refreshCache(urls.join('\n'));
48
+ console.log('Please Wait For RefreshCache...');
49
+ for (let i = 0; i <= 200; i++) {
50
+ const desResult = await cdn.describeRefreshTaskById(
51
+ refreshResult.RefreshTaskId
52
+ );
53
+ let successCount = 0;
54
+ for (const item of desResult.Tasks) {
55
+ if (item.Status === 'Complete') {
56
+ successCount++;
57
+ } else if (item.Status === 'Failed') {
58
+ throw new Error('RefreshCache Failed');
59
+ }
60
+ }
61
+ if (successCount === desResult.Tasks.length) {
62
+ break;
63
+ }
64
+ if (i === 200) {
65
+ throw new Error('refresh cache timeout 10min');
66
+ }
67
+ await delay(3000);
68
+ }
69
+ console.log('RefreshCache Done');
58
70
  };
59
71
 
60
72
  export default async (cmd: any) => {
61
- try {
62
- //create cicd object
63
- const cicd = CICD.createByDefault(cmd);
64
- //construct cmd object
65
- 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);
66
96
 
67
- console.log('Start Publish-----');
68
- const target = Array.isArray(cicdCmd.cicd.target)
69
- ? cicdCmd.cicd.target[0]
70
- : 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;
71
101
 
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;
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;
162
173
 
163
- if (!uriRewrite) {
164
- continue;
165
- }
174
+ if (!uriRewrite) {
175
+ continue;
176
+ }
166
177
 
167
- for (const domain of endpoint.domains) {
168
- if (cicd.web_type !== 'hash'){
169
- setRewriteUriPromises.push(
170
- setRewriteUri(
171
- domain,
172
- '^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)',
173
- `/${endpoint.deployDir.replace(/\\/g, '/')}/$1`,
174
- cdn
175
- )
176
- );
177
- }else{
178
- setRewriteUriPromises.push(
179
- setRewriteUri(
180
- domain,
181
- '^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)',
182
- `/$1`,
183
- cdn
184
- )
185
- );
186
- }
187
- setRewriteUriPromises.push(
188
- setRewriteUri(
189
- domain,
190
- `${
191
- uriRewrite.original_regexp
192
- ? uriRewrite.original_regexp
193
- : uriRewrite.original
194
- }`,
195
- `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
196
- cdn
197
- )
198
- );
199
- urls.push(`https://${domain}${uriRewrite.original}`);
200
- }
201
- }
202
- }
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
+ }
203
205
 
204
- // 回源URI改写
205
- console.log('Please Wait For Set RWrite URI...');
206
- if (setRewriteUriPromises.length > 0) {
207
- await Promise.all(setRewriteUriPromises);
208
- } else {
209
- console.log('Not Have To Set RWrite URI');
210
- }
211
- 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');
212
227
 
213
- //刷新cdn
214
- if (urls.length > 0) {
215
- await refreshCache(urls, cdn);
216
- } else {
217
- console.log('Not Have To RefreshCache');
218
- }
219
- console.log('Publish Done-----');
220
- } catch (e: any) {
221
- console.error(e.message);
222
- process.exit(1);
223
- }
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
+ }
224
239
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.1.26",
3
+ "version": "2.1.29",
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",