@xfe-repo/mini-app 1.6.5 → 2.0.0-beta.2

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/dist/preview.js CHANGED
@@ -1,424 +1,110 @@
1
1
  "use strict";
2
- function _array_like_to_array(arr, len) {
3
- if (len == null || len > arr.length) len = arr.length;
4
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
- return arr2;
6
- }
7
- function _array_with_holes(arr) {
8
- if (Array.isArray(arr)) return arr;
9
- }
10
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
- try {
12
- var info = gen[key](arg);
13
- var value = info.value;
14
- } catch (error) {
15
- reject(error);
16
- return;
17
- }
18
- if (info.done) {
19
- resolve(value);
20
- } else {
21
- Promise.resolve(value).then(_next, _throw);
22
- }
23
- }
24
- function _async_to_generator(fn) {
25
- return function() {
26
- var self = this, args = arguments;
27
- return new Promise(function(resolve, reject) {
28
- var gen = fn.apply(self, args);
29
- function _next(value) {
30
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
31
- }
32
- function _throw(err) {
33
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
34
- }
35
- _next(undefined);
36
- });
37
- };
38
- }
39
- function _inherits(subClass, superClass) {
40
- if (typeof superClass !== "function" && superClass !== null) {
41
- throw new TypeError("Super expression must either be null or a function");
42
- }
43
- subClass.prototype = Object.create(superClass && superClass.prototype, {
44
- constructor: {
45
- value: subClass,
46
- writable: true,
47
- configurable: true
48
- }
49
- });
50
- if (superClass) _set_prototype_of(subClass, superClass);
51
- }
52
- function _iterable_to_array_limit(arr, i) {
53
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
54
- if (_i == null) return;
55
- var _arr = [];
56
- var _n = true;
57
- var _d = false;
58
- var _s, _e;
59
- try {
60
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
61
- _arr.push(_s.value);
62
- if (i && _arr.length === i) break;
63
- }
64
- } catch (err) {
65
- _d = true;
66
- _e = err;
67
- } finally{
68
- try {
69
- if (!_n && _i["return"] != null) _i["return"]();
70
- } finally{
71
- if (_d) throw _e;
72
- }
73
- }
74
- return _arr;
75
- }
76
- function _non_iterable_rest() {
77
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
78
- }
79
- function _set_prototype_of(o, p) {
80
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
81
- o.__proto__ = p;
82
- return o;
83
- };
84
- return _set_prototype_of(o, p);
85
- }
86
- function _sliced_to_array(arr, i) {
87
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
88
- }
89
- function _type_of(obj) {
90
- "@swc/helpers - typeof";
91
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
92
- }
93
- function _unsupported_iterable_to_array(o, minLen) {
94
- if (!o) return;
95
- if (typeof o === "string") return _array_like_to_array(o, minLen);
96
- var n = Object.prototype.toString.call(o).slice(8, -1);
97
- if (n === "Object" && o.constructor) n = o.constructor.name;
98
- if (n === "Map" || n === "Set") return Array.from(n);
99
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
100
- }
101
- function _wrap_reg_exp(re, groups) {
102
- _wrap_reg_exp = function(re, groups) {
103
- return new WrappedRegExp(re, undefined, groups);
104
- };
105
- var _super = RegExp.prototype;
106
- var _groups = new WeakMap();
107
- function WrappedRegExp(re, flags, groups) {
108
- var _re = new RegExp(re, flags);
109
- _groups.set(_re, groups || _groups.get(re));
110
- return _set_prototype_of(_re, WrappedRegExp.prototype);
111
- }
112
- _inherits(WrappedRegExp, RegExp);
113
- WrappedRegExp.prototype.exec = function(str) {
114
- var result = _super.exec.call(this, str);
115
- if (result) {
116
- result.groups = buildGroups(result, this);
117
- var indices = result.indices;
118
- if (indices) indices.groups = buildGroups(indices, this);
119
- }
120
- return result;
121
- };
122
- WrappedRegExp.prototype[Symbol.replace] = function(str, substitution) {
123
- if (typeof substitution === "string") {
124
- var groups = _groups.get(this);
125
- return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function(_, name) {
126
- var group = groups ? groups[name] : undefined;
127
- if (group === undefined) return "";
128
- return "$" + (Array.isArray(group) ? group.join("$") : group);
129
- }));
130
- }
131
- if (typeof substitution === "function") {
132
- var _this = this;
133
- return _super[Symbol.replace].call(this, str, function() {
134
- var args = arguments;
135
- if (typeof args[args.length - 1] !== "object") {
136
- args = [].slice.call(args);
137
- args.push(buildGroups(args, _this));
138
- }
139
- return substitution.apply(this, args);
140
- });
141
- }
142
- return _super[Symbol.replace].call(this, str, substitution);
143
- };
144
- function buildGroups(result, re) {
145
- var g = _groups.get(re);
146
- return Object.keys(g).reduce(function(groups, name) {
147
- var i = g[name];
148
- if (typeof i === "number") groups[name] = result[i];
149
- else {
150
- var k = 0;
151
- while(result[i[k]] === undefined && k + 1 < i.length)k++;
152
- groups[name] = result[i[k]];
153
- }
154
- return groups;
155
- }, Object.create(null));
156
- }
157
- return _wrap_reg_exp.apply(this, arguments);
158
- }
159
- function _ts_generator(thisArg, body) {
160
- var f, y, t, _ = {
161
- label: 0,
162
- sent: function() {
163
- if (t[0] & 1) throw t[1];
164
- return t[1];
165
- },
166
- trys: [],
167
- ops: []
168
- }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
169
- return d(g, "next", {
170
- value: verb(0)
171
- }), d(g, "throw", {
172
- value: verb(1)
173
- }), d(g, "return", {
174
- value: verb(2)
175
- }), typeof Symbol === "function" && d(g, Symbol.iterator, {
176
- value: function() {
177
- return this;
178
- }
179
- }), g;
180
- function verb(n) {
181
- return function(v) {
182
- return step([
183
- n,
184
- v
185
- ]);
186
- };
187
- }
188
- function step(op) {
189
- if (f) throw new TypeError("Generator is already executing.");
190
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
191
- 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;
192
- if (y = 0, t) op = [
193
- op[0] & 2,
194
- t.value
195
- ];
196
- switch(op[0]){
197
- case 0:
198
- case 1:
199
- t = op;
200
- break;
201
- case 4:
202
- _.label++;
203
- return {
204
- value: op[1],
205
- done: false
206
- };
207
- case 5:
208
- _.label++;
209
- y = op[1];
210
- op = [
211
- 0
212
- ];
213
- continue;
214
- case 7:
215
- op = _.ops.pop();
216
- _.trys.pop();
217
- continue;
218
- default:
219
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
220
- _ = 0;
221
- continue;
222
- }
223
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
224
- _.label = op[1];
225
- break;
226
- }
227
- if (op[0] === 6 && _.label < t[1]) {
228
- _.label = t[1];
229
- t = op;
230
- break;
231
- }
232
- if (t && _.label < t[2]) {
233
- _.label = t[2];
234
- _.ops.push(op);
235
- break;
236
- }
237
- if (t[2]) _.ops.pop();
238
- _.trys.pop();
239
- continue;
240
- }
241
- op = body.call(thisArg, _);
242
- } catch (e) {
243
- op = [
244
- 6,
245
- e
246
- ];
247
- y = 0;
248
- } finally{
249
- f = t = 0;
250
- }
251
- if (op[0] & 5) throw op[1];
252
- return {
253
- value: op[0] ? op[1] : void 0,
254
- done: true
255
- };
256
- }
257
- }
258
2
  var __create = Object.create;
