@pisell/common 0.0.68 → 0.0.70

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.
@@ -0,0 +1,176 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ var ENV_CHOICES = ['release', 'pre', 'prod'];
8
+ var BUMP_CHOICES = ['patch', 'minor', 'major'];
9
+ var getFlagValue = function getFlagValue(_ref) {
10
+ var args = _ref.args,
11
+ index = _ref.index,
12
+ flagName = _ref.flagName;
13
+ var current = args[index];
14
+ var _current$split = current.split('='),
15
+ _current$split2 = _slicedToArray(_current$split, 2),
16
+ _current$split2$ = _current$split2[1],
17
+ valueFromEqual = _current$split2$ === void 0 ? '' : _current$split2$;
18
+ if (valueFromEqual) {
19
+ return {
20
+ value: valueFromEqual,
21
+ nextIndex: index
22
+ };
23
+ }
24
+ var next = args[index + 1];
25
+ if (!next || next.startsWith('-')) {
26
+ return {
27
+ error: "\u53C2\u6570 ".concat(flagName, " \u7F3A\u5C11\u503C"),
28
+ nextIndex: index
29
+ };
30
+ }
31
+ return {
32
+ value: next,
33
+ nextIndex: index + 1
34
+ };
35
+ };
36
+ var parseDeployArgs = function parseDeployArgs() {
37
+ var rawArgs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
38
+ var parsed = {
39
+ action: null,
40
+ env: '',
41
+ version: '',
42
+ bump: '',
43
+ changelog: '',
44
+ isRelease: true,
45
+ whetherBuild: true,
46
+ isConfirm: true,
47
+ isManuallyUploadOss: false,
48
+ hasCliOptions: false,
49
+ errors: []
50
+ };
51
+ for (var index = 0; index < rawArgs.length; index++) {
52
+ var arg = rawArgs[index];
53
+ if (!arg.startsWith('-')) {
54
+ continue;
55
+ }
56
+ parsed.hasCliOptions = true;
57
+ if (arg === '--release') {
58
+ if (parsed.action && parsed.action !== 'release') {
59
+ parsed.errors.push('不能同时指定 --release 和 --upload');
60
+ }
61
+ parsed.action = 'release';
62
+ continue;
63
+ }
64
+ if (arg === '--upload') {
65
+ if (parsed.action && parsed.action !== 'uploadCode') {
66
+ parsed.errors.push('不能同时指定 --release 和 --upload');
67
+ }
68
+ parsed.action = 'uploadCode';
69
+ continue;
70
+ }
71
+ if (arg === '--yes') {
72
+ parsed.isConfirm = true;
73
+ continue;
74
+ }
75
+ if (arg === '--no-release') {
76
+ parsed.isRelease = false;
77
+ continue;
78
+ }
79
+ if (arg === '--build') {
80
+ parsed.whetherBuild = true;
81
+ continue;
82
+ }
83
+ if (arg === '--no-build') {
84
+ parsed.whetherBuild = false;
85
+ continue;
86
+ }
87
+ if (arg === '--manual-oss') {
88
+ parsed.isManuallyUploadOss = true;
89
+ continue;
90
+ }
91
+ if (arg === '--no-manual-oss') {
92
+ parsed.isManuallyUploadOss = false;
93
+ continue;
94
+ }
95
+ if (arg === '--patch' || arg === '--minor' || arg === '--major') {
96
+ parsed.bump = arg.replace('--', '');
97
+ continue;
98
+ }
99
+ if (arg === '--env' || arg.startsWith('--env=')) {
100
+ var _getFlagValue = getFlagValue({
101
+ args: rawArgs,
102
+ index: index,
103
+ flagName: '--env'
104
+ }),
105
+ value = _getFlagValue.value,
106
+ nextIndex = _getFlagValue.nextIndex,
107
+ error = _getFlagValue.error;
108
+ if (error) {
109
+ parsed.errors.push(error);
110
+ continue;
111
+ }
112
+ parsed.env = value;
113
+ index = nextIndex;
114
+ continue;
115
+ }
116
+ if (arg === '--version' || arg.startsWith('--version=')) {
117
+ var _getFlagValue2 = getFlagValue({
118
+ args: rawArgs,
119
+ index: index,
120
+ flagName: '--version'
121
+ }),
122
+ _value = _getFlagValue2.value,
123
+ _nextIndex = _getFlagValue2.nextIndex,
124
+ _error = _getFlagValue2.error;
125
+ if (_error) {
126
+ parsed.errors.push(_error);
127
+ continue;
128
+ }
129
+ parsed.version = _value;
130
+ index = _nextIndex;
131
+ continue;
132
+ }
133
+ if (arg === '--bump' || arg.startsWith('--bump=')) {
134
+ var _getFlagValue3 = getFlagValue({
135
+ args: rawArgs,
136
+ index: index,
137
+ flagName: '--bump'
138
+ }),
139
+ _value2 = _getFlagValue3.value,
140
+ _nextIndex2 = _getFlagValue3.nextIndex,
141
+ _error2 = _getFlagValue3.error;
142
+ if (_error2) {
143
+ parsed.errors.push(_error2);
144
+ continue;
145
+ }
146
+ parsed.bump = _value2;
147
+ index = _nextIndex2;
148
+ continue;
149
+ }
150
+ if (arg === '--changelog' || arg.startsWith('--changelog=')) {
151
+ var _getFlagValue4 = getFlagValue({
152
+ args: rawArgs,
153
+ index: index,
154
+ flagName: '--changelog'
155
+ }),
156
+ _value3 = _getFlagValue4.value,
157
+ _nextIndex3 = _getFlagValue4.nextIndex,
158
+ _error3 = _getFlagValue4.error;
159
+ if (_error3) {
160
+ parsed.errors.push(_error3);
161
+ continue;
162
+ }
163
+ parsed.changelog = _value3;
164
+ index = _nextIndex3;
165
+ continue;
166
+ }
167
+ }
168
+ if (parsed.env && !ENV_CHOICES.includes(parsed.env)) {
169
+ parsed.errors.push("--env \u4EC5\u652F\u6301 ".concat(ENV_CHOICES.join(', '), "\uFF0C\u5F53\u524D\u503C\u4E3A ").concat(parsed.env));
170
+ }
171
+ if (parsed.bump && !BUMP_CHOICES.includes(parsed.bump)) {
172
+ parsed.errors.push("--bump \u4EC5\u652F\u6301 ".concat(BUMP_CHOICES.join(', '), "\uFF0C\u5F53\u524D\u503C\u4E3A ").concat(parsed.bump));
173
+ }
174
+ return parsed;
175
+ };
176
+ export { ENV_CHOICES, BUMP_CHOICES, parseDeployArgs };
@@ -3,6 +3,7 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
5
  import inquirer from 'inquirer';
