rigjs 2.0.7 → 2.0.9
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 +101 -101
- package/lib/build/index.ts +30 -23
- package/lib/classes/cicd/CICD.ts +4 -1
- package/lib/classes/cicd/CICDCmd.ts +3 -0
- package/lib/deploy/index.ts +7 -4
- package/lib/init/index.js +9 -0
- package/lib/publish/index.ts +46 -38
- package/lib/rig/index.ts +1 -0
- package/package.json +1 -1
package/lib/build/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import CICD, {Define} from '@/classes/cicd/CICD';
|
|
2
2
|
import CICDCmd from '@/classes/cicd/CICDCmd';
|
|
3
|
-
import shell from 'shelljs';
|
|
3
|
+
import shell, {cat} from 'shelljs';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import fs from 'fs';
|
|
6
|
-
|
|
6
|
+
import util from 'util';
|
|
7
7
|
const JSON5 = require('json5');
|
|
8
8
|
|
|
9
9
|
const replaceDefine = (target: string, defines?: Define) => {
|
|
@@ -30,28 +30,35 @@ const replaceDefine = (target: string, defines?: Define) => {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
export default async (cmd: any) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
try{
|
|
34
|
+
console.log('start building');
|
|
35
|
+
//create cicd object
|
|
36
|
+
const cicd = CICD.createByDefault(cmd);
|
|
37
|
+
//construct cmd object
|
|
38
|
+
const cicdCmd = new CICDCmd(cmd, cicd);
|
|
39
|
+
//build by cicdCmd and cicdConfig
|
|
40
|
+
if (cicdCmd.endpoints.length===0){
|
|
41
|
+
throw new Error('Must have validate endpoints')
|
|
42
|
+
}
|
|
43
|
+
const regexPublicPath = new RegExp('\\$public_path', 'g');
|
|
44
|
+
for (let i = 0; i < cicdCmd.endpoints.length; i++) {
|
|
45
|
+
const ep = cicdCmd.endpoints[i];
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
ep.build = ep.build.replace(regexPublicPath, ep.publicPath);
|
|
48
|
+
try {
|
|
49
|
+
//替换define中的$public_path
|
|
50
|
+
Object.keys(ep.defines).forEach(key=>{
|
|
51
|
+
ep.defines[key] = ep.defines[key].replace(regexPublicPath, ep.publicPath);
|
|
52
|
+
})
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.log('JSON5 error:', ep.defines,e.message);
|
|
55
|
+
}
|
|
56
|
+
console.log('exec build:', ep, ep.build, ep.defines);
|
|
57
|
+
shell.exec(ep.build);
|
|
58
|
+
replaceDefine(path.join(cicd.source.root_path, ep.dir), ep.defines);
|
|
52
59
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
}catch (e) {
|
|
61
|
+
console.error(e.message);
|
|
62
|
+
process.exit(1);
|
|
56
63
|
}
|
|
57
64
|
}
|
package/lib/classes/cicd/CICD.ts
CHANGED
|
@@ -4,6 +4,7 @@ import fs from 'fs';
|
|
|
4
4
|
|
|
5
5
|
const JSON5 = require('json5');
|
|
6
6
|
import qs from 'querystring';
|
|
7
|
+
import util from 'util';
|
|
7
8
|
export enum CloudType {
|
|
8
9
|
alicloud = 'alicloud',
|
|
9
10
|
}
|
|
@@ -102,7 +103,9 @@ class CICD {
|
|
|
102
103
|
const regex = new RegExp(regStr, 'g');
|
|
103
104
|
cicdStr = cicdStr.replace(regex, params[key] as string);
|
|
104
105
|
});
|
|
105
|
-
|
|
106
|
+
const cicd = new CICD(JSON5.parse(cicdStr))
|
|
107
|
+
console.log(util.inspect(cicd, false, null, true))
|
|
108
|
+
return cicd;
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
matchEndpoints(cmdDirStrArr: string[]) {
|
|
@@ -3,6 +3,7 @@ import CICD, {CICDConfig} from '@/classes/cicd/CICD';
|
|
|
3
3
|
import qs, {ParsedUrlQuery} from 'querystring';
|
|
4
4
|
import path from 'path'
|
|
5
5
|
import fsHelper from '@/utils/fsHelper';
|
|
6
|
+
import util from 'util';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @class CICDCmd
|
|
@@ -27,6 +28,7 @@ class CICDCmd {
|
|
|
27
28
|
|
|
28
29
|
constructor(cmd: any, cicd: CICD) {
|
|
29
30
|
const cmdArgs = cmd.args;
|
|
31
|
+
console.log('build command:', cmdArgs[0]);
|
|
30
32
|
this.dir = cmdArgs[0];
|
|
31
33
|
//获取需要被设置的schema变量
|
|
32
34
|
const schemaKeys = this.dir.match(/(?<=\{)[a-zA-Z]+(?=\})/g) || [];
|
|
@@ -46,6 +48,7 @@ class CICDCmd {
|
|
|
46
48
|
this.dirInSchemaStrArr = this.dir.split('/').filter((dirStr, index) => dirStr.length > 0 && index < cicd.schema.length);
|
|
47
49
|
this.cicd = cicd;
|
|
48
50
|
this.createTargetEndpoints();
|
|
51
|
+
console.log(util.inspect(this.endpoints, false, null, true))
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
private createTargetEndpoints() {
|
package/lib/deploy/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ import path from 'path';
|
|
|
3
3
|
import CICD from '@/classes/cicd/CICD';
|
|
4
4
|
import CICDCmd from '@/classes/cicd/CICDCmd';
|
|
5
5
|
import AliOSS from '@/classes/cicd/Deploy/AliDeploy';
|
|
6
|
-
import CDN from '@/classes/cicd/Deploy/CDN';
|
|
7
6
|
|
|
8
7
|
let filesList: string[] = [];
|
|
9
8
|
const traverseFolder = (url: string) => {
|
|
@@ -35,6 +34,9 @@ export default async (cmd: any) => {
|
|
|
35
34
|
|
|
36
35
|
const aliOss = new AliOSS(target);
|
|
37
36
|
console.log('Please Wait for Upload OSS...');
|
|
37
|
+
if (!cicdCmd.endpoints || cicdCmd.endpoints.length === 0) {
|
|
38
|
+
throw new Error('Endpoints.length Can Not Be 0!');
|
|
39
|
+
}
|
|
38
40
|
for (let i = 0; i < cicdCmd.endpoints.length; i++) {
|
|
39
41
|
const distPath = path.join(
|
|
40
42
|
process.cwd(),
|
|
@@ -46,13 +48,14 @@ export default async (cmd: any) => {
|
|
|
46
48
|
filesList,
|
|
47
49
|
cicdCmd.endpoints[i].deployDir.replace(/\\/g, '/'),
|
|
48
50
|
cicdCmd.endpoints[i].dir,
|
|
49
|
-
cicd.source.root_path
|
|
51
|
+
cicd.source.root_path
|
|
50
52
|
);
|
|
51
53
|
filesList = [];
|
|
52
54
|
}
|
|
53
55
|
console.log('Upload OSS Done');
|
|
54
56
|
console.log('Deploy Done-----');
|
|
55
|
-
} catch (e) {
|
|
56
|
-
|
|
57
|
+
} catch (e: any) {
|
|
58
|
+
console.error(e.message);
|
|
59
|
+
process.exit(1);
|
|
57
60
|
}
|
|
58
61
|
};
|
package/lib/init/index.js
CHANGED
|
@@ -62,6 +62,7 @@ module.exports = {
|
|
|
62
62
|
`
|
|
63
63
|
fs.writeFileSync(`${process.cwd()}/rig_helper.js`, template);
|
|
64
64
|
}
|
|
65
|
+
//检查是否存在cicd.rig.json5
|
|
65
66
|
if (fs.existsSync(`${process.cwd()}/cicd.rig.json5`)) {
|
|
66
67
|
console.log(chalk.green('cicd.rig.json5 already exists~'));
|
|
67
68
|
} else {
|
|
@@ -79,6 +80,14 @@ module.exports = {
|
|
|
79
80
|
fs.writeFileSync(`${process.cwd()}/cicd.rig.json5`, template);
|
|
80
81
|
|
|
81
82
|
}
|
|
83
|
+
//检查是否存在env.rig.json5
|
|
84
|
+
if (fs.existsSync(`${process.cwd()}/env.rig.json5`)) {
|
|
85
|
+
console.log(chalk.green('env.rig.json5 already exists~'));
|
|
86
|
+
} else {
|
|
87
|
+
console.log(chalk.green('create env.rig.json5'));
|
|
88
|
+
let template = `{}`;
|
|
89
|
+
fs.writeFileSync(`${process.cwd()}/cicd.rig.json5`, template);
|
|
90
|
+
}
|
|
82
91
|
//检查rigs是否存在
|
|
83
92
|
if (fs.existsSync('./rigs') && fs.lstatSync('./rigs').isDirectory()) {
|
|
84
93
|
console.log(chalk.green('folder rigs already exists~'));
|
package/lib/publish/index.ts
CHANGED
|
@@ -50,47 +50,55 @@ const refreshCache = async (urls: string[], cdn: CDN) => {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export default async (cmd: any) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
try {
|
|
54
|
+
//create cicd object
|
|
55
|
+
const cicd = CICD.createByDefault(cmd);
|
|
56
|
+
//construct cmd object
|
|
57
|
+
const cicdCmd = new CICDCmd(cmd, cicd);
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
console.log('Start Publish-----');
|
|
60
|
+
const target = Array.isArray(cicdCmd.cicd.target)
|
|
61
|
+
? cicdCmd.cicd.target[0]
|
|
62
|
+
: cicdCmd.cicd.target;
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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}`);
|
|
64
|
+
const cdn = new CDN(target);
|
|
65
|
+
const urls: string[] = [];
|
|
66
|
+
const setRewriteUriPromises: Promise<any>[] = [];
|
|
67
|
+
if (!cicdCmd.endpoints || cicdCmd.endpoints.length === 0) {
|
|
68
|
+
throw new Error('Endpoints.length Can Not Be 0!');
|
|
85
69
|
}
|
|
86
|
-
|
|
70
|
+
for (const endpoint of cicdCmd.endpoints) {
|
|
71
|
+
const uriRewrite = endpoint.uri_rewrite
|
|
72
|
+
? endpoint.uri_rewrite
|
|
73
|
+
: target.uri_rewrite;
|
|
87
74
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
75
|
+
for (const domain of endpoint.domains) {
|
|
76
|
+
setRewriteUriPromises.push(
|
|
77
|
+
setRewriteUri(
|
|
78
|
+
domain,
|
|
79
|
+
`${
|
|
80
|
+
uriRewrite.original_regexp
|
|
81
|
+
? uriRewrite.original_regexp
|
|
82
|
+
: uriRewrite.original
|
|
83
|
+
}`,
|
|
84
|
+
`/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
|
|
85
|
+
cdn
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
urls.push(`https://${domain}${uriRewrite.original}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
// 回源URI改写
|
|
93
|
+
console.log('Please Wait For Set RWrite URI...');
|
|
94
|
+
await Promise.all(setRewriteUriPromises);
|
|
95
|
+
console.log('Set RWrite URI Done');
|
|
96
|
+
|
|
97
|
+
//刷新cdn
|
|
98
|
+
await refreshCache(urls, cdn);
|
|
99
|
+
console.log('Publish Done-----');
|
|
100
|
+
} catch (e: any) {
|
|
101
|
+
console.error(e.message);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
96
104
|
};
|
package/lib/rig/index.ts
CHANGED
package/package.json
CHANGED