@xfe-repo/mini-app 2.0.0-beta.1 → 2.0.0-beta.3

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.
@@ -1,343 +1,74 @@
1
- function _array_like_to_array(arr, len) {
2
- if (len == null || len > arr.length) len = arr.length;
3
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
- return arr2;
5
- }
6
- function _array_with_holes(arr) {
7
- if (Array.isArray(arr)) return arr;
8
- }
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
- try {
11
- var info = gen[key](arg);
12
- var value = info.value;
13
- } catch (error) {
14
- reject(error);
15
- return;
16
- }
17
- if (info.done) {
18
- resolve(value);
19
- } else {
20
- Promise.resolve(value).then(_next, _throw);
21
- }
22
- }
23
- function _async_to_generator(fn) {
24
- return function() {
25
- var self = this, args = arguments;
26
- return new Promise(function(resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
37
- }
38
- function _inherits(subClass, superClass) {
39
- if (typeof superClass !== "function" && superClass !== null) {
40
- throw new TypeError("Super expression must either be null or a function");
41
- }
42
- subClass.prototype = Object.create(superClass && superClass.prototype, {
43
- constructor: {
44
- value: subClass,
45
- writable: true,
46
- configurable: true
47
- }
48
- });
49
- if (superClass) _set_prototype_of(subClass, superClass);
50
- }
51
- function _iterable_to_array_limit(arr, i) {
52
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
53
- if (_i == null) return;
54
- var _arr = [];
55
- var _n = true;
56
- var _d = false;
57
- var _s, _e;
58
- try {
59
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
60
- _arr.push(_s.value);
61
- if (i && _arr.length === i) break;
62
- }
63
- } catch (err) {
64
- _d = true;
65
- _e = err;
66
- } finally{
67
- try {
68
- if (!_n && _i["return"] != null) _i["return"]();
69
- } finally{
70
- if (_d) throw _e;
71
- }
72
- }
73
- return _arr;
74
- }
75
- function _non_iterable_rest() {
76
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
77
- }
78
- function _set_prototype_of(o, p) {
79
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
80
- o.__proto__ = p;
81
- return o;
82
- };
83
- return _set_prototype_of(o, p);
84
- }
85
- function _sliced_to_array(arr, i) {
86
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
87
- }
88
- function _unsupported_iterable_to_array(o, minLen) {
89
- if (!o) return;
90
- if (typeof o === "string") return _array_like_to_array(o, minLen);
91
- var n = Object.prototype.toString.call(o).slice(8, -1);
92
- if (n === "Object" && o.constructor) n = o.constructor.name;
93
- if (n === "Map" || n === "Set") return Array.from(n);
94
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
95
- }
96
- function _wrap_reg_exp(re, groups) {
97
- _wrap_reg_exp = function(re, groups) {
98
- return new WrappedRegExp(re, undefined, groups);
99
- };
100
- var _super = RegExp.prototype;
101
- var _groups = new WeakMap();
102
- function WrappedRegExp(re, flags, groups) {
103
- var _re = new RegExp(re, flags);
104
- _groups.set(_re, groups || _groups.get(re));
105
- return _set_prototype_of(_re, WrappedRegExp.prototype);
106
- }
107
- _inherits(WrappedRegExp, RegExp);
108
- WrappedRegExp.prototype.exec = function(str) {
109
- var result = _super.exec.call(this, str);
110
- if (result) {
111
- result.groups = buildGroups(result, this);
112
- var indices = result.indices;
113
- if (indices) indices.groups = buildGroups(indices, this);
114
- }
115
- return result;
116
- };
117
- WrappedRegExp.prototype[Symbol.replace] = function(str, substitution) {
118
- if (typeof substitution === "string") {
119
- var groups = _groups.get(this);
120
- return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function(_, name) {
121
- var group = groups ? groups[name] : undefined;
122
- if (group === undefined) return "";
123
- return "$" + (Array.isArray(group) ? group.join("$") : group);
124
- }));
125
- }
126
- if (typeof substitution === "function") {
127
- var _this = this;
128
- return _super[Symbol.replace].call(this, str, function() {
129
- var args = arguments;
130
- if (typeof args[args.length - 1] !== "object") {
131
- args = [].slice.call(args);
132
- args.push(buildGroups(args, _this));
133
- }
134
- return substitution.apply(this, args);
135
- });
136
- }
137
- return _super[Symbol.replace].call(this, str, substitution);
138
- };
139
- function buildGroups(result, re) {
140
- var g = _groups.get(re);
141
- return Object.keys(g).reduce(function(groups, name) {
142
- var i = g[name];
143
- if (typeof i === "number") groups[name] = result[i];
144
- else {
145
- var k = 0;
146
- while(result[i[k]] === undefined && k + 1 < i.length)k++;
147
- groups[name] = result[i[k]];
148
- }
149
- return groups;
150
- }, Object.create(null));
151
- }
152
- return _wrap_reg_exp.apply(this, arguments);
153
- }
154
- function _ts_generator(thisArg, body) {
155
- var f, y, t, _ = {
156
- label: 0,
157
- sent: function() {
158
- if (t[0] & 1) throw t[1];
159
- return t[1];
160
- },
161
- trys: [],
162
- ops: []
163
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
164
- return d(g, "next", {
165
- value: verb(0)
166
- }), d(g, "throw", {
167
- value: verb(1)
168
- }), d(g, "return", {
169
- value: verb(2)
170
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
171
- value: function() {
172
- return this;
173
- }
174
- }), g;
175
- function verb(n) {
176
- return function(v) {
177
- return step([
178
- n,
179
- v
180
- ]);
181
- };
182
- }
183
- function step(op) {
184
- if (f) throw new TypeError("Generator is already executing.");
185
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
186
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
187
- if (y = 0, t) op = [
188
- op[0] & 2,
189
- t.value
190
- ];
191
- switch(op[0]){
192
- case 0:
193
- case 1:
194
- t = op;
195
- break;
196
- case 4:
197
- _.label++;
198
- return {
199
- value: op[1],
200
- done: false
201
- };
202
- case 5:
203
- _.label++;
204
- y = op[1];
205
- op = [
206
- 0
207
- ];
208
- continue;
209
- case 7:
210
- op = _.ops.pop();
211
- _.trys.pop();
212
- continue;
213
- default:
214
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
215
- _ = 0;
216
- continue;
217
- }
218
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
219
- _.label = op[1];
220
- break;
221
- }
222
- if (op[0] === 6 && _.label < t[1]) {
223
- _.label = t[1];
224
- t = op;
225
- break;
226
- }
227
- if (t && _.label < t[2]) {
228
- _.label = t[2];
229
- _.ops.push(op);
230
- break;
231
- }
232
- if (t[2]) _.ops.pop();
233
- _.trys.pop();
234
- continue;
235
- }
236
- op = body.call(thisArg, _);
237
- } catch (e) {
238
- op = [
239
- 6,
240
- e
241
- ];
242
- y = 0;
243
- } finally{
244
- f = t = 0;
245
- }
246
- if (op[0] & 5) throw op[1];
247
- return {
248
- value: op[0] ? op[1] : void 0,
249
- done: true
250
- };
251
- }
252
- }
253
1
  // src/preview.ts