6
+ import { parseDeployArgs } from "./args.js";
6
7
  import release from "./release/index.js";
7
8
  import uploadCode from "./uploadCode/index.js";
8
9
  var actions = {
@@ -25,16 +26,37 @@ var inquirerResult = function inquirerResult() {
25
26
  };
26
27
  var deploy = /*#__PURE__*/function () {
27
28
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
28
- var res;
29
+ var _len,
30
+ rawArgs,
31
+ _key,
32
+ cliArgs,
33
+ res,
34
+ _args = arguments;
29
35
  return _regeneratorRuntime().wrap(function _callee$(_context) {
30
36
  while (1) switch (_context.prev = _context.next) {
31
37
  case 0:
32
- _context.next = 2;
38
+ for (_len = _args.length, rawArgs = new Array(_len), _key = 0; _key < _len; _key++) {
39
+ rawArgs[_key] = _args[_key];
40
+ }
41
+ cliArgs = parseDeployArgs(rawArgs);
42
+ if (cliArgs.errors.length) {
43
+ cliArgs.errors.forEach(function (item) {
44
+ return console.log("\u274C ".concat(item));
45
+ });
46
+ process.exit(1);
47
+ }
48
+ if (!cliArgs.action) {
49
+ _context.next = 5;
50
+ break;
51
+ }
52
+ return _context.abrupt("return", actions[cliArgs.action](cliArgs));
53
+ case 5:
54
+ _context.next = 7;
33
55
  return inquirerResult();
34
- case 2:
56
+ case 7:
35
57
  res = _context.sent;
36
- return _context.abrupt("return", actions[res.action]());
37
- case 4:
58
+ return _context.abrupt("return", actions[res.action](cliArgs));
59
+ case 9:
38
60
  case "end":
39
61
  return _context.stop();
40
62
  }
@@ -4,6 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
5
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
6
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+ import path from 'path';
7
8
  import { fileURLToPath } from 'url';
8
9
  import deploy from "./deploy.js";
9
10
  import { loadJSON } from "./utils/index.js";
@@ -29,6 +30,9 @@ var __dirname = path.dirname(fileURLToPath(import.meta.url));
29
30
  console.log('pisell -h --help -H [全部命令]');
30
31
  console.log('pisell -v --version -V [显示版本]');
31
32
  console.log('pisell deploy [上传代码|发布代码]');
33
+ console.log('pisell deploy --release --env=release [直接发布, 未传--version默认最新版本]');
34
+ console.log('pisell deploy --upload --env=pre --patch --changelog="xxx" --no-release --yes');
35
+ console.log('deploy 参数: --release --upload --env --version --bump --patch --minor --major --changelog --no-release --build --no-build --manual-oss --yes');
32
36
  break;
33
37
  default:
34
38
  break;
@@ -107,14 +107,33 @@ function init() {
107
107
  }
108
108
  function _init() {
109
109
  _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
110
- var projectAndEnv, versionList, res, releaseInstance;
110
+ var cliArgs,
111
+ projectAndEnv,
112
+ versionList,
113
+ isCliMode,
114
+ res,
115
+ releaseInstance,
116
+ _args2 = arguments;
111
117
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
112
118
  while (1) switch (_context2.prev = _context2.next) {
113
119
  case 0:
114
- _context2.next = 2;
120
+ cliArgs = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
121
+ if (!cliArgs.env) {
122
+ _context2.next = 5;
123
+ break;
124
+ }
125
+ _context2.t0 = {
126
+ env: cliArgs.env
127
+ };
128
+ _context2.next = 8;
129
+ break;
130
+ case 5:
131
+ _context2.next = 7;
115
132
  return selectProject();
116
- case 2:
117
- projectAndEnv = _context2.sent;
133
+ case 7:
134
+ _context2.t0 = _context2.sent;
135
+ case 8:
136
+ projectAndEnv = _context2.t0;
118
137
  /** 之前选择项目模式改为获取当前主项目 */
119
138
  projectAndEnv.project = {
120
139
  path: './',
@@ -122,39 +141,74 @@ function _init() {
122
141
  };
123
142
 
124
143
  /** 通过项目和环境查询对应版本号 */
125
- _context2.next = 6;
144
+ _context2.next = 12;
126
145
  return getVersionList(projectAndEnv);
127
- case 6:
146
+ case 12:
128
147
  versionList = _context2.sent;
129
- _context2.next = 9;
148
+ if (versionList.length) {
149
+ _context2.next = 16;
150
+ break;
151
+ }
152
+ console.log('未获取到可发布版本');
153
+ return _context2.abrupt("return");
154
+ case 16:
155
+ isCliMode = Boolean(cliArgs.action === 'release' || cliArgs.version);
156
+ if (!(cliArgs.version && !versionList.includes(cliArgs.version))) {
157
+ _context2.next = 20;
158
+ break;
159
+ }
160
+ console.log("\u672A\u627E\u5230\u7248\u672C ".concat(cliArgs.version, "\uFF0C\u53EF\u9009\u7248\u672C: ").concat(versionList.join(', ')));
161
+ return _context2.abrupt("return");
162
+ case 20:
163
+ if (!isCliMode) {
164
+ _context2.next = 24;
165
+ break;
166
+ }
167
+ _context2.t1 = {
168
+ version: cliArgs.version || versionList[0],
169
+ is_release: cliArgs.isConfirm
170
+ };
171
+ _context2.next = 27;
172
+ break;
173
+ case 24:
174
+ _context2.next = 26;
130
175
  return inquirerResult(versionList);
131
- case 9:
132
- res = _context2.sent;
176
+ case 26:
177
+ _context2.t1 = _context2.sent;
178
+ case 27:
179
+ res = _context2.t1;
180
+ if (res.is_release) {
181
+ _context2.next = 31;
182
+ break;
183
+ }
184
+ console.log('取消发布');
185
+ return _context2.abrupt("return");
186
+ case 31:
133
187
  releaseInstance = new Release(_objectSpread(_objectSpread({}, res), projectAndEnv));
134
- _context2.prev = 11;
135
- _context2.next = 14;
188
+ _context2.prev = 32;
189
+ _context2.next = 35;
136
190
  return releaseInstance.setConfig();
137
- case 14:
138
- _context2.next = 16;
191
+ case 35:
192
+ _context2.next = 37;
139
193
  return releaseInstance.connectServer();
140
- case 16:
141
- _context2.next = 18;
194
+ case 37:
195
+ _context2.next = 39;
142
196
  return releaseInstance.release();
143
- case 18:
144
- _context2.next = 20;
197
+ case 39:
198
+ _context2.next = 41;
145
199
  return releaseInstance.disconnectServer();
146
- case 20:
147
- _context2.next = 25;
200
+ case 41:
201
+ _context2.next = 46;
148
202
  break;
149
- case 22:
150
- _context2.prev = 22;
151
- _context2.t0 = _context2["catch"](11);
152
- console.log(_context2.t0);
153
- case 25:
203
+ case 43:
204
+ _context2.prev = 43;
205
+ _context2.t2 = _context2["catch"](32);
206
+ console.log(_context2.t2);
207
+ case 46:
154
208
  case "end":
155
209
  return _context2.stop();
156
210
  }
157
- }, _callee2, null, [[11, 22]]);
211
+ }, _callee2, null, [[32, 43]]);
158
212
  }));