259
3
  var __defProp = Object.defineProperty;
260
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
261
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
262
6
  var __getProtoOf = Object.getPrototypeOf;
263
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
264
- var __export = function __export(target, all) {
265
- for(var name in all)__defProp(target, name, {
266
- get: all[name],
267
- enumerable: true
268
- });
269
- };
270
- var __copyProps = function __copyProps(to, from, except, desc) {
271
- if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") {
272
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
273
- try {
274
- var _loop = function() {
275
- var key = _step.value;
276
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
277
- get: function get() {
278
- return from[key];
279
- },
280
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
281
- });
282
- };
283
- for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
284
- } catch (err) {
285
- _didIteratorError = true;
286
- _iteratorError = err;
287
- } finally{
288
- try {
289
- if (!_iteratorNormalCompletion && _iterator.return != null) {
290
- _iterator.return();
291
- }
292
- } finally{
293
- if (_didIteratorError) {
294
- throw _iteratorError;
295
- }
296
- }
297
- }
298
- }
299
- return to;
300
- };
301
- var __toESM = function __toESM(mod, isNodeMode, target) {
302
- return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
303
- // file that has been converted to a CommonJS file using a Babel-
304
- // compatible transform (i.e. "__esModule" has not been set), then set
305
- // "default" to the CommonJS "module.exports" for node compatibility.
306
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
307
- value: mod,
308
- enumerable: true
309
- }) : target, mod);
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
310
11
  };
