sparrow-ci 1.0.7 → 1.0.9

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-01 17:17:29
5
+ * @LastEditTime: 2022-09-24 13:11:54
6
6
  * @FilePath: /sparrow-ci/README.md
7
7
  * @Description: README
8
8
  -->
@@ -68,11 +68,12 @@ module.exports = {
68
68
  | --edit-live | -e | 编辑live直播插件json |
69
69
  | --git-pull | -g | 拉取远端master代码 |
70
70
  | --clone | -c | 克隆文件夹 |
71
-
71
+ | --robot | -r | 修改开发者机器人id |
72
72
  比如,上传测试代码:
73
73
 
74
74
  ```shell
75
75
  ci --upload
76
+ ci --robot xxx
76
77
  ```
77
78
 
78
79
  4.注意:
package/bin/ci.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-12 15:56:29
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2022-09-03 10:15:33
5
+ * @LastEditTime: 2022-09-24 13:05:17
6
6
  * @FilePath: /sparrow-ci/bin/ci.js
7
7
  * @Description:
8
8
  */
@@ -13,7 +13,7 @@ const inquirer = require('inquirer');
13
13
  const chalk = require('chalk');
14
14
  const { getProInfo, commonFilePath, configOutPut, createVersion, handleList, printSuccess, printFail, printWarnning, handleVersion } = require('./utils/index');
15
15
  const { isDependentExisted, writeToFile, installAndBuild, installPackages, handleLivePlugin, handleExecFile, handleFolder } = require('./utils/node_utils.js');
16
- const { environment, helpDescription } = require('../ci.config');
16
+ const { environment, helpDescription, robotList } = require('../ci.config');
17
17
  const { uploadCi, packNpmCi, previewCi } = require('./command');
18
18
 
19
19
  const currentWorkingDirectory = process.cwd(); // 命令执行位置的路径
@@ -33,7 +33,8 @@ class Ci {
33
33
  packageJSONPath 项目中package.json文件的位置
34
34
  cliFileExisted cli.js文件是否已经创建了,默认为false
35
35
  needCheckNpmPackages 需要检查更新的包
36
- appid
36
+ appid 小程序id
37
+ robotNum 上传机器人
37
38
  */
38
39
  version = '';
39
40
  description = '';
@@ -43,9 +44,10 @@ class Ci {
43
44
  mainCliFilePath = '';
44
45
  packageJSONPath = '';
45
46
  cliFileExisted = false;
46
- needCheckNpmPackages = '';
47
+ needCheckNpmPackages = [];
47
48
  appid = '';
48
49
  environment = environment.DEV;
50
+ robotNum = robotList['default'];
49
51
  constructor() {
50
52
  this.projectRoot = currentWorkingDirectory;
51
53
  const { version, description } = getProInfo(currentWorkingDirectory);
@@ -92,6 +94,7 @@ class Ci {
92
94
  description: this.description,
93
95
  projectRoot: this.projectRoot,
94
96
  needCheckNpmPackages: this.needCheckNpmPackages,
97
+ robotNum: this.robotNum,
95
98
  };
96
99
  }
97
100
 
@@ -103,6 +106,7 @@ class Ci {
103
106
  description,
104
107
  projectRoot,
105
108
  needCheckNpmPackages,
109
+ robotNum,
106
110
  } = data;
107
111
  // 给相应属性赋值
108
112
  this.environment = environment;
@@ -110,6 +114,7 @@ class Ci {
110
114
  this.description = description;
111
115
  this.projectRoot = projectRoot;
112
116
  this.needCheckNpmPackages = needCheckNpmPackages;
117
+ this.robotNum = robotNum;
113
118
  }
114
119
 
115
120
  // 检查配置文件是否已经创建过了;TODO 如果主包存在,就以主包为准;如果主包不存在,就提示创建;然后复制到所有独立分包中
@@ -165,6 +170,7 @@ class Ci {
165
170
  description = this.description,
166
171
  projectRoot = this.projectRoot,
167
172
  needCheckNpmPackages = this.needCheckNpmPackages.join(','),
173
+ robotNum = this.robotNum,
168
174
  } = data;
169
175
 
170
176
  // 这个对象是为了用来初始化cli实例的
@@ -174,6 +180,7 @@ class Ci {
174
180
  description,
175
181
  projectRoot,
176
182
  needCheckNpmPackages,
183
+ robotNum,
177
184
  };
178
185
 
179
186
  const configDataString = this.formatData('', false, configData);
@@ -224,17 +231,18 @@ class Ci {
224
231
  // 组合文件要写的内容
225
232
  formatData(filePath, isTrue = true, configParams) {
226
233
  if (isTrue) this.readCliFile(filePath);
227
- const needCheckNpmPackages = isTrue ? this.needCheckNpmPackages.join(',') : configParams.needCheckNpmPackages;
234
+ let needCheckNpmPackages = isTrue ? this.needCheckNpmPackages.join(',') : configParams.needCheckNpmPackages;
235
+
228
236
  let needCheckNpmPackagesArr = [];
229
- if (needCheckNpmPackages) {
237
+ if (needCheckNpmPackages.length) {
230
238
  needCheckNpmPackagesArr = needCheckNpmPackages.split(',');
231
239
  }
232
240
  const needCheckNpmPackagesString = JSON.stringify(needCheckNpmPackagesArr);
233
241
  if (!isTrue) {
234
- const { environment, version, description, projectRoot } = configParams;
235
- return configOutPut(environment, version, description, projectRoot, needCheckNpmPackagesString)
242
+ const { environment, version, description, projectRoot, robotNum } = configParams;
243
+ return configOutPut(environment, version, description, projectRoot, needCheckNpmPackagesString, robotNum)
236
244
  };
237
- return configOutPut(this.environment, this.version, this.description, this.projectRoot, needCheckNpmPackagesString);
245
+ return configOutPut(this.environment, this.version, this.description, this.projectRoot, needCheckNpmPackagesString, this.robotNum);
238
246
  }
239
247
 
240
248
  async online() {
@@ -262,12 +270,18 @@ class Ci {
262
270
  const answers = await this.showSimpleCliConfig(type);
263
271
  if (!answers) return;
264
272
  }
273
+
274
+ if (type === 'online') {
275
+ this.robotNum = robotList['online']; // 如果是online, 上传着变为1
276
+ }
277
+
265
278
  await uploadCi({
266
279
  projectPath: this.projectRoot,
267
280
  version: this.version,
268
281
  description: this.description,
269
282
  keyPath: this.miniprogramRoot,
270
283
  appid: this.appid,
284
+ robotNum: this.robotNum,
271
285
  });
272
286
  if (type === 'online') return;
273
287
  const packageObj = require(this.packageJSONPath);
@@ -294,8 +308,9 @@ class Ci {
294
308
  version: this.version,
295
309
  description: this.description,
296
310
  projectPath: this.projectRoot,
297
- keyPath: __dirname,
298
- projectRoot: this.projectRoot
311
+ keyPath: this.miniprogramRoot,
312
+ projectRoot: this.projectRoot,
313
+ appid: this.appid,
299
314
  })
300
315
  }
301
316
 
@@ -345,6 +360,15 @@ class Ci {
345
360
  });
346
361
  }
347
362
 
363
+ // 初始化个人上传账号
364
+ async robot(name) {
365
+ let robotNum = robotList[name] || robotList['default'];
366
+ const writeFileSuccess = await this.writeCliFile({ robotNum });
367
+ if (writeFileSuccess) {
368
+ printSuccess(`上传用户成功切换为${robotNum}`);
369
+ }
370
+ }
371
+
348
372
  // 帮助
349
373
  // 查看帮助
350
374
  help() {
@@ -2,7 +2,7 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-12 10:20:19
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2022-09-01 17:17:37
5
+ * @LastEditTime: 2022-09-24 11:57:03
6
6
  * @FilePath: /sparrow-ci/bin/command/index.js
7
7
  * @Description: 上传代码
8
8
  */
@@ -28,7 +28,7 @@ function project(params) {
28
28
  async function uploadCi(params) {
29
29
  const spinner = ora(`${chalk.blue('准备上传')}\n`).start();
30
30
  spinner.color = 'blue';
31
- const { version, description } = params;
31
+ const { version, description, robotNum } = params;
32
32
  try {
33
33
  const { subPackageInfo } = await ci.upload({
34
34
  project: project(params),
@@ -42,7 +42,7 @@ async function uploadCi(params) {
42
42
  minifyWXSS: true, // 压缩 WXSS 代码
43
43
  minifyJS: true, // 压缩 JS 代码
44
44
  },
45
- robot: 1,
45
+ robot: robotNum,
46
46
  onProgressUpdate: (res) => {
47
47
  const { _status } = res;
48
48
  if (_status === 'doing') {
@@ -91,42 +91,44 @@ function packNpmCi(params) {
91
91
  }
92
92
 
93
93
  async function previewCi(params) {
94
- const { version, description, pagePath, searchQuery, scene, projectRoot, keyPath } = params;
95
- const previewResult = await ci.preview({
96
- project: project(params),
97
- desc: description,
98
- version,
99
- setting: {
100
- es6: true, // 对应小程序开发者工具的 "es6 转 es5"
101
- minify: true, // 压缩所有代码,对应小程序开发者工具的 "压缩代码"
102
- autoPrefixWXSS: true, // 对应小程序开发者工具的 "样式自动补全"
103
- minifyWXML: true, // 压缩 WXML 代码
104
- minifyWXSS: true, // 压缩 WXSS 代码
105
- minifyJS: true, // 压缩 JS 代码
106
- },
107
- qrcodeFormat: 'base64',
108
- qrcodeOutputDest: '/Users/wq/Desktop/qrcode/destination.jpg',
109
- onProgressUpdate: (res) => {
110
- const { _status, subPackageInfo } = res;
111
- if (_status === 'doing') {
112
- console.log('==============');
113
- console.log('_status', _status);
114
- console.log('==============');
115
- }
116
- if (_status === 'done') {
117
- console.log('==============');
118
- console.log('_status', _status, subPackageInfo);
119
- console.log('==============');
120
- }
121
- },
122
- pagePath, // 预览页面 pages/index/index
123
- searchQuery, // 预览参数 [注意!]这里的`&`字符在命令行中应写成转义字符`\&` a=1&b=2
124
- scene, // 场景值 1011
125
- })
126
- const { subPackageInfo } = previewResult;
127
- console.log('==============');
128
- console.log('subPackageInfo', subPackageInfo);
129
- console.log('==============');
94
+ const spinner = ora(`${chalk.blue('准备中...')}\n`).start();
95
+ spinner.color = 'blue';
96
+ const { version, description, pagePath, searchQuery, scene } = params;
97
+ try {
98
+ const previewResult = await ci.preview({
99
+ project: project(params),
100
+ desc: description,
101
+ version,
102
+ setting: {
103
+ es6: true, // 对应小程序开发者工具的 "es6 转 es5"
104
+ minify: true, // 压缩所有代码,对应小程序开发者工具的 "压缩代码"
105
+ autoPrefixWXSS: true, // 对应小程序开发者工具的 "样式自动补全"
106
+ minifyWXML: true, // 压缩 WXML 代码
107
+ minifyWXSS: true, // 压缩 WXSS 代码
108
+ minifyJS: true, // 压缩 JS 代码
109
+ },
110
+ qrcodeFormat: 'image',
111
+ qrcodeOutputDest: path.join('../', `qrcode${version}.jpg`),
112
+ onProgressUpdate: (res) => {
113
+ const { _status } = res;
114
+ if (_status === 'doing') {
115
+ spinner.text = `${chalk.blue('生成预览中')}\n`;
116
+ spinner.color = 'blue';
117
+ }
118
+ if (_status === 'done') {
119
+ spinner.text = `${chalk.green('生成预览成功')}\n`;
120
+ spinner.color = 'green';
121
+ spinner.succeed();
122
+ }
123
+ },
124
+ pagePath, // 预览页面 pages/index/index
125
+ searchQuery, // 预览参数 [注意!]这里的`&`字符在命令行中应写成转义字符`\&` a=1&b=2
126
+ scene, // 场景值 1011
127
+ })
128
+ } catch(err) {
129
+ spinner.text = `${chalk.red('生成预览失败')}\n${chalk.yellow(err)}`;
130
+ spinner.fail();
131
+ }
130
132
  }
131
133
 
132
134
  module.exports = {
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-08-31 17:23:47
6
+ * @LastEditTime: 2022-09-24 11:35:50
7
7
  * @LastEditor: wangqi
8
8
  * @Description: 脚手架的类
9
9
  */
@@ -22,6 +22,7 @@ program
22
22
  .option('-e, --edit-live', '编辑live直播插件json')
23
23
  .option('-g, --git-pull', '拉取远端master代码')
24
24
  .option('-c, --clone', '克隆文件夹')
25
+ .option('-r, --robot', '初始化个人上传账号')
25
26
  .option('-h, --help', '描述如何使用')
26
27
 
27
28
  program.parse(process.argv); // 处理传入的参数
@@ -58,6 +59,9 @@ async function main () {
58
59
  case Boolean(program.clone): // 编辑直播插件
59
60
  ci.clone();
60
61
  break;
62
+ case Boolean(program.robot): // 编辑直播插件
63
+ ci.robot(program.args[0]);
64
+ break;
61
65
  case Boolean(program.help): // 查看帮助
62
66
  ci.help();
63
67
  break;
@@ -2,7 +2,7 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-12 17:10:25
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2022-09-01 18:13:11
5
+ * @LastEditTime: 2022-09-24 12:18:53
6
6
  * @FilePath: /sparrow-ci/bin/utils/index.js
7
7
  * @Description: 公用方法
8
8
  */
@@ -48,14 +48,15 @@ function commonFilePath(pathUrl, file) {
48
48
  }
49
49
 
50
50
  // 输出需要的配置
51
- function configOutPut(environment, version, description, projectRoot, needCheckNpmPackagesString) {
51
+ function configOutPut(environment, version, description, projectRoot, needCheckNpmPackagesString, robotNum) {
52
52
  const configDataString =
53
53
  `module.exports = {
54
54
  "environment": "${environment}",
55
55
  "version": "${version}",
56
56
  "description": "${description}",
57
57
  "projectRoot": "${projectRoot}",
58
- "needCheckNpmPackages": ${needCheckNpmPackagesString}
58
+ "needCheckNpmPackages": ${needCheckNpmPackagesString},
59
+ "robotNum": ${robotNum},
59
60
  };
60
61
  `;
61
62
  return configDataString;
@@ -2,7 +2,7 @@
2
2
  * @Author: wangqi
3
3
  * @Date: 2022-08-26 10:39:50
4
4
  * @LastEditors: wangqi
5
- * @LastEditTime: 2022-09-01 17:16:49
5
+ * @LastEditTime: 2022-09-24 12:54:56
6
6
  * @FilePath: /sparrow-ci/bin/utils/node_utils.js
7
7
  * @Description: 工具方法
8
8
  */
@@ -14,7 +14,9 @@ const fs = require('fs');
14
14
  const logSymbols = require('log-symbols');
15
15
  const inquirer = require('inquirer');
16
16
  const { spawnSync } = require('child_process');
17
- const { mkdirSync, existsSync, writeFile, readFile, execFile } = require('fs');
17
+ const { mkdirSync, existsSync, writeFile, readFile } = require('fs');
18
+ const util = require('util');
19
+ const execFile = util.promisify(require('child_process').execFile);
18
20
  const { handleList, printSuccess, printWarnning, printFail } = require('./index');
19
21
  const { packNpmCi } = require('../command');
20
22
  const { liveJsonArr, liveUrl, folderSrc } = require('../../ci.config');
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-08-31 17:35:45
5
+ * @LastEditTime: 2022-09-24 13:10:55
6
6
  * @FilePath: /sparrow-ci/ci.config.js
7
7
  * @Description: 全局配置文件
8
8
  */
@@ -12,6 +12,14 @@ module.exports = {
12
12
  DEV: 'DEV', // 开发环境
13
13
  PRO: 'PRO', // 生产环境
14
14
  },
15
+ robotList: { // 个人机器人编号
16
+ 'online': 1, // 线上发布
17
+ 'default': 2, // 默认本地测试
18
+ '史明华': 30,
19
+ '马坤坤': 29,
20
+ '王其': 28,
21
+ '丁宇': 27,
22
+ },
15
23
  miniShopPath: '/Users/wq/Desktop/company/miniapp_shop',
16
24
  // 直播插件地址
17
25
  liveUrl: 'plugin-private://wx2b03c6e691cd7370/components/subscribe/subscribe',
@@ -37,5 +45,6 @@ module.exports = {
37
45
  | --edit-live | -e | 编辑live直播插件json |
38
46
  | --git-pull | -g | 拉取远端master代码 |
39
47
  | --clone | -c | 克隆文件夹 |
48
+ | --robot | -r | 修改开发者机器人id |
40
49
  `,
41
50
  };
package/git.sh CHANGED
@@ -2,8 +2,8 @@
2
2
  # @Author: wangqi
3
3
  # @Date: 2022-05-06 10:24:20
4
4
  # @LastEditors: wangqi
5
- # @LastEditTime: 2022-08-12 15:54:14
6
- # @FilePath: /sparrow-ci/git.sh
5
+ # @LastEditTime: 2022-05-07 14:22:20
6
+ # @FilePath: /miniapp_cli/git.sh
7
7
  # @Description: git拉取脚本命令
8
8
  ###
9
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sparrow-ci",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "基于miniprogram-ci开发的小程序命令行工具",
5
5
  "main": "",
6
6
  "bin": {