@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.
- package/README.md +35 -0
- package/config/index.ts +2 -0
- package/deploy/.drone.yml +154 -156
- package/deploy/Dockerfile +4 -0
- package/deploy/helm/Chart.yaml +1 -1
- package/deploy/helm/templates/deployment.yaml +60 -22
- package/deploy/helm/templates/pvc.yaml +17 -0
- package/deploy/helm/templates/template.yaml +16 -0
- package/deploy/helm/templates/virtualService.yaml +13 -8
- package/deploy/helm/values.yaml +40 -7
- package/dist/chunk-4JD7C4FF.mjs +22 -164
- package/dist/chunk-MLSNG3O7.mjs +67 -336
- package/dist/chunk-MSNDQMQN.mjs +153 -0
- package/dist/chunk-Y6FXYEAI.mjs +9 -10
- package/dist/cli.js +503 -703
- package/dist/cli.mjs +53 -367
- package/dist/config.d.mts +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +168 -301
- package/dist/config.mjs +10 -2
- package/dist/preview.js +87 -401
- package/dist/preview.mjs +10 -2
- package/dist/upload.js +83 -349
- package/dist/upload.mjs +6 -2
- package/dist/workspace-7FXUJJOQ.mjs +220 -0
- package/package.json +5 -4
- package/dist/chunk-UC6ZB6VU.mjs +0 -242
package/dist/config.js
CHANGED
|
@@ -1,323 +1,190 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
3
|
-
try {
|
|
4
|
-
var info = gen[key](arg);
|
|
5
|
-
var value = info.value;
|
|
6
|
-
} catch (error) {
|
|
7
|
-
reject(error);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (info.done) {
|
|
11
|
-
resolve(value);
|
|
12
|
-
} else {
|
|
13
|
-
Promise.resolve(value).then(_next, _throw);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
function _async_to_generator(fn) {
|
|
17
|
-
return function() {
|
|
18
|
-
var self = this, args = arguments;
|
|
19
|
-
return new Promise(function(resolve, reject) {
|
|
20
|
-
var gen = fn.apply(self, args);
|
|
21
|
-
function _next(value) {
|
|
22
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
23
|
-
}
|
|
24
|
-
function _throw(err) {
|
|
25
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
26
|
-
}
|
|
27
|
-
_next(undefined);
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function _type_of(obj) {
|
|
32
|
-
"@swc/helpers - typeof";
|
|
33
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
34
|
-
}
|
|
35
|
-
function _ts_generator(thisArg, body) {
|
|
36
|
-
var f, y, t, _ = {
|
|
37
|
-
label: 0,
|
|
38
|
-
sent: function() {
|
|
39
|
-
if (t[0] & 1) throw t[1];
|
|
40
|
-
return t[1];
|
|
41
|
-
},
|
|
42
|
-
trys: [],
|
|
43
|
-
ops: []
|
|
44
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
45
|
-
return d(g, "next", {
|
|
46
|
-
value: verb(0)
|
|
47
|
-
}), d(g, "throw", {
|
|
48
|
-
value: verb(1)
|
|
49
|
-
}), d(g, "return", {
|
|
50
|
-
value: verb(2)
|
|
51
|
-
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
52
|
-
value: function() {
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
}), g;
|
|
56
|
-
function verb(n) {
|
|
57
|
-
return function(v) {
|
|
58
|
-
return step([
|
|
59
|
-
n,
|
|
60
|
-
v
|
|
61
|
-
]);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function step(op) {
|
|
65
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
66
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
67
|
-
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;
|
|
68
|
-
if (y = 0, t) op = [
|
|
69
|
-
op[0] & 2,
|
|
70
|
-
t.value
|
|
71
|
-
];
|
|
72
|
-
switch(op[0]){
|
|
73
|
-
case 0:
|
|
74
|
-
case 1:
|
|
75
|
-
t = op;
|
|
76
|
-
break;
|
|
77
|
-
case 4:
|
|
78
|
-
_.label++;
|
|
79
|
-
return {
|
|
80
|
-
value: op[1],
|
|
81
|
-
done: false
|
|
82
|
-
};
|
|
83
|
-
case 5:
|
|
84
|
-
_.label++;
|
|
85
|
-
y = op[1];
|
|
86
|
-
op = [
|
|
87
|
-
0
|
|
88
|
-
];
|
|
89
|
-
continue;
|
|
90
|
-
case 7:
|
|
91
|
-
op = _.ops.pop();
|
|
92
|
-
_.trys.pop();
|
|
93
|
-
continue;
|
|
94
|
-
default:
|
|
95
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
96
|
-
_ = 0;
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
100
|
-
_.label = op[1];
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
104
|
-
_.label = t[1];
|
|
105
|
-
t = op;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
if (t && _.label < t[2]) {
|
|
109
|
-
_.label = t[2];
|
|
110
|
-
_.ops.push(op);
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
if (t[2]) _.ops.pop();
|
|
114
|
-
_.trys.pop();
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
op = body.call(thisArg, _);
|
|
118
|
-
} catch (e) {
|
|
119
|
-
op = [
|
|
120
|
-
6,
|
|
121
|
-
e
|
|
122
|
-
];
|
|
123
|
-
y = 0;
|
|
124
|
-
} finally{
|
|
125
|
-
f = t = 0;
|
|
126
|
-
}
|
|
127
|
-
if (op[0] & 5) throw op[1];
|
|
128
|
-
return {
|
|
129
|
-
value: op[0] ? op[1] : void 0,
|
|
130
|
-
done: true
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
2
|
var __create = Object.create;
|
|
135
3
|
var __defProp = Object.defineProperty;
|
|
136
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
137
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
138
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
139
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
140
|
-
var __export =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
enumerable: true
|
|
144
|
-
});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
145
11
|
};
|
|
146
|
-
var __copyProps =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
get: function get() {
|
|
154
|
-
return from[key];
|
|
155
|
-
},
|
|
156
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
160
|
-
} catch (err) {
|
|
161
|
-
_didIteratorError = true;
|
|
162
|
-
_iteratorError = err;
|
|
163
|
-
} finally{
|
|
164
|
-
try {
|
|
165
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
166
|
-
_iterator.return();
|
|
167
|
-
}
|
|
168
|
-
} finally{
|
|
169
|
-
if (_didIteratorError) {
|
|
170
|
-
throw _iteratorError;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return to;
|
|
176
|
-
};
|
|
177
|
-
var __toESM = function __toESM(mod, isNodeMode, target) {
|
|
178
|
-
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
|
|
179
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
180
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
181
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
182
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
183
|
-
value: mod,
|
|
184
|
-
enumerable: true
|
|
185
|
-
}) : target, mod);
|
|
186
|
-
};
|
|
187
|
-
var __toCommonJS = function __toCommonJS(mod) {
|
|
188
|
-
return __copyProps(__defProp({}, "__esModule", {
|
|
189
|
-
value: true
|
|
190
|
-
}), 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;
|
|
191
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
|
+
|
|
192
30
|
// src/config.ts
|
|
193
31
|
var config_exports = {};
|
|
194
32
|
__export(config_exports, {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
getJwtEnv: function getJwtEnv1() {
|
|
199
|
-
return getJwtEnv;
|
|
200
|
-
},
|
|
201
|
-
loadXfeConfig: function loadXfeConfig1() {
|
|
202
|
-
return loadXfeConfig;
|
|
203
|
-
}
|
|
33
|
+
configDeploy: () => configDeploy,
|
|
34
|
+
getJwtEnv: () => getJwtEnv,
|
|
35
|
+
loadXfeConfig: () => loadXfeConfig
|
|
204
36
|
});
|
|
205
37
|
module.exports = __toCommonJS(config_exports);
|
|
206
|
-
var import_path = __toESM(require("path"));
|
|
207
38
|
var import_fs = __toESM(require("fs"));
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
39
|
+
|
|
40
|
+
// src/config/deploy.ts
|
|
41
|
+
var import_node_path2 = __toESM(require("path"));
|
|
42
|
+
var import_node_url = require("url");
|
|
43
|
+
|
|
44
|
+
// ../../shared/deploy/config.ts
|
|
45
|
+
var import_node_fs = __toESM(require("fs"));
|
|
46
|
+
var import_node_path = __toESM(require("path"));
|
|
47
|
+
var import_node_module = require("module");
|
|
48
|
+
var DeployEnvironment = /* @__PURE__ */ ((DeployEnvironment2) => {
|
|
49
|
+
DeployEnvironment2["Test"] = "test";
|
|
50
|
+
DeployEnvironment2["Stage"] = "stage";
|
|
51
|
+
DeployEnvironment2["Prod"] = "prod";
|
|
52
|
+
DeployEnvironment2["Stable"] = "stable";
|
|
53
|
+
return DeployEnvironment2;
|
|
54
|
+
})(DeployEnvironment || {});
|
|
55
|
+
var generateDeploy = ({
|
|
56
|
+
deploy,
|
|
57
|
+
frameworkRoot,
|
|
58
|
+
isMini = false
|
|
59
|
+
}) => {
|
|
60
|
+
const yaml = (0, import_node_module.createRequire)(import_node_path.default.join(frameworkRoot, "package.json"))("yaml");
|
|
61
|
+
const supportedFields = ["values", "environments", "pushHelmChart", ...isMini ? ["platforms"] : []];
|
|
62
|
+
if (deploy === void 0) return;
|
|
63
|
+
if (!deploy || typeof deploy !== "object" || Array.isArray(deploy) || Object.keys(deploy).some(
|
|
64
|
+
/** 运行参数只能来自 values,流水线开关保留独立入口。 */
|
|
65
|
+
(key) => !supportedFields.includes(key)
|
|
66
|
+
)) {
|
|
67
|
+
throw new Error(`xfe.json.deploy \u4EC5\u652F\u6301 ${supportedFields.join("\u3001")}\uFF1B\u8FD0\u884C\u53C2\u6570\u8BF7\u653E\u5165 values`);
|
|
68
|
+
}
|
|
69
|
+
const environments = deploy.environments === void 0 ? Object.values(DeployEnvironment) : deploy.environments;
|
|
70
|
+
if (!Array.isArray(environments) || environments.some(
|
|
71
|
+
/** 只接受已知的环境名称,非法值不能误开启发布。 */
|
|
72
|
+
(environment) => !Object.values(DeployEnvironment).includes(environment)
|
|
73
|
+
))
|
|
74
|
+
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");
|
|
75
|
+
if (deploy.pushHelmChart !== void 0 && typeof deploy.pushHelmChart !== "boolean") throw new Error("deploy.pushHelmChart \u5FC5\u987B\u662F\u5E03\u5C14\u503C");
|
|
76
|
+
const platforms = deploy.platforms === void 0 ? ["weapp", "h5"] : deploy.platforms;
|
|
77
|
+
if (!Array.isArray(platforms) || platforms.some((platform) => !["weapp", "h5"].includes(platform))) {
|
|
78
|
+
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");
|
|
79
|
+
}
|
|
80
|
+
const h5Environments = platforms.includes("h5") ? environments : [];
|
|
81
|
+
const miniEnvironments = platforms.includes("weapp") ? environments : [];
|
|
82
|
+
const pushHelmChart = deploy.pushHelmChart !== false && h5Environments.includes("prod" /* Prod */);
|
|
83
|
+
const source = import_node_path.default.join(frameworkRoot, "deploy");
|
|
84
|
+
const target = import_node_path.default.join(process.cwd(), "deploy");
|
|
85
|
+
let overrides = deploy.values === void 0 ? {} : deploy.values;
|
|
86
|
+
if (typeof overrides === "string") {
|
|
87
|
+
const valuesPath = import_node_fs.default.realpathSync(import_node_path.default.resolve(overrides));
|
|
88
|
+
if (valuesPath.startsWith(target + import_node_path.default.sep) && valuesPath !== import_node_path.default.join(target, "values.yaml")) {
|
|
89
|
+
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");
|
|
213
90
|
}
|
|
214
|
-
|
|
215
|
-
|
|
91
|
+
overrides = yaml.parse(import_node_fs.default.readFileSync(valuesPath, "utf8"));
|
|
92
|
+
}
|
|
93
|
+
if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) {
|
|
94
|
+
throw new Error("deploy.values \u5FC5\u987B\u662F\u5BF9\u8C61\u6216\u6307\u5411 YAML \u5BF9\u8C61\u6587\u4EF6\u7684\u8DEF\u5F84");
|
|
95
|
+
}
|
|
96
|
+
if (Object.hasOwn(overrides, "environments") || Object.hasOwn(overrides, "pushHelmChart"))
|
|
97
|
+
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");
|
|
98
|
+
const defaults = yaml.parse(import_node_fs.default.readFileSync(import_node_path.default.join(source, "helm/values.yaml"), "utf8"));
|
|
99
|
+
const values = mergeDeployValues(defaults, overrides);
|
|
100
|
+
if (typeof values.host !== "string" || /[\\/?#@:\s]/.test(values.host)) {
|
|
101
|
+
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");
|
|
102
|
+
}
|
|
103
|
+
if (!["saas", "infra"].includes(values.targetK8s)) throw new Error("deploy.values.targetK8s \u53EA\u80FD\u4E3A saas \u6216 infra");
|
|
104
|
+
if (target === source) throw new Error("\u90E8\u7F72\u8F93\u51FA\u4E0D\u80FD\u8986\u76D6\u6846\u67B6\u6A21\u677F\u76EE\u5F55");
|
|
105
|
+
if (import_node_fs.default.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");
|
|
106
|
+
const disabledEvents = "[custom, tag]";
|
|
107
|
+
const drone = import_node_fs.default.readFileSync(import_node_path.default.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(
|
|
108
|
+
"<<EXCLUDE_EVENTS_weapp>>",
|
|
109
|
+
miniEnvironments.some((environment) => environment !== "stable" /* Stable */) ? "[]" : disabledEvents
|
|
110
|
+
).replace(
|
|
111
|
+
/<<EXCLUDE_EVENTS_weapp_(test|stage|prod)>>/g,
|
|
112
|
+
(_placeholder, environment) => miniEnvironments.includes(environment) ? "[]" : disabledEvents
|
|
113
|
+
).replaceAll("<<EXCLUDE_EVENTS_push_helm_chart>>", pushHelmChart ? "[]" : disabledEvents).replace(
|
|
114
|
+
/<<EXCLUDE_EVENTS_(test|stage|prod|stable)>>/g,
|
|
115
|
+
/** 开启时不排除事件,关闭时由 Drone 原生 when 跳过该步骤。 */
|
|
116
|
+
(_placeholder, environment) => h5Environments.includes(environment) ? "[]" : disabledEvents
|
|
117
|
+
);
|
|
118
|
+
import_node_fs.default.cpSync(source, target, { recursive: true });
|
|
119
|
+
import_node_fs.default.writeFileSync(
|
|
120
|
+
import_node_path.default.join(target, "helm/values.yaml"),
|
|
121
|
+
yaml.stringify(values, {
|
|
122
|
+
defaultStringType: "QUOTE_SINGLE",
|
|
123
|
+
defaultKeyType: "PLAIN"
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
import_node_fs.default.writeFileSync(import_node_path.default.join(target, ".drone.yml"), drone);
|
|
216
127
|
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
128
|
+
function mergeDeployValues(base, overrides) {
|
|
129
|
+
return Object.fromEntries(
|
|
130
|
+
Object.entries({ ...base, ...overrides }).map(
|
|
131
|
+
/** 仅合并普通对象,列表保持声明的顺序。 */
|
|
132
|
+
([key, value]) => {
|
|
133
|
+
const previous = base[key];
|
|
134
|
+
const previousObject = previous && typeof previous === "object" && !Array.isArray(previous);
|
|
135
|
+
if (value === true && previousObject) {
|
|
136
|
+
return [key, Object.hasOwn(previous, "enabled") ? { ...previous, enabled: true } : previous];
|
|
137
|
+
}
|
|
138
|
+
const mergeable = value && previousObject && typeof value === "object" && !Array.isArray(value);
|
|
139
|
+
return [key, mergeable ? mergeDeployValues(previous, value) : value];
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/config/deploy.ts
|
|
146
|
+
var import_meta = {};
|
|
147
|
+
var generateDeploy2 = (deploy) => {
|
|
148
|
+
const directory = typeof __dirname === "string" ? __dirname : import_node_path2.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url));
|
|
149
|
+
generateDeploy({ deploy, frameworkRoot: import_node_path2.default.resolve(directory, ".."), isMini: true });
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/config.ts
|
|
153
|
+
var loadXfeConfig = () => {
|
|
154
|
+
const xfeConfigPath = "./xfe.json";
|
|
155
|
+
if (!import_fs.default.existsSync(xfeConfigPath)) {
|
|
156
|
+
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");
|
|
157
|
+
}
|
|
158
|
+
const xfeConfigContent = import_fs.default.readFileSync(xfeConfigPath, "utf8");
|
|
159
|
+
return JSON.parse(xfeConfigContent);
|
|
247
160
|
};
|
|
248
|
-
var
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
case 2:
|
|
272
|
-
_state.trys.push([
|
|
273
|
-
2,
|
|
274
|
-
4,
|
|
275
|
-
,
|
|
276
|
-
6
|
|
277
|
-
]);
|
|
278
|
-
return [
|
|
279
|
-
4,
|
|
280
|
-
jwkRes.json()
|
|
281
|
-
];
|
|
282
|
-
case 3:
|
|
283
|
-
JwkResponseJson = _state.sent();
|
|
284
|
-
return [
|
|
285
|
-
3,
|
|
286
|
-
6
|
|
287
|
-
];
|
|
288
|
-
case 4:
|
|
289
|
-
err = _state.sent();
|
|
290
|
-
_ = Error.bind;
|
|
291
|
-
_2 = (_1 = "远程获取密钥失败,响应解析错误: ".concat(err.message, ", response text: ")).concat;
|
|
292
|
-
return [
|
|
293
|
-
4,
|
|
294
|
-
jwkRes.text()
|
|
295
|
-
];
|
|
296
|
-
case 5:
|
|
297
|
-
throw new (_.apply(Error, [
|
|
298
|
-
void 0,
|
|
299
|
-
_2.apply(_1, [
|
|
300
|
-
_state.sent()
|
|
301
|
-
])
|
|
302
|
-
]));
|
|
303
|
-
case 6:
|
|
304
|
-
_ref = (JwkResponseJson === null || JwkResponseJson === void 0 ? void 0 : JwkResponseJson.data) || {}, keyId = _ref.keyId, privateKeyPkcs8 = _ref.privateKeyPkcs8;
|
|
305
|
-
if (!keyId || !privateKeyPkcs8) throw new Error("未获取到项目签名密钥, 请检查aud是否正确: ".concat(aud));
|
|
306
|
-
return [
|
|
307
|
-
2,
|
|
308
|
-
{
|
|
309
|
-
XFE_JWT_AUD: aud,
|
|
310
|
-
XFE_JWT_KEY_ID: keyId,
|
|
311
|
-
XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
|
|
312
|
-
}
|
|
313
|
-
];
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
})();
|
|
161
|
+
var configDeploy = () => generateDeploy2(loadXfeConfig().deploy);
|
|
162
|
+
var getJwtEnv = async () => {
|
|
163
|
+
const xfeConfig = loadXfeConfig();
|
|
164
|
+
if (!xfeConfig?.jwt) return {};
|
|
165
|
+
const { aud = "" } = xfeConfig.jwt;
|
|
166
|
+
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");
|
|
167
|
+
const jwkRes = await fetch(`https://app.eshetang.com/jwk?appId=${aud}`);
|
|
168
|
+
if (!jwkRes.ok) {
|
|
169
|
+
throw new Error(`\u8FDC\u7A0B\u83B7\u53D6\u5BC6\u94A5\u5931\u8D25: ${jwkRes.status} ${jwkRes.statusText}`);
|
|
170
|
+
}
|
|
171
|
+
let JwkResponseJson;
|
|
172
|
+
try {
|
|
173
|
+
JwkResponseJson = await jwkRes.json();
|
|
174
|
+
} catch (err) {
|
|
175
|
+
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()}`);
|
|
176
|
+
}
|
|
177
|
+
const { keyId, privateKeyPkcs8 } = JwkResponseJson?.data || {};
|
|
178
|
+
if (!keyId || !privateKeyPkcs8) throw new Error(`\u672A\u83B7\u53D6\u5230\u9879\u76EE\u7B7E\u540D\u5BC6\u94A5, \u8BF7\u68C0\u67E5aud\u662F\u5426\u6B63\u786E: ${aud}`);
|
|
179
|
+
return {
|
|
180
|
+
XFE_JWT_AUD: aud,
|
|
181
|
+
XFE_JWT_KEY_ID: keyId,
|
|
182
|
+
XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
|
|
183
|
+
};
|
|
317
184
|
};
|
|
318
185
|
// Annotate the CommonJS export names for ESM import in node:
|
|
319
186
|
0 && (module.exports = {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
187
|
+
configDeploy,
|
|
188
|
+
getJwtEnv,
|
|
189
|
+
loadXfeConfig
|
|
323
190
|
});
|
package/dist/config.mjs
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
configDeploy,
|
|
3
|
+
getJwtEnv,
|
|
4
|
+
loadXfeConfig
|
|
5
|
+
} from "./chunk-MSNDQMQN.mjs";
|
|
2
6
|
import "./chunk-Y6FXYEAI.mjs";
|
|
3
|
-
export {
|
|
7
|
+
export {
|
|
8
|
+
configDeploy,
|
|
9
|
+
getJwtEnv,
|
|
10
|
+
loadXfeConfig
|
|
11
|
+
};
|