rigjs 2.1.28 → 3.0.1-alpha.1
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/README.md +146 -183
- package/README_CN.md +151 -137
- package/built/index.js +143 -173
- package/demo/package.json +8 -6
- package/demo/package.rig.json5 +64 -10
- package/demo/rig_dev/.gitkeep +0 -0
- package/demo/rig_helper.js +5 -9
- package/demo/vue.config.js +1 -1
- package/doc/cicd_cn.md +120 -0
- package/doc/cmd_cn.md +0 -0
- package/doc/dependencies.md +0 -0
- package/doc/dependencies_cn.md +28 -0
- package/doc/share_cn.md +8 -0
- package/jest/test.rig.json5 +14 -0
- package/jest.config.ts +10 -1
- package/lib/add/index.ts +37 -0
- package/lib/build/build.md +6 -0
- package/lib/build/index.ts +64 -59
- package/lib/classes/RigConfig.test.ts +14 -0
- package/lib/classes/RigConfig.ts +191 -0
- package/lib/classes/cicd/CICD.ts +6 -7
- package/lib/classes/cicd/CICDCmd.ts +1 -0
- package/lib/classes/cicd/DirLevel.ts +1 -1
- package/lib/classes/cicd/Endpoint.ts +7 -1
- package/lib/classes/dependencies/Dep.ts +56 -0
- package/lib/dev/index.ts +44 -0
- package/lib/init/index.ts +118 -0
- package/lib/install/{index.js → index.ts} +3 -6
- package/lib/postinstall/{index.js → index.ts} +12 -20
- package/lib/preinstall/index.ts +78 -0
- package/lib/print/index.ts +38 -0
- package/lib/publish/index.ts +4 -4
- package/lib/rig/index.ts +29 -13
- package/lib/sync/index.test.ts +4 -0
- package/lib/sync/index.ts +32 -0
- package/lib/utils/fsHelper.ts +37 -1
- package/lib/utils/objectHelper.ts +12 -0
- package/lib/utils/regexHelper.test.ts +12 -0
- package/lib/utils/{regex.ts → regexHelper.ts} +4 -1
- package/package.json +10 -8
- package/package.rig.json5 +8 -0
- package/tsconfig.json +4 -2
- package/demo/cicd.rig.json5 +0 -56
- package/demo/yarn.lock +0 -6068
- package/lib/init/cicd.rig.json5 +0 -11
- package/lib/init/index.d.ts +0 -6
- package/lib/init/index.js +0 -189
- package/lib/init/rig_helper.js +0 -14
- package/lib/install/index.d.ts +0 -5
- package/lib/postinstall/index.d.ts +0 -6
- package/lib/preinstall/index.d.ts +0 -7
- package/lib/preinstall/index.js +0 -198
- package/lib/preinstall/index.test.js +0 -16
- package/lib/print/index.js +0 -33
package/README.md
CHANGED
|
@@ -1,210 +1,173 @@
|
|
|
1
1
|
# rig
|
|
2
|
+
*[中文文档](./README_CN.md)*
|
|
3
|
+
- [Goals](#Goals)
|
|
4
|
+
- [Get started:Modular developing by rigjs](#Get started:Modular developing by rigjs.)
|
|
5
|
+
- [dependencies config](./doc/dependencies_cn.md)
|
|
6
|
+
- [CICD config](./doc/cicd_cn.md)
|
|
7
|
+
- [share config](./doc/share_cn.md)
|
|
2
8
|
|
|
3
|
-
## [中文文档](./README_CN.md)
|
|
4
|
-
|
|
5
|
-
- [Getting Started](#getting-started)
|
|
6
|
-
- [How It Works](#how-it-works)
|
|
7
|
-
- Commands
|
|
8
|
-
- [`rig init`](#rig-init)
|
|
9
|
-
- [`rig install`](#rig-install)
|
|
10
|
-
- [`rig check`](#rig-check)
|
|
11
|
-
- [`rig tag`](#rig-tag)
|
|
12
|
-
|
|
13
|
-
## Getting started
|
|
14
|
-
###Prerequisites
|
|
15
|
-
- Should install yarn first.Rig is using yarn workspace to do module-hoisting.
|
|
16
|
-
```shell
|
|
17
|
-
npm i -g yarn
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
###Installation
|
|
21
9
|
|
|
22
|
-
|
|
10
|
+
## Get started:Modular developing by rigjs.
|
|
11
|
+
### 0.Prerequisites
|
|
12
|
+
#### Install yarn
|
|
13
|
+
```shell
|
|
23
14
|
yarn global add rigjs
|
|
24
15
|
```
|
|
16
|
+
Rigjs use yarn workspaces to achieve module-hoisting. [About yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces).
|
|
17
|
+
#### NodeJS version >= 14
|
|
18
|
+
Use [n](https://github.com/tj/n) to update NodeJS.
|
|
19
|
+
```shell
|
|
20
|
+
yarn global add n
|
|
21
|
+
#upgrade to lts
|
|
22
|
+
sudo n lts
|
|
23
|
+
#specify the version.
|
|
24
|
+
sudo n 14.19.1
|
|
25
|
+
```
|
|
25
26
|
|
|
26
|
-
###
|
|
27
|
-
You could try the demo for quick practice.
|
|
28
|
-
|
|
29
|
-
####1.init rig in your project
|
|
30
|
-
In your project's root path.
|
|
27
|
+
### 1.Initialize rigjs configuration。
|
|
31
28
|
|
|
32
29
|
```shell script
|
|
30
|
+
#in your project's root path(same level with package.json):
|
|
33
31
|
rig init
|
|
34
32
|
```
|
|
33
|
+
package.rig.json5 will be added in root path.
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
rig-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
####3.configuring package.rig.json5
|
|
35
|
+
### 2.Use rigjs to install existing repos.
|
|
36
|
+
#### 2.1 Method-one:rig add
|
|
37
|
+
rig add [your git ssh url] [tag]
|
|
38
|
+
e.g.
|
|
39
|
+
```shell
|
|
40
|
+
rig add git@github.com:FlashHand/rig-demo-1.git 0.0.1
|
|
41
|
+
```
|
|
42
|
+
import or require the module.
|
|
43
|
+
```ecmascript 6
|
|
44
|
+
const {hello} = require('rig-demo-1');
|
|
45
|
+
hello();
|
|
46
|
+
```
|
|
50
47
|
|
|
51
|
-
|
|
48
|
+
#### 2.2 Method-two:change package.rig.json5
|
|
52
49
|
```json5
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// },
|
|
60
|
-
{
|
|
61
|
-
name: 'rig-test-1',
|
|
62
|
-
source: 'git@github.com:FlashHand/rig-test-1.git',
|
|
63
|
-
version: '1.0.0',
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: 'rig-test-2',
|
|
67
|
-
source: 'git@github.com:FlashHand/rig-test-2.git',
|
|
68
|
-
version: '1.0.1',
|
|
69
|
-
dev: true
|
|
50
|
+
{
|
|
51
|
+
dependencies: {
|
|
52
|
+
'rig-demo-1': {
|
|
53
|
+
source: 'git@github.com:FlashHand/rig-demo-1.git',
|
|
54
|
+
version: '0.0.1',
|
|
55
|
+
}
|
|
70
56
|
}
|
|
71
|
-
|
|
57
|
+
}
|
|
72
58
|
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
yarn
|
|
59
|
+
then
|
|
60
|
+
```shell
|
|
61
|
+
yarn install
|
|
77
62
|
```
|
|
63
|
+
### 3.Use rigjs to develop an existing repo.
|
|
64
|
+
#### 3.1 Method-one:rig dev
|
|
65
|
+
rig dev [package's name|git-ssh-url]
|
|
78
66
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
rig-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
1. Git is enough.No need to publish to npm or private registry.Much simpler than git submodule.
|
|
88
|
-
2. Easily configurable.After configuration in simply use 'yarn install' and import/require your modules just like npm modules.
|
|
89
|
-
3. Support modules in any scale: from a simple js file to many web page files.
|
|
90
|
-
4.
|
|
91
|
-
|
|
92
|
-
###Easily develop and debug modules inside your project.
|
|
93
|
-
|
|
94
|
-
###All modules managed by rigjs are flatten.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
1. Put the modules you wanna intergrating in git repos.
|
|
99
|
-
2. Configure those modules in
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
1. Integrating other git reposCreated for modular architecture.
|
|
103
|
-
2. An organizer for multi repos.
|
|
104
|
-
3. You can develop and test your module within your project just by setting **dev** to true,then rigjs automatically create shortcuts in node_modules folder for your developing modules in rigs folder.
|
|
105
|
-
4. Modules are hoisted,because rigjs uses yarn's workspace.
|
|
106
|
-
5. Automatically create shortcuts in node_modules folder for your developing modules in rigs folder.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
## How it works
|
|
110
|
-
|
|
111
|
-
#### package.rig.json5
|
|
112
|
-
|
|
113
|
-
Rig is inspired by cocoapods. Not like those popular monorepo solutions,rig is a tool for organizing multi repos. So rig
|
|
114
|
-
create a file named "package.rig.json5". Data in "package.rig.json5" can look like this:
|
|
67
|
+
When package is already in package.rig.json5:
|
|
68
|
+
```shell
|
|
69
|
+
rig dev rig-demo-1
|
|
70
|
+
```
|
|
71
|
+
When package is not in package.rig.json5:
|
|
72
|
+
```shell
|
|
73
|
+
rig dev git@github.com:FlashHand/rig-demo-1.git
|
|
74
|
+
```
|
|
115
75
|
|
|
76
|
+
**rig-demo-1** will be installed in rig_dev directory.And a symlink of the module will be created in node_modules.
|
|
77
|
+
#### 3.1 Method-two:change package.rig.json5
|
|
116
78
|
```json5
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// },
|
|
125
|
-
{
|
|
126
|
-
name: 'r-b',
|
|
127
|
-
source: 'git@git.domain.com:common/r-b.git',
|
|
128
|
-
version: '1.0.0',
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
name: 'r-c',
|
|
132
|
-
source: 'git@git.domain.com:common/r-c.git',
|
|
133
|
-
version: '1.0.0',
|
|
134
|
-
dev: true
|
|
79
|
+
{
|
|
80
|
+
dependencies: {
|
|
81
|
+
'rig-demo-1': {
|
|
82
|
+
source: 'git@github.com:FlashHand/rig-demo-1.git',
|
|
83
|
+
version: '0.0.1',
|
|
84
|
+
dev: true //false by default
|
|
85
|
+
}
|
|
135
86
|
}
|
|
136
|
-
]
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
package.rig.json5 has an array of modules.
|
|
140
|
-
|
|
141
|
-
So rig create a folder named "rigs".
|
|
142
|
-
|
|
143
|
-
When dev is true,the module will be cloned in rigs/**(using master branch)**.
|
|
144
|
-
|
|
145
|
-
And it gets automatically linked in node_modules.
|
|
146
|
-
|
|
147
|
-
#### How rig modifies package.json
|
|
148
|
-
|
|
149
|
-
```javascript
|
|
150
|
-
//Rig will insert these to package.json
|
|
151
|
-
//Rig won't cover your preinstall or postinstall's settings.Scripts and workspaces will be appended.
|
|
152
|
-
let inserted = {
|
|
153
|
-
private: true,
|
|
154
|
-
workspaces: [
|
|
155
|
-
"rigs/*",
|
|
156
|
-
"rigs_dev/*"
|
|
157
|
-
],
|
|
158
|
-
scripts: {
|
|
159
|
-
preinstall: "rig preinstall",
|
|
160
|
-
postinstall: "rig postinstall",
|
|
161
|
-
}
|
|
162
87
|
}
|
|
163
88
|
```
|
|
164
|
-
|
|
165
|
-
**How to remove your modules**
|
|
166
|
-
|
|
167
|
-
Remove your modules from both package.json and package.rig.json5 then run **rig install** or **yarn install**.
|
|
168
|
-
|
|
169
|
-
//TODO:
|
|
170
|
-
rig check //if has dev:true then end shell rig tag //using package.json version
|
|
171
|
-
|
|
172
|
-
## Command
|
|
173
|
-
|
|
174
|
-
### rig init
|
|
175
|
-
|
|
176
|
-
1. create a "package.rig.json5" file
|
|
177
|
-
2. insert config to package.json
|
|
178
|
-
3. create "rigs" folder
|
|
179
|
-
4. modify .gitignore
|
|
180
|
-
|
|
181
|
-
### rig install
|
|
182
|
-
|
|
183
|
-
equals to "yarn install"
|
|
184
|
-
|
|
185
|
-
### rig check
|
|
186
|
-
|
|
187
|
-
If a module's dev status is true in "package.rig.json5",the config will not be passed!
|
|
188
|
-
|
|
189
|
-
Make sure you are not using developing modules for production.
|
|
190
|
-
|
|
191
|
-
### rig tag
|
|
192
|
-
|
|
193
|
-
Using version in package.json to tag.
|
|
194
|
-
|
|
195
|
-
### rig --vueenv <env>
|
|
196
|
-
|
|
197
|
-
This command is specially for vue.This command reads the file named "env.rig.json5" in the root directory, and looks for
|
|
198
|
-
the environment configuration in mode <env>.Then it will create a file named ".env.rig" or overwrite the file if ".env.rig" is not
|
|
199
|
-
existed.
|
|
200
|
-
After "rig --vueenv" you must use "--mode rig" to make it effective.
|
|
201
|
-
e.g.
|
|
89
|
+
then
|
|
202
90
|
```shell
|
|
203
|
-
|
|
204
|
-
rig --env dev && vue-cli-service serve --mode rig
|
|
205
|
-
#building a site in prod enviroment
|
|
206
|
-
rig --env prod && vue-cli-service build --mode rig
|
|
91
|
+
yarn install
|
|
207
92
|
```
|
|
208
93
|
|
|
94
|
+
### 4.Create and develop a new rigjs module。
|
|
95
|
+
#### 4.1 Create a git repo。
|
|
96
|
+
get git-ssh url: git@github.com:FlashHand/rig-demo-1.git
|
|
97
|
+
#### 4.2 Start developing your modules in rigjs dependencies
|
|
98
|
+
rig dev git@github.com:FlashHand/rig-demo-1.git
|
|
99
|
+
#### 4.3 Initialize your module
|
|
100
|
+
```shell
|
|
101
|
+
cd your_project_path
|
|
102
|
+
cd rig_dev/rig-demo-1
|
|
103
|
+
yarn init
|
|
104
|
+
echo "module.export={hello:()=>{console.log('hello')}}" > index.js
|
|
105
|
+
```
|
|
106
|
+
#### 4.4 Use rigjs modules in your main project。
|
|
107
|
+
```ecmascript 6
|
|
108
|
+
const {hello} = require('rig-demo-1');
|
|
109
|
+
hello();
|
|
110
|
+
```
|
|
111
|
+
#### 4.5 Use rigjs module in production。
|
|
112
|
+
publish tag
|
|
113
|
+
```shell
|
|
114
|
+
cd rig_dev/rig-demo-1
|
|
115
|
+
git add .
|
|
116
|
+
git commit -m 'demo for rig'
|
|
117
|
+
git tag 0.0.1
|
|
118
|
+
git push origin your_branch --tag
|
|
119
|
+
```
|
|
120
|
+
Modify package.rig.json5
|
|
121
|
+
- Change the module's version
|
|
122
|
+
- Set dev to false.Don't use dev mode in production and should specify the version you need.
|
|
123
|
+
```json5
|
|
124
|
+
{
|
|
125
|
+
dependencies: {
|
|
126
|
+
'rig-demo-1': {
|
|
127
|
+
source: 'git@github.com:FlashHand/rig-demo-1.git',
|
|
128
|
+
version: '0.0.1',
|
|
129
|
+
// dev:true//Don't use dev mode in production and should specify the version you need.
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
209
134
|
|
|
135
|
+
## Advantages
|
|
136
|
+
- 💡Rigjs only needs git.No need to publish packages to private registry.
|
|
137
|
+
- ⚡️Instant code sharing between multiple projects and multiple developers.Packages can be easily installed by git-ssh-url and tag.
|
|
138
|
+
- ⚙️Auto npm link in dev mode.Import or require packages just like normal node_modules with friendly code suggestion.
|
|
139
|
+
- 🔍Easily develop packages within your projects.Packages in *dev* mode are all in *rig_dev* folder.
|
|
140
|
+
- 💨Easily transform existing code into a sharable package for multiple projects.
|
|
141
|
+
- 📏Large content scale.You can share from a simple js file to multiple files that contains many pages.
|
|
142
|
+
- 🧹Flat dependencies.No need to worry complex packages' relationship.
|
|
143
|
+
|
|
144
|
+
## Goals
|
|
145
|
+
### Sharing codes or files.
|
|
146
|
+
1. Reuse codes between different developers or different projects in most flexible and unobtrusive way.
|
|
147
|
+
2. Easily turn modules into developing mode,no need to use npm link or change package.json.
|
|
148
|
+
3. Also support sharing files between projects like '.eslintrc.js' or 'tsconfig.json'...
|
|
149
|
+
4. Developing one website in multiple modules.
|
|
150
|
+
|
|
151
|
+
### Serverless CI/CD
|
|
152
|
+
1. Build multiple versions for different environments at same time.
|
|
153
|
+
2. Support deploying and publishing(Only support ali-cloud's oss and cdn by now).
|
|
154
|
+
|
|
155
|
+
### Remote modules' helper(in development)
|
|
156
|
+
- Working with webpack5's module federation.
|
|
157
|
+
- Easily active modules' developing mode.
|
|
158
|
+
- Friendly Code suggestion.
|
|
159
|
+
- Simple router that can brings you everywhere.
|
|
160
|
+
- Sandbox,state sharing....
|
|
161
|
+
|
|
162
|
+
### Current Limits
|
|
163
|
+
- Rigjs packages can share source code directly in node_modules.So transpiling or compiling might be needed.
|
|
164
|
+
- Rigjs can not remove redundant codes for remote modules.
|
|
165
|
+
- Although rigjs supports developing one website in multiple repos,
|
|
166
|
+
But they all need to be built together into one application package.
|
|
167
|
+
So it wastes time to build those unchanged modules ,which seems wrong when your website has hundreds or thousands of pages.
|
|
168
|
+
- CI/CD only supports ali-cloud's oss and cdn.I don't have plans to make it better for now.
|
|
169
|
+
|
|
170
|
+
I'm still developing new features in most flexible and unobtrusive way.So my team won't cost extra time to upgrade their applications' architecture.
|
|
171
|
+
|
|
172
|
+
Rigjs works great for my team in development of vue-apps,uni-apps,electron apps and nodejs apps.If you don't need many remote modules,it will work fine for you too.
|
|
210
173
|
|
package/README_CN.md
CHANGED
|
@@ -1,157 +1,171 @@
|
|
|
1
1
|
# rig
|
|
2
|
-
- [
|
|
3
|
-
- [
|
|
4
|
-
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
- [目标](#目标)
|
|
3
|
+
- [快速开始](#快速开始:基于rig的模块化开发)
|
|
4
|
+
- [dependencies配置](./doc/dependencies_cn.md)
|
|
5
|
+
- [CICD配置](./doc/cicd_cn.md)
|
|
6
|
+
- [share 文件共享](./doc/share_cn.md)
|
|
7
|
+
|
|
8
|
+
## 快速开始:基于rig的模块化开发
|
|
9
|
+
### 0.前提准备
|
|
10
|
+
#### 安装yarn,
|
|
11
|
+
```shell
|
|
12
|
+
yarn global add rigjs
|
|
13
|
+
```
|
|
14
|
+
rig采用yarn workspaces实现依赖晋升。[关于yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces)
|
|
15
|
+
#### NodeJS版本不低于14
|
|
16
|
+
使用 [n](https://github.com/tj/n) 更新NodeJS
|
|
17
|
+
```shell
|
|
18
|
+
yarn global add n
|
|
19
|
+
#更新到lts
|
|
20
|
+
sudo n lts
|
|
21
|
+
#或指定版本
|
|
22
|
+
sudo n 14.19.1
|
|
23
|
+
```
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
### 1.在项目中初始化rig配置。
|
|
16
26
|
|
|
17
27
|
```shell script
|
|
18
|
-
|
|
19
|
-
yarn global add rigjs
|
|
28
|
+
#在你的项目根目录中(和package.json同级)执行:
|
|
20
29
|
rig init
|
|
21
30
|
```
|
|
22
|
-
package.rig.json5
|
|
31
|
+
package.rig.json5 会被添加到工程根目录。
|
|
32
|
+
|
|
33
|
+
### 2.使用rig安装现有的代码库
|
|
34
|
+
#### 2.1 方法一:rig add
|
|
35
|
+
rig add [your git ssh url] [tag]
|
|
36
|
+
e.g.
|
|
37
|
+
```shell
|
|
38
|
+
rig add git@github.com:FlashHand/rig-demo-1.git 0.0.1
|
|
39
|
+
```
|
|
40
|
+
引用该仓库
|
|
41
|
+
```ecmascript 6
|
|
42
|
+
const {hello} = require('rig-demo-1');
|
|
43
|
+
hello();
|
|
44
|
+
```
|
|
23
45
|
|
|
24
|
-
|
|
46
|
+
#### 2.2 方法二:在package.rig.json5中修改配置
|
|
25
47
|
```json5
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// },
|
|
33
|
-
{
|
|
34
|
-
name: 'r-b',
|
|
35
|
-
source: 'git@git.domain.com:common/r-b.git',
|
|
36
|
-
version: '1.0.0',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: 'r-c',
|
|
40
|
-
source: 'git@git.domain.com:common/r-c.git',
|
|
41
|
-
version: '1.0.0',
|
|
42
|
-
dev: true
|
|
48
|
+
{
|
|
49
|
+
dependencies: {
|
|
50
|
+
'rig-demo-1': {
|
|
51
|
+
source: 'git@github.com:FlashHand/rig-demo-1.git',
|
|
52
|
+
version: '0.0.1',
|
|
53
|
+
}
|
|
43
54
|
}
|
|
44
|
-
|
|
45
|
-
```
|
|
46
|
-
version等于tag
|
|
47
|
-
|
|
48
|
-
**3.run install:**
|
|
49
|
-
```shell script
|
|
50
|
-
rig install
|
|
55
|
+
}
|
|
51
56
|
```
|
|
52
|
-
|
|
53
|
-
```shell
|
|
57
|
+
然后执行
|
|
58
|
+
```shell
|
|
54
59
|
yarn install
|
|
55
60
|
```
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
ig由cocoaprods启发。
|
|
70
|
-
不像那些流行的monorepo的解决方案。Rig是一个多库开发的集成工具。
|
|
61
|
+
### 3.在rig管理下,开发一个现有的代码库
|
|
62
|
+
#### 3.1 方法一:rig dev
|
|
63
|
+
rig dev [包名称|git-ssh-url]
|
|
64
|
+
当package已经存在于package.rig.json5
|
|
65
|
+
```shell
|
|
66
|
+
rig dev rig-demo-1
|
|
67
|
+
```
|
|
68
|
+
当package还不存在于package.rig.json5.
|
|
69
|
+
```shell
|
|
70
|
+
#安装代码包并设为开发模式
|
|
71
|
+
rig dev rig-demo-1 git@github.com:FlashHand/rig-demo-1.git
|
|
72
|
+
```
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
package.rig.json5
|
|
74
|
+
rig-demo-1会被安装到rig_dev目录下。node_modules会存在rig-demo-1的symlink.
|
|
75
|
+
#### 3.1 方法二:在package.rig.json5中修改配置
|
|
74
76
|
```json5
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
name: 'r-b',
|
|
84
|
-
source: 'git@git.domain.com:common/r-b.git',
|
|
85
|
-
version: '1.0.0',
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
name: 'r-c',
|
|
89
|
-
source: 'git@git.domain.com:common/r-c.git',
|
|
90
|
-
version: '1.0.0',
|
|
91
|
-
dev: true
|
|
77
|
+
{
|
|
78
|
+
dependencies: {
|
|
79
|
+
'rig-demo-1': {
|
|
80
|
+
source: 'git@github.com:FlashHand/rig-demo-1.git',
|
|
81
|
+
version: '0.0.1',
|
|
82
|
+
dev: true //默认是false,
|
|
83
|
+
}
|
|
92
84
|
}
|
|
93
|
-
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
然后执行
|
|
88
|
+
```shell
|
|
89
|
+
yarn install
|
|
94
90
|
```
|
|
95
|
-
package.rig.json5拥有一组模块,每个模块都可以给自己定义单独的源。
|
|
96
|
-
|
|
97
|
-
rig 会创建一个叫rigs的文件夹
|
|
98
|
-
|
|
99
|
-
当dev为true时文件的主干会被clone到rigs下
|
|
100
|
-
|
|
101
|
-
而且代码库会被自动链接到node_modules中。
|
|
102
|
-
|
|
103
|
-
#### rig如何修改package.rig.json5
|
|
104
91
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
92
|
+
### 4.制作和开发新的rig代码库。
|
|
93
|
+
#### 4.1 创建一个git仓库。
|
|
94
|
+
获取git ssh url例如: git@github.com:FlashHand/rig-demo-1.git
|
|
95
|
+
#### 4.2 在rig依赖中添加你的仓库
|
|
96
|
+
rig dev git@github.com:FlashHand/rig-demo-1.git
|
|
97
|
+
#### 4.3 开发你的rig库
|
|
98
|
+
```shell
|
|
99
|
+
cd your_project_path
|
|
100
|
+
cd rigs_dev/rig-demo-1
|
|
101
|
+
#如果项目没有初始化,执行初始化,并创建index
|
|
102
|
+
yarn init
|
|
103
|
+
echo "module.export={hello:()=>{console.log('hello')}}" > index.js
|
|
104
|
+
```
|
|
105
|
+
#### 4.4 在项目中使用rig仓库。
|
|
106
|
+
```ecmascript 6
|
|
107
|
+
const {hello} = require('rig-demo-1');
|
|
108
|
+
hello();
|
|
109
|
+
```
|
|
110
|
+
#### 4.5 在生产环境中使用rig仓库。
|
|
111
|
+
发布rig仓库的tag
|
|
112
|
+
```shell
|
|
113
|
+
cd rigs_dev/rig-demo-1
|
|
114
|
+
git add .
|
|
115
|
+
git commit -m 'demo for rig'
|
|
116
|
+
git tag 0.0.1
|
|
117
|
+
git push origin your_branch --tag
|
|
118
|
+
```
|
|
119
|
+
在package.rig.json5中修改配置
|
|
120
|
+
- 修改version
|
|
121
|
+
- 设dev为false,生产环境中不要使用dev模式,应该指定安装确定的version.
|
|
122
|
+
```json5
|
|
123
|
+
{
|
|
124
|
+
dependencies: {
|
|
125
|
+
'rig-demo-1': {
|
|
126
|
+
source: 'git@github.com:FlashHand/rig-demo-1.git',
|
|
127
|
+
version: '0.0.1',
|
|
128
|
+
// dev:true//生产环境中不要使用dev模式,应该指定安装确定的version.
|
|
118
129
|
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
119
132
|
```
|
|
120
|
-
rig机制概括起来就是分库开发,整体构建。
|
|
121
|
-

|
|
122
|
-

|
|
123
|
-
#### 主要功能
|
|
124
|
-
|
|
125
|
-
1. 更方便的进行模块化开发,
|
|
126
|
-
2. 自动集成多个开发库
|
|
127
|
-
3. 只要将dev设为true,就可以在项目中开发调试任何模块。
|
|
128
|
-
4. 采用yarn的workspaces,避免依赖冗余.
|
|
129
|
-
5. 自动对rigs中的模块做软链接。
|
|
130
|
-
6. 生产环境检查,运行rig check可以防止开发中的库被部署(dev:true),一般用于部署脚本。
|
|
131
|
-
7. 无侵入,与一般微前端方案无冲突。
|
|
132
|
-
|
|
133
|
-
## Command
|
|
134
|
-
|
|
135
|
-
### rig init
|
|
136
|
-
1. 创建"package.rig.json5"
|
|
137
|
-
2. 将配置注入到package.json中
|
|
138
|
-
3. 创建rigs文件夹
|
|
139
|
-
4. 修改.gitignore文件
|
|
140
|
-
|
|
141
|
-
### rig install
|
|
142
|
-
等价于 "yarn install"
|
|
143
|
-
|
|
144
|
-
### rig check
|
|
145
|
-
如果有模块处于开发模式(dev:true)检查不会通过,构建脚本抛出异常。
|
|
146
|
-
该命令用于部署,以确保开发模式的代码不会被发到线上。
|
|
147
|
-
|
|
148
|
-
### rig tag
|
|
149
|
-
使用package.json中的version打tag
|
|
150
|
-
//TODO:自动检查是否存在未提交代码。
|
|
151
|
-
|
|
152
|
-
### rig --env fp_test
|
|
153
|
-
该指令首先会在根目录下寻找名为'env.rig.json5'的文件,然后根据所传变量fp_test去该文件读取相应配置,
|
|
154
|
-
最后自动将该配置写入固定名称为".env.rig"的文件。注意:类似"fp_test"的变量为必传项。
|
|
155
133
|
|
|
156
|
-
|
|
157
|
-
|
|
134
|
+
## Advantages
|
|
135
|
+
- 💡Rigjs only needs git.No need to publish packages to private registry.
|
|
136
|
+
- ⚡️Instant code sharing between multiple projects and multiple developers.Packages can be easily installed by git-ssh-url and tag.
|
|
137
|
+
- ⚙️Auto npm link in dev mode.Import or require packages just like normal node_modules with friendly code suggestion.
|
|
138
|
+
- 🔍Easily develop packages within your projects.Packages in *dev* mode are all in *rig_dev* folder.
|
|
139
|
+
- 💨Easily transform existing code into a sharable package for multiple projects.
|
|
140
|
+
- 📏Large content scale.You can share from a simple js file to multiple files that contains many pages.
|
|
141
|
+
- 🧹Flat dependencies.No need to worry complex packages' relationship.
|
|
142
|
+
|
|
143
|
+
## Goals
|
|
144
|
+
### Sharing codes or files.
|
|
145
|
+
1. Reuse codes between different developers or different projects in most flexible and unobtrusive way.
|
|
146
|
+
2. Easily turn modules into developing mode,no need to use npm link or change package.json.
|
|
147
|
+
3. Also support sharing files between projects like '.eslintrc.js' or 'tsconfig.json'...
|
|
148
|
+
4. Developing one website in multiple modules.
|
|
149
|
+
|
|
150
|
+
### Serverless CI/CD
|
|
151
|
+
1. Build multiple versions for different environments at same time.
|
|
152
|
+
2. Support deploying and publishing(Only support ali-cloud's oss and cdn by now).
|
|
153
|
+
|
|
154
|
+
### Remote modules' helper(in development)
|
|
155
|
+
- Working with webpack5's module federation.
|
|
156
|
+
- Easily active modules' developing mode.
|
|
157
|
+
- Friendly Code suggestion.
|
|
158
|
+
- Simple router that can brings you everywhere.
|
|
159
|
+
- Sandbox,state sharing....
|
|
160
|
+
|
|
161
|
+
### Current Limits
|
|
162
|
+
- Rigjs packages can share source code directly in node_modules.So transpiling or compiling might be needed.
|
|
163
|
+
- Rigjs can not remove redundant codes for remote modules.
|
|
164
|
+
- Although rigjs supports developing one website in multiple repos,
|
|
165
|
+
But they all need to be built together into one application package.
|
|
166
|
+
So it wastes time to build those unchanged modules ,which seems wrong when your website has hundreds or thousands of pages.
|
|
167
|
+
- CI/CD only supports ali-cloud's oss and cdn.I don't have plans to make it better for now.
|
|
168
|
+
|
|
169
|
+
I'm still developing new features in most flexible and unobtrusive way.So my team won't cost extra time to upgrade their applications' architecture.
|
|
170
|
+
|
|
171
|
+
Rigjs works great for my team in development of vue-apps,uni-apps,electron apps and nodejs apps.If you don't need many remote modules,it will work fine for you too.
|