311
- var __toCommonJS = function __toCommonJS(mod) {
312
- return __copyProps(__defProp({}, "__esModule", {
313
- value: true
314
- }), mod);
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
315
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
316
30
  // src/preview.ts
317
31
  var preview_exports = {};
318
32
  __export(preview_exports, {
319
- choiceRobot: function choiceRobot1() {
320
- return choiceRobot;
321
- },
322
- getProject: function getProject1() {
323
- return getProject;
324
- },
325
- previewMini: function previewMini1() {
326
- return previewMini;
327
- }
33
+ choiceRobot: () => choiceRobot,
34
+ getProject: () => getProject,
35
+ previewMini: () => previewMini
328
36
  });
329
37
  module.exports = __toCommonJS(preview_exports);
330
38
  var import_fs = __toESM(require("fs"));
331
39
  var import_path = __toESM(require("path"));
332
40
  var import_miniprogram_ci = require("miniprogram-ci");
333
- var getProject = function getProject() {
334
- var rwaPrivateKey = "", rawProjectConfig = "";
335
- var projectRoot = process.cwd();
336
- try {
337
- rwaPrivateKey = import_fs.default.readFileSync(import_path.default.join(projectRoot, "private.key")).toString();
338
- } catch (unused) {
339
- 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");
340
- process.exit(1);
341
- }
342
- try {
343
- rawProjectConfig = import_fs.default.readFileSync(import_path.default.join(projectRoot, "project.config.json")).toString();
344
- } catch (unused) {
345
- 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");
346
- process.exit(1);
347
- }
348
- var projectConfig = JSON.parse(rawProjectConfig);
349
- return new import_miniprogram_ci.Project({
350
- appid: projectConfig.appid,
351
- projectPath: projectConfig.miniprogramRoot,
352
- privateKey: rwaPrivateKey,
353
- type: "miniProgram",
354
- ignores: [
355
- "node_modules/**/*"
356
- ]
357
- });
41
+ var getProject = () => {
42
+ let rwaPrivateKey = "", rawProjectConfig = "";
43
+ const projectRoot = process.cwd();
44
+ try {
45
+ rwaPrivateKey = import_fs.default.readFileSync(import_path.default.join(projectRoot, "private.key")).toString();
46
+ } catch {
47
+ 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");
48
+ process.exit(1);
49
+ }
50
+ try {
51
+ rawProjectConfig = import_fs.default.readFileSync(import_path.default.join(projectRoot, "project.config.json")).toString();
52
+ } catch {
53
+ 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");
54
+ process.exit(1);
55
+ }
56
+ const projectConfig = JSON.parse(rawProjectConfig);
57
+ return new import_miniprogram_ci.Project({
58
+ appid: projectConfig.appid,
59
+ projectPath: projectConfig.miniprogramRoot,
60
+ privateKey: rwaPrivateKey,
61
+ type: "miniProgram",
62
+ ignores: ["node_modules/**/*"]
63
+ });
358
64
  };
359
- function previewMini(version) {
360
- 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;
361
- return _async_to_generator(function() {
362
- var _pageUrl_split, pagePath, searchQuery, project, robot;
363
- return _ts_generator(this, function(_state) {
364
- switch(_state.label){
365
- case 0:
366
- _pageUrl_split = _sliced_to_array(pageUrl.split("?"), 2), pagePath = _pageUrl_split[0], searchQuery = _pageUrl_split[1];
367
- project = getProject();
368
- robot = choiceRobot();
369
- return [
370
- 4,
371
- (0, import_miniprogram_ci.preview)({
372
- project: project,
373
- version: version,
374
- qrcodeFormat: "terminal",
375
- qrcodeOutputDest: "deploy/preview.qrcode.jpg",
376
- pagePath: pagePath,
377
- searchQuery: searchQuery,
378
- desc: desc,
379
- robot: robot,
380
- scene: scene
381
- })
382
- ];
383
- case 1:
384
- _state.sent();
385
- return [
386
- 2
387
- ];
388
- }
389
- });
390
- })();
65
+ async function previewMini(version, pageUrl = "", desc = "", scene = 1011, progress = false) {
66
+ const [pagePath, searchQuery] = pageUrl.split("?");
67
+ const project = getProject();
68
+ const robot = choiceRobot();
69
+ await (0, import_miniprogram_ci.preview)({
70
+ project,
71
+ version,
72
+ qrcodeFormat: "terminal",
73
+ qrcodeOutputDest: "deploy/preview.qrcode.jpg",
74
+ pagePath,
75
+ searchQuery,
76
+ desc,
77
+ robot,
78
+ scene
79
+ });
391
80
  }
392
- var choiceRobot = function choiceRobot() {
393
- 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;
394
- var groups = (API_ENV.match(_wrap_reg_exp(/^(prod|beta|stage|test)(.*)/, {
395
- env: 1,
396
- sn: 2
397
- })) || {}).groups;
398
- var env = (groups === null || groups === void 0 ? void 0 : groups.env) || "other";
399
- var sn = Number(groups === null || groups === void 0 ? void 0 : groups.sn) || 0;
400
- var robot;
401
- switch(env){
402
- case "prod":
403
- case "beta":
404
- robot = 1;
405
- break;
406
- case "stage":
407
- robot = 2;
408
- break;
409
- case "test":
410
- robot = sn % 29 >= 3 ? sn % 29 : 3;
411
- break;
412
- case "other":
413
- robot = 30;
414
- break;
415
- }
416
- console.log("将使用CI".concat(robot, "机器人"));
417
- return robot;
81
+ var choiceRobot = () => {
82
+ const { API_ENV = "" } = process.env;
83
+ const { groups } = API_ENV.match(/^(?<env>prod|beta|stage|test)(?<sn>.*)/) || {};
84
+ const env = groups?.env || "other";
85
+ const sn = Number(groups?.sn) || 0;
86
+ let robot;
87
+ switch (env) {
88
+ case "prod":
89
+ case "beta":
90
+ robot = 1;
91
+ break;
92
+ case "stage":
93
+ robot = 2;
94
+ break;
95
+ case "test":
96
+ robot = sn % 29 >= 3 ? sn % 29 : 3;
97
+ break;
98
+ case "other":
99
+ robot = 30;
100
+ break;
101
+ }
102
+ console.log(`\u5C06\u4F7F\u7528CI${robot}\u673A\u5668\u4EBA`);
103
+ return robot;
418
104
  };
419
105
  // Annotate the CommonJS export names for ESM import in node:
420
106
  0 && (module.exports = {
421
- choiceRobot: choiceRobot,
422
- getProject: getProject,
423
- previewMini: previewMini
107
+ choiceRobot,
108
+ getProject,
109
+ previewMini
424
110
  });
package/dist/preview.mjs CHANGED
@@ -1,2 +1,11 @@
1
- import { choiceRobot, getProject, previewMini } from "./chunk-MLSNG3O7.mjs";
2
- export { choiceRobot, getProject, previewMini };
1
+ import {
2
+ choiceRobot,
3
+ getProject,
4
+ previewMini
5
+ } from "./chunk-MLSNG3O7.mjs";
6
+ import "./chunk-Y6FXYEAI.mjs";
7
+ export {
8
+ choiceRobot,
9
+ getProject,
10
+ previewMini
11
+ };