sparrow-ci 1.1.3 → 1.1.4

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: 2022-09-24 13:15:49
5
+ * @LastEditTime: 2023-02-13 10:50:34
6
6
  * @FilePath: /sparrow-ci/README.md
7
7
  * @Description: README
8
8
  -->
@@ -27,7 +27,7 @@ npm install sparrow-ci --save-dev
27
27
  ```json
28
28
  "scripts": {
29
29
  ...
30
- "ci": "ci "
30
+ "ci": "ci"
31
31
  },
32
32
  ```
33
33
 
@@ -39,7 +39,7 @@ npm install sparrow-ci --save-dev
39
39
 
40
40
  设置 -> 安全设置 -> 服务端口
41
41
 
42
- 2.执行`cli`指令初始化之后,会生成一个`cli.js`文件,文件内容是这样的:
42
+ 2.执行`ci`指令初始化之后,会生成一个`cli.js`文件,文件内容是这样的:
43
43
 
44
44
  ```javascript
45
45
  module.exports = {
@@ -47,7 +47,8 @@ module.exports = {
47
47
  "version": "版本号",
48
48
  "description": "描述文本",
49
49
  "projectRoot": "电脑里面项目的路径",
50
- "needCheckNpmPackages": ["需要检查的包的名字"]
50
+ "needCheckNpmPackages": ["需要检查的包的名字"],
51
+ "robotNum": 2,
51
52
  };
52
53
  ```
53
54
 
