rigjs 2.1.8 → 2.1.11
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 +98 -98
- package/lib/build/index.ts +8 -5
- package/lib/classes/cicd/CICD.ts +19 -8
- package/lib/classes/cicd/Deploy/AliDeploy.ts +2 -8
- package/lib/classes/cicd/Endpoint.ts +4 -1
- package/lib/deploy/index.ts +2 -7
- package/lib/publish/index.ts +80 -22
- package/package.json +1 -1
package/lib/build/index.ts
CHANGED
|
@@ -6,8 +6,6 @@ import fs from 'fs';
|
|
|
6
6
|
import vueEnv from '../vue-env';
|
|
7
7
|
const print = require('../print');
|
|
8
8
|
|
|
9
|
-
const JSON5 = require('json5');
|
|
10
|
-
|
|
11
9
|
const replaceDefine = (target: string, defines?: Define) => {
|
|
12
10
|
console.log(`start replaceDefine:${target}`);
|
|
13
11
|
const dirs = fs.readdirSync(target);
|
|
@@ -44,6 +42,8 @@ export default async (cmd: any) => {
|
|
|
44
42
|
}
|
|
45
43
|
//替换build中的可替换变量
|
|
46
44
|
const regexPublicPath = new RegExp('\\$public_path', 'g');
|
|
45
|
+
const regexPublicPath2 = new RegExp('__PUBLIC_PATH__', 'g');
|
|
46
|
+
const regexDomain = new RegExp('__DOMAIN__', 'g');
|
|
47
47
|
|
|
48
48
|
for (let i = 0; i < cicdCmd.endpoints.length; i++) {
|
|
49
49
|
const ep = cicdCmd.endpoints[i];
|
|
@@ -52,6 +52,8 @@ export default async (cmd: any) => {
|
|
|
52
52
|
if (ep.defines){
|
|
53
53
|
Object.keys(ep.defines).forEach(key => {
|
|
54
54
|
ep.defines[key] = ep.defines[key].replace(regexPublicPath, ep.publicPath);
|
|
55
|
+
ep.defines[key] = ep.defines[key].replace(regexPublicPath2, ep.publicPath);
|
|
56
|
+
ep.defines[key] = ep.defines[key].replace(regexDomain, ep.domains[0]);
|
|
55
57
|
});
|
|
56
58
|
}
|
|
57
59
|
} catch (e) {
|
|
@@ -64,7 +66,7 @@ export default async (cmd: any) => {
|
|
|
64
66
|
}
|
|
65
67
|
if (!ep.extra_env) ep.extra_env = {};
|
|
66
68
|
ep.extra_env['PUBLIC_PATH'] = ep.publicPath;
|
|
67
|
-
ep.extra_env['OUTPUT_DIR'] = path.join(cicd.source.root_path, ep.
|
|
69
|
+
ep.extra_env['OUTPUT_DIR'] = path.join(cicd.source.root_path, ep.publicPath);
|
|
68
70
|
|
|
69
71
|
switch (frameworktype) {
|
|
70
72
|
case FrameworkType.vue: {
|
|
@@ -81,10 +83,11 @@ export default async (cmd: any) => {
|
|
|
81
83
|
shell.exec(ep.build);
|
|
82
84
|
//setup default defines and replace text in built source.
|
|
83
85
|
if (!ep.defines) ep.defines = {};
|
|
84
|
-
ep.defines['
|
|
86
|
+
ep.defines['__PUBLIC_PATH__'] = ep.publicPath;
|
|
87
|
+
ep.defines['__DEPLOY_DIR__'] = ep.publicPath;
|
|
85
88
|
ep.defines['__RIG_PUBLIC_PATH__'] = ep.publicPath;
|
|
86
89
|
ep.defines['__RIG_DEPLOY_DIR__'] = ep.publicPath;
|
|
87
|
-
replaceDefine(path.join(cicd.source.root_path, ep.
|
|
90
|
+
replaceDefine(path.join(cicd.source.root_path, ep.publicPath), ep.defines);
|
|
88
91
|
}
|
|
89
92
|
} catch (e) {
|
|
90
93
|
console.error(e.message);
|
package/lib/classes/cicd/CICD.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import DirLevel from '@/classes/cicd/DirLevel';
|
|
2
|
-
import Endpoint, {
|
|
2
|
+
import Endpoint, {EndpointDict} from '@/classes/cicd/Endpoint';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
|
|
5
5
|
const JSON5 = require('json5');
|
|
6
6
|
import qs from 'querystring';
|
|
7
7
|
import util from 'util';
|
|
8
|
+
|
|
8
9
|
export enum CloudType {
|
|
9
10
|
alicloud = 'alicloud',
|
|
10
11
|
}
|
|
12
|
+
|
|
11
13
|
export enum FrameworkType {
|
|
12
14
|
vue = 'vue',
|
|
13
15
|
}
|
|
16
|
+
|
|
14
17
|
/**
|
|
15
18
|
* Bundle source
|
|
16
19
|
*/
|
|
@@ -29,9 +32,11 @@ export interface DeployTarget {
|
|
|
29
32
|
access_key: string;
|
|
30
33
|
access_secret: string;
|
|
31
34
|
root_path: '/';
|
|
35
|
+
bucket_root_path: '/';//equals to root_path
|
|
36
|
+
web_entry_path: '/';
|
|
32
37
|
uri_rewrite: {
|
|
33
|
-
original
|
|
34
|
-
original_regexp
|
|
38
|
+
original?: string;
|
|
39
|
+
original_regexp?: string;
|
|
35
40
|
final?: string;
|
|
36
41
|
} | undefined;
|
|
37
42
|
}
|
|
@@ -48,10 +53,12 @@ export interface DirGroup {
|
|
|
48
53
|
level: string,
|
|
49
54
|
includes: string[],
|
|
50
55
|
}
|
|
51
|
-
|
|
56
|
+
|
|
57
|
+
export interface Define {
|
|
52
58
|
[replace: string]: String;
|
|
53
59
|
}
|
|
54
|
-
|
|
60
|
+
|
|
61
|
+
export interface DefineDict {
|
|
55
62
|
[group: string]: Define;
|
|
56
63
|
}
|
|
57
64
|
|
|
@@ -64,6 +71,7 @@ export interface CICDConfig {
|
|
|
64
71
|
* fafafafa
|
|
65
72
|
*/
|
|
66
73
|
tree_schema: string;
|
|
74
|
+
web_type: 'spa'|'mpa';
|
|
67
75
|
source: DeploySource;
|
|
68
76
|
target: DeployTarget | DeployTarget[];
|
|
69
77
|
endpoints: EndpointDict;
|
|
@@ -77,6 +85,7 @@ class CICD {
|
|
|
77
85
|
* @type {string}
|
|
78
86
|
*/
|
|
79
87
|
treeSchema: string;
|
|
88
|
+
web_type: 'spa' | 'mpa' = 'spa';
|
|
80
89
|
/**
|
|
81
90
|
* DirLevel shows every level of the directory structure
|
|
82
91
|
* @type {DirLevel[]}
|
|
@@ -93,13 +102,15 @@ class CICD {
|
|
|
93
102
|
|
|
94
103
|
constructor(config: CICDConfig) {
|
|
95
104
|
this.treeSchema = config.tree_schema;
|
|
105
|
+
this.web_type = config.web_type || 'spa';
|
|
96
106
|
this.schema = DirLevel.createSchema(this.treeSchema);
|
|
97
|
-
this.endpoints = Endpoint.createEndpointArr(config,this.schema);
|
|
107
|
+
this.endpoints = Endpoint.createEndpointArr(config, this.schema);
|
|
98
108
|
this.source = config.source;
|
|
99
109
|
this.target = config.target;
|
|
100
110
|
this.groups = config.groups;
|
|
101
111
|
}
|
|
102
|
-
|
|
112
|
+
|
|
113
|
+
static createByDefault(cmd: any) {
|
|
103
114
|
//replace params
|
|
104
115
|
let cicdStr = fs.readFileSync(`${process.cwd()}/cicd.rig.json5`).toString();
|
|
105
116
|
const paramsStr = cmd.params;
|
|
@@ -110,7 +121,7 @@ class CICD {
|
|
|
110
121
|
const regex = new RegExp(regStr, 'g');
|
|
111
122
|
cicdStr = cicdStr.replace(regex, params[key] as string);
|
|
112
123
|
});
|
|
113
|
-
const cicd =
|
|
124
|
+
const cicd = new CICD(JSON5.parse(cicdStr))
|
|
114
125
|
return cicd;
|
|
115
126
|
}
|
|
116
127
|
|
|
@@ -32,12 +32,7 @@ class AliOSS {
|
|
|
32
32
|
} catch (e) {}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public async putStreamFiles(
|
|
36
|
-
filesList: string[],
|
|
37
|
-
ossBasePath: string,
|
|
38
|
-
dir: string,
|
|
39
|
-
rootPath: string
|
|
40
|
-
) {
|
|
35
|
+
public async putStreamFiles(filesList: string[], rootPath: string) {
|
|
41
36
|
for (let i = 0; i < filesList.length; i++) {
|
|
42
37
|
let filePath = '';
|
|
43
38
|
if (os.platform() === 'win32') {
|
|
@@ -45,8 +40,7 @@ class AliOSS {
|
|
|
45
40
|
} else {
|
|
46
41
|
filePath = filesList[i].split(`${rootPath}/`)[1];
|
|
47
42
|
}
|
|
48
|
-
const ossPath =
|
|
49
|
-
ossBasePath + filePath.replace(/\\/g, '/').replace(dir, '');
|
|
43
|
+
const ossPath = filePath.replace(/\\/g, '/');
|
|
50
44
|
|
|
51
45
|
//@ts-ignore
|
|
52
46
|
let options: aliOSS.PutStreamOptions = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
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
|
+
//Mapping endpoints in cicd.rig.json5
|
|
5
5
|
interface EndpointInfo {
|
|
6
6
|
build: string;
|
|
7
7
|
target: string;
|
|
@@ -10,6 +10,7 @@ interface EndpointInfo {
|
|
|
10
10
|
defines: Define;
|
|
11
11
|
vue_env?: string;
|
|
12
12
|
extra_env?:{[env: string]: String};
|
|
13
|
+
web_entry_path: string;
|
|
13
14
|
uri_rewrite: {
|
|
14
15
|
original: string;
|
|
15
16
|
original_regexp: string;
|
|
@@ -34,6 +35,7 @@ class Endpoint {
|
|
|
34
35
|
extra_env?:{[env: string]: String};
|
|
35
36
|
publicPath: string = '';
|
|
36
37
|
defines: Define;
|
|
38
|
+
web_entry_path: string = '/';//effective when no validate uri_rewrite
|
|
37
39
|
uri_rewrite: {
|
|
38
40
|
original: string,
|
|
39
41
|
original_regexp: string;
|
|
@@ -60,6 +62,7 @@ class Endpoint {
|
|
|
60
62
|
this.domains = info.domains
|
|
61
63
|
this.defines = info.defines;
|
|
62
64
|
this.uri_rewrite = info.uri_rewrite;
|
|
65
|
+
this.web_entry_path = info.web_entry_path || '/';
|
|
63
66
|
this.vue_env = info.vue_env;
|
|
64
67
|
this.extra_env = info.extra_env;
|
|
65
68
|
|
package/lib/deploy/index.ts
CHANGED
|
@@ -41,15 +41,10 @@ export default async (cmd: any) => {
|
|
|
41
41
|
const distPath = path.join(
|
|
42
42
|
process.cwd(),
|
|
43
43
|
cicd.source.root_path,
|
|
44
|
-
cicdCmd.endpoints[i].
|
|
44
|
+
cicdCmd.endpoints[i].deployDir
|
|
45
45
|
);
|
|
46
46
|
traverseFolder(distPath);
|
|
47
|
-
await aliOss.putStreamFiles(
|
|
48
|
-
filesList,
|
|
49
|
-
cicdCmd.endpoints[i].deployDir.replace(/\\/g, '/'),
|
|
50
|
-
cicdCmd.endpoints[i].dir,
|
|
51
|
-
cicd.source.root_path
|
|
52
|
-
);
|
|
47
|
+
await aliOss.putStreamFiles(filesList, cicd.source.root_path);
|
|
53
48
|
filesList = [];
|
|
54
49
|
}
|
|
55
50
|
console.log('Upload OSS Done');
|
package/lib/publish/index.ts
CHANGED
|
@@ -18,7 +18,7 @@ const setRewriteUri = async (
|
|
|
18
18
|
domain,
|
|
19
19
|
[original],
|
|
20
20
|
[deployDir],
|
|
21
|
-
[
|
|
21
|
+
['enhance_break']
|
|
22
22
|
);
|
|
23
23
|
|
|
24
24
|
const configId = rwriteResult?.DomainConfigList.DomainConfigModel[0].ConfigId;
|
|
@@ -76,34 +76,92 @@ export default async (cmd: any) => {
|
|
|
76
76
|
throw new Error('Endpoints.length Can Not Be 0!');
|
|
77
77
|
}
|
|
78
78
|
for (const endpoint of cicdCmd.endpoints) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
if (
|
|
80
|
+
!endpoint.uri_rewrite &&
|
|
81
|
+
(!target.uri_rewrite ||
|
|
82
|
+
!target.uri_rewrite.original ||
|
|
83
|
+
!target.uri_rewrite.original_regexp)
|
|
84
|
+
) {
|
|
85
|
+
let webEntryPath: string;
|
|
86
|
+
if (cicd.web_type === 'mpa') {
|
|
87
|
+
webEntryPath = '/';
|
|
88
|
+
} else {
|
|
89
|
+
webEntryPath = endpoint.web_entry_path
|
|
90
|
+
? endpoint.web_entry_path
|
|
91
|
+
: target.web_entry_path || '/';
|
|
92
|
+
}
|
|
93
|
+
for (const domain of endpoint.domains) {
|
|
94
|
+
if (cicd.web_type === 'mpa') {
|
|
95
|
+
setRewriteUriPromises.push(
|
|
96
|
+
setRewriteUri(
|
|
97
|
+
domain,
|
|
98
|
+
'^\\/(.*\\.\\w+)($|\\?)',
|
|
99
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/$1`,
|
|
100
|
+
cdn
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
setRewriteUriPromises.push(
|
|
104
|
+
setRewriteUri(
|
|
105
|
+
domain,
|
|
106
|
+
'^\\/([\\w-]+)($|\\/$|\\?)(?!.*.\\w+)',
|
|
107
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/$1.html`,
|
|
108
|
+
cdn
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
setRewriteUriPromises.push(
|
|
113
|
+
setRewriteUri(
|
|
114
|
+
domain,
|
|
115
|
+
'^\\/(.*\\.\\w+)($|\\?)',
|
|
116
|
+
`/$1`,
|
|
117
|
+
cdn
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
setRewriteUriPromises.push(
|
|
122
|
+
setRewriteUri(
|
|
123
|
+
domain,
|
|
124
|
+
`^(${webEntryPath})($|\\?|#|\\/\\?|\\/$)`,
|
|
125
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
|
|
126
|
+
cdn
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
urls.push(`https://${domain}${webEntryPath}`);
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
const uriRewrite = endpoint.uri_rewrite
|
|
133
|
+
? endpoint.uri_rewrite
|
|
134
|
+
: target.uri_rewrite;
|
|
82
135
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
136
|
+
if (!uriRewrite) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
86
139
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
140
|
+
for (const domain of endpoint.domains) {
|
|
141
|
+
setRewriteUriPromises.push(
|
|
142
|
+
setRewriteUri(
|
|
143
|
+
domain,
|
|
144
|
+
`${
|
|
145
|
+
uriRewrite.original_regexp
|
|
146
|
+
? uriRewrite.original_regexp
|
|
147
|
+
: uriRewrite.original
|
|
148
|
+
}`,
|
|
149
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
|
|
150
|
+
cdn
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
urls.push(`https://${domain}${uriRewrite.original}`);
|
|
154
|
+
}
|
|
101
155
|
}
|
|
102
156
|
}
|
|
103
157
|
|
|
104
158
|
// 回源URI改写
|
|
105
159
|
console.log('Please Wait For Set RWrite URI...');
|
|
106
|
-
|
|
160
|
+
if (setRewriteUriPromises.length > 0) {
|
|
161
|
+
await Promise.all(setRewriteUriPromises);
|
|
162
|
+
} else {
|
|
163
|
+
console.log('Not Have To Set RWrite URI');
|
|
164
|
+
}
|
|
107
165
|
console.log('Set RWrite URI Done');
|
|
108
166
|
|
|
109
167
|
//刷新cdn
|
package/package.json
CHANGED