sparrow-ci 1.1.6 → 1.1.7

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-12 15:36:41
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2023-02-13 10:50:34
5
+ * @LastEditTime: 2024-01-05 10:39:08
6
6
  * @FilePath: /sparrow-ci/README.md
7
7
  * @Description: README
8
8
  -->
@@ -47,7 +47,6 @@ module.exports = {
47
47
  "version": "版本号",
48
48
  "description": "描述文本",
49
49
  "projectRoot": "电脑里面项目的路径",
50
- "needCheckNpmPackages": ["需要检查的包的名字"],
51
50
  "robotNum": 2,
52
51
  };
53
52
  ```
package/bin/ci.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-12 15:56:29
4
- * @LastEditors: makunkun
5
- * @LastEditTime: 2024-01-03 17:26:52
4
+ * @LastEditors: wangqi
5
+ * @LastEditTime: 2024-01-05 10:38:30
6
6
  * @FilePath: /sparrow-ci/bin/ci.js
7
7
  * @Description: ci
8
8
  */
@@ -12,7 +12,7 @@ const fs = require('fs');
12
12
  const inquirer = require('inquirer');
13
13
  const chalk = require('chalk');
14
14
  const { getProInfo, commonFilePath, configOutPut, handleList, printSuccess, printFail, printWarnning } = require('./utils/index');
15
- const { isDependentExisted, writeToFile, installAndBuild, installPackages, handleExecFile, handleFolder } = require('./utils/node_utils.js');
15
+ const { isDependentExisted, writeToFile, installPackages, handleExecFile, handleFolder } = require('./utils/node_utils.js');
16
16
  const { environment, helpDescription, robotList } = require('../ci.config');
17
17
  const { uploadCi, packNpmCi, packNpmListCi, previewCi } = require('./command');
18
18
 
@@ -32,7 +32,6 @@ class Ci {
32
32
  mainCliFilePath cli.js 文件的路径
33
33
  packageJSONPath 项目中package.json文件的位置
34
34
  cliFileExisted cli.js文件是否已经创建了,默认为false
35
- needCheckNpmPackages 需要检查更新的包
36
35
  appid 小程序id
37
36
  robotNum 上传机器人
38
37
  */
@@ -44,7 +43,6 @@ class Ci {
44
43
  mainCliFilePath = '';
45
44
  packageJSONPath = '';
46
45
  cliFileExisted = false;
47
- needCheckNpmPackages = [];
48
46
  appid = '';
49
47
  environment = environment.DEV;
50
48
  robotNum = robotList['default'];
@@ -94,7 +92,6 @@ class Ci {
94
92
  version: this.version,
95
93
  description: this.description,
96
94
  projectRoot: this.projectRoot,
97
- needCheckNpmPackages: this.needCheckNpmPackages || [],
98
95
  robotNum: this.robotNum,
99
96
  };
100
97
  }
@@ -106,7 +103,6 @@ class Ci {
106
103
  version,
107
104
  description,
108
105
  projectRoot,
109
- needCheckNpmPackages,
110
106
  robotNum,
111
107
  } = data;
112
108
  // 给相应属性赋值
@@ -114,7 +110,6 @@ class Ci {
114
110
  this.version = version;
115
111
  this.description = description;
116
112
  this.projectRoot = projectRoot;
117
- this.needCheckNpmPackages = needCheckNpmPackages || [];
118
113
  this.robotNum = robotNum;
119
114
  }
120
115
 
@@ -168,7 +163,6 @@ class Ci {
168
163
  version = this.version,
169
164
  description = this.description,
170
165
  projectRoot = this.projectRoot,
171
- needCheckNpmPackages = this.needCheckNpmPackages.join(','),
172
166
  robotNum = this.robotNum,
173
167
  } = data;
174
168
 
@@ -178,7 +172,6 @@ class Ci {
178
172
  version,
179
173
  description,
180
174
  projectRoot,
181
- needCheckNpmPackages,
182
175
  robotNum,
183
176
  };
184
177
 
@@ -233,18 +226,11 @@ class Ci {
233
226
  // 组合文件要写的内容
234
227
  formatData(filePath, isTrue = true, configParams) {
235
228
  if (isTrue) this.readCliFile(filePath);
236
- let needCheckNpmPackages = isTrue ? this.needCheckNpmPackages.join(',') : configParams.needCheckNpmPackages;
237
-
238
- let needCheckNpmPackagesArr = [];
239
- if (needCheckNpmPackages.length) {
240
- needCheckNpmPackagesArr = needCheckNpmPackages.split(',');
241
- }
242
- const needCheckNpmPackagesString = JSON.stringify(needCheckNpmPackagesArr);
243
229
  if (!isTrue) {
244
230
  const { environment, version, description, projectRoot, robotNum } = configParams;
245
- return configOutPut(environment, version, description, projectRoot, needCheckNpmPackagesString, robotNum)
231
+ return configOutPut(environment, version, description, projectRoot, robotNum)
246
232
  };
247
- return configOutPut(this.environment, this.version, this.description, this.projectRoot, needCheckNpmPackagesString, this.robotNum);
233
+ return configOutPut(this.environment, this.version, this.description, this.projectRoot, this.robotNum);
248
234
  }
249
235
 
250
236
  async online() {
@@ -279,8 +265,6 @@ class Ci {
279
265
  // 上传代码
280
266
  // @isPublish 是否自动上传
281
267
  async upload(type = 'upload') {
282
- const installAndBuildSuccess = await installAndBuild(this.needCheckNpmPackages, this.packageJSONPath, this.miniprogramRoot); // 检查安装的版本和package.json文件中的版本是否一致,不一致的话要重新安装和构建
283
- if (!installAndBuildSuccess) return;
284
268
  // 获取用户填写的版本和描述,写入cli
285
269
  if (type !== 'online') {
286
270
  const answers = await this.showSimpleCliConfig(type);
@@ -317,17 +301,14 @@ class Ci {
317
301
 
318
302
  // 构建
319
303
  async buildNpm() {
320
- if(this.packNpmRelationList.length>0){
321
- const data = await packNpmListCi(this.packNpmRelationList);
322
- return data;
323
- }else{
324
- const data = await packNpmCi({
304
+ if(this.packNpmRelationList.length > 0){
305
+ return await packNpmListCi(this.packNpmRelationList);
306
+ } else {
307
+ return await packNpmCi({
325
308
  packageJSONPath: this.packageJSONPath,
326
309
  miniprogramRoot: this.miniprogramRoot,
327
310
  });
328
- return data;
329
311
  }
330
-
331
312
  }
332
313
 
333
314
  // 预览
@@ -2,7 +2,7 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-12 17:10:25
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2023-02-13 14:02:17
5
+ * @LastEditTime: 2024-01-05 10:40:10
6
6
  * @FilePath: /sparrow-ci/bin/utils/index.js
7
7
  * @Description: 公用方法
8
8
  */
@@ -55,14 +55,13 @@ function commonFilePath(pathUrl, file) {
55
55
  }
56
56
 
57
57
  // 输出需要的配置
58
- function configOutPut(environment, version, description, projectRoot, needCheckNpmPackagesString, robotNum) {
58
+ function configOutPut(environment, version, description, projectRoot, robotNum) {
59
59
  const configDataString =
60
60
  `module.exports = {
61
61
  "environment": "${environment}",
62
62
  "version": "${version}",
63
63
  "description": "${description}",
64
64
  "projectRoot": "${projectRoot}",
65
- "needCheckNpmPackages": ${needCheckNpmPackagesString},
66
65
  "robotNum": ${robotNum},
67
66
  };