159
213
  return _init.apply(this, arguments);
160
214
  }
@@ -111,32 +111,83 @@ function init() {
111
111
  */
112
112
  function _init() {
113
113
  _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
114
- var res, isManuallyOss, isManuallyOssRes, uploadCode, version, currentUserName, result, _fileName, ossRes, conn, releaseInstance, branch, grayBranch;
114
+ var cliArgs,
115
+ isCliMode,
116
+ isBumpVersion,
117
+ res,
118
+ isManuallyOss,
119
+ isManuallyOssRes,
120
+ uploadCode,
121
+ version,
122
+ currentUserName,
123
+ result,
124
+ _fileName,
125
+ ossRes,
126
+ conn,
127
+ releaseInstance,
128
+ branch,
129
+ grayBranch,
130
+ _args = arguments;
115
131
  return _regeneratorRuntime().wrap(function _callee$(_context) {
116
132
  while (1) switch (_context.prev = _context.next) {
117
133
  case 0:
118
- _context.next = 2;
134
+ cliArgs = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
135
+ isCliMode = Boolean(cliArgs.action === 'uploadCode');
136
+ isBumpVersion = cliArgs.version === 'patch' || cliArgs.version === 'minor' || cliArgs.version === 'major';
137
+ if (!(isCliMode && cliArgs.version && !isBumpVersion && !cliArgs.bump)) {
138
+ _context.next = 6;
139
+ break;
140
+ }
141
+ console.log("upload \u6A21\u5F0F\u4E0B --version \u4EC5\u652F\u6301 patch/minor/major\uFF0C\u6216\u6539\u7528 --bump\uFF0C\u5F53\u524D\u503C\u4E3A ".concat(cliArgs.version));
142
+ return _context.abrupt("return");
143
+ case 6:
144
+ if (!isCliMode) {
145
+ _context.next = 10;
146
+ break;
147
+ }
148
+ _context.t0 = {
149
+ env: cliArgs.env || 'release',
150
+ version: cliArgs.bump || cliArgs.version || 'patch',
151
+ changelog: cliArgs.changelog || 'update',
152
+ is_release: cliArgs.isRelease,
153
+ whether_build: cliArgs.whetherBuild,
154
+ is_confirm: cliArgs.isConfirm
155
+ };
156
+ _context.next = 13;
157
+ break;
158
+ case 10:
159
+ _context.next = 12;
119
160
  return inquirerResult();
120
- case 2:
121
- res = _context.sent;
161
+ case 12:
162
+ _context.t0 = _context.sent;
163
+ case 13:
164
+ res = _context.t0;
122
165
  isManuallyOss = false;
123
166
  if (res.is_confirm) {
124
- _context.next = 7;
167
+ _context.next = 18;
125
168
  break;
126
169
  }
127
170
  console.log('取消发布');
128
171
  return _context.abrupt("return");
129
- case 7:
172
+ case 18:
130
173
  if (!(res.env === 'prod')) {
131
- _context.next = 12;
174
+ _context.next = 27;
175
+ break;
176
+ }
177
+ if (!isCliMode) {
178
+ _context.next = 23;
132
179
  break;
133
180
  }
134
- _context.next = 10;
181
+ isManuallyOss = cliArgs.isManuallyUploadOss;
182
+ _context.next = 27;
183
+ break;
184
+ case 23:
185
+ _context.next = 25;
135
186
  return isManuallyUploadOss();
136
- case 10:
187
+ case 25:
137
188
  isManuallyOssRes = _context.sent;
138
189
  isManuallyOss = isManuallyOssRes.is_manually_upload_OSS;
139
- case 12:
190
+ case 27:
140
191
  /** 之前选择项目模式改为获取当前主项目 */
141
192
  res.project = {
142
193
  path: './',
@@ -146,30 +197,30 @@ function _init() {
146
197
  // const data = await $`curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"post","content":""}' https://open.feishu.cn/open-apis/bot/v2/hook/08349b0d-016c-4133-9442-9e95d4adc1e8`
147
198
 
148
199
  // 删除本地在远程不存在的tag
149
- _context.next = 15;
200
+ _context.next = 30;
150
201
  return $(_templateObject || (_templateObject = _taggedTemplateLiteral(["git fetch --prune-tags"])));
151
- case 15:
202
+ case 30:
152
203
  uploadCode = new UploadCode(res);
153
- _context.next = 18;
204
+ _context.next = 33;
154
205
  return uploadCode.check();
155
- case 18:
206
+ case 33:
156
207
  if (_context.sent) {
157
- _context.next = 20;
208
+ _context.next = 35;
158
209
  break;
159
210
  }
160
211
  return _context.abrupt("return");
161
- case 20:
212
+ case 35:
162
213
  console.log('开始更新版本号');
163
- _context.next = 23;
214
+ _context.next = 38;
164
215
  return uploadCode.updateVersion();
165
- case 23:
216
+ case 38:
166
217
  version = _context.sent;
167
218
  console.log('✅ 版本更新完成');
168
- _context.next = 27;
219
+ _context.next = 42;
169
220
  return getCurrentUserName();
170
- case 27:
221
+ case 42:
171
222
  currentUserName = _context.sent;
172
- _context.next = 30;
223
+ _context.next = 45;
173
224
  return sendWebhook({
174
225
  title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883\u5F00\u59CB").concat(res.is_release ? '上传并发布' : '上传'),
175
226
  content: [{
@@ -183,68 +234,72 @@ function _init() {
183
234
  value: version || ''
184
235
  }]
185
236
  });
186
- case 30:
237
+ case 45:
187
238
  result = _context.sent;
188
239
  console.log(result, 'result');
189
- _context.prev = 32;
240
+ _context.prev = 47;
190
241
  if (!res.whether_build) {
191
- _context.next = 40;
242
+ _context.next = 55;
192
243
  break;
193
244
  }
194
245
  console.log('开始打包');
195
- _context.next = 37;
246
+ _context.next = 52;
196
247
  return uploadCode.build();
197
- case 37:
248
+ case 52:
198
249
  console.log('✅ 打包完成');
199
- _context.next = 41;
250
+ _context.next = 56;
200
251
  break;
201
- case 40:
252
+ case 55:
202
253
  console.log('使用本地/dist');
203
- case 41:
254
+ case 56:
204
255
  if (!(res.env === 'prod')) {
205
- _context.next = 51;
256
+ _context.next = 67;
206
257
  break;
207
258
  }
208
259
  if (isManuallyOss) {
209
- _context.next = 51;
260
+ _context.next = 67;
210
261
  break;
211
262
  }
212
263
  _fileName = res.project.fileName; // 上传oss
213
- _context.next = 46;
264
+ _context.next = 61;
214
265
  return uploadStaticToOSS(_fileName);
215
- case 46:
216
- _context.next = 48;
266
+ case 61:
267
+ if (isCliMode) {
268
+ _context.next = 67;
269
+ break;
270
+ }
271
+ _context.next = 64;
217
272
  return inquirerOss();
218
- case 48:
273
+ case 64:
219
274
  ossRes = _context.sent;
220
275
  if (ossRes.is_upload_completed_OSS) {
221
- _context.next = 51;
276
+ _context.next = 67;
222
277
  break;
223
278
  }
224
279
  return _context.abrupt("return");
225
- case 51:
280
+ case 67:
226
281
  console.log('开始压缩');
227
- _context.next = 54;
282
+ _context.next = 70;
228
283
  return uploadCode.compress();
229
- case 54:
284
+ case 70:
230
285
  console.log('✅ 压缩完成');
231
286
  console.log('开始连接服务器');
232
- _context.next = 58;
287
+ _context.next = 74;
233
288
  return uploadCode.connectServer();
234
- case 58:
289
+ case 74:
235
290
  conn = _context.sent;
236
291
  console.log('✅ 连接服务器完成');
237
292
  console.log('开始上传');
238
- _context.next = 63;
293
+ _context.next = 79;
239
294
  return uploadCode.serverUpload();
240
- case 63:
295
+ case 79:
241
296
  console.log('✅ 上传完成');
242
297
  console.log('开始解压');
243
- _context.next = 67;
298
+ _context.next = 83;
244
299
  return uploadCode.serverUnpack();
245
- case 67:
300
+ case 83:
246
301
  if (!res.is_release) {
247
- _context.next = 77;
302
+ _context.next = 93;
248
303
  break;
249
304
  }
250
305
  releaseInstance = new Release({
@@ -254,40 +309,40 @@ function _init() {
254
309
  conn: conn
255
310
  });
256
311
  console.log('开始发布');
257
- _context.next = 72;
312
+ _context.next = 88;
258
313
  return getGitCurrentBranch();
259
- case 72:
314
+ case 88:
260
315
  branch = _context.sent;
261
316
  grayBranch = 'master';
262
317
  if (!originBranch.includes(branch.trim())) {
263
318
  grayBranch = branch;
264
319
  }
265
- _context.next = 77;
320
+ _context.next = 93;
266
321
  return releaseInstance.release(grayBranch);
267
- case 77:
268
- _context.next = 79;
322
+ case 93:
323
+ _context.next = 95;
269
324
  return uploadCode.disconnectServer();
270
- case 79:
271
- _context.next = 81;
325
+ case 95:
326
+ _context.next = 97;
272
327
  return $(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["git pull --no-edit"])));
273
- case 81:
274
- _context.next = 83;
328
+ case 97:
329
+ _context.next = 99;
275
330
  return $(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["git push --follow-tags"])));
276
- case 83:
331
+ case 99:
277
332
  console.log('✅ 成功后推送到git');
278
333
 
279
334
  // 只有在shop端发布
280
335
  if (!(res.project.fileName === 'my_pisel_shop')) {
281
- _context.next = 87;
336
+ _context.next = 103;
282
337
  break;
283
338
  }
284
- _context.next = 87;
339
+ _context.next = 103;
285
340
  return updateVersion({
286
341
  version: version,
287
342
  changelog: res.changelog
288
343
  }, res.env);
289
- case 87:
290
- _context.next = 89;
344
+ case 103:
345
+ _context.next = 105;
291
346
  return sendWebhook({
292
347
  title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u6210\u529F"),
293
348
  content: [{
@@ -301,20 +356,20 @@ function _init() {
301
356
  value: version || ''
302
357
  }]
303
358
  });
304
- case 89:
305
- _context.next = 100;
359
+ case 105:
360
+ _context.next = 116;
306
361
  break;
307
- case 91:
308
- _context.prev = 91;
309
- _context.t0 = _context["catch"](32);
310
- console.log(_context.t0, '执行出错 请排查重试');
311
- _context.next = 96;
362
+ case 107:
363
+ _context.prev = 107;
364
+ _context.t1 = _context["catch"](47);
365
+ console.log(_context.t1, '执行出错 请排查重试');
366
+ _context.next = 112;
312
367
  return $(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["git reset HEAD~1"])));
313
- case 96:
314
- _context.next = 98;
368
+ case 112:
369
+ _context.next = 114;
315
370
  return deleteGitTag("v".concat(uploadCode.currentVersion));
316
- case 98:
317
- _context.next = 100;
371
+ case 114:
372
+ _context.next = 116;
318
373
  return sendWebhook({
319
374
  title: "".concat(res.project.fileName, " ").concat(res.env, "\u73AF\u5883").concat(res.is_release ? '上传并发布' : '上传', "\u5931\u8D25"),
320
375
  content: [{
@@ -328,16 +383,16 @@ function _init() {
328
383
  value: version || ''
329
384
  }, {
330
385
  key: '错误信息',
331
- value: "".concat(_context.t0) || ''
386
+ value: "".concat(_context.t1) || ''
332
387
  }]
333
388
  });
334
- case 100:
389
+ case 116:
335
390
  uploadCode.deleteLocalZip();
336
- case 101:
391
+ case 117:
337
392
  case "end":
338
393
  return _context.stop();
339
394
  }
340
- }, _callee, null, [[32, 91]]);
395
+ }, _callee, null, [[47, 107]]);
341
396
  }));
