rigjs 2.0.0-alpha.8 → 2.0.2

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.
@@ -8,126 +8,178 @@ const shell = require('shelljs');
8
8
  const fs = require('fs');
9
9
  const json5 = require('json5');
10
10
  const print = require('../print');
11
- let semverReg = /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/;
11
+ const path = require('path');
12
+ // let semverReg = /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/;
12
13
  let gitUrlReg = /(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)(\/?|\#[-\d\w._]+?)$/;
13
14
  const validateName = (name) => {
14
- if (name) {
15
- return true;
16
- } else {
17
- print.error(`name value(${name}) invalidate!`);
18
- return false;
19
- }
15
+ if (name) {
16
+ return true;
17
+ } else {
18
+ print.error(`name value(${name}) invalidate!`);
19
+ return false;
20
+ }
20
21
  }
21
22
  const validateSource = (source) => {
22
- let isValidate;
23
- try {
24
- isValidate = gitUrlReg.test(source);
25
- } catch (e) {
26
- isValidate = false;
27
- print.error(e.message);
28
- }
29
- if (!isValidate) {
30
- print.error(`source value(${source}) invalidate!`);
31
- }
32
- return isValidate;
23
+ let isValidate;
24
+ try {
25
+ isValidate = gitUrlReg.test(source);
26
+ } catch (e) {
27
+ isValidate = false;
28
+ print.error(e.message);
29
+ }
30
+ if (!isValidate) {
31
+ print.error(`source value(${source}) invalidate!`);
32
+ }
33
+ return isValidate;
33
34
  }
34
35
  const validateVersion = (version) => {
35
- let isValidate;
36
- try {
37
- isValidate = semverReg.test(version);
38
- } catch (e) {
39
- isValidate = false;
40
- print.error(e.message);
41
- }
42
- if (!isValidate) {
43
- print.error(`version value(${version}) invalidate!`);
44
- }
45
- return isValidate;
36
+ let isValidate;
37
+ try {
38
+ isValidate = version.length > 0;
39
+ } catch (e) {
40
+ isValidate = false;
41
+ print.error(e.message);
42
+ }
43
+ if (!isValidate) {
44
+ print.error(`version value(${version}) invalidate!`);
45
+ }
46
+ return isValidate;
46
47
  }
47
48
  const validate = (rigJson5) => {
48
- let isValidate = true;
49
- try {
50
- for (let dep of rigJson5) {
51
- if (!(validateName(dep.name) && validateSource(dep.source) && validateVersion(dep.version))) {
52
- isValidate = false;
53
- print.error(`!INVALID CONFIG!:${JSON.stringify(dep)}`);
54
- break;
55
- }
56
- }
57
- } catch (e) {
58
- print.error(e.message);
59
- isValidate = false;
60
- }
61
- if (!isValidate) {
62
- print.info(`Visit https://github.com/FlashHand/rig for documentation`);
63
- }
64
- return isValidate;
49
+ let isValidate = true;
50
+ try {
51
+ for (let dep of rigJson5) {
52
+ if (!(validateName(dep.name) && validateSource(dep.source) && validateVersion(dep.version))) {
53
+ isValidate = false;
54
+ print.error(`!INVALID CONFIG!:${JSON.stringify(dep)}`);
55
+ break;
56
+ }
57
+ }
58
+ } catch (e) {
59
+ print.error(e.message);
60
+ isValidate = false;
61
+ }
62
+ if (!isValidate) {
63
+ print.info(`Visit https://github.com/FlashHand/rig for documentation`);
64
+ }
65
+ return isValidate;
65
66
  }
66
67
  const clone = (target, dep) => {
67
- print.info(`cloning ${dep.name}`);
68
- let cloneProcess = shell.exec(`git clone ${dep.source} ${target}/${dep.name}`,
69
- {silent: true}
70
- );
71
- if (cloneProcess.stderr && !fs.existsSync(`${target}/${dep.name}`)) {
72
- print.error(`clone failed:${dep.source}`);
73
- print.error(cloneProcess.stderr);
74
- process.exit(1);
75
- }
68
+ print.info(`cloning ${dep.name}`);
69
+ let cloneProcess = shell.exec(`git clone ${dep.source} ${target}/${dep.name}`,
70
+ {silent: true}
71
+ );
72
+ if (cloneProcess.stderr && !fs.existsSync(`${target}/${dep.name}`)) {
73
+ print.error(`clone failed:${dep.source}`);
74
+ print.error(cloneProcess.stderr);
75
+ process.exit(1);
76
+ }
77
+ }
78
+ const checkDepsValid = (rigJson5) => {
79
+ // git show origin/master:package.json
80
+ // ➜ projects git show tags/2.0.1:package.json
81
+ for (let rig of rigJson5) {
82
+ try {
83
+ const cmd = `git fetch ${rig.source} --tag ${rig.version} -n && git show FETCH_HEAD:package.json`;
84
+ console.log(cmd);
85
+ let showPackageProcess = shell.exec(cmd,
86
+ {silent: true}
87
+ );
88
+ let pkgStr = showPackageProcess.stdout.trim();
89
+ const pkg = JSON.parse(pkgStr);
90
+ console.log(pkgStr);
91
+ //获取rig依赖
92
+ if (pkg.rig){
93
+ const rigConfig = pkg.rig;
94
+ //遍历rig依赖
95
+ Object.keys(rigConfig).forEach(key => {
96
+ //获取该rig依赖的要求的版本范围
97
+ let max='';
98
+ let min = '';
99
+ if (Array.isArray(rigConfig[key]) ) {
100
+ //使用数组的情况
101
+ if (rigConfig[key].length === 2){
102
+ console.log('array\'s length must equal to 2!');
103
+ process.exit(1);
104
+ }else{
105
+ min = rigConfig[key][0]
106
+ max = rigConfig[key][1];
107
+ }
108
+ } else {
109
+ //使用字典的情况
110
+ min = rigConfig[key]['min'];
111
+ max = rigConfig[key]['max'];
112
+ }
113
+ //从rigJson5获取该依赖的版本号
114
+ const dep = rigJson5.find(r => r.name === key);
115
+ if (dep){
116
+
117
+ }else{
118
+ console.log(`${key}[${min},${max}] is required`);
119
+ process.exit(1);
120
+ }
121
+ })
122
+ }
123
+ } catch (e) {
124
+ console.log(e);
125
+ }
126
+ }
76
127
  }
77
128
  //加载命令控制器
78
129
  const load = async (cmd) => {
79
- print.info('start rig preinstall');
80
- try {
81
- //读取package.rig.json5
82
- let rigJson5Str = fs.readFileSync('package.rig.json5');
83
- let rigJson5 = json5.parse(rigJson5Str);
84
- if (!validate(rigJson5)) process.exit(1);
85
- //重置rigs
86
- if (!(fs.existsSync('./rigs') && fs.lstatSync('./rigs').isDirectory())) {
87
- print.info('create folder rigs');
88
- fs.mkdirSync('rigs');
89
- fs.writeFileSync('rigs/.gitkeep', '')
90
- }
91
- shell.chmod('777', 'rigs');
92
- let target = 'rigs';
93
- let pkgJson = JSON.parse(fs.readFileSync('package.json').toString());
94
- let dependencies = pkgJson['dependencies'];
95
- /**
96
- * 核心原则
97
- * 1. install 不应该覆盖或删除已经clone到rigs下的模块,由开发者自己选择要不要删
98
- * 2. rigs下的模块更新,由开发者自己git操作解决。
99
- */
100
- for (let dep of rigJson5) {
101
- if (dep.dev) {
102
- //不去覆盖已下载的库
103
- if (fs.existsSync(`${target}/${dep.name}`)) {
104
- print.info(`${dep.name} already exists.`);
105
- } else {
106
- clone(target, dep);
107
- }
108
- } else {
109
- //不是开发中状态,不处理,不去删除已下载的模块
110
- //预安装时在node_modules中要先清除json5里的库
111
- if (fs.existsSync(`node_modules/${dep.name}`)) {
112
- shell.rm('-rf', `node_modules/${dep.name}`);
113
- }
114
- if (fs.existsSync(`node_modules/.yarn-integrity`)) {
115
- shell.rm('-rf', `node_modules/.yarn-integrity`);
116
- }
117
- }
118
- dependencies[dep.name] = `git+ssh://${dep.source}#${dep.version}`
119
- }
120
- //覆盖package.json
121
- pkgJson.dependencies = dependencies;
122
- fs.writeFileSync('package.json', JSON.stringify(pkgJson, null, 2));
123
- //收尾
124
- print.succeed(`preinstall SUCCEED! Will do "yarn install"`);
125
- //远程链接设置完成,开发库设置完成,准备执行yarn install
126
- } catch (e) {
127
- print.error(e.message);
128
- }
130
+ print.info('start rig preinstall');
131
+ try {
132
+ //读取package.rig.json5
133
+ let rigJson5Str = fs.readFileSync(path.join(process.cwd(), 'package.rig.json5'));
134
+ let rigJson5 = json5.parse(rigJson5Str);
135
+ if (!validate(rigJson5)) process.exit(1);
136
+ checkDepsValid(rigJson5);
137
+ //重置rigs
138
+ if (!(fs.existsSync('./rigs') && fs.lstatSync('./rigs').isDirectory())) {
139
+ print.info('create folder rigs');
140
+ fs.mkdirSync('rigs');
141
+ fs.writeFileSync('rigs/.gitkeep', '')
142
+ }
143
+ shell.chmod('777', 'rigs');
144
+ let target = 'rigs';
145
+ let pkgJson = JSON.parse(fs.readFileSync('package.json').toString());
146
+ let dependencies = pkgJson['dependencies'];
147
+ /**
148
+ * 核心原则
149
+ * 1. install 不应该覆盖或删除已经clone到rigs下的模块,由开发者自己选择要不要删
150
+ * 2. rigs下的模块更新,由开发者自己git操作解决。
151
+ */
152
+ for (let dep of rigJson5) {
153
+ if (dep.dev) {
154
+ //不去覆盖已下载的库
155
+ if (fs.existsSync(`${target}/${dep.name}`)) {
156
+ print.info(`${dep.name} already exists.`);
157
+ } else {
158
+ clone(target, dep);
159
+ }
160
+ } else {
161
+ //不是开发中状态,不处理,不去删除已下载的模块
162
+ //预安装时在node_modules中要先清除json5里的库
163
+ if (fs.existsSync(`node_modules/${dep.name}`)) {
164
+ shell.rm('-rf', `node_modules/${dep.name}`);
165
+ }
166
+ if (fs.existsSync(`node_modules/.yarn-integrity`)) {
167
+ shell.rm('-rf', `node_modules/.yarn-integrity`);
168
+ }
169
+ }
170
+ dependencies[dep.name] = `git+ssh://${dep.source}#${dep.version}`
171
+ }
172
+ //覆盖package.json
173
+ pkgJson.dependencies = dependencies;
174
+ fs.writeFileSync('package.json', JSON.stringify(pkgJson, null, 2));
175
+ //收尾
176
+ print.succeed(`preinstall SUCCEED! Will do "yarn install"`);
177
+ //远程链接设置完成,开发库设置完成,准备执行yarn install
178
+ } catch (e) {
179
+ print.error(e.message);
180
+ }
129
181
  }
130
182
  module.exports = {
131
- name: 'install',
132
- load
183
+ name: 'install',
184
+ load
133
185
  }
@@ -1,25 +1,21 @@
1
- import fsHelper from '../utils/fsHelper';
2
1
  import CICD from '@/classes/cicd/CICD';
3
2
  import CICDCmd from '@/classes/cicd/CICDCmd';
4
- import shell from 'shelljs';
5
- import path from 'path';
6
3
  import CDN from '@/classes/cicd/Deploy/CDN';
7
4
 
8
- const setRWriteUri = async (
5
+ const setRewriteUri = async (
9
6
  domain: string,
10
7
  original: string,
11
8
  deployDir: string,
12
9
  cdn: CDN
13
10
  ) => {
14
- const rwriteResult = await cdn.setRWriteUri(
11
+ const rwriteResult = await cdn.setRewriteUri(
15
12
  domain,
16
13
  [original],
17
14
  [deployDir],
18
- ['enhance_break']
15
+ [null]
19
16
  );
20
17
 
21
18
  const configId = rwriteResult?.DomainConfigList.DomainConfigModel[0].ConfigId;
22
- console.log('Please Wait For Set RWrite URI...');
23
19
  while (true) {
24
20
  const configInfo = await cdn.describeCdnDomainConfigs(domain, configId);
25
21
  if (configInfo.DomainConfigs.DomainConfig[0].Status === 'success') {
@@ -29,7 +25,6 @@ const setRWriteUri = async (
29
25
  throw new Error('cdn rewrite fail');
30
26
  }
31
27
  }
32
- console.log('Set RWrite URI Done');
33
28
  };
34
29
 
35
30
  const refreshCache = async (urls: string[], cdn: CDN) => {
@@ -67,18 +62,26 @@ export default async (cmd: any) => {
67
62
 
68
63
  const cdn = new CDN(target);
69
64
  const urls: string[] = [];
65
+ const setRewriteUriPromises: Promise<any>[] = [];
70
66
  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
67
+ const uriRewrite = endpoint.uri_rewrite ? endpoint.uri_rewrite : target.uri_rewrite;
68
+ setRewriteUriPromises.push(
69
+ setRewriteUri(
70
+ endpoint.domain,
71
+ `${uriRewrite.original_regexp ? uriRewrite.original_regexp : uriRewrite.original}`,
72
+ `/${endpoint.deployDir.replace(/\\/g, '/')}/index.html`,
73
+ cdn
74
+ )
77
75
  );
78
- urls.push(`https://${endpoint.domain}/${target.uri_rewrite.original}`);
76
+ urls.push(`https://${endpoint.domain}${uriRewrite.original}`);
79
77
  }
80
78
 
79
+ // 回源URI改写
80
+ console.log('Please Wait For Set RWrite URI...');
81
+ await Promise.all(setRewriteUriPromises);
82
+ console.log('Set RWrite URI Done');
83
+
81
84
  //刷新cdn
82
85
  await refreshCache(urls, cdn);
83
- console.log('Start Publish-----');
86
+ console.log('Publish Done-----');
84
87
  };
package/lib/rig/index.ts CHANGED
@@ -50,8 +50,8 @@ program.command('publish')
50
50
  .option('-p , --params <params>', 'replace words in cicd.rig.json5, only words in ${} are replacable')
51
51
  .action(publish);
52
52
 
53
- import env from '../env';
53
+ import env from '../vue-env';
54
54
 
55
- program.option('-e, --env <env>', 'specify env').action(env.load);
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);
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.0.0-alpha.8",
3
+ "version": "2.0.2",
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",