254
2
  import fs from "fs";
255
3
  import path from "path";
256
4
  import { Project, preview } from "miniprogram-ci";
257
- var getProject = function getProject() {
258
- var rwaPrivateKey = "", rawProjectConfig = "";
259
- var projectRoot = process.cwd();
260
- try {
261
- rwaPrivateKey = fs.readFileSync(path.join(projectRoot, "private.key")).toString();
262
- } catch (unused) {
263
- console.error("Error: \u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA private.key \u6587\u4EF6\uFF0C\u5185\u5BB9\u4E3A\u5C0F\u7A0B\u5E8F\u7684\u79C1\u94A5");
264
- process.exit(1);
265
- }
266
- try {
267
- rawProjectConfig = fs.readFileSync(path.join(projectRoot, "project.config.json")).toString();
268
- } catch (unused) {
269
- console.error("Error: \u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA project.config.json \u6587\u4EF6\uFF0C\u5185\u5BB9\u4E3A\u5C0F\u7A0B\u5E8F\u7684\u914D\u7F6E");
270
- process.exit(1);
271
- }
272
- var projectConfig = JSON.parse(rawProjectConfig);
273
- return new Project({
274
- appid: projectConfig.appid,
275
- projectPath: projectConfig.miniprogramRoot,
276
- privateKey: rwaPrivateKey,
277
- type: "miniProgram",
278
- ignores: [
279
- "node_modules/**/*"
280
- ]
281
- });
5
+ var getProject = () => {
6
+ let rwaPrivateKey = "", rawProjectConfig = "";
7
+ const projectRoot = process.cwd();
8
+ try {
9
+ rwaPrivateKey = fs.readFileSync(path.join(projectRoot, "private.key")).toString();
10
+ } catch {
11
+ console.error("Error: \u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA private.key \u6587\u4EF6\uFF0C\u5185\u5BB9\u4E3A\u5C0F\u7A0B\u5E8F\u7684\u79C1\u94A5");
12
+ process.exit(1);
13
+ }
14
+ try {
15
+ rawProjectConfig = fs.readFileSync(path.join(projectRoot, "project.config.json")).toString();
16
+ } catch {
17
+ console.error("Error: \u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA project.config.json \u6587\u4EF6\uFF0C\u5185\u5BB9\u4E3A\u5C0F\u7A0B\u5E8F\u7684\u914D\u7F6E");
18
+ process.exit(1);
19
+ }
20
+ const projectConfig = JSON.parse(rawProjectConfig);
21
+ return new Project({
22
+ appid: projectConfig.appid,
23
+ projectPath: projectConfig.miniprogramRoot,
24
+ privateKey: rwaPrivateKey,
25
+ type: "miniProgram",
26
+ ignores: ["node_modules/**/*"]
27
+ });
282
28
  };
283
- function previewMini(version) {
284
- var pageUrl = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "", desc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "", scene = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 1011, progress = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : false;
285
- return _async_to_generator(function() {
286
- var _pageUrl_split, pagePath, searchQuery, project, robot;
287
- return _ts_generator(this, function(_state) {
288
- switch(_state.label){
289
- case 0:
290
- _pageUrl_split = _sliced_to_array(pageUrl.split("?"), 2), pagePath = _pageUrl_split[0], searchQuery = _pageUrl_split[1];
291
- project = getProject();
292
- robot = choiceRobot();
293
- return [
294
- 4,
295
- preview({
296
- project: project,
297
- version: version,
298
- qrcodeFormat: "terminal",
299
- qrcodeOutputDest: "deploy/preview.qrcode.jpg",
300
- pagePath: pagePath,
301
- searchQuery: searchQuery,
302
- desc: desc,
303
- robot: robot,
304
- scene: scene
305
- })
306
- ];
307
- case 1:
308
- _state.sent();
309
- return [
310
- 2
311
- ];
312
- }
313
- });
314
- })();
29
+ async function previewMini(version, pageUrl = "", desc = "", scene = 1011, progress = false) {
30
+ const [pagePath, searchQuery] = pageUrl.split("?");
31
+ const project = getProject();
32
+ const robot = choiceRobot();
33
+ await preview({
34
+ project,
35
+ version,
36
+ qrcodeFormat: "terminal",
37
+ qrcodeOutputDest: "deploy/preview.qrcode.jpg",
38
+ pagePath,
39
+ searchQuery,
40
+ desc,
41
+ robot,
42
+ scene
43
+ });
315
44
  }
316
- var choiceRobot = function choiceRobot() {
317
- var _process_env = process.env, _process_env_API_ENV = _process_env.API_ENV, API_ENV = _process_env_API_ENV === void 0 ? "" : _process_env_API_ENV;
318
- var groups = (API_ENV.match(_wrap_reg_exp(/^(prod|beta|stage|test)(.*)/, {
319
- env: 1,
320
- sn: 2
321
- })) || {}).groups;
322
- var env = (groups === null || groups === void 0 ? void 0 : groups.env) || "other";
323
- var sn = Number(groups === null || groups === void 0 ? void 0 : groups.sn) || 0;
324
- var robot;
325
- switch(env){
326
- case "prod":
327
- case "beta":
328
- robot = 1;
329
- break;
330
- case "stage":
331
- robot = 2;
332
- break;
333
- case "test":
334
- robot = sn % 29 >= 3 ? sn % 29 : 3;
335
- break;
336
- case "other":
337
- robot = 30;
338
- break;
339
- }
340
- console.log("将使用CI".concat(robot, "机器人"));
341
- return robot;
45
+ var choiceRobot = () => {
46
+ const { API_ENV = "" } = process.env;
47
+ const { groups } = API_ENV.match(/^(?<env>prod|beta|stage|test)(?<sn>.*)/) || {};
48
+ const env = groups?.env || "other";
49
+ const sn = Number(groups?.sn) || 0;
50
+ let robot;
51
+ switch (env) {
52
+ case "prod":
53
+ case "beta":
54
+ robot = 1;
55
+ break;
56
+ case "stage":
57
+ robot = 2;
58
+ break;
59
+ case "test":
60
+ robot = sn % 29 >= 3 ? sn % 29 : 3;
61
+ break;
62
+ case "other":
63
+ robot = 30;
64
+ break;
65
+ }
66
+ console.log(`\u5C06\u4F7F\u7528CI${robot}\u673A\u5668\u4EBA`);
67
+ return robot;
68
+ };
69
+
70
+ export {
71
+ getProject,
72
+ previewMini,
73
+ choiceRobot
342
74
  };
343
- export { getProject, previewMini, choiceRobot };
@@ -1,11 +1,10 @@
1
- var __require = /* @__PURE__ */ function(x) {
2
- return typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: function get(a, b) {
4
- return (typeof require !== "undefined" ? require : a)[b];
5
- }
6
- }) : x;
7
- }(function(x) {
8
- if (typeof require !== "undefined") return require.apply(this, arguments);
9
- throw Error('Dynamic require of "' + x + '" is not supported');
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
10
6
  });
11
- export { __require };
7
+
8
+ export {
9
+ __require
10
+ };