342
397
  return _init.apply(this, arguments);
343
398
  }
@@ -172,7 +172,7 @@ var serverUnpack = function serverUnpack(conn, _ref5) {
172
172
  reject(err);
173
173
  return;
174
174
  }
175
- stream.end(" ".concat(env === 'prod' ? 'sudo -i' : '', "\n cd /tmp\n mv ").concat(fullFileName, " ").concat(path, "\n cd ").concat(path, "\n unzip ").concat(fullFileName, " -d ").concat(fileName, " && mv ").concat(fileName, "/dist/* ").concat(fileName, "/ && rmdir ").concat(fileName, "/dist\n rm -rf ").concat(fullFileName, "\n echo \"").concat(changelog, "\" > ./").concat(fileName, "/changelog.md\n sh deleteOldVersion.sh\n exit\n ").concat(env === 'prod' ? 'exit' : '', "\n ") // 打开到path
175
+ stream.end(" ".concat(env === 'prod' ? 'sudo -i' : '', "\n cd /tmp\n mv ").concat(fullFileName, " ").concat(path, "\n cd ").concat(path, "\n unzip ").concat(fullFileName, " -d ").concat(fileName, " && \\mv -f ").concat(fileName, "/dist/* ").concat(fileName, "/ && rmdir ").concat(fileName, "/dist\n rm -rf ").concat(fullFileName, "\n echo \"").concat(changelog, "\" > ./").concat(fileName, "/changelog.md\n sh deleteOldVersion.sh\n exit\n ").concat(env === 'prod' ? 'exit' : '', "\n ") // 打开到path
176
176
  // 解压 1.0.0.zip 文件到 1.0.0 移动dist中内容到 1.0.0内 删除dist
177
177
  // 删除1.0.0.zip
178
178
  // 写入changelog到changelog.md
@@ -0,0 +1,180 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/script/args.js
20
+ var args_exports = {};
21
+ __export(args_exports, {
22
+ BUMP_CHOICES: () => BUMP_CHOICES,
23
+ ENV_CHOICES: () => ENV_CHOICES,
24
+ parseDeployArgs: () => parseDeployArgs
25
+ });
26
+ module.exports = __toCommonJS(args_exports);
27
+ var ENV_CHOICES = ["release", "pre", "prod"];
28
+ var BUMP_CHOICES = ["patch", "minor", "major"];
29
+ var getFlagValue = ({ args, index, flagName }) => {
30
+ const current = args[index];
31
+ const [, valueFromEqual = ""] = current.split("=");
32
+ if (valueFromEqual) {
33
+ return { value: valueFromEqual, nextIndex: index };
34
+ }
35
+ const next = args[index + 1];
36
+ if (!next || next.startsWith("-")) {
37
+ return {
38
+ error: `参数 ${flagName} 缺少值`,
39
+ nextIndex: index
40
+ };
41
+ }
42
+ return { value: next, nextIndex: index + 1 };
43
+ };
44
+ var parseDeployArgs = (rawArgs = []) => {
45
+ const parsed = {
46
+ action: null,
47
+ env: "",
48
+ version: "",
49
+ bump: "",
50
+ changelog: "",
51
+ isRelease: true,
52
+ whetherBuild: true,
53
+ isConfirm: true,
54
+ isManuallyUploadOss: false,
55
+ hasCliOptions: false,
56
+ errors: []
57
+ };
58
+ for (let index = 0; index < rawArgs.length; index++) {
59
+ const arg = rawArgs[index];
60
+ if (!arg.startsWith("-")) {
61
+ continue;
62
+ }
63
+ parsed.hasCliOptions = true;
64
+ if (arg === "--release") {
65
+ if (parsed.action && parsed.action !== "release") {
66
+ parsed.errors.push("不能同时指定 --release 和 --upload");
67
+ }
68
+ parsed.action = "release";
69
+ continue;
70
+ }
71
+ if (arg === "--upload") {
72
+ if (parsed.action && parsed.action !== "uploadCode") {
73
+ parsed.errors.push("不能同时指定 --release 和 --upload");
74
+ }
75
+ parsed.action = "uploadCode";
76
+ continue;
77
+ }
78
+ if (arg === "--yes") {
79
+ parsed.isConfirm = true;
80
+ continue;
81
+ }
82
+ if (arg === "--no-release") {
83
+ parsed.isRelease = false;
84
+ continue;
85
+ }
86
+ if (arg === "--build") {
87
+ parsed.whetherBuild = true;
88
+ continue;
89
+ }
90
+ if (arg === "--no-build") {
91
+ parsed.whetherBuild = false;
92
+ continue;
93
+ }
94
+ if (arg === "--manual-oss") {
95
+ parsed.isManuallyUploadOss = true;
96
+ continue;
97
+ }
98
+ if (arg === "--no-manual-oss") {
99
+ parsed.isManuallyUploadOss = false;
100
+ continue;
101
+ }
102
+ if (arg === "--patch" || arg === "--minor" || arg === "--major") {
103
+ parsed.bump = arg.replace("--", "");
104
+ continue;
105
+ }
106
+ if (arg === "--env" || arg.startsWith("--env=")) {
107
+ const { value, nextIndex, error } = getFlagValue({
108
+ args: rawArgs,
109
+ index,
110
+ flagName: "--env"
111
+ });
112
+ if (error) {
113
+ parsed.errors.push(error);
114
+ continue;
115
+ }
116
+ parsed.env = value;
117
+ index = nextIndex;
118
+ continue;
119
+ }
120
+ if (arg === "--version" || arg.startsWith("--version=")) {
121
+ const { value, nextIndex, error } = getFlagValue({
122
+ args: rawArgs,
123
+ index,
124
+ flagName: "--version"
125
+ });
126
+ if (error) {
127
+ parsed.errors.push(error);
128
+ continue;
129
+ }
130
+ parsed.version = value;
131
+ index = nextIndex;
132
+ continue;
133
+ }
134
+ if (arg === "--bump" || arg.startsWith("--bump=")) {
135
+ const { value, nextIndex, error } = getFlagValue({
136
+ args: rawArgs,
137
+ index,
138
+ flagName: "--bump"
139
+ });
140
+ if (error) {
141
+ parsed.errors.push(error);
142
+ continue;
143
+ }
144
+ parsed.bump = value;
145
+ index = nextIndex;
146
+ continue;
147
+ }
148
+ if (arg === "--changelog" || arg.startsWith("--changelog=")) {
149
+ const { value, nextIndex, error } = getFlagValue({
150
+ args: rawArgs,
151
+ index,
152
+ flagName: "--changelog"
153
+ });
154
+ if (error) {
155
+ parsed.errors.push(error);
156
+ continue;
157
+ }
158
+ parsed.changelog = value;
159
+ index = nextIndex;
160
+ continue;
161
+ }
162
+ }
163
+ if (parsed.env && !ENV_CHOICES.includes(parsed.env)) {
164
+ parsed.errors.push(
165
+ `--env 仅支持 ${ENV_CHOICES.join(", ")},当前值为 ${parsed.env}`
166
+ );
167
+ }
168
+ if (parsed.bump && !BUMP_CHOICES.includes(parsed.bump)) {
169
+ parsed.errors.push(
170
+ `--bump 仅支持 ${BUMP_CHOICES.join(", ")},当前值为 ${parsed.bump}`
171
+ );
172
+ }
173
+ return parsed;
174
+ };
175
+ // Annotate the CommonJS export names for ESM import in node:
176
+ 0 && (module.exports = {
177
+ BUMP_CHOICES,
178
+ ENV_CHOICES,
179
+ parseDeployArgs
180
+ });
@@ -33,6 +33,7 @@ __export(deploy_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(deploy_exports);
35
35
  var import_inquirer = __toESM(require("inquirer"));
36
+ var import_args = require("./args.js");
36
37
  var import_release = __toESM(require("./release/index.js"));
37
38
  var import_uploadCode = __toESM(require("./uploadCode/index.js"));
38
39
  var actions = {
@@ -52,9 +53,17 @@ var inquirerResult = () => {
52
53
  }
53
54
  ]);
54
55
  };
55
- var deploy = async () => {
56
+ var deploy = async (...rawArgs) => {
57
+ const cliArgs = (0, import_args.parseDeployArgs)(rawArgs);
58
+ if (cliArgs.errors.length) {
59
+ cliArgs.errors.forEach((item) => console.log(`❌ ${item}`));
60
+ process.exit(1);
61
+ }
62
+ if (cliArgs.action) {
63
+ return actions[cliArgs.action](cliArgs);
64
+ }
56
65
  let res = await inquirerResult();
57
- return actions[res.action]();
66
+ return actions[res.action](cliArgs);
58
67
  };
59
68
  var deploy_default = deploy;
60
69
  // Annotate the CommonJS export names for ESM import in node:
@@ -22,6 +22,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  ));
23
23
 
