rigjs 2.0.0-alpha.10 → 2.0.0-alpha.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/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
  ]
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rigjs",
3
- "version": "2.0.0-alpha.10",
3
+ "version": "2.0.0-alpha.11",
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",