rigjs 2.0.2 → 2.0.5
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 +71 -71
- package/lib/classes/cicd/Deploy/AliDeploy.ts +62 -64
- package/lib/classes/cicd/Deploy/CDN.ts +1 -1
- package/lib/classes/cicd/Endpoint.ts +4 -1
- package/lib/publish/index.ts +19 -10
- package/package.json +1 -1
|
@@ -1,78 +1,76 @@
|
|
|
1
1
|
import aliOSS from 'ali-oss';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import {DeployTarget} from '../CICD';
|
|
3
|
+
import { DeployTarget } from '../CICD';
|
|
4
4
|
import os from 'os';
|
|
5
|
-
import {cat} from 'shelljs';
|
|
6
5
|
|
|
7
6
|
class AliOSS {
|
|
8
|
-
|
|
7
|
+
ossClient: aliOSS;
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
constructor(target: DeployTarget) {
|
|
10
|
+
this.ossClient = new aliOSS({
|
|
11
|
+
region: target.region,
|
|
12
|
+
accessKeyId: target.access_key,
|
|
13
|
+
accessKeySecret: target.access_secret,
|
|
14
|
+
bucket: target.bucket,
|
|
15
|
+
timeout: 600000,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
try{
|
|
19
|
+
private async progress(p: number, filePath: string, ossPath: string) {
|
|
20
|
+
// 上传进度。
|
|
21
|
+
try {
|
|
22
|
+
process.stdout.clearLine(1);
|
|
23
|
+
process.stdout.cursorTo(0);
|
|
24
|
+
} catch (e) {}
|
|
25
|
+
try {
|
|
29
26
|
process.stdout.write(
|
|
30
|
-
`progress: ${p.toFixed(
|
|
27
|
+
`progress: ${p.toFixed(
|
|
28
|
+
2
|
|
29
|
+
)}%, Upload '${filePath}' To OSS_PATH:${ossPath}`
|
|
31
30
|
);
|
|
32
|
-
}catch (e) {
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|
|
31
|
+
} catch (e) {}
|
|
32
|
+
}
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
34
|
+
public async putStreamFiles(
|
|
35
|
+
filesList: string[],
|
|
36
|
+
ossBasePath: string,
|
|
37
|
+
dir: string,
|
|
38
|
+
rootPath: string
|
|
39
|
+
) {
|
|
40
|
+
for (let i = 0; i < filesList.length; i++) {
|
|
41
|
+
let filePath = '';
|
|
42
|
+
if (os.platform() === 'win32') {
|
|
43
|
+
filePath = filesList[i].split(`${rootPath}\\`)[1];
|
|
44
|
+
} else {
|
|
45
|
+
filePath = filesList[i].split(`${rootPath}/`)[1];
|
|
46
|
+
}
|
|
47
|
+
const ossPath =
|
|
48
|
+
ossBasePath + filePath.replace(/\\/g, '/').replace(dir, '');
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
50
|
+
//@ts-ignore
|
|
51
|
+
let options: aliOSS.PutStreamOptions = {
|
|
52
|
+
contentLength: fs.statSync(filesList[i]).size,
|
|
53
|
+
};
|
|
54
|
+
if (filesList[i].includes('index.html')) {
|
|
55
|
+
options = Object.assign({
|
|
56
|
+
headers: { 'Cache-Control': 'max-age=0', Expires: -1 },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const fileResult = await this.ossClient.putStream(
|
|
60
|
+
ossPath,
|
|
61
|
+
fs.createReadStream(filesList[i]),
|
|
62
|
+
options
|
|
63
|
+
);
|
|
64
|
+
if (fileResult.res.status !== 200) {
|
|
65
|
+
throw new Error('Upload OSS Error');
|
|
66
|
+
}
|
|
67
|
+
if (fileResult.res.status === 200) {
|
|
68
|
+
const p = ((i + 1) * 100) / filesList.length;
|
|
69
|
+
this.progress(p, filesList[i], ossPath);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
console.log('\n');
|
|
73
|
+
}
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
export default AliOSS;
|
|
@@ -6,7 +6,8 @@ interface EndpointInfo {
|
|
|
6
6
|
build: string;
|
|
7
7
|
target: string;
|
|
8
8
|
domain: string;
|
|
9
|
-
|
|
9
|
+
domains: string[];
|
|
10
|
+
defines: Define;
|
|
10
11
|
uri_rewrite: {
|
|
11
12
|
original: string;
|
|
12
13
|
original_regexp: string;
|
|
@@ -25,6 +26,7 @@ class Endpoint {
|
|
|
25
26
|
target: string;
|
|
26
27
|
build: string;
|
|
27
28
|
domain: string;
|
|
29
|
+
domains: string[];
|
|
28
30
|
deployDir: string = '';
|
|
29
31
|
|
|
30
32
|
publicPath: string = '';
|
|
@@ -51,6 +53,7 @@ class Endpoint {
|
|
|
51
53
|
this.target = info.target;
|
|
52
54
|
this.build = info.build;
|
|
53
55
|
this.domain = info.domain;
|
|
56
|
+
this.domains = info.domains
|
|
54
57
|
this.defines = info.defines;
|
|
55
58
|
this.uri_rewrite = info.uri_rewrite;
|
|
56
59
|
}
|
package/lib/publish/index.ts
CHANGED
|
@@ -64,16 +64,25 @@ export default async (cmd: any) => {
|
|
|
64
64
|
const urls: string[] = [];
|
|
65
65
|
const setRewriteUriPromises: Promise<any>[] = [];
|
|
66
66
|
for (const endpoint of cicdCmd.endpoints) {
|
|
67
|
-
const uriRewrite = endpoint.uri_rewrite
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
const uriRewrite = endpoint.uri_rewrite
|
|
68
|
+
? endpoint.uri_rewrite
|
|
69
|
+
: target.uri_rewrite;
|
|
70
|
+
|
|
71
|
+
for (const domain of endpoint.domains) {
|
|
72
|
+
setRewriteUriPromises.push(
|
|
73
|
+
setRewriteUri(
|
|
74
|
+
domain,
|
|
75
|
+
`${
|
|
76
|
+
uriRewrite.original_regexp
|
|
77
|
+
? uriRewrite.original_regexp
|
|
78
|
+
: uriRewrite.original
|
|
79
|
+
}`,
|
|
80
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
|
|
81
|
+
cdn
|
|
82
|
+
)
|
|
83
|
+
);
|
|
84
|
+
urls.push(`https://${domain}${uriRewrite.original}`);
|
|
85
|
+
}
|
|
77
86
|
}
|
|
78
87
|
|
|
79
88
|
// 回源URI改写
|
package/package.json
CHANGED