24
24
  // src/script/index.js
25
+ var import_path = __toESM(require("path"));
25
26
  var import_url = require("url");
26
27
  var import_deploy = __toESM(require("./deploy.js"));
27
28
  var import_utils = require("./utils/index.js");
@@ -33,7 +34,7 @@ var isVersion = (v) => {
33
34
  var isHelp = (v) => {
34
35
  return ["-h", "--help", "-H"].includes(v);
35
36
  };
36
- var __dirname = path.dirname((0, import_url.fileURLToPath)(import_meta.url));
37
+ var __dirname = import_path.default.dirname((0, import_url.fileURLToPath)(import_meta.url));
37
38
  (() => {
38
39
  try {
39
40
  const params = args.slice(1);
@@ -43,13 +44,22 @@ var __dirname = path.dirname((0, import_url.fileURLToPath)(import_meta.url));
43
44
  break;
44
45
  case isVersion(args[0]):
45
46
  console.log(
46
- `@pisell/common@${(0, import_utils.loadJSON)(path.join(__dirname, "../../package.json")).version}`
47
+ `@pisell/common@${(0, import_utils.loadJSON)(import_path.default.join(__dirname, "../../package.json")).version}`
47
48
  );
48
49
  break;
49
50
  case isHelp(args[0]):
50
51
  console.log("pisell -h --help -H [全部命令]");
51
52
  console.log("pisell -v --version -V [显示版本]");
52
53
  console.log("pisell deploy [上传代码|发布代码]");
54
+ console.log(
55
+ "pisell deploy --release --env=release [直接发布, 未传--version默认最新版本]"
56
+ );
57
+ console.log(
58
+ 'pisell deploy --upload --env=pre --patch --changelog="xxx" --no-release --yes'
59
+ );
60
+ console.log(
61
+ "deploy 参数: --release --upload --env --version --bump --patch --minor --major --changelog --no-release --build --no-build --manual-oss --yes"
62
+ );
53
63
  break;
54
64
  default:
55
65
  break;
@@ -94,14 +94,32 @@ var getVersionList = async ({ env, project }) => {
94
94
  ).then((res) => res.json());
95
95
  return (0, import_utils.versionSort)(versionList.filter((item) => !ignoreName.includes(item)));
96
96
  };
97
- async function init() {
98
- let projectAndEnv = await selectProject();
97
+ async function init(cliArgs = {}) {
98
+ let projectAndEnv = cliArgs.env ? { env: cliArgs.env } : await selectProject();
99
99
  projectAndEnv.project = {
100
100
  path: "./",
101
101
  fileName: (0, import_utils.getCurrentProjectName)()
102
102
  };
103
103
  const versionList = await getVersionList(projectAndEnv);
104
- const res = await inquirerResult(versionList);
104
+ if (!versionList.length) {
105
+ console.log("未获取到可发布版本");
106
+ return;
107
+ }
108
+ const isCliMode = Boolean(cliArgs.action === "release" || cliArgs.version);
109
+ if (cliArgs.version && !versionList.includes(cliArgs.version)) {
110
+ console.log(
111
+ `未找到版本 ${cliArgs.version},可选版本: ${versionList.join(", ")}`
112
+ );
113
+ return;
114
+ }
115
+ const res = isCliMode ? {
116
+ version: cliArgs.version || versionList[0],
117
+ is_release: cliArgs.isConfirm
118
+ } : await inquirerResult(versionList);
119
+ if (!res.is_release) {
120
+ console.log("取消发布");
121
+ return;
122
+ }
105
123
  const releaseInstance = new import_release.default({ ...res, ...projectAndEnv });
106
124
  try {
107
125
  await releaseInstance.setConfig();
@@ -121,16 +121,35 @@ var inquirerOss = () => {
121
121
  }
122
122
  ]);
123
123
  };
124
- async function init() {
125
- let res = await inquirerResult();
124
+ async function init(cliArgs = {}) {
125
+ const isCliMode = Boolean(cliArgs.action === "uploadCode");
126
+ const isBumpVersion = cliArgs.version === "patch" || cliArgs.version === "minor" || cliArgs.version === "major";
127
+ if (isCliMode && cliArgs.version && !isBumpVersion && !cliArgs.bump) {
128
+ console.log(
129
+ `upload 模式下 --version 仅支持 patch/minor/major,或改用 --bump,当前值为 ${cliArgs.version}`
130
+ );
131
+ return;
132
+ }
133
+ let res = isCliMode ? {
134
+ env: cliArgs.env || "release",
135
+ version: cliArgs.bump || cliArgs.version || "patch",
136
+ changelog: cliArgs.changelog || "update",
137
+ is_release: cliArgs.isRelease,
138
+ whether_build: cliArgs.whetherBuild,
139
+ is_confirm: cliArgs.isConfirm
140
+ } : await inquirerResult();
126
141
  let isManuallyOss = false;
127
142
  if (!res.is_confirm) {
128
143
  console.log("取消发布");
129
144
  return;
130
145
  }
131
146
  if (res.env === "prod") {
132
- const isManuallyOssRes = await isManuallyUploadOss();
133
- isManuallyOss = isManuallyOssRes.is_manually_upload_OSS;
147
+ if (isCliMode) {
148
+ isManuallyOss = cliArgs.isManuallyUploadOss;
149
+ } else {
150
+ const isManuallyOssRes = await isManuallyUploadOss();
151
+ isManuallyOss = isManuallyOssRes.is_manually_upload_OSS;
152
+ }
134
153
  }
135
154
  res.project = {
136
155
  path: "./",
@@ -175,9 +194,11 @@ async function init() {
175
194
  if (!isManuallyOss) {
176
195
  let _fileName = res.project.fileName;
177
196
  await (0, import_aws.uploadStaticToOSS)(_fileName);
178
- const ossRes = await inquirerOss();
179
- if (!ossRes.is_upload_completed_OSS) {
180
- return;
197
+ if (!isCliMode) {
198
+ const ossRes = await inquirerOss();
199
+ if (!ossRes.is_upload_completed_OSS) {
200
+ return;
201
+ }
181
202
  }
182
203
  }
183
204
  }
@@ -130,7 +130,7 @@ var serverUnpack = (conn, { path: path2, fileName, fullFileName, changelog, env
130
130
  cd /tmp
131
131
  mv ${fullFileName} ${path2}
132
132
  cd ${path2}
133
- unzip ${fullFileName} -d ${fileName} && mv ${fileName}/dist/* ${fileName}/ && rmdir ${fileName}/dist
133
+ unzip ${fullFileName} -d ${fileName} && \\mv -f ${fileName}/dist/* ${fileName}/ && rmdir ${fileName}/dist
134
134
  rm -rf ${fullFileName}
135
135
  echo "${changelog}" > ./${fileName}/changelog.md
136
136
  sh deleteOldVersion.sh
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/common",
3
- "version": "0.0.68",
3
+ "version": "0.0.70",
4
4
  "description": "A collection of reusable UI components for web development",
5
5
  "license": "MIT",
6
6
  "sideEffects": [