@@ -59,14 +60,11 @@ module.exports = {
59
60
 
60
61
  | 选项 | 简写 | 作用 |
61
62
  | --------------- | ---- | --------------------------- |
62
- | --publish | -pub | 上传正式代码 |
63
63
  | --upload | -u | 上传测试代码 |
64
64
  | --preview | -p | 预览 |
65
65
  | --switch | -s | 切换环境 |
66
66
  | --build-npm | -b | npm构建 |
67
67
  | --help | -h | 描述如何使用 |
68
- | --edit-live | -e | 编辑live直播插件json |
69
- | --git-pull | -g | 拉取远端master代码 |
70
68
  | --clone | -c | 克隆文件夹 |
71
69
  | --robot | -r | 修改开发者机器人id |
72
70
 
package/bin/ci.js CHANGED
@@ -2,17 +2,17 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-12 15:56:29
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2023-02-10 16:17:16
5
+ * @LastEditTime: 2023-02-14 11:06:15
6
6
  * @FilePath: /sparrow-ci/bin/ci.js
7
- * @Description:
7
+ * @Description: ci
8
8
  */
9
9
 
10
10
  const path = require('path');
11
11
  const fs = require('fs');
12
12
  const inquirer = require('inquirer');
13
13
  const chalk = require('chalk');
14
- const { getProInfo, commonFilePath, configOutPut, createVersion, handleList, printSuccess, printFail, printWarnning, handleVersion } = require('./utils/index');
15
- const { isDependentExisted, writeToFile, installAndBuild, installPackages, handleLivePlugin, handleExecFile, handleFolder } = require('./utils/node_utils.js');
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');
16
16
  const { environment, helpDescription, robotList } = require('../ci.config');
17
17
  const { uploadCi, packNpmCi, previewCi } = require('./command');
18
18
 
@@ -43,7 +43,6 @@ class Ci {
43
43
  subPackages = '';
44
44
  mainCliFilePath = '';
45
45
  packageJSONPath = '';
46
- versionJSONPath = '';
47
46
  cliFileExisted = false;
48
47
  needCheckNpmPackages = [];
49
48
  appid = '';
@@ -66,7 +65,6 @@ class Ci {
66
65
  this.independentSubPackages = this.subPackages.filter(inPackage => inPackage.independent);
67
66
  this.mainCliFilePath = path.join(this.miniprogramRoot, 'cli.js');
68
67
  this.packageJSONPath = path.join(this.projectRoot, 'package.json');
69
- this.versionJSONPath = path.join(this.projectRoot, 'version.json');
70
68
  // 独立分包是否存在
71
69
  isDependentExisted(this.miniprogramRoot, this.independentSubPackages);
72
70
  // cli.js是否存在
@@ -95,7 +93,7 @@ class Ci {
95
93
  version: this.version,
96
94
  description: this.description,
97
95
  projectRoot: this.projectRoot,
98
- needCheckNpmPackages: this.needCheckNpmPackages,
96
+ needCheckNpmPackages: this.needCheckNpmPackages || [],
99
97
  robotNum: this.robotNum,
100
98
  };
101
99
  }
@@ -115,7 +113,7 @@ class Ci {
115
113
  this.version = version;
116
114
  this.description = description;
117
115
  this.projectRoot = projectRoot;
118
- this.needCheckNpmPackages = needCheckNpmPackages;
116
+ this.needCheckNpmPackages = needCheckNpmPackages || [];
119
117
  this.robotNum = robotNum;
120
118
  }
121
119
 
@@ -154,11 +152,9 @@ class Ci {
154
152
  // 读取cli.js文件的信息
155
153
  readCliFile(filePath) {
156
154
  const cliFileData = require(filePath);
157
- const { version, description } = require(this.versionJSONPath);
158
155
  // 把package里的版本和版本描述同步到cli中,当使用cli -u时写入到cli
159
- // 22.1.8新加miniapp_version
160
- cliFileData.version = version;
161
- cliFileData.description = description || ''
156
+ cliFileData.version = this.version || '';
157
+ cliFileData.description = this.description || ''
162
158
  this.setConfigInfo(cliFileData);
163
159
  }
164
160
 
@@ -220,6 +216,9 @@ class Ci {
220
216
  resolve(false);
221
217
  return;
222
218
  }
219
+ if (this.robotNum === 1 && type === 'upload') {
220
+ answers.robotNum = robotList['default'];
221
+ }
223
222
  await this.writeCliFile(answers);
224
223
  resolve(answers);
225
224
  })
@@ -251,17 +250,6 @@ class Ci {
251
250
  await this.upload('online');
252
251
  }
253
252
 
254
- async publish() {
255
- // 拉取master
256
- await this.pull();
257
- // 处理直播插件 默认添加
258
- const writeFileSuccess = await handleLivePlugin(this.miniprogramRoot);
259
- if (writeFileSuccess) {
260
- printSuccess(`直播插件${writeFileSuccess}`);
261
- }
262
- await this.upload('publish');
263
- }
264
-
265
253
  // 读取git tag 修改配置
266
254
  async changeVerConfig() {
267
255
  try {
@@ -304,9 +292,14 @@ class Ci {
304
292
  if (version && description) {
305
293
  this.version = version;
306
294
  this.description = description;
295
+ await this.writeCliFile();
307
296
  }
308
- await this.writeCliFile();
309
297
  }
298
+
299
+ // if (this.robotNum === 1 && type === 'upload') {
300
+ // this.robotNum = robotList['default'];
301
+ // await this.writeCliFile();
302
+ // }
310
303
 
311
304
  await uploadCi({
312
305
  projectPath: this.projectRoot,
@@ -318,11 +311,7 @@ class Ci {
318
311
  });
319
312
 
320
313
  if (type === 'online') return;
321
- const packageObj = require(this.versionJSONPath);
322
- packageObj.version = handleVersion(this.version);
323
- packageObj.description = this.description;
324
- const packageStr = JSON.stringify(packageObj, null, 2);
325
- writeToFile(this.versionJSONPath, packageStr);
314
+
326
315
  console.log(`上传成功后可至微信小程序管理后台 ${chalk.blue('https://mp.weixin.qq.com/wxamp/wacodepage/getcodepage')} 将上传的版本选为体验版`);
327
316
  }
328
317
 
@@ -347,30 +336,6 @@ class Ci {
347
336
  })
348
337
  }
349
338
 
350
- // 添加/删除直播插件
351
- subscribe() {
352
- let promptArr = handleList(['status'], { status: 'add' });
353
- inquirer
354
- .prompt(promptArr)
355
- .then(async (answers) => {
356
- const writeFileSuccess = await handleLivePlugin(this.miniprogramRoot, answers.status);
357
- if (writeFileSuccess) {
358
- printSuccess(`直播插件${writeFileSuccess}`);
359
- }
360
- })
361
- .catch(error => {
362
- printFail(`${error}`);
363
- });
364
- }
365
-
366
- // 拉取远端代码
367
- async pull() {
368
- //获取文件路径
369
- const filepath = path.join(__dirname, '../git.sh');
370
- // 执行拉取
371
- await handleExecFile(filepath);
372
- }
373
-
374
339
  // 克隆文件夹(克隆到独立分包)
375
340
  clone() {
376
341
  handleFolder(this.independentSubPackages, this.miniprogramRoot);
package/bin/main.js CHANGED
@@ -3,7 +3,7 @@
3
3
  /*
4
4
  * @Author: wangqi
5
5
  * @Date: 2020-11-06 13:33:56
6
- * @LastEditTime: 2022-09-24 11:35:50
6
+ * @LastEditTime: 2023-02-13 10:56:18
7
7
  * @LastEditor: wangqi
8
8
  * @Description: 脚手架的类
9
9
  */
@@ -13,14 +13,11 @@ const Ci = require('./ci');
13
13
 
14
14
  // 设置命令行的选项
15
15
  program
16
- .option('-o, --online', '自动发布代码')
17
- .option('-pub, --publish', '发布正式环境代码')
16
+ .option('-onlinePublishCode, --online-publish-code', '自动发布代码')
18
17
  .option('-u, --upload', '上传代码')
19
18
  .option('-p, --preview', '预览')
20
19
  .option('-s, --switch', '切换环境')
21
20
  .option('-b, --build-npm', 'npm构建')
22
- .option('-e, --edit-live', '编辑live直播插件json')
23
- .option('-g, --git-pull', '拉取远端master代码')
24
21
  .option('-c, --clone', '克隆文件夹')
25
22
  .option('-r, --robot', '初始化个人上传账号')
26
23
  .option('-h, --help', '描述如何使用')
@@ -32,12 +29,9 @@ async function main () {
32
29
  // 等待实例初始化完成
33
30
  await ci.init();
34
31
  switch (true) {
35
- case Boolean(program.online): // 自动发布代码
32
+ case Boolean(program.onlinePublishCode): // 自动发布代码
36
33
  ci.online();
37
34
  break;
38
- case Boolean(program.publish): // 发布正式环境代码
39
- ci.publish();
40
- break;
41
35
  case Boolean(program.upload): // 上传
42
36
  ci.upload();
43
37
  break;
@@ -50,16 +44,10 @@ async function main () {
50
44
  case Boolean(program.buildNpm): // npm构建
51
45
  ci.buildNpm();
52
46
  break;
53
- case Boolean(program.editLive): // 编辑直播插件
54
- ci.subscribe();
55
- break;
56
- case Boolean(program.gitPull): // 编辑直播插件
57
- ci.pull();
58
- break;
59
- case Boolean(program.clone): // 编辑直播插件
47
+ case Boolean(program.clone): // 克隆
60
48
  ci.clone();
61
49
  break;
62
- case Boolean(program.robot): // 编辑直播插件
50
+ case Boolean(program.robot): // 修改上传机器人
63
51
  ci.robot(program.args[0]);
64
52
  break;
65
53
  case Boolean(program.help): // 查看帮助
@@ -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-07 17:22:11
5
+ * @LastEditTime: 2023-02-13 14:02:17
6
6
  * @FilePath: /sparrow-ci/bin/utils/index.js
7
7
  * @Description: 公用方法
8
8
  */
@@ -35,11 +35,18 @@ function handleVersion(miniappVersion) {
35
35
 
36
36
  // 获取项目版本和描述
37
37
  function getProInfo(projectRoot) {
38
- const versionJson = commonFilePath(projectRoot, 'version.json'); // 项目versionJson的路径
39
- const { version, description } = versionJson;
40
- return {
41
- version,
42
- description,
38
+ try {
39
+ const config = commonFilePath(projectRoot, '/src/cli.js'); // 项目versionJson的路径
40
+ const { version, description } = config;
41
+ return {
42
+ version,
43
+ description,
44
+ }
45
+ } catch (err) {
46
+ return {
47
+ version: '',
48
+ description: '',
49
+ }
43
50
  }
44
51
  }
45
52
 
@@ -2,7 +2,7 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-26 10:39:50
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2023-02-10 12:55:39
5
+ * @LastEditTime: 2023-02-13 10:44:24
6
6
  * @FilePath: /sparrow-ci/bin/utils/node_utils.js
7
7
  * @Description: 工具方法
8
8
  */
@@ -159,46 +159,6 @@ async function installPackages(packageJSONPath, packageNames = []) {
159
159
  });
160
160
  }
161
161
 
162
- // 处理直播插件
163
- function handleLivePlugin(pathFile, status = 'add') {
164
- return new Promise((resolve, reject) => {
165
- liveJsonArr.forEach(item => {
166
- readFile(path.join(pathFile, item), 'utf8', (err, data) => {
167
- if (err) {
168
- reject(err);
169
- return
170
- }
171
-
172
- const configComponent = JSON.parse(data);
173
- let { usingComponents } = configComponent;
174
-
175
- if (!usingComponents) reject(err);
176
-
177
- if (status === 'add') { // 添加
178
- if (usingComponents.subscribe) {
179
- resolve('已添加!');
180
- return;
181
- }
182
- usingComponents.subscribe = liveUrl;
183
- } else { // 删除
184
- if (!usingComponents.subscribe) {
185
- resolve('已删除!');
186
- return;
187
- };
188
- delete usingComponents.subscribe;
189
- }
190
- writeFile(path.join(pathFile, item), JSON.stringify(configComponent, null, "\t"), "utf8", (err1) => {
191
- if (err1) {
192
- reject(err1);
193
- return;
194
- }
195
- resolve(status === 'add' ? '添加成功' : '删除成功');
196
- })
197
- });
198
- });
199
- });
200
- }
201
-
202
162
  async function handleExecFile(filePath) {
203
163
  const { stdout, stderr } = await execFile(filePath, { cwd: '.' });
204
164
  console.log('===================================');
@@ -273,7 +233,6 @@ module.exports = {
273
233
  askUsersInitQuestions,
274
234
  installAndBuild,
275
235
  installPackages,
276
- handleLivePlugin,
277
236
  handleExecFile,
278
237
  handleFolder,
279
238
  }
package/ci.config.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-04-29 17:18:33
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2022-09-24 13:10:55
5
+ * @LastEditTime: 2023-02-13 10:20:52
6
6
  * @FilePath: /sparrow-ci/ci.config.js
7
7
  * @Description: 全局配置文件
8
8
  */
@@ -36,14 +36,11 @@ module.exports = {
36
36
 
37
37
  | 选项 | 简写 | 作用 |
38
38
  | --------------- | ---- | --------------------------- |
39
- | --publish | -pub | 上传正式代码 |
40
39
  | --upload | -u | 上传测试代码 |
41
40
  | --preview | -p | 预览 |
42
41
  | --switch | -s | 切换环境 |
43
42
  | --build-npm | -b | npm构建 |
44
43
  | --help | -h | 描述如何使用 |
45
- | --edit-live | -e | 编辑live直播插件json |
46
- | --git-pull | -g | 拉取远端master代码 |
47
44
  | --clone | -c | 克隆文件夹 |
48
45
  | --robot | -r | 修改开发者机器人id |
49
46
  `,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparrow-ci",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "基于miniprogram-ci开发的小程序命令行工具",
5
5
  "main": "",
6
6
  "bin": {