rigjs 2.0.0-alpha.2 → 2.0.0-alpha.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 +115 -114
- package/demo/cicd.rig.json5 +2 -2
- package/demo/src/App.vue +6 -0
- package/lib/build/index.ts +28 -5
- package/lib/classes/cicd/CICD.ts +1 -1
- package/lib/classes/cicd/Deploy/AliDeploy.ts +13 -9
- package/lib/classes/cicd/Deploy/CDN.ts +117 -54
- package/lib/classes/cicd/Endpoint.ts +6 -4
- package/lib/deploy/index.ts +12 -16
- package/lib/publish/index.ts +84 -0
- package/lib/rig/index.ts +8 -0
- package/package.json +1 -1
- package/lib/publish/index.js +0 -14
package/demo/cicd.rig.json5
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
NGINX_REPLACE_B: 'http://',
|
|
23
23
|
NGINX_REPLACE_A: '替换了',
|
|
24
24
|
},
|
|
25
|
-
domain: '
|
|
25
|
+
domain: 'cdn.rys.com',
|
|
26
26
|
},
|
|
27
27
|
'ykp/test/oem2': {
|
|
28
28
|
// build: 'yarn build:test:oem2',
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
NGINX_REPLACE_B: 'http://',
|
|
32
32
|
NGINX_REPLACE_A: '替换了',
|
|
33
33
|
},
|
|
34
|
-
domain: '
|
|
34
|
+
domain: 'cdn.rys.com'
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
groups: [
|
package/demo/src/App.vue
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
<div id="app">
|
|
3
3
|
<img alt="Vue logo" src="./assets/logo.png">
|
|
4
4
|
<HelloWorld msg="Welcome to Your Vue.js App"/>
|
|
5
|
+
<span>test_replace:{{ test_replace}}</span>
|
|
5
6
|
</div>
|
|
6
7
|
</template>
|
|
7
8
|
|
|
@@ -10,6 +11,11 @@ import HelloWorld from './components/HelloWorld.vue'
|
|
|
10
11
|
|
|
11
12
|
export default {
|
|
12
13
|
name: 'App',
|
|
14
|
+
data() {
|
|
15
|
+
return {
|
|
16
|
+
test_replace: 'NGINX_REPLACE_A'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
13
19
|
components: {
|
|
14
20
|
HelloWorld
|
|
15
21
|
}
|
package/lib/build/index.ts
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import fsHelper from '../utils/fsHelper';
|
|
2
|
-
import CICD from '@/classes/cicd/CICD';
|
|
2
|
+
import CICD, {Define} from '@/classes/cicd/CICD';
|
|
3
3
|
import CICDCmd from '@/classes/cicd/CICDCmd';
|
|
4
4
|
import shell from 'shelljs';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
const replaceDefine = (target:string,defines?:Define)=>{
|
|
8
|
+
const dirs = fs.readdirSync(target);
|
|
9
|
+
for (let dir of dirs){
|
|
10
|
+
const stat = fs.statSync(path.join(target, dir));
|
|
11
|
+
if (stat.isDirectory()){
|
|
12
|
+
replaceDefine(path.join(target, dir),defines);
|
|
13
|
+
}else{
|
|
14
|
+
if (defines){
|
|
15
|
+
const namePieces = dir.split('.');
|
|
16
|
+
const fileType = namePieces[namePieces.length - 1];
|
|
17
|
+
if (['js','ts'].indexOf(fileType)>=0){
|
|
18
|
+
let file = fs.readFileSync(path.join(target, dir)).toString();
|
|
19
|
+
const replaceArr = Object.keys(defines);
|
|
20
|
+
for (let replace of replaceArr){
|
|
21
|
+
file = file.replace(new RegExp(replace,'g'),defines[replace] as string);
|
|
22
|
+
}
|
|
23
|
+
fs.writeFileSync(path.join(target, dir),file);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
7
29
|
export default async (cmd: any) => {
|
|
8
30
|
//create cicd object
|
|
9
31
|
const cicd = CICD.createByDefault(cmd);
|
|
@@ -12,10 +34,11 @@ export default async (cmd: any) => {
|
|
|
12
34
|
console.log(cicd)
|
|
13
35
|
//build by cicdCmd and cicdConfig
|
|
14
36
|
console.log(cicdCmd.endpoints);
|
|
37
|
+
|
|
15
38
|
for (let i = 0; i < cicdCmd.endpoints.length; i++) {
|
|
16
39
|
const ep = cicdCmd.endpoints[i];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
40
|
+
ep.build = ep.build.replace('${public_path}', ep.publicPath);
|
|
41
|
+
shell.exec(ep.build);
|
|
42
|
+
replaceDefine(path.join(cicd.source.root_path, ep.dir), ep.defines);
|
|
20
43
|
}
|
|
21
44
|
}
|
package/lib/classes/cicd/CICD.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import aliOSS from "ali-oss";
|
|
2
2
|
import fs from "fs";
|
|
3
|
+
import { DeployTarget } from "../CICD";
|
|
3
4
|
class AliOSS {
|
|
4
5
|
ossClient: aliOSS;
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(target: DeployTarget) {
|
|
6
7
|
this.ossClient = new aliOSS({
|
|
7
|
-
region,
|
|
8
|
-
accessKeyId:
|
|
9
|
-
accessKeySecret:
|
|
10
|
-
bucket,
|
|
8
|
+
region: target.region,
|
|
9
|
+
accessKeyId: target.access_key,
|
|
10
|
+
accessKeySecret: target.access_secret,
|
|
11
|
+
bucket: target.bucket,
|
|
11
12
|
timeout: 600000,
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
private async progress(p: number, filePath: string, ossPath: string) {
|
|
16
17
|
// 上传进度。
|
|
17
|
-
process.stdout.clearLine(
|
|
18
|
+
process.stdout.clearLine(1);
|
|
18
19
|
process.stdout.cursorTo(0);
|
|
19
20
|
process.stdout.write(
|
|
20
21
|
`progress: ${p.toFixed(2)}%, Upload '${filePath}' To OSS_PATH:${ossPath}`
|
|
@@ -34,10 +35,13 @@ class AliOSS {
|
|
|
34
35
|
ossPath,
|
|
35
36
|
fs.createReadStream(filesList[i])
|
|
36
37
|
);
|
|
37
|
-
if (fileResult.res.status
|
|
38
|
-
|
|
39
|
-
this.progress(p, filesList[i], ossPath);
|
|
38
|
+
if (fileResult.res.status !== 200) {
|
|
39
|
+
throw new Error('Upload OSS Error')
|
|
40
40
|
}
|
|
41
|
+
// if (fileResult.res.status === 200) {
|
|
42
|
+
// const p = ((i + 1) * 100) / filesList.length;
|
|
43
|
+
// this.progress(p, filesList[i], ossPath);
|
|
44
|
+
// }
|
|
41
45
|
}
|
|
42
46
|
console.log("\n");
|
|
43
47
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import moment from
|
|
2
|
-
import qs from
|
|
3
|
-
import crypto from
|
|
4
|
-
import axios from
|
|
5
|
-
import * as uuid from
|
|
1
|
+
import moment from 'dayjs';
|
|
2
|
+
import qs from 'qs';
|
|
3
|
+
import crypto from 'crypto';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
import * as uuid from 'uuid';
|
|
6
|
+
import { DeployTarget } from '../CICD';
|
|
6
7
|
|
|
7
|
-
type TFlag =
|
|
8
|
+
type TFlag = 'break' | 'enhance_break' | null;
|
|
8
9
|
|
|
9
10
|
class CDN {
|
|
10
11
|
AccessKeySecret: string;
|
|
11
12
|
AccessKeyId: string;
|
|
12
|
-
constructor(
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
13
|
+
constructor(target: DeployTarget) {
|
|
14
|
+
this.AccessKeyId = target.access_key;
|
|
15
|
+
this.AccessKeySecret = target.access_secret;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* 访问CDN通用接口
|
|
@@ -22,31 +23,39 @@ class CDN {
|
|
|
22
23
|
private async getCdnData(actionName: string, paramObj: Object) {
|
|
23
24
|
let config = {
|
|
24
25
|
Action: actionName,
|
|
25
|
-
Format:
|
|
26
|
-
Version:
|
|
26
|
+
Format: 'JSON',
|
|
27
|
+
Version: '2018-05-10',
|
|
27
28
|
AccessKeyId: this.AccessKeyId,
|
|
28
|
-
SignatureMethod:
|
|
29
|
+
SignatureMethod: 'HMAC-SHA1',
|
|
29
30
|
Timestamp: moment().toDate().toISOString(),
|
|
30
|
-
SignatureVersion:
|
|
31
|
+
SignatureVersion: '1.0',
|
|
31
32
|
SignatureNonce: uuid.v1(),
|
|
32
33
|
};
|
|
33
34
|
config = Object.assign(config, paramObj);
|
|
34
35
|
let paramConfig = qs.stringify(config, {
|
|
35
|
-
sort: (a:
|
|
36
|
+
sort: (a: any, b: any) => {
|
|
36
37
|
return a < b ? -1 : 1;
|
|
37
38
|
},
|
|
38
|
-
charset:
|
|
39
|
+
charset: 'utf-8',
|
|
39
40
|
});
|
|
40
41
|
|
|
41
42
|
const strSign = `GET&%2F&${encodeURIComponent(paramConfig)}`;
|
|
42
|
-
console.log(`strSign: ${strSign}`);
|
|
43
|
-
const hmacSha1 = crypto.createHmac(
|
|
43
|
+
// console.log(`strSign: ${strSign}\n`);
|
|
44
|
+
const hmacSha1 = crypto.createHmac('sha1', `${this.AccessKeySecret}&`);
|
|
44
45
|
hmacSha1.update(strSign);
|
|
45
|
-
const signature = hmacSha1.digest(
|
|
46
|
-
|
|
46
|
+
const signature = hmacSha1.digest('base64');
|
|
47
|
+
config = Object.assign(config, {
|
|
48
|
+
Signature: signature,
|
|
49
|
+
});
|
|
50
|
+
paramConfig = qs.stringify(config, {
|
|
51
|
+
sort: (a, b) => {
|
|
52
|
+
return a < b ? -1 : 1;
|
|
53
|
+
},
|
|
54
|
+
charset: 'utf-8',
|
|
55
|
+
format: 'RFC3986',
|
|
56
|
+
});
|
|
47
57
|
|
|
48
58
|
const url = `http://cdn.aliyuncs.com?${paramConfig}`;
|
|
49
|
-
console.log(url);
|
|
50
59
|
|
|
51
60
|
const res = await axios.create().get(url);
|
|
52
61
|
return res.data;
|
|
@@ -66,35 +75,42 @@ class CDN {
|
|
|
66
75
|
targetUrls: string[],
|
|
67
76
|
flags: TFlag[]
|
|
68
77
|
) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
try {
|
|
79
|
+
if (sourceUrls.length !== targetUrls.length) {
|
|
80
|
+
throw new Error(`sourceUrls's length not equal targetUrls's length`);
|
|
81
|
+
}
|
|
82
|
+
const Functions: Object[] = [];
|
|
83
|
+
sourceUrls.forEach((item, index) => {
|
|
84
|
+
Functions.push({
|
|
85
|
+
functionArgs: [
|
|
86
|
+
{
|
|
87
|
+
argName: 'source_url',
|
|
88
|
+
argValue: item,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
argName: 'target_url',
|
|
92
|
+
argValue: targetUrls[index],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
argName: 'flag',
|
|
96
|
+
argValue: flags[index],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
functionName: 'back_to_origin_url_rewrite',
|
|
100
|
+
});
|
|
90
101
|
});
|
|
91
|
-
});
|
|
92
102
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
103
|
+
const data = await this.getCdnData('BatchSetCdnDomainConfig', {
|
|
104
|
+
DomainNames: domainName,
|
|
105
|
+
Functions: JSON.stringify(Functions),
|
|
106
|
+
});
|
|
107
|
+
return data;
|
|
108
|
+
} catch (e) {
|
|
109
|
+
console.error(
|
|
110
|
+
`Error: ${e.response ? JSON.stringify(e.response.data.Message) : e}`
|
|
111
|
+
);
|
|
112
|
+
throw new Error(e.response.data.Message);
|
|
113
|
+
}
|
|
98
114
|
}
|
|
99
115
|
|
|
100
116
|
/**
|
|
@@ -102,12 +118,21 @@ class CDN {
|
|
|
102
118
|
* @param {刷新URL, 格式为加速域名或刷新的文件或目录。多个URL之间使用换行符(\n)或(\r\n)分隔} objectPath
|
|
103
119
|
* @param {刷新的类型 File: 文件; Directory: 目录} objectType
|
|
104
120
|
*/
|
|
105
|
-
public async refreshCache(objectPath: string, objectType
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
121
|
+
public async refreshCache(objectPath: string, objectType?: string) {
|
|
122
|
+
try {
|
|
123
|
+
let param = {
|
|
124
|
+
ObjectPath: objectPath,
|
|
125
|
+
};
|
|
126
|
+
if (objectType) {
|
|
127
|
+
param = Object.assign(param, { ObjectType: objectType });
|
|
128
|
+
}
|
|
129
|
+
const data = await this.getCdnData('RefreshObjectCaches', param);
|
|
130
|
+
return data;
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.error('Error:');
|
|
133
|
+
console.error(e.response.data.Message);
|
|
134
|
+
throw new Error(e.response.data.Message);
|
|
135
|
+
}
|
|
111
136
|
}
|
|
112
137
|
|
|
113
138
|
/**
|
|
@@ -116,11 +141,49 @@ class CDN {
|
|
|
116
141
|
* @returns
|
|
117
142
|
*/
|
|
118
143
|
async pushCache(objectPath: string) {
|
|
119
|
-
const data = await this.getCdnData(
|
|
144
|
+
const data = await this.getCdnData('PushObjectCache', {
|
|
120
145
|
ObjectPath: objectPath,
|
|
121
146
|
});
|
|
122
147
|
return data;
|
|
123
148
|
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 通过任务编号查询刷新预热任务信息
|
|
152
|
+
* @param {支持同时传入多个任务ID,多个任务ID之间用英文逗号(,)分隔,最多支持同时传入10个任务ID} taskIds
|
|
153
|
+
* @returns
|
|
154
|
+
*/
|
|
155
|
+
async describeRefreshTaskById(taskIds: string) {
|
|
156
|
+
try {
|
|
157
|
+
const data = await this.getCdnData('DescribeRefreshTaskById', {
|
|
158
|
+
TaskId: taskIds,
|
|
159
|
+
});
|
|
160
|
+
return data;
|
|
161
|
+
} catch (e) {
|
|
162
|
+
console.error('Error:');
|
|
163
|
+
console.error(e.response.data.Message);
|
|
164
|
+
throw new Error(e.response.data.Message);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* 刷新CDN节点
|
|
170
|
+
* @param {加速域名} domainName
|
|
171
|
+
* @param {功能配置ID} configId
|
|
172
|
+
* @returns
|
|
173
|
+
*/
|
|
174
|
+
async describeCdnDomainConfigs(domainName: string, configId?: string) {
|
|
175
|
+
try {
|
|
176
|
+
const data = await this.getCdnData('DescribeCdnDomainConfigs', {
|
|
177
|
+
DomainName: domainName,
|
|
178
|
+
ConfigId: configId,
|
|
179
|
+
});
|
|
180
|
+
return data;
|
|
181
|
+
} catch (e) {
|
|
182
|
+
console.error('Error:');
|
|
183
|
+
console.error(e.response.data.Message);
|
|
184
|
+
throw new Error(e.response.data.Message);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
124
187
|
}
|
|
125
188
|
|
|
126
189
|
export default CDN;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {CICDConfig, DefineDict, DirGroup} from './CICD';
|
|
1
|
+
import {CICDConfig, Define, DefineDict, DeployTarget, DirGroup} from './CICD';
|
|
2
2
|
import {mkdirSync} from 'fs';
|
|
3
3
|
import DirLevel from '@/classes/cicd/DirLevel';
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ interface EndpointInfo {
|
|
|
6
6
|
build: string;
|
|
7
7
|
target: string;
|
|
8
8
|
domain: string;
|
|
9
|
-
|
|
9
|
+
defines: Define;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface EndpointDict {
|
|
@@ -21,18 +21,20 @@ class Endpoint {
|
|
|
21
21
|
build: string;
|
|
22
22
|
domain: string;
|
|
23
23
|
deployDir: string;
|
|
24
|
-
|
|
24
|
+
publicPath: string;
|
|
25
|
+
defines: Define;
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
constructor(dir: string, info: EndpointInfo, schema: DirLevel[]) {
|
|
28
29
|
this.dir = dir;
|
|
29
30
|
this.deployDir = dir;
|
|
31
|
+
this.publicPath = dir;
|
|
30
32
|
this.dirStrArr = dir.split('/').filter(d => d.length > 0);
|
|
31
33
|
this.dirArr = DirLevel.createDirArr(dir, schema);
|
|
32
34
|
this.target = info.target;
|
|
33
35
|
this.build = info.build;
|
|
34
36
|
this.domain = info.domain;
|
|
35
|
-
this.
|
|
37
|
+
this.defines = info.defines;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
static createEndpointArr(cicdConfig: CICDConfig, schema: DirLevel[]) {
|
package/lib/deploy/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import CICD from
|
|
4
|
-
import CICDCmd from
|
|
5
|
-
import AliOSS from
|
|
6
|
-
import CDN from
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import CICD from '@/classes/cicd/CICD';
|
|
4
|
+
import CICDCmd from '@/classes/cicd/CICDCmd';
|
|
5
|
+
import AliOSS from '@/classes/cicd/Deploy/AliDeploy';
|
|
6
|
+
import CDN from '@/classes/cicd/Deploy/CDN';
|
|
7
7
|
|
|
8
8
|
let filesList: string[] = [];
|
|
9
9
|
const traverseFolder = (url: string) => {
|
|
@@ -22,6 +22,7 @@ const traverseFolder = (url: string) => {
|
|
|
22
22
|
|
|
23
23
|
export default async (cmd: any) => {
|
|
24
24
|
try {
|
|
25
|
+
console.log('Start Deploy-----');
|
|
25
26
|
//create cicd object
|
|
26
27
|
const cicd = CICD.createByDefault(cmd);
|
|
27
28
|
//construct cmd object
|
|
@@ -31,8 +32,8 @@ export default async (cmd: any) => {
|
|
|
31
32
|
? cicdCmd.cicd.target[0]
|
|
32
33
|
: cicdCmd.cicd.target;
|
|
33
34
|
|
|
34
|
-
const aliOss = new AliOSS(target
|
|
35
|
-
|
|
35
|
+
const aliOss = new AliOSS(target);
|
|
36
|
+
console.log('Please Wait for Upload OSS...');
|
|
36
37
|
for (let i = 0; i < cicdCmd.endpoints.length; i++) {
|
|
37
38
|
const distPath = path.join(
|
|
38
39
|
process.cwd(),
|
|
@@ -42,18 +43,13 @@ export default async (cmd: any) => {
|
|
|
42
43
|
traverseFolder(distPath);
|
|
43
44
|
await aliOss.putStreamFiles(
|
|
44
45
|
filesList,
|
|
45
|
-
cicdCmd.endpoints[i].deployDir.replace(/\\/g,
|
|
46
|
+
cicdCmd.endpoints[i].deployDir.replace(/\\/g, '/'),
|
|
46
47
|
cicdCmd.endpoints[i].dir
|
|
47
48
|
);
|
|
48
|
-
|
|
49
|
-
// await cdn.setRWriteUri(
|
|
50
|
-
// cicdCmd.endpoints[i].domain,
|
|
51
|
-
// [""],
|
|
52
|
-
// [""],
|
|
53
|
-
// ["break"]
|
|
54
|
-
// );
|
|
55
49
|
filesList = [];
|
|
56
50
|
}
|
|
51
|
+
console.log('Upload OSS Done');
|
|
52
|
+
console.log('Deploy Done-----');
|
|
57
53
|
} catch (e) {
|
|
58
54
|
throw e;
|
|
59
55
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import fsHelper from '../utils/fsHelper';
|
|
2
|
+
import CICD from '@/classes/cicd/CICD';
|
|
3
|
+
import CICDCmd from '@/classes/cicd/CICDCmd';
|
|
4
|
+
import shell from 'shelljs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import CDN from '@/classes/cicd/Deploy/CDN';
|
|
7
|
+
|
|
8
|
+
const setRWriteUri = async (
|
|
9
|
+
domain: string,
|
|
10
|
+
original: string,
|
|
11
|
+
deployDir: string,
|
|
12
|
+
cdn: CDN
|
|
13
|
+
) => {
|
|
14
|
+
const rwriteResult = await cdn.setRWriteUri(
|
|
15
|
+
domain,
|
|
16
|
+
[original],
|
|
17
|
+
[deployDir],
|
|
18
|
+
['enhance_break']
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const configId = rwriteResult?.DomainConfigList.DomainConfigModel[0].ConfigId;
|
|
22
|
+
console.log('Please Wait For Set RWrite URI...');
|
|
23
|
+
while (true) {
|
|
24
|
+
const configInfo = await cdn.describeCdnDomainConfigs(domain, configId);
|
|
25
|
+
if (configInfo.DomainConfigs.DomainConfig[0].Status === 'success') {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
if (configInfo.DomainConfigs.DomainConfig[0].Status === 'failed') {
|
|
29
|
+
throw new Error('cdn rewrite fail');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
console.log('Set RWrite URI Done');
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const refreshCache = async (urls: string[], cdn: CDN) => {
|
|
36
|
+
const refreshResult = await cdn.refreshCache(urls.join('\n'));
|
|
37
|
+
console.log('Please Wait For RefreshCache...');
|
|
38
|
+
while (true) {
|
|
39
|
+
const desResult = await cdn.describeRefreshTaskById(
|
|
40
|
+
refreshResult.RefreshTaskId
|
|
41
|
+
);
|
|
42
|
+
let successCount = 0;
|
|
43
|
+
for (const item of desResult.Tasks) {
|
|
44
|
+
if (item.Status === 'Complete') {
|
|
45
|
+
successCount++;
|
|
46
|
+
} else if (item.Status === 'Failed') {
|
|
47
|
+
throw new Error('RefreshCache Failed');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (successCount === desResult.Tasks.length) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
console.log('RefreshCache Done');
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default async (cmd: any) => {
|
|
58
|
+
//create cicd object
|
|
59
|
+
const cicd = CICD.createByDefault(cmd);
|
|
60
|
+
//construct cmd object
|
|
61
|
+
const cicdCmd = new CICDCmd(cmd, cicd);
|
|
62
|
+
|
|
63
|
+
console.log('Start Publish-----');
|
|
64
|
+
const target = Array.isArray(cicdCmd.cicd.target)
|
|
65
|
+
? cicdCmd.cicd.target[0]
|
|
66
|
+
: cicdCmd.cicd.target;
|
|
67
|
+
|
|
68
|
+
const cdn = new CDN(target);
|
|
69
|
+
const urls: string[] = [];
|
|
70
|
+
for (const endpoint of cicdCmd.endpoints) {
|
|
71
|
+
// 目前只支持set一个original
|
|
72
|
+
await setRWriteUri(
|
|
73
|
+
endpoint.domain,
|
|
74
|
+
`/${target.uri_rewrite.original}`,
|
|
75
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
|
|
76
|
+
cdn
|
|
77
|
+
);
|
|
78
|
+
urls.push(`https://${endpoint.domain}/${target.uri_rewrite.original}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//刷新cdn
|
|
82
|
+
await refreshCache(urls, cdn);
|
|
83
|
+
console.log('Start Publish-----');
|
|
84
|
+
};
|
package/lib/rig/index.ts
CHANGED
|
@@ -42,6 +42,14 @@ program.command('deploy')
|
|
|
42
42
|
.option('-s, --schema <schema>', 'specify params in tree_schema')
|
|
43
43
|
.option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
|
|
44
44
|
.action(deploy);
|
|
45
|
+
|
|
46
|
+
import publish from '../publish';
|
|
47
|
+
|
|
48
|
+
program.command('publish')
|
|
49
|
+
.option('-s, --schema <schema>', 'specify params in tree_schema')
|
|
50
|
+
.option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
|
|
51
|
+
.action(publish);
|
|
52
|
+
|
|
45
53
|
import env from '../env';
|
|
46
54
|
|
|
47
55
|
program.option('-e, --env <env>', 'specify env').action(env.load);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rigjs",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.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",
|