68
67
  `;
@@ -130,12 +129,6 @@ function handleList(listName, configObj, independentSubPackages) {
130
129
  default: projectRoot,
131
130
  message: '项目根路径:'
132
131
  },
133
- {
134
- name: 'needCheckNpmPackages',
135
- type: 'input',
136
- default: '',
137
- message: '需要检查更新的组件(以,分隔):',
138
- },
139
132
  {
140
133
  name: 'name',
141
134
  type: 'input',
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-26 10:39:50
4
- * @LastEditors: makunkun
5
- * @LastEditTime: 2024-01-03 17:38:02
4
+ * @LastEditors: wangqi
5
+ * @LastEditTime: 2024-01-05 10:39:57
6
6
  * @FilePath: /sparrow-ci/bin/utils/node_utils.js
7
7
  * @Description: 工具方法
8
8
  */
@@ -47,8 +47,8 @@ function writeToFile(filePath, configDataString, isLog = true) {
47
47
 
48
48
  // 提问用户初始化相关的问题
49
49
  async function askUsersInitQuestions(params) {
50
- const { environment, version, description, projectRoot, needCheckNpmPackages } = params;
51
- const promptArr = handleList(['environment', 'version', 'description', 'projectRoot', 'needCheckNpmPackages'], { environment, version, description, projectRoot, needCheckNpmPackages });
50
+ const { environment, version, description, projectRoot } = params;
51
+ const promptArr = handleList(['environment', 'version', 'description', 'projectRoot'], { environment, version, description, projectRoot });
52
52
  return new Promise((resolve) => {
53
53
  inquirer
54
54
  .prompt(promptArr)
@@ -71,66 +71,6 @@ async function askUsersInitQuestions(params) {
71
71
  });
72
72
  }
73
73
 
74
- // 检查npm包的版本是否一直
75
- function checkNpmVersionConsistent(needCheckNpmPackages, packageJSONPath) {
76
- return new Promise((resolve) => {
77
- const checkedPackagesCount = needCheckNpmPackages.length;
78
-
79
- const packageJSON = require(packageJSONPath);
80
-
81
- let inconsistentPackages = []; // 版本不一致的包
82
- let count = 0;
83
-
84
- if (checkedPackagesCount < 1) {
85
- resolve(inconsistentPackages);
86
- return;
87
- }
88
-
89
- for (let i = 0; i < checkedPackagesCount; i++) {
90
- const packageName = needCheckNpmPackages[i];
91
- if (packageName) {
92
- let installedPackageVersion = spawnSync('npm', ['ls', packageName]); // 检查这个包本地安装的版本
93
- installedPackageVersion = installedPackageVersion.stdout.toString().trim();
94
- const packageNameIndex = installedPackageVersion.indexOf(packageName);
95
- installedPackageVersion = packageNameIndex === -1 ? '' : installedPackageVersion.slice(packageNameIndex + packageName.length + 1);
96
-
97
- const packageVersionInPackageJSON = packageJSON.dependencies[packageName]; // 本地package.json文件中包的版本
98
- let packageLocalVersion = packageVersionInPackageJSON;
99
- if (packageVersionInPackageJSON.indexOf('^') > -1) { // 如果版本号包含^,需要把^去掉
100
- packageLocalVersion = packageVersionInPackageJSON.slice(1);
101
- }
102
-
103
- if (installedPackageVersion !== packageLocalVersion) {
104
- inconsistentPackages.push(packageName + `@${packageLocalVersion}`);
105
- }
106
- }
107
- count++;
108
- if (count === checkedPackagesCount) {
109
- resolve(inconsistentPackages);
110
- }
111
- }
112
- });
113
- }
114
-
115
- // 安装和进行npm构建
116
- async function installAndBuild(needCheckNpmPackages, packageJSONPath, miniprogramRoot) {
117
- const checkedPackagesCount = needCheckNpmPackages.length;
118
- if (checkedPackagesCount === 0) return true; // 没有设置要检查的包
119
- const checkConsistentSpinner = ora('检查package.json文件中包的版本与实际安装的版本是否一致...').start();
120
- const inconsistentPackages = await checkNpmVersionConsistent(); // 检查npm包的版本是否一致
121
- checkConsistentSpinner.stop();
122
- if (inconsistentPackages.length < 1) {
123
- console.log('package.json文件中包的版本与实际安装的版本一致', chalk.magenta('不必重新构建'));
124
- return true;
125
- }
126
- const inconsistentPackagesStr = inconsistentPackages.join(',');
127
- // package.json中包的版本和实际安装的版本不一致时,重新进行npm install 和 npm 构建
128
- console.log(`package.json文件中`, chalk.magenta(`${inconsistentPackagesStr}`), `包的版本与实际安装的版本不同,`, chalk.magenta(`重新进行npm安装和npm构建中,请稍候...`));
129
- const installSuccess = await installPackages(packageJSONPath, inconsistentPackages);
130
- if (!installSuccess) return; // 依赖没有安装成功直接返回
131
- return await packNpmCi({packageJSONPath, miniprogramRoot});
132
- }
133
-
134
74
  // 安装依赖
135
75
  async function installPackages(packageJSONPath, packageNames = []) {
136
76
  return new Promise((resolve) => {
@@ -231,7 +171,6 @@ module.exports = {
231
171
  isDependentExisted,
232
172
  writeToFile,
233
173
  askUsersInitQuestions,
234
- installAndBuild,
235
174
  installPackages,
236
175
  handleExecFile,
237
176
  handleFolder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparrow-ci",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "基于miniprogram-ci开发的小程序命令行工具",
5
5
  "main": "",
6
6
  "bin": {