@xfe-repo/mini-app 2.0.0-beta.1 → 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.
@@ -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 };
@@ -0,0 +1,153 @@
1
+ // src/config.ts
2
+ import fs2 from "fs";
3
+
4
+ // src/config/deploy.ts
5
+ import path2 from "path";
6
+ import { fileURLToPath } from "url";
7
+
8
+ // ../../shared/deploy/config.ts
9
+ import fs from "fs";
10
+ import path from "path";
11
+ import { createRequire } from "module";
12
+ var DeployEnvironment = /* @__PURE__ */ ((DeployEnvironment2) => {
13
+ DeployEnvironment2["Test"] = "test";
14
+ DeployEnvironment2["Stage"] = "stage";
15
+ DeployEnvironment2["Prod"] = "prod";
16
+ DeployEnvironment2["Stable"] = "stable";
17
+ return DeployEnvironment2;
18
+ })(DeployEnvironment || {});
19
+ var generateDeploy = ({
20
+ deploy,
21
+ frameworkRoot,
22
+ isMini = false
23
+ }) => {
24
+ const yaml = createRequire(path.join(frameworkRoot, "package.json"))("yaml");
25
+ const supportedFields = ["values", "environments", "pushHelmChart", ...isMini ? ["platforms"] : []];
26
+ if (deploy === void 0) return;
27
+ if (!deploy || typeof deploy !== "object" || Array.isArray(deploy) || Object.keys(deploy).some(
28
+ /** 运行参数只能来自 values,流水线开关保留独立入口。 */
29
+ (key) => !supportedFields.includes(key)
30
+ )) {
31
+ throw new Error(`xfe.json.deploy \u4EC5\u652F\u6301 ${supportedFields.join("\u3001")}\uFF1B\u8FD0\u884C\u53C2\u6570\u8BF7\u653E\u5165 values`);
32
+ }
33
+ const environments = deploy.environments === void 0 ? Object.values(DeployEnvironment) : deploy.environments;
34
+ if (!Array.isArray(environments) || environments.some(
35
+ /** 只接受已知的环境名称,非法值不能误开启发布。 */
36
+ (environment) => !Object.values(DeployEnvironment).includes(environment)
37
+ ))
38
+ throw new Error("deploy.environments \u5FC5\u987B\u662F test\u3001stage\u3001prod\u3001stable \u7EC4\u6210\u7684\u6570\u7EC4\uFF1B\u7A7A\u6570\u7EC4\u5173\u95ED\u5168\u90E8\u90E8\u7F72");
39
+ if (deploy.pushHelmChart !== void 0 && typeof deploy.pushHelmChart !== "boolean") throw new Error("deploy.pushHelmChart \u5FC5\u987B\u662F\u5E03\u5C14\u503C");
40
+ const platforms = deploy.platforms === void 0 ? ["weapp", "h5"] : deploy.platforms;
41
+ if (!Array.isArray(platforms) || platforms.some((platform) => !["weapp", "h5"].includes(platform))) {
42
+ throw new Error("deploy.platforms \u5FC5\u987B\u662F weapp\u3001h5 \u7EC4\u6210\u7684\u6570\u7EC4\uFF1B\u7A7A\u6570\u7EC4\u5173\u95ED\u5168\u90E8\u53D1\u5E03");
43
+ }
44
+ const h5Environments = platforms.includes("h5") ? environments : [];
45
+ const miniEnvironments = platforms.includes("weapp") ? environments : [];
46
+ const pushHelmChart = deploy.pushHelmChart !== false && h5Environments.includes("prod" /* Prod */);
47
+ const source = path.join(frameworkRoot, "deploy");
48
+ const target = path.join(process.cwd(), "deploy");
49
+ let overrides = deploy.values === void 0 ? {} : deploy.values;
50
+ if (typeof overrides === "string") {
51
+ const valuesPath = fs.realpathSync(path.resolve(overrides));
52
+ if (valuesPath.startsWith(target + path.sep) && valuesPath !== path.join(target, "values.yaml")) {
53
+ throw new Error("\u9879\u76EE values \u6587\u4EF6\u4E0D\u80FD\u653E\u5728\u751F\u6210\u5B50\u76EE\u5F55\u4E2D\uFF0C\u8BF7\u4F7F\u7528 deploy/values.yaml \u6216\u9879\u76EE\u6839\u76EE\u5F55\u7684 values.yaml");
54
+ }
55
+ overrides = yaml.parse(fs.readFileSync(valuesPath, "utf8"));
56
+ }
57
+ if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) {
58
+ throw new Error("deploy.values \u5FC5\u987B\u662F\u5BF9\u8C61\u6216\u6307\u5411 YAML \u5BF9\u8C61\u6587\u4EF6\u7684\u8DEF\u5F84");
59
+ }
60
+ if (Object.hasOwn(overrides, "environments") || Object.hasOwn(overrides, "pushHelmChart"))
61
+ throw new Error("values \u4E0D\u518D\u652F\u6301 environments \u6216 pushHelmChart\uFF1B\u8BF7\u8FC1\u5165 xfe.json.deploy\uFF0C\u73AF\u5883\u5F00\u5173\u4F7F\u7528\u6570\u7EC4");
62
+ const defaults = yaml.parse(fs.readFileSync(path.join(source, "helm/values.yaml"), "utf8"));
63
+ const values = mergeDeployValues(defaults, overrides);
64
+ if (typeof values.host !== "string" || /[\\/?#@:\s]/.test(values.host)) {
65
+ throw new Error("values.host \u5FC5\u987B\u662F\u4E0D\u542B\u534F\u8BAE\u3001\u7AEF\u53E3\u548C\u8DEF\u5F84\u7684\u4E3B\u673A\u540D\uFF0C\u4F8B\u5982 specdoc.example.com");
66
+ }
67
+ if (!["saas", "infra"].includes(values.targetK8s)) throw new Error("deploy.values.targetK8s \u53EA\u80FD\u4E3A saas \u6216 infra");
68
+ if (target === source) throw new Error("\u90E8\u7F72\u8F93\u51FA\u4E0D\u80FD\u8986\u76D6\u6846\u67B6\u6A21\u677F\u76EE\u5F55");
69
+ if (fs.lstatSync(target, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error("deploy \u4E0D\u80FD\u4E3A\u7B26\u53F7\u94FE\u63A5\uFF0C\u4EE5\u514D\u8986\u76D6\u5916\u90E8\u76EE\u5F55");
70
+ const disabledEvents = "[custom, tag]";
71
+ const drone = fs.readFileSync(path.join(source, ".drone.yml"), "utf8").replaceAll("<<TARGET_K8S>>", values.targetK8s).replaceAll("<<EXCLUDE_EVENTS_deploy>>", h5Environments.length ? "[]" : disabledEvents).replaceAll("<<EXCLUDE_EVENTS_h5>>", h5Environments.length ? "[]" : disabledEvents).replaceAll(
72
+ "<<EXCLUDE_EVENTS_weapp>>",
73
+ miniEnvironments.some((environment) => environment !== "stable" /* Stable */) ? "[]" : disabledEvents
74
+ ).replace(
75
+ /<<EXCLUDE_EVENTS_weapp_(test|stage|prod)>>/g,
76
+ (_placeholder, environment) => miniEnvironments.includes(environment) ? "[]" : disabledEvents
77
+ ).replaceAll("<<EXCLUDE_EVENTS_push_helm_chart>>", pushHelmChart ? "[]" : disabledEvents).replace(
78
+ /<<EXCLUDE_EVENTS_(test|stage|prod|stable)>>/g,
79
+ /** 开启时不排除事件,关闭时由 Drone 原生 when 跳过该步骤。 */
80
+ (_placeholder, environment) => h5Environments.includes(environment) ? "[]" : disabledEvents
81
+ );
82
+ fs.cpSync(source, target, { recursive: true });
83
+ fs.writeFileSync(
84
+ path.join(target, "helm/values.yaml"),
85
+ yaml.stringify(values, {
86
+ defaultStringType: "QUOTE_SINGLE",
87
+ defaultKeyType: "PLAIN"
88
+ })
89
+ );
90
+ fs.writeFileSync(path.join(target, ".drone.yml"), drone);
91
+ };
92
+ function mergeDeployValues(base, overrides) {
93
+ return Object.fromEntries(
94
+ Object.entries({ ...base, ...overrides }).map(
95
+ /** 仅合并普通对象,列表保持声明的顺序。 */
96
+ ([key, value]) => {
97
+ const previous = base[key];
98
+ const previousObject = previous && typeof previous === "object" && !Array.isArray(previous);
99
+ if (value === true && previousObject) {
100
+ return [key, Object.hasOwn(previous, "enabled") ? { ...previous, enabled: true } : previous];
101
+ }
102
+ const mergeable = value && previousObject && typeof value === "object" && !Array.isArray(value);
103
+ return [key, mergeable ? mergeDeployValues(previous, value) : value];
104
+ }
105
+ )
106
+ );
107
+ }
108
+
109
+ // src/config/deploy.ts
110
+ var generateDeploy2 = (deploy) => {
111
+ const directory = typeof __dirname === "string" ? __dirname : path2.dirname(fileURLToPath(import.meta.url));
112
+ generateDeploy({ deploy, frameworkRoot: path2.resolve(directory, ".."), isMini: true });
113
+ };
114
+
115
+ // src/config.ts
116
+ var loadXfeConfig = () => {
117
+ const xfeConfigPath = "./xfe.json";
118
+ if (!fs2.existsSync(xfeConfigPath)) {
119
+ throw new Error("xfe.json \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF0C\u8BF7\u5728\u9879\u76EE\u6839\u76EE\u5F55\u4E0B\u521B\u5EFA\u8BE5\u6587\u4EF6\u3002");
120
+ }
121
+ const xfeConfigContent = fs2.readFileSync(xfeConfigPath, "utf8");
122
+ return JSON.parse(xfeConfigContent);
123
+ };
124
+ var configDeploy = () => generateDeploy2(loadXfeConfig().deploy);
125
+ var getJwtEnv = async () => {
126
+ const xfeConfig = loadXfeConfig();
127
+ if (!xfeConfig?.jwt) return {};
128
+ const { aud = "" } = xfeConfig.jwt;
129
+ if (!aud) throw new Error("xfe.json \u4E2D\u7684 jwt \u914D\u7F6E\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u786E\u4FDD\u5305\u542B aud \u5B57\u6BB5\u3002");
130
+ const jwkRes = await fetch(`https://app.eshetang.com/jwk?appId=${aud}`);
131
+ if (!jwkRes.ok) {
132
+ throw new Error(`\u8FDC\u7A0B\u83B7\u53D6\u5BC6\u94A5\u5931\u8D25: ${jwkRes.status} ${jwkRes.statusText}`);
133
+ }
134
+ let JwkResponseJson;
135
+ try {
136
+ JwkResponseJson = await jwkRes.json();
137
+ } catch (err) {
138
+ throw new Error(`\u8FDC\u7A0B\u83B7\u53D6\u5BC6\u94A5\u5931\u8D25\uFF0C\u54CD\u5E94\u89E3\u6790\u9519\u8BEF: ${err.message}, response text: ${await jwkRes.text()}`);
139
+ }
140
+ const { keyId, privateKeyPkcs8 } = JwkResponseJson?.data || {};
141
+ if (!keyId || !privateKeyPkcs8) throw new Error(`\u672A\u83B7\u53D6\u5230\u9879\u76EE\u7B7E\u540D\u5BC6\u94A5, \u8BF7\u68C0\u67E5aud\u662F\u5426\u6B63\u786E: ${aud}`);
142
+ return {
143
+ XFE_JWT_AUD: aud,
144
+ XFE_JWT_KEY_ID: keyId,
145
+ XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
146
+ };
147
+ };
148
+
149
+ export {
150
+ loadXfeConfig,
151
+ configDeploy,
152
+ getJwtEnv
153
+ };
@@ -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
+ };