rigjs 2.0.0-alpha.9 → 2.0.3

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.
@@ -12,21 +12,22 @@
12
12
  access_secret: '${as}',
13
13
  root_path: '/',
14
14
  uri_rewrite: {
15
- original: 'view-fp',
15
+ original: '/',
16
16
  }
17
17
  },
18
18
  endpoints: {
19
19
  'ykp/test/oem1': {
20
- build: 'yarn build:oem1',
20
+ build: 'cross-env PUBLIC_PATH=$public_path npx vue-cli-service build --mode oem1',
21
21
  defines: {
22
22
  NGINX_REPLACE_B: 'http://',
23
23
  NGINX_REPLACE_A: '替换了',
24
+ RIG_REPLACE_PUBLIC: '$public_path',
24
25
  },
25
26
  domain: 'cdn.rys.com',
26
27
  },
27
28
  'ykp/test/oem2': {
28
29
  // build: 'yarn build:test:oem2',
29
- build: 'yarn build:oem2',
30
+ build: 'cross-env PUBLIC_PATH=$public_path npx vue-cli-service build --mode oem2',
30
31
  defines: {
31
32
  NGINX_REPLACE_B: 'http://',
32
33
  NGINX_REPLACE_A: '替换了',
package/demo/package.json CHANGED
@@ -13,7 +13,9 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "core-js": "^3.8.3",
16
- "vue": "^2.6.14"
16
+ "vue": "^2.6.14",
17
+ "rig-test-1": "git+ssh://git@github.com:FlashHand/rig-test-1.git#1.0.1",
18
+ "rig-test-2": "git+ssh://git@github.com:FlashHand/rig-test-2.git#1.0.1"
17
19
  },
18
20
  "devDependencies": {
19
21
  "@babel/core": "^7.12.16",
@@ -1,7 +1,12 @@
1
1
  [
2
- // {
3
- // name: "your project name",
4
- // source: "git ssh url",
5
- // version: "semver version(like 1.0.0)",
6
- // },
2
+ {
3
+ name: "rig-test-1",
4
+ source: "git@github.com:FlashHand/rig-test-1.git",
5
+ version: "1.0.1",
6
+ },
7
+ {
8
+ name: "rig-test-2",
9
+ source: "git@github.com:FlashHand/rig-test-2.git",
10
+ version: "1.0.1",
11
+ },
7
12
  ]
@@ -1,26 +1,28 @@
1
- import fsHelper from '../utils/fsHelper';
2
1
  import CICD, {Define} from '@/classes/cicd/CICD';
3
2
  import CICDCmd from '@/classes/cicd/CICDCmd';
4
3
  import shell from 'shelljs';
5
4
  import path from 'path';
6
5
  import fs from 'fs';
7
- const replaceDefine = (target:string,defines?:Define)=>{
6
+
7
+ const JSON5 = require('json5');
8
+
9
+ const replaceDefine = (target: string, defines?: Define) => {
8
10
  const dirs = fs.readdirSync(target);
9
- for (let dir of dirs){
11
+ for (let dir of dirs) {
10
12
  const stat = fs.statSync(path.join(target, dir));
11
- if (stat.isDirectory()){
12
- replaceDefine(path.join(target, dir),defines);
13
- }else{
14
- if (defines){
13
+ if (stat.isDirectory()) {
14
+ replaceDefine(path.join(target, dir), defines);
15
+ } else {
16
+ if (defines) {
15
17
  const namePieces = dir.split('.');
16
18
  const fileType = namePieces[namePieces.length - 1];
17
- if (['js','ts'].indexOf(fileType)>=0){
19
+ if (['js', 'ts','html'].indexOf(fileType) >= 0) {
18
20
  let file = fs.readFileSync(path.join(target, dir)).toString();
19
21
  const replaceArr = Object.keys(defines);
20
- for (let replace of replaceArr){
21
- file = file.replace(new RegExp(replace,'g'),defines[replace] as string);
22
+ for (let replace of replaceArr) {
23
+ file = file.replace(new RegExp(replace, 'g'), defines[replace] as string);
22
24
  }
23
- fs.writeFileSync(path.join(target, dir),file);
25
+ fs.writeFileSync(path.join(target, dir), file);
24
26
  }
25
27
  }
26
28
  }
@@ -34,11 +36,20 @@ export default async (cmd: any) => {
34
36
  console.log(cicd)
35
37
  //build by cicdCmd and cicdConfig
36
38
  console.log(cicdCmd.endpoints);
37
-
39
+ const regexPublicPath = new RegExp('\\$public_path', 'g');
38
40
  for (let i = 0; i < cicdCmd.endpoints.length; i++) {
39
41
  const ep = cicdCmd.endpoints[i];
40
- ep.build = ep.build.replace('$public_path', ep.publicPath);
41
- console.log('exec build:', ep.build);
42
+
43
+ ep.build = ep.build.replace(regexPublicPath, ep.publicPath);
44
+ try {
45
+ //替换define中的$public_path
46
+ Object.keys(ep.defines).forEach(key=>{
47
+ ep.defines[key] = ep.defines[key].replace(regexPublicPath, ep.publicPath);
48
+ })
49
+ } catch (e) {
50
+ console.log('JSON5 error:', ep.defines,e.message);
51
+ }
52
+ console.log('exec build:', ep, ep.build, ep.defines);
42
53
  shell.exec(ep.build);
43
54
  replaceDefine(path.join(cicd.source.root_path, ep.dir), ep.defines);
44
55
  }
@@ -28,6 +28,7 @@ export interface DeployTarget {
28
28
  root_path: '/';
29
29
  uri_rewrite: {
30
30
  original: string;
31
+ original_regexp: string;
31
32
  final?: string;
32
33
  };
33
34
  }
@@ -1,50 +1,78 @@
1
- import aliOSS from "ali-oss";
2
- import fs from "fs";
3
- import { DeployTarget } from "../CICD";
1
+ import aliOSS from 'ali-oss';
2
+ import fs from 'fs';
3
+ import {DeployTarget} from '../CICD';
4
+ import os from 'os';
5
+ import {cat} from 'shelljs';
6
+
4
7
  class AliOSS {
5
- ossClient: aliOSS;
6
- constructor(target: DeployTarget) {
7
- this.ossClient = new aliOSS({
8
- region: target.region,
9
- accessKeyId: target.access_key,
10
- accessKeySecret: target.access_secret,
11
- bucket: target.bucket,
12
- timeout: 600000,
13
- });
14
- }
15
-
16
- private async progress(p: number, filePath: string, ossPath: string) {
17
- // 上传进度。
18
- process.stdout.clearLine(1);
19
- process.stdout.cursorTo(0);
20
- process.stdout.write(
21
- `progress: ${p.toFixed(2)}%, Upload '${filePath}' To OSS_PATH:${ossPath}`
22
- );
23
- }
24
-
25
- public async putStreamFiles(
26
- filesList: string[],
27
- ossBasePath: string,
28
- dir: string
29
- ) {
30
- for (let i = 0; i < filesList.length; i++) {
31
- const filePath = filesList[i].split("dist\\")[1];
32
- const ossPath =
33
- ossBasePath + filePath.replace(/\\/g, "/").replace(dir, "");
34
- const fileResult = await this.ossClient.putStream(
35
- ossPath,
36
- fs.createReadStream(filesList[i])
8
+ ossClient: aliOSS;
9
+
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
+ }
19
+
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{
29
+ process.stdout.write(
30
+ `progress: ${p.toFixed(2)}%, Upload '${filePath}' To OSS_PATH:${ossPath}`
37
31
  );
38
- if (fileResult.res.status !== 200) {
39
- throw new Error('Upload OSS Error')
40
- }
41
- // if (fileResult.res.status === 200) {
42
- // const p = ((i + 1) * 100) / filesList.length;
43
- // this.progress(p, filesList[i], ossPath);
44
- // }
32
+ }catch (e) {
33
+
45
34
  }
46
- console.log("\n");
47
- }
35
+
36
+ }
37
+
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, '');
53
+
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
+ }
48
76
  }
49
77
 
50
78
  export default AliOSS;
@@ -7,6 +7,14 @@ import { DeployTarget } from '../CICD';
7
7
 
8
8
  type TFlag = 'break' | 'enhance_break' | null;
9
9
 
10
+ enum CDNInterfaceEnum {
11
+ BatchSetCdnDomainConfig = 'BatchSetCdnDomainConfig', //批量修改域名信息
12
+ RefreshObjectCaches = 'RefreshObjectCaches', //刷新节点上的文件内容
13
+ PushObjectCache = 'PushObjectCache', //预热CDN节点
14
+ DescribeRefreshTaskById = 'DescribeRefreshTaskById', //通过任务编号查询刷新预热任务信息
15
+ DescribeCdnDomainConfigs = 'DescribeCdnDomainConfigs', // 获取加速域名的配置信息
16
+ }
17
+
10
18
  class CDN {
11
19
  AccessKeySecret: string;
12
20
  AccessKeyId: string;
@@ -69,7 +77,7 @@ class CDN {
69
77
  * @param {改写操作执行规则 数组 值为null、break或enhance_break} flags
70
78
  * @returns
71
79
  */
72
- public async setRWriteUri(
80
+ public async setRewriteUri(
73
81
  domainName: string,
74
82
  sourceUrls: string[],
75
83
  targetUrls: string[],
@@ -100,7 +108,7 @@ class CDN {
100
108
  });
101
109
  });
102
110
 
103
- const data = await this.getCdnData('BatchSetCdnDomainConfig', {
111
+ const data = await this.getCdnData(CDNInterfaceEnum.BatchSetCdnDomainConfig, {
104
112
  DomainNames: domainName,
105
113
  Functions: JSON.stringify(Functions),
106
114
  });
@@ -126,7 +134,7 @@ class CDN {
126
134
  if (objectType) {
127
135
  param = Object.assign(param, { ObjectType: objectType });
128
136
  }
129
- const data = await this.getCdnData('RefreshObjectCaches', param);
137
+ const data = await this.getCdnData(CDNInterfaceEnum.RefreshObjectCaches, param);
130
138
  return data;
131
139
  } catch (e) {
132
140
  console.error('Error:');
@@ -141,7 +149,7 @@ class CDN {
141
149
  * @returns
142
150
  */
143
151
  async pushCache(objectPath: string) {
144
- const data = await this.getCdnData('PushObjectCache', {
152
+ const data = await this.getCdnData(CDNInterfaceEnum.PushObjectCache, {
145
153
  ObjectPath: objectPath,
146
154
  });
147
155
  return data;
@@ -154,7 +162,7 @@ class CDN {
154
162
  */
155
163
  async describeRefreshTaskById(taskIds: string) {
156
164
  try {
157
- const data = await this.getCdnData('DescribeRefreshTaskById', {
165
+ const data = await this.getCdnData(CDNInterfaceEnum.DescribeRefreshTaskById, {
158
166
  TaskId: taskIds,
159
167
  });
160
168
  return data;
@@ -166,14 +174,14 @@ class CDN {
166
174
  }
167
175
 
168
176
  /**
169
- * 刷新CDN节点
177
+ * 获取加速域名的配置信息
170
178
  * @param {加速域名} domainName
171
179
  * @param {功能配置ID} configId
172
180
  * @returns
173
181
  */
174
182
  async describeCdnDomainConfigs(domainName: string, configId?: string) {
175
183
  try {
176
- const data = await this.getCdnData('DescribeCdnDomainConfigs', {
184
+ const data = await this.getCdnData(CDNInterfaceEnum.DescribeCdnDomainConfigs, {
177
185
  DomainName: domainName,
178
186
  ConfigId: configId,
179
187
  });
@@ -1,31 +1,47 @@
1
- import {CICDConfig, Define, DefineDict, DeployTarget, DirGroup} from './CICD';
2
- import {mkdirSync} from 'fs';
1
+ import { CICDConfig, Define, DefineDict, DeployTarget, DirGroup } from './CICD';
2
+ import { mkdirSync } from 'fs';
3
3
  import DirLevel from '@/classes/cicd/DirLevel';
4
4
 
5
5
  interface EndpointInfo {
6
- build: string;
7
- target: string;
8
- domain: string;
9
- defines: Define;
6
+ build: string;
7
+ target: string;
8
+ domain: string;
9
+ defines: Define;
10
+ uri_rewrite: {
11
+ original: string;
12
+ original_regexp: string;
13
+ final?: string;
14
+ };
10
15
  }
11
16
 
12
17
  export interface EndpointDict {
13
- [dir: string]: EndpointInfo;
18
+ [dir: string]: EndpointInfo;
14
19
  }
15
20
 
16
21
  class Endpoint {
17
- dir: string;
18
- dirStrArr: string[];
19
- dirArr: DirLevel[];
20
- target: string;
21
- build: string;
22
- domain: string;
23
- deployDir: string = '';
22
+ dir: string;
23
+ dirStrArr: string[];
24
+ dirArr: DirLevel[];
25
+ target: string;
26
+ build: string;
27
+ domain: string;
28
+ deployDir: string = '';
24
29
 
25
30
  publicPath: string = '';
26
31
  defines: Define;
32
+ uri_rewrite: {
33
+ original: string,
34
+ original_regexp: string;
35
+ final?: string;
36
+ } | undefined ;
27
37
 
28
-
38
+ static createEndpointArr(cicdConfig: CICDConfig, schema: DirLevel[]) {
39
+ const endpointDict = cicdConfig.endpoints;
40
+ return Object.keys(endpointDict).map((dir) => {
41
+ const info = endpointDict[dir];
42
+ return new Endpoint(dir, info, schema);
43
+ });
44
+ }
29
45
  constructor(dir: string, info: EndpointInfo, schema: DirLevel[]) {
30
46
  this.dir = dir;
31
47
  this.deployDir = dir;
@@ -36,56 +52,47 @@ class Endpoint {
36
52
  this.build = info.build;
37
53
  this.domain = info.domain;
38
54
  this.defines = info.defines;
55
+ this.uri_rewrite = info.uri_rewrite;
39
56
  }
40
57
 
41
-
42
- static createEndpointArr(cicdConfig: CICDConfig, schema: DirLevel[]) {
43
- const endpointDict = cicdConfig.endpoints;
44
- return Object.keys(endpointDict).map(dir => {
45
- const info = endpointDict[dir];
46
- return new Endpoint(dir, info, schema);
47
- });
48
- }
49
-
50
- matchCmd(dirSchemaStrArr: string[], groups: DirGroup[]) {
51
- if (this.dirStrArr.length < dirSchemaStrArr.length) {
52
- return false;
53
- }
54
- for (let i = 0; i < dirSchemaStrArr.length; i++) {
55
- const cmdDir = dirSchemaStrArr[i];
56
- const dir = this.dirStrArr[i];
57
- const dirLevel = this.dirArr[i];
58
- //check if dir is wildcard
59
- if (cmdDir !== '%') {
60
- //not wildcard
61
- //check if dir is group alias
62
- if (cmdDir.indexOf('%') === 0) {
63
- //dir is group
64
- //find group
65
- const group = groups.find(g => g.name === cmdDir);
66
- if (group) {
67
- //group found
68
- //check if group includes this dir
69
- if (group.includes.indexOf(dir) < 0) {
70
- //not include
71
- return false;
72
- }
73
- } else {
74
- return false;
75
- }
76
-
77
- } else {
78
- //cmdDir is not group
79
- if (cmdDir !== dir) {
80
- return false;
81
- }
82
- }
83
- } else {
84
- if (!dirLevel.dynamic) return false;
85
- }
86
- }
87
- return true;
88
- }
58
+ matchCmd(dirSchemaStrArr: string[], groups: DirGroup[]) {
59
+ if (this.dirStrArr.length < dirSchemaStrArr.length) {
60
+ return false;
61
+ }
62
+ for (let i = 0; i < dirSchemaStrArr.length; i++) {
63
+ const cmdDir = dirSchemaStrArr[i];
64
+ const dir = this.dirStrArr[i];
65
+ const dirLevel = this.dirArr[i];
66
+ //check if dir is wildcard
67
+ if (cmdDir !== '%') {
68
+ //not wildcard
69
+ //check if dir is group alias
70
+ if (cmdDir.indexOf('%') === 0) {
71
+ //dir is group
72
+ //find group
73
+ const group = groups.find((g) => g.name === cmdDir);
74
+ if (group) {
75
+ //group found
76
+ //check if group includes this dir
77
+ if (group.includes.indexOf(dir) < 0) {
78
+ //not include
79
+ return false;
80
+ }
81
+ } else {
82
+ return false;
83
+ }
84
+ } else {
85
+ //cmdDir is not group
86
+ if (cmdDir !== dir) {
87
+ return false;
88
+ }
89
+ }
90
+ } else {
91
+ if (!dirLevel.dynamic) return false;
92
+ }
93
+ }
94
+ return true;
95
+ }
89
96
  }
90
97
 
91
98
  export default Endpoint;
@@ -27,6 +27,7 @@ export default async (cmd: any) => {
27
27
  const cicd = CICD.createByDefault(cmd);
28
28
  //construct cmd object
29
29
  const cicdCmd = new CICDCmd(cmd, cicd);
30
+ console.log('cicdCmd:', cicdCmd.endpoints);
30
31
 
31
32
  const target = Array.isArray(cicdCmd.cicd.target)
32
33
  ? cicdCmd.cicd.target[0]
@@ -44,7 +45,8 @@ export default async (cmd: any) => {
44
45
  await aliOss.putStreamFiles(
45
46
  filesList,
46
47
  cicdCmd.endpoints[i].deployDir.replace(/\\/g, '/'),
47
- cicdCmd.endpoints[i].dir
48
+ cicdCmd.endpoints[i].dir,
49
+ cicd.source.root_path,
48
50
  );
49
51
  filesList = [];
50
52
  }