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.
@@ -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
- ossClient: aliOSS;
7
+ ossClient: aliOSS;
9
8
 
10
- constructor(target: DeployTarget) {
11
- this.ossClient = new aliOSS({
12
- region: target.region,
13
- accessKeyId: target.access_key,
14
- accessKeySecret: target.access_secret,
15
- bucket: target.bucket,
16
- timeout: 600000,
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
- private async progress(p: number, filePath: string, ossPath: string) {
21
- // 上传进度。
22
- try {
23
- process.stdout.clearLine(1);
24
- process.stdout.cursorTo(0);
25
- } catch (e) {
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(2)}%, Upload '${filePath}' To OSS_PATH:${ossPath}`
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
- public async putStreamFiles(
39
- filesList: string[],
40
- ossBasePath: string,
41
- dir: string,
42
- rootPath: string
43
- ) {
44
- for (let i = 0; i < filesList.length; i++) {
45
- let filePath = '';
46
- if (os.platform() === 'win32') {
47
- filePath = filesList[i].split(`${rootPath}\\`)[1];
48
- } else {
49
- filePath = filesList[i].split(`${rootPath}/`)[1];
50
- }
51
- const ossPath =
52
- ossBasePath + filePath.replace(/\\/g, '/').replace(dir, '');
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
- //@ts-ignore
55
- let options: aliOSS.PutStreamOptions = {
56
- contentLength: fs.statSync(filesList[i]).size,
57
- };
58
- if (filesList[i].includes('index.html')) {
59
- options = Object.assign({headers: {'Cache-Control': 'max-age=0'}});
60
- }
61
- const fileResult = await this.ossClient.putStream(
62
- ossPath,
63
- fs.createReadStream(filesList[i]),
64
- options
65
- );
66
- if (fileResult.res.status !== 200) {
67
- throw new Error('Upload OSS Error');
68
- }
69
- if (fileResult.res.status === 200) {
70
- const p = ((i + 1) * 100) / filesList.length;
71
- this.progress(p, filesList[i], ossPath);
72
- }
73
- }
74
- console.log('\n');
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;
@@ -101,7 +101,7 @@ class CDN {
101
101
  },
102
102
  {
103
103
  argName: 'flag',
104
- argValue: flags[index],
104
+ argValue: flags[index] || null,
105
105
  },
106
106
  ],
107
107
  functionName: 'back_to_origin_url_rewrite',
@@ -6,7 +6,8 @@ interface EndpointInfo {
6
6
  build: string;
7
7
  target: string;
8
8
  domain: string;
9
- defines: Define;
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
  }
@@ -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 ? endpoint.uri_rewrite : target.uri_rewrite;
68
- setRewriteUriPromises.push(
69
- setRewriteUri(
70
- endpoint.domain,
71
- `${uriRewrite.original_regexp ? uriRewrite.original_regexp : uriRewrite.original}`,
72
- `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
73
- cdn
74
- )
75
- );
76
- urls.push(`https://${endpoint.domain}${uriRewrite.original}`);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.0.2",
3
+ "version": "2.0.5",
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",