rigjs 2.0.6 → 2.0.10

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,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
- //create cicd object
34
- const cicd = CICD.createByDefault(cmd);
35
- //construct cmd object
36
- const cicdCmd = new CICDCmd(cmd, cicd);
37
- console.log(cicd)
38
- //build by cicdCmd and cicdConfig
39
- console.log(cicdCmd.endpoints);
40
- const regexPublicPath = new RegExp('\\$public_path', 'g');
41
- for (let i = 0; i < cicdCmd.endpoints.length; i++) {
42
- const ep = cicdCmd.endpoints[i];
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
- ep.build = ep.build.replace(regexPublicPath, ep.publicPath);
45
- try {
46
- //替换define中的$public_path
47
- Object.keys(ep.defines).forEach(key=>{
48
- ep.defines[key] = ep.defines[key].replace(regexPublicPath, ep.publicPath);
49
- })
50
- } catch (e) {
51
- console.log('JSON5 error:', ep.defines,e.message);
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
- console.log('exec build:', ep, ep.build, ep.defines);
54
- shell.exec(ep.build);
55
- replaceDefine(path.join(cicd.source.root_path, ep.dir), ep.defines);
60
+ }catch (e) {
61
+ console.error(e.message);
62
+ process.exit(1);
56
63
  }
57
64
  }
@@ -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
- return new CICD(JSON5.parse(cicdStr));
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() {
@@ -53,7 +53,7 @@ class AliOSS {
53
53
  };
54
54
  if (filesList[i].includes('index.html')) {
55
55
  options = Object.assign({
56
- headers: { 'Cache-Control': 'max-age=0', Expires: -1 },
56
+ headers: { 'Cache-Control': 'no-cache', Expires: -1 },
57
57
  });
58
58
  }
59
59
  const fileResult = await this.ossClient.putStream(
@@ -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
- throw e;
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~'));
@@ -50,47 +50,55 @@ const refreshCache = async (urls: string[], cdn: CDN) => {
50
50
  };
51
51
 
52
52
  export default async (cmd: any) => {
53
- //create cicd object
54
- const cicd = CICD.createByDefault(cmd);
55
- //construct cmd object
56
- const cicdCmd = new CICDCmd(cmd, cicd);
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
- console.log('Start Publish-----');
59
- const target = Array.isArray(cicdCmd.cicd.target)
60
- ? cicdCmd.cicd.target[0]
61
- : cicdCmd.cicd.target;
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
- const cdn = new CDN(target);
64
- const urls: string[] = [];
65
- const setRewriteUriPromises: Promise<any>[] = [];
66
- for (const endpoint of cicdCmd.endpoints) {
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}`);
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
- // 回源URI改写
89
- console.log('Please Wait For Set RWrite URI...');
90
- await Promise.all(setRewriteUriPromises);
91
- console.log('Set RWrite URI Done');
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
- //刷新cdn
94
- await refreshCache(urls, cdn);
95
- console.log('Publish Done-----');
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
@@ -55,3 +55,4 @@ import env from '../vue-env';
55
55
  program.option('--vueenv <vueenv>', 'specify vue env').action(env.load);
56
56
  program.version(require('../../package.json').version, '-v,--version');
57
57
  program.parse(process.argv);
58
+
@@ -24,12 +24,15 @@ const load = async (cmd) => {
24
24
  }
25
25
  fs.writeFile('./.env.rig', content, {flag: "w"}, err => {
26
26
  err && print.error(err);
27
+ process.exit(1)
27
28
  });
28
29
  } else {
29
30
  print.error("请先在env.rig.json5文件中配置" + mode + "模式的环境变量");
31
+ process.exit(1)
30
32
  }
31
33
  } catch (e) {
32
34
  print.error(e.message);
35
+ process.exit(1)
33
36
  }
34
37
  }
35
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.0.6",
3
+ "version": "2.0.10",
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",