rigjs 2.1.27 → 3.0.0-alpha
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/README.md +146 -183
- package/README_CN.md +151 -137
- package/built/index.js +145 -175
- package/demo/package.json +8 -6
- package/demo/package.rig.json5 +64 -10
- package/demo/rig_dev/.gitkeep +0 -0
- package/demo/rig_helper.js +5 -9
- package/demo/vue.config.js +1 -1
- package/demo/yarn.lock +20 -7
- package/doc/cicd_cn.md +120 -0
- package/doc/cmd_cn.md +0 -0
- package/doc/dependencies.md +0 -0
- package/doc/dependencies_cn.md +28 -0
- package/doc/share_cn.md +8 -0
- package/jest/test.rig.json5 +14 -0
- package/jest.config.ts +10 -1
- package/lib/add/index.ts +37 -0
- package/lib/build/build.md +6 -0
- package/lib/build/index.ts +64 -58
- package/lib/classes/RigConfig.test.ts +14 -0
- package/lib/classes/RigConfig.ts +191 -0
- package/lib/classes/cicd/CICD.ts +6 -7
- package/lib/classes/cicd/CICDCmd.ts +1 -0
- package/lib/classes/cicd/Deploy/CDN.ts +1 -1
- package/lib/classes/cicd/DirLevel.ts +1 -1
- package/lib/classes/cicd/Endpoint.ts +7 -1
- package/lib/classes/dependencies/Dep.ts +56 -0
- package/lib/dev/index.ts +44 -0
- package/lib/init/index.ts +118 -0
- package/lib/install/{index.js → index.ts} +3 -6
- package/lib/postinstall/{index.js → index.ts} +12 -20
- package/lib/preinstall/index.ts +78 -0
- package/lib/print/index.ts +38 -0
- package/lib/publish/index.ts +187 -177
- package/lib/rig/index.ts +29 -13
- package/lib/sync/index.test.ts +4 -0
- package/lib/sync/index.ts +32 -0
- package/lib/utils/fsHelper.ts +37 -1
- package/lib/utils/objectHelper.ts +12 -0
- package/lib/utils/regexHelper.test.ts +12 -0
- package/lib/utils/{regex.ts → regexHelper.ts} +4 -1
- package/package.json +9 -8
- package/package.rig.json5 +8 -0
- package/tsconfig.json +4 -2
- package/demo/cicd.rig.json5 +0 -56
- package/lib/init/cicd.rig.json5 +0 -11
- package/lib/init/index.d.ts +0 -6
- package/lib/init/index.js +0 -189
- package/lib/init/rig_helper.js +0 -14
- package/lib/install/index.d.ts +0 -5
- package/lib/postinstall/index.d.ts +0 -6
- package/lib/preinstall/index.d.ts +0 -7
- package/lib/preinstall/index.js +0 -198
- package/lib/preinstall/index.test.js +0 -16
- package/lib/print/index.js +0 -33
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ignore
|
|
3
|
+
* @Description nothing
|
|
4
|
+
* @author Wang Bo (ralwayne@163.com)
|
|
5
|
+
* @date 2020/10/20 7:32 PM
|
|
6
|
+
*/
|
|
7
|
+
const ora = require('ora');
|
|
8
|
+
const chalk = require('chalk');
|
|
9
|
+
|
|
10
|
+
let printer = ora();
|
|
11
|
+
|
|
12
|
+
const start = (str: string) => {
|
|
13
|
+
printer.start(chalk.blueBright(str));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const info = (str: string) => {
|
|
17
|
+
printer.info(chalk.hex('#37BA85')(str));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const error = (str: string) => {
|
|
21
|
+
printer.fail(chalk.hex('#FF4848')(str));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const warn = (str: string) => {
|
|
25
|
+
printer.warn(chalk.yellowBright(str));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const succeed = (str: string) => {
|
|
29
|
+
printer.succeed(chalk.greenBright(str));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default {
|
|
33
|
+
start,
|
|
34
|
+
info,
|
|
35
|
+
error,
|
|
36
|
+
warn,
|
|
37
|
+
succeed,
|
|
38
|
+
}
|
package/lib/publish/index.ts
CHANGED
|
@@ -3,33 +3,40 @@ 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 | string[],
|
|
14
|
+
deployDir: string | string[],
|
|
15
|
+
cdn: CDN
|
|
16
16
|
) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
for (let i = 0; i <=
|
|
25
|
+
for (let i = 0; i <= 100; i++) {
|
|
26
26
|
const configInfo = await cdn.describeCdnDomainConfigs(domain, configId);
|
|
27
|
-
|
|
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
|
-
if (i ===
|
|
39
|
+
if (i === 100) {
|
|
33
40
|
throw new Error('cdn rewrite timeout 10min');
|
|
34
41
|
}
|
|
35
42
|
await delay(3000);
|
|
@@ -39,7 +46,7 @@ const setRewriteUri = async (
|
|
|
39
46
|
const refreshCache = async (urls: string[], cdn: CDN) => {
|
|
40
47
|
const refreshResult = await cdn.refreshCache(urls.join('\n'));
|
|
41
48
|
console.log('Please Wait For RefreshCache...');
|
|
42
|
-
for (let i = 0; i <=
|
|
49
|
+
for (let i = 0; i <= 100; i++) {
|
|
43
50
|
const desResult = await cdn.describeRefreshTaskById(
|
|
44
51
|
refreshResult.RefreshTaskId
|
|
45
52
|
);
|
|
@@ -54,7 +61,7 @@ const refreshCache = async (urls: string[], cdn: CDN) => {
|
|
|
54
61
|
if (successCount === desResult.Tasks.length) {
|
|
55
62
|
break;
|
|
56
63
|
}
|
|
57
|
-
if (i ===
|
|
64
|
+
if (i === 100) {
|
|
58
65
|
throw new Error('refresh cache timeout 10min');
|
|
59
66
|
}
|
|
60
67
|
await delay(3000);
|
|
@@ -63,167 +70,170 @@ const refreshCache = async (urls: string[], cdn: CDN) => {
|
|
|
63
70
|
};
|
|
64
71
|
|
|
65
72
|
export default async (cmd: any) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
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
|
-
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
174
|
+
if (!uriRewrite) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
171
177
|
|
|
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
|
-
`/${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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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/lib/rig/index.ts
CHANGED
|
@@ -1,30 +1,46 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import print from '../print';
|
|
3
|
+
import add from '../add';
|
|
4
|
+
import dev from '../dev';
|
|
5
|
+
import preinstall from '../preinstall';
|
|
6
|
+
import postinstall from '../postinstall';
|
|
7
|
+
import build from '../build';
|
|
8
|
+
import deploy from '../deploy';
|
|
9
|
+
import publish from '../publish';
|
|
10
|
+
|
|
11
|
+
import sync from '../sync';
|
|
12
|
+
const nodeMin = '14.0.0';
|
|
13
|
+
if (semver.gte(nodeMin,process.version)){
|
|
14
|
+
print.error('NodeJS version must be at least 14.');
|
|
15
|
+
process.exit(0);
|
|
16
|
+
}
|
|
1
17
|
import {Command} from 'commander';
|
|
2
18
|
|
|
3
19
|
const program = new Command();
|
|
4
|
-
console.log('Hello');
|
|
5
20
|
|
|
6
21
|
import check from '../check';
|
|
7
22
|
|
|
8
23
|
program.command('check').action(check.load);
|
|
9
24
|
import init from '../init';
|
|
10
25
|
|
|
11
|
-
program.command('init').action(init
|
|
26
|
+
program.command('init').action(init);
|
|
12
27
|
import install from '../install';
|
|
13
28
|
|
|
14
|
-
program.command('install').action(install
|
|
15
|
-
program.command('i').action(install
|
|
16
|
-
import preinstall from '../preinstall';
|
|
17
|
-
import postinstall from '../postinstall';
|
|
29
|
+
program.command('install').action(install);
|
|
30
|
+
program.command('i').action(install);
|
|
18
31
|
|
|
19
|
-
program.command('preinstall').action(preinstall
|
|
20
|
-
program.command('postinstall').action(postinstall
|
|
32
|
+
program.command('preinstall').action(preinstall);
|
|
33
|
+
program.command('postinstall').action(postinstall);
|
|
21
34
|
import tag from '../tag';
|
|
22
35
|
|
|
23
36
|
program.command('tag').action(tag.load);
|
|
24
37
|
import info from '../info';
|
|
25
38
|
|
|
26
39
|
program.command('info').action(info.load);
|
|
27
|
-
|
|
40
|
+
|
|
41
|
+
program.command('add').action(add);
|
|
42
|
+
|
|
43
|
+
program.command('dev').action(dev);
|
|
28
44
|
|
|
29
45
|
program.command('build')
|
|
30
46
|
.option('-s, --schema <schema>', 'specify params in tree_schema')
|
|
@@ -36,20 +52,20 @@ program.command('build')
|
|
|
36
52
|
// .option('-s, --schema <schema>', 'specify params in tree_schema')
|
|
37
53
|
// .option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
|
|
38
54
|
// .action(define);
|
|
39
|
-
import deploy from '../deploy';
|
|
40
|
-
|
|
41
55
|
program.command('deploy')
|
|
42
56
|
.option('-s, --schema <schema>', 'specify params in tree_schema')
|
|
43
57
|
.option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
|
|
44
58
|
.action(deploy);
|
|
45
59
|
|
|
46
|
-
import publish from '../publish';
|
|
47
|
-
|
|
48
60
|
program.command('publish')
|
|
49
61
|
.option('-s, --schema <schema>', 'specify params in tree_schema')
|
|
50
62
|
.option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
|
|
51
63
|
.action(publish);
|
|
52
64
|
|
|
65
|
+
program.command('sync')
|
|
66
|
+
.option('-f, --force <force>', 'force to overwrite files from package.rig.json5')
|
|
67
|
+
.action(sync);
|
|
68
|
+
|
|
53
69
|
import env from '../vue-env';
|
|
54
70
|
|
|
55
71
|
program.option('--vueenv <vueenv>', 'specify vue env').action(env.load);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import RigConfig from '@/classes/RigConfig';
|
|
3
|
+
import url from 'url';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import print from '../print';
|
|
7
|
+
|
|
8
|
+
const syncFile = async (shareContent: string, force: boolean = false) => {
|
|
9
|
+
const filename = path.basename(url.parse(shareContent).pathname!);
|
|
10
|
+
const shareFilePath = path.join(process.cwd(), filename);
|
|
11
|
+
if (fs.existsSync(shareFilePath) && !force) {
|
|
12
|
+
print.info(`${filename} already exists.`);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
print.info(`Start downloading ${filename}`);
|
|
16
|
+
const fileStr = (await axios.get(shareContent)).data;
|
|
17
|
+
fs.writeFileSync(shareFilePath, fileStr);
|
|
18
|
+
};
|
|
19
|
+
export default async (cmd: any) => {
|
|
20
|
+
const rigConfig = RigConfig.createFromCWD();
|
|
21
|
+
for (let key in rigConfig.share) {
|
|
22
|
+
if (Array.isArray(rigConfig.share[key])) {
|
|
23
|
+
const shareContentArr = rigConfig.share[key] as string[];
|
|
24
|
+
for (let shareContent of shareContentArr) {
|
|
25
|
+
await syncFile(shareContent, cmd.force);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
const shareContent = rigConfig.share[key] as string;
|
|
29
|
+
await syncFile(shareContent, cmd.force);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/lib/utils/fsHelper.ts
CHANGED
|
@@ -5,6 +5,42 @@ const readCICDConfig = () => {
|
|
|
5
5
|
const cicdStr = fs.readFileSync(`${process.cwd()}/cicd.rig.json5`);
|
|
6
6
|
return JSON5.parse(cicdStr);
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* 读取rig配置文件
|
|
10
|
+
* @param {string} path absolute path to config json5.
|
|
11
|
+
* @returns {any}
|
|
12
|
+
*/
|
|
13
|
+
const readConfig = (path: string = '') => {
|
|
14
|
+
try {
|
|
15
|
+
if (path) {
|
|
16
|
+
const rigJson5Str = fs.readFileSync(path);
|
|
17
|
+
return JSON5.parse(rigJson5Str);
|
|
18
|
+
}
|
|
19
|
+
const rigJson5Str = fs.readFileSync(`${process.cwd()}/package.rig.json5`);
|
|
20
|
+
return JSON5.parse(rigJson5Str);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
throw new Error(`readConfig failed:${e.message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const writeConfig = (config: any, path: string = '') => {
|
|
27
|
+
try {
|
|
28
|
+
if (path) {
|
|
29
|
+
fs.writeFileSync(path, config.toString());
|
|
30
|
+
} else {
|
|
31
|
+
fs.writeFileSync(`${process.cwd()}/package.rig.json5`, config.toString());
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
throw new Error(`rig writeConfig failed:${e.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const readPkgStrInRepo = (rigRepoName: string) => {
|
|
38
|
+
return fs.readFileSync(`${process.cwd()}/rig_dev/${rigRepoName}/package.json`).toString();
|
|
39
|
+
}
|
|
40
|
+
|
|
8
41
|
export default {
|
|
9
|
-
readCICDConfig
|
|
42
|
+
readCICDConfig,
|
|
43
|
+
readConfig,
|
|
44
|
+
writeConfig,
|
|
45
|
+
readPkgStrInRepo
|
|
10
46
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import regexHelper from '@/utils/regexHelper';
|
|
2
|
+
test('matchGitName', () => {
|
|
3
|
+
const retGit = 'git@git.domain.com:f2e-common/r-test.git'.match(regexHelper.matchGitName);
|
|
4
|
+
const retHttp = 'https://git.domain.com/f2e-common/r-test.git'.match(regexHelper.matchGitName);
|
|
5
|
+
if (retGit) {
|
|
6
|
+
expect(retGit[2]).toContain('r-test');
|
|
7
|
+
}
|
|
8
|
+
if (retHttp) {
|
|
9
|
+
expect(retHttp[2]).toContain('r-test');
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* @author Wang Bo (ralwayne@163.com)
|
|
5
5
|
* @date 2020/10/10 3:57 PM
|
|
6
6
|
*/
|
|
7
|
+
// `^\\/([^?]*\\.[a-zA-Z0-9]+)($|\\?)`,
|
|
7
8
|
const gitURL = /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/;
|
|
9
|
+
const matchGitName = /^(git|http).*\/(.*)(\.git)$/;
|
|
8
10
|
const path = /^(\/\w+){0,2}\/?$/;
|
|
9
11
|
/**
|
|
10
12
|
* 文字下划线中划线
|
|
@@ -14,5 +16,6 @@ const dynamicDir = /(^\[[\w\-]+\]$)|(^\{[\w\-]+\}$)/
|
|
|
14
16
|
export default {
|
|
15
17
|
gitURL,
|
|
16
18
|
path,
|
|
17
|
-
dynamicDir
|
|
19
|
+
dynamicDir,
|
|
20
|
+
matchGitName
|
|
18
21
|
}
|