rigjs 2.0.0-alpha.7 → 2.0.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.
@@ -12,21 +12,22 @@
12
12
  access_secret: '${as}',
13
13
  root_path: '/',
14
14
  uri_rewrite: {
15
- original: 'view-fp',
15
+ original: '/',
16
16
  }
17
17
  },
18
18
  endpoints: {
19
19
  'ykp/test/oem1': {
20
- build: 'yarn build:oem1',
20
+ build: 'cross-env PUBLIC_PATH=$public_path npx vue-cli-service build --mode oem1',
21
21
  defines: {
22
22
  NGINX_REPLACE_B: 'http://',
23
23
  NGINX_REPLACE_A: '替换了',
24
+ RIG_REPLACE_PUBLIC: '$public_path',
24
25
  },
25
26
  domain: 'cdn.rys.com',
26
27
  },
27
28
  'ykp/test/oem2': {
28
29
  // build: 'yarn build:test:oem2',
29
- build: 'yarn build:oem2',
30
+ build: 'cross-env PUBLIC_PATH=$public_path npx vue-cli-service build --mode oem2',
30
31
  defines: {
31
32
  NGINX_REPLACE_B: 'http://',
32
33
  NGINX_REPLACE_A: '替换了',
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
  ]
@@ -1,26 +1,28 @@
1
- import fsHelper from '../utils/fsHelper';
2
1
  import CICD, {Define} from '@/classes/cicd/CICD';
3
2
  import CICDCmd from '@/classes/cicd/CICDCmd';
4
3
  import shell from 'shelljs';
5
4
  import path from 'path';
6
5
  import fs from 'fs';
7
- const replaceDefine = (target:string,defines?:Define)=>{
6
+
7
+ const JSON5 = require('json5');
8
+
9
+ const replaceDefine = (target: string, defines?: Define) => {
8
10
  const dirs = fs.readdirSync(target);
9
- for (let dir of dirs){
11
+ for (let dir of dirs) {
10
12
  const stat = fs.statSync(path.join(target, dir));
11
- if (stat.isDirectory()){
12
- replaceDefine(path.join(target, dir),defines);
13
- }else{
14
- if (defines){
13
+ if (stat.isDirectory()) {
14
+ replaceDefine(path.join(target, dir), defines);
15
+ } else {
16
+ if (defines) {
15
17
  const namePieces = dir.split('.');
16
18
  const fileType = namePieces[namePieces.length - 1];
17
- if (['js','ts'].indexOf(fileType)>=0){
19
+ if (['js', 'ts','html'].indexOf(fileType) >= 0) {
18
20
  let file = fs.readFileSync(path.join(target, dir)).toString();
19
21
  const replaceArr = Object.keys(defines);
20
- for (let replace of replaceArr){
21
- file = file.replace(new RegExp(replace,'g'),defines[replace] as string);
22
+ for (let replace of replaceArr) {
23
+ file = file.replace(new RegExp(replace, 'g'), defines[replace] as string);
22
24
  }
23
- fs.writeFileSync(path.join(target, dir),file);
25
+ fs.writeFileSync(path.join(target, dir), file);
24
26
  }
25
27
  }
26
28
  }
@@ -34,10 +36,20 @@ export default async (cmd: any) => {
34
36
  console.log(cicd)
35
37
  //build by cicdCmd and cicdConfig
36
38
  console.log(cicdCmd.endpoints);
37
-
39
+ const regexPublicPath = new RegExp('\\$public_path', 'g');
38
40
  for (let i = 0; i < cicdCmd.endpoints.length; i++) {
39
41
  const ep = cicdCmd.endpoints[i];
40
- ep.build = ep.build.replace('${public_path}', ep.publicPath);
42
+
43
+ ep.build = ep.build.replace(regexPublicPath, ep.publicPath);
44
+ try {
45
+ //替换define中的$public_path
46
+ Object.keys(ep.defines).forEach(key=>{
47
+ ep.defines[key] = ep.defines[key].replace(regexPublicPath, ep.publicPath);
48
+ })
49
+ } catch (e) {
50
+ console.log('JSON5 error:', ep.defines,e.message);
51
+ }
52
+ console.log('exec build:', ep, ep.build, ep.defines);
41
53
  shell.exec(ep.build);
42
54
  replaceDefine(path.join(cicd.source.root_path, ep.dir), ep.defines);
43
55
  }
@@ -28,6 +28,7 @@ export interface DeployTarget {
28
28
  root_path: '/';
29
29
  uri_rewrite: {
30
30
  original: string;
31
+ original_regexp: string;
31
32
  final?: string;
32
33
  };
33
34
  }
@@ -1,50 +1,78 @@
1
- import aliOSS from "ali-oss";
2
- import fs from "fs";
3
- import { DeployTarget } from "../CICD";
1
+ import aliOSS from 'ali-oss';
2
+ import fs from 'fs';
3
+ import {DeployTarget} from '../CICD';
4
+ import os from 'os';
5
+ import {cat} from 'shelljs';
6
+
4
7
  class AliOSS {
5
- ossClient: aliOSS;
6
- constructor(target: DeployTarget) {
7
- this.ossClient = new aliOSS({
8
- region: target.region,
9
- accessKeyId: target.access_key,
10
- accessKeySecret: target.access_secret,
11
- bucket: target.bucket,
12
- timeout: 600000,
13
- });
14
- }
15
-
16
- private async progress(p: number, filePath: string, ossPath: string) {
17
- // 上传进度。
18
- process.stdout.clearLine(1);
19
- process.stdout.cursorTo(0);
20
- process.stdout.write(
21
- `progress: ${p.toFixed(2)}%, Upload '${filePath}' To OSS_PATH:${ossPath}`
22
- );
23
- }
24
-
25
- public async putStreamFiles(
26
- filesList: string[],
27
- ossBasePath: string,
28
- dir: string
29
- ) {
30
- for (let i = 0; i < filesList.length; i++) {
31
- const filePath = filesList[i].split("dist\\")[1];
32
- const ossPath =
33
- ossBasePath + filePath.replace(/\\/g, "/").replace(dir, "");
34
- const fileResult = await this.ossClient.putStream(
35
- ossPath,
36
- fs.createReadStream(filesList[i])
8
+ ossClient: aliOSS;
9
+
10
+ constructor(target: DeployTarget) {
11
+ this.ossClient = new aliOSS({
12
+ region: target.region,
13
+ accessKeyId: target.access_key,
14
+ accessKeySecret: target.access_secret,
15
+ bucket: target.bucket,
16
+ timeout: 600000,
17
+ });
18
+ }
19
+
20
+ private async progress(p: number, filePath: string, ossPath: string) {
21
+ // 上传进度。
22
+ try {
23
+ process.stdout.clearLine(1);
24
+ process.stdout.cursorTo(0);
25
+ } catch (e) {
26
+
27
+ }
28
+ try{
29
+ process.stdout.write(
30
+ `progress: ${p.toFixed(2)}%, Upload '${filePath}' To OSS_PATH:${ossPath}`
37
31
  );
38
- if (fileResult.res.status !== 200) {
39
- throw new Error('Upload OSS Error')
40
- }
41
- // if (fileResult.res.status === 200) {
42
- // const p = ((i + 1) * 100) / filesList.length;
43
- // this.progress(p, filesList[i], ossPath);
44
- // }
32
+ }catch (e) {
33
+
45
34
  }
46
- console.log("\n");
47
- }
35
+
36
+ }
37
+
38
+ public async putStreamFiles(
39
+ filesList: string[],
40
+ ossBasePath: string,
41
+ dir: string,
42
+ rootPath: string
43
+ ) {
44
+ for (let i = 0; i < filesList.length; i++) {
45
+ let filePath = '';
46
+ if (os.platform() === 'win32') {
47
+ filePath = filesList[i].split(`${rootPath}\\`)[1];
48
+ } else {
49
+ filePath = filesList[i].split(`${rootPath}/`)[1];
50
+ }
51
+ const ossPath =
52
+ ossBasePath + filePath.replace(/\\/g, '/').replace(dir, '');
53
+
54
+ //@ts-ignore
55
+ let options: aliOSS.PutStreamOptions = {
56
+ contentLength: fs.statSync(filesList[i]).size,
57
+ };
58
+ if (filesList[i].includes('index.html')) {
59
+ options = Object.assign({headers: {'Cache-Control': 'max-age=0'}});
60
+ }
61
+ const fileResult = await this.ossClient.putStream(
62
+ ossPath,
63
+ fs.createReadStream(filesList[i]),
64
+ options
65
+ );
66
+ if (fileResult.res.status !== 200) {
67
+ throw new Error('Upload OSS Error');
68
+ }
69
+ if (fileResult.res.status === 200) {
70
+ const p = ((i + 1) * 100) / filesList.length;
71
+ this.progress(p, filesList[i], ossPath);
72
+ }
73
+ }
74
+ console.log('\n');
75
+ }
48
76
  }
49
77
 
50
78
  export default AliOSS;
@@ -7,6 +7,14 @@ import { DeployTarget } from '../CICD';
7
7
 
8
8
  type TFlag = 'break' | 'enhance_break' | null;
9
9
 
10
+ enum CDNInterfaceEnum {
11
+ BatchSetCdnDomainConfig = 'BatchSetCdnDomainConfig', //批量修改域名信息
12
+ RefreshObjectCaches = 'RefreshObjectCaches', //刷新节点上的文件内容
13
+ PushObjectCache = 'PushObjectCache', //预热CDN节点
14
+ DescribeRefreshTaskById = 'DescribeRefreshTaskById', //通过任务编号查询刷新预热任务信息
15
+ DescribeCdnDomainConfigs = 'DescribeCdnDomainConfigs', // 获取加速域名的配置信息
16
+ }
17
+
10
18
  class CDN {
11
19
  AccessKeySecret: string;
12
20
  AccessKeyId: string;
@@ -100,7 +108,7 @@ class CDN {
100
108
  });
101
109
  });
102
110
 
103
- const data = await this.getCdnData('BatchSetCdnDomainConfig', {
111
+ const data = await this.getCdnData(CDNInterfaceEnum.BatchSetCdnDomainConfig, {
104
112
  DomainNames: domainName,
105
113
  Functions: JSON.stringify(Functions),
106
114
  });
@@ -126,7 +134,7 @@ class CDN {
126
134
  if (objectType) {
127
135
  param = Object.assign(param, { ObjectType: objectType });
128
136
  }
129
- const data = await this.getCdnData('RefreshObjectCaches', param);
137
+ const data = await this.getCdnData(CDNInterfaceEnum.RefreshObjectCaches, param);
130
138
  return data;
131
139
  } catch (e) {
132
140
  console.error('Error:');
@@ -141,7 +149,7 @@ class CDN {
141
149
  * @returns
142
150
  */
143
151
  async pushCache(objectPath: string) {
144
- const data = await this.getCdnData('PushObjectCache', {
152
+ const data = await this.getCdnData(CDNInterfaceEnum.PushObjectCache, {
145
153
  ObjectPath: objectPath,
146
154
  });
147
155
  return data;
@@ -154,7 +162,7 @@ class CDN {
154
162
  */
155
163
  async describeRefreshTaskById(taskIds: string) {
156
164
  try {
157
- const data = await this.getCdnData('DescribeRefreshTaskById', {
165
+ const data = await this.getCdnData(CDNInterfaceEnum.DescribeRefreshTaskById, {
158
166
  TaskId: taskIds,
159
167
  });
160
168
  return data;
@@ -166,14 +174,14 @@ class CDN {
166
174
  }
167
175
 
168
176
  /**
169
- * 刷新CDN节点
177
+ * 获取加速域名的配置信息
170
178
  * @param {加速域名} domainName
171
179
  * @param {功能配置ID} configId
172
180
  * @returns
173
181
  */
174
182
  async describeCdnDomainConfigs(domainName: string, configId?: string) {
175
183
  try {
176
- const data = await this.getCdnData('DescribeCdnDomainConfigs', {
184
+ const data = await this.getCdnData(CDNInterfaceEnum.DescribeCdnDomainConfigs, {
177
185
  DomainName: domainName,
178
186
  ConfigId: configId,
179
187
  });
@@ -7,6 +7,10 @@ interface EndpointInfo {
7
7
  target: string;
8
8
  domain: string;
9
9
  defines: Define;
10
+ uri_rewrite: {
11
+ original: string,
12
+ original_regexp: string;
13
+ }
10
14
  }
11
15
 
12
16
  export interface EndpointDict {
@@ -24,6 +28,10 @@ class Endpoint {
24
28
 
25
29
  publicPath: string = '';
26
30
  defines: Define;
31
+ uri_rewrite: {
32
+ original: string,
33
+ original_regexp: string;
34
+ } | undefined ;
27
35
 
28
36
 
29
37
  constructor(dir: string, info: EndpointInfo, schema: DirLevel[]) {
@@ -36,6 +44,7 @@ class Endpoint {
36
44
  this.build = info.build;
37
45
  this.domain = info.domain;
38
46
  this.defines = info.defines;
47
+ this.uri_rewrite = info.uri_rewrite;
39
48
  }
40
49
 
41
50
 
@@ -27,6 +27,7 @@ export default async (cmd: any) => {
27
27
  const cicd = CICD.createByDefault(cmd);
28
28
  //construct cmd object
29
29
  const cicdCmd = new CICDCmd(cmd, cicd);
30
+ console.log('cicdCmd:', cicdCmd.endpoints);
30
31
 
31
32
  const target = Array.isArray(cicdCmd.cicd.target)
32
33
  ? cicdCmd.cicd.target[0]
@@ -44,7 +45,8 @@ export default async (cmd: any) => {
44
45
  await aliOss.putStreamFiles(
45
46
  filesList,
46
47
  cicdCmd.endpoints[i].deployDir.replace(/\\/g, '/'),
47
- cicdCmd.endpoints[i].dir
48
+ cicdCmd.endpoints[i].dir,
49
+ cicd.source.root_path,
48
50
  );
49
51
  filesList = [];
50
52
  }
@@ -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
  }