@xfe-repo/web-app 1.3.11 → 1.3.15

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/config/env.js CHANGED
@@ -58,7 +58,7 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '')
58
58
 
59
59
  // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
60
60
  // injected into the application via DefinePlugin in webpack configuration.
61
- const REACT_APP = /^(REACT_APP|XFE)_/i
61
+ const REACT_APP = /^(REACT_APP|XFE)_/i;
62
62
 
63
63
  function getClientEnvironment(publicUrl) {
64
64
  const raw = Object.keys(process.env)
@@ -0,0 +1,203 @@
1
+ // src/config.ts
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 _ts_generator(thisArg, body) {
32
+ var f, y, t, g, _ = {
33
+ label: 0,
34
+ sent: function() {
35
+ if (t[0] & 1) throw t[1];
36
+ return t[1];
37
+ },
38
+ trys: [],
39
+ ops: []
40
+ };
41
+ return g = {
42
+ next: verb(0),
43
+ "throw": verb(1),
44
+ "return": verb(2)
45
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
46
+ return this;
47
+ }), g;
48
+ function verb(n) {
49
+ return function(v) {
50
+ return step([
51
+ n,
52
+ v
53
+ ]);
54
+ };
55
+ }
56
+ function step(op) {
57
+ if (f) throw new TypeError("Generator is already executing.");
58
+ while(_)try {
59
+ 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;
60
+ if (y = 0, t) op = [
61
+ op[0] & 2,
62
+ t.value
63
+ ];
64
+ switch(op[0]){
65
+ case 0:
66
+ case 1:
67
+ t = op;
68
+ break;
69
+ case 4:
70
+ _.label++;
71
+ return {
72
+ value: op[1],
73
+ done: false
74
+ };
75
+ case 5:
76
+ _.label++;
77
+ y = op[1];
78
+ op = [
79
+ 0
80
+ ];
81
+ continue;
82
+ case 7:
83
+ op = _.ops.pop();
84
+ _.trys.pop();
85
+ continue;
86
+ default:
87
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
88
+ _ = 0;
89
+ continue;
90
+ }
91
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
92
+ _.label = op[1];
93
+ break;
94
+ }
95
+ if (op[0] === 6 && _.label < t[1]) {
96
+ _.label = t[1];
97
+ t = op;
98
+ break;
99
+ }
100
+ if (t && _.label < t[2]) {
101
+ _.label = t[2];
102
+ _.ops.push(op);
103
+ break;
104
+ }
105
+ if (t[2]) _.ops.pop();
106
+ _.trys.pop();
107
+ continue;
108
+ }
109
+ op = body.call(thisArg, _);
110
+ } catch (e) {
111
+ op = [
112
+ 6,
113
+ e
114
+ ];
115
+ y = 0;
116
+ } finally{
117
+ f = t = 0;
118
+ }
119
+ if (op[0] & 5) throw op[1];
120
+ return {
121
+ value: op[0] ? op[1] : void 0,
122
+ done: true
123
+ };
124
+ }
125
+ }
126
+ import path from "path";
127
+ import fs from "fs";
128
+ import yaml from "yaml";
129
+ var loadXfeConfig = function() {
130
+ var xfeConfigPath = "./xfe.json";
131
+ if (!fs.existsSync(xfeConfigPath)) {
132
+ throw new Error("xfe.json 配置文件不存在,请在项目根目录下创建该文件。");
133
+ }
134
+ var xfeConfigContent = fs.readFileSync(xfeConfigPath, "utf8");
135
+ return JSON.parse(xfeConfigContent);
136
+ };
137
+ var configDeploy = function() {
138
+ var xfeConfig = loadXfeConfig();
139
+ if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.deploy)) return;
140
+ var droneConfigFilePath = path.resolve(__dirname, "../deploy/.drone.yml");
141
+ fs.cpSync(droneConfigFilePath, xfeConfig.deploy.droneConfigPath || "./.drone.yml");
142
+ var valuesYamlFilePath = path.resolve(__dirname, "../deploy/helm/values.yaml");
143
+ var valuesYamlFile = fs.readFileSync(valuesYamlFilePath, "utf8");
144
+ var valuesYaml = yaml.parse(valuesYamlFile);
145
+ if (!valuesYaml.virtualService) valuesYaml.virtualService = {};
146
+ if (!valuesYaml.virtualService.hosts) valuesYaml.virtualService.hosts = {
147
+ test: [],
148
+ stage: [],
149
+ prod: []
150
+ };
151
+ var _xfeConfig_deploy = xfeConfig.deploy, _xfeConfig_deploy_virtualServiceEnabled = _xfeConfig_deploy.virtualServiceEnabled, virtualServiceEnabled = _xfeConfig_deploy_virtualServiceEnabled === void 0 ? true : _xfeConfig_deploy_virtualServiceEnabled, _xfeConfig_deploy_hostsProd = _xfeConfig_deploy.hostsProd, hostsProd = _xfeConfig_deploy_hostsProd === void 0 ? [] : _xfeConfig_deploy_hostsProd, _xfeConfig_deploy_hostsStage = _xfeConfig_deploy.hostsStage, hostsStage = _xfeConfig_deploy_hostsStage === void 0 ? [] : _xfeConfig_deploy_hostsStage, _xfeConfig_deploy_hostsTest = _xfeConfig_deploy.hostsTest, hostsTest = _xfeConfig_deploy_hostsTest === void 0 ? [] : _xfeConfig_deploy_hostsTest, _xfeConfig_deploy_gateways = _xfeConfig_deploy.gateways, gateways = _xfeConfig_deploy_gateways === void 0 ? [
152
+ "common-gateway-eshetang"
153
+ ] : _xfeConfig_deploy_gateways;
154
+ var _xfeConfig_deploy1 = xfeConfig.deploy, _xfeConfig_deploy_targetK8s = _xfeConfig_deploy1.targetK8s, targetK8s = _xfeConfig_deploy_targetK8s === void 0 ? "saas" : _xfeConfig_deploy_targetK8s, _xfeConfig_deploy_targetNamespace = _xfeConfig_deploy1.targetNamespace, targetNamespace = _xfeConfig_deploy_targetNamespace === void 0 ? "" : _xfeConfig_deploy_targetNamespace;
155
+ valuesYaml.virtualService.enabled = virtualServiceEnabled;
156
+ valuesYaml.virtualService.gateways = gateways;
157
+ valuesYaml.virtualService.hosts.prod = hostsProd;
158
+ valuesYaml.virtualService.hosts.stage = hostsStage;
159
+ valuesYaml.virtualService.hosts.test = hostsTest;
160
+ valuesYaml.targetK8s = targetK8s;
161
+ valuesYaml.namespace = targetNamespace;
162
+ var valuesYamlStr = yaml.stringify(valuesYaml, {
163
+ defaultStringType: "QUOTE_SINGLE",
164
+ defaultKeyType: "PLAIN"
165
+ });
166
+ fs.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
167
+ };
168
+ var getJwtEnv = function() {
169
+ var _ref = _async_to_generator(function() {
170
+ var xfeConfig, _xfeConfig_jwt, _xfeConfig_jwt_aud, aud, jwkRes, _ref, keyId, privateKeyPkcs8;
171
+ return _ts_generator(this, function(_state) {
172
+ switch(_state.label){
173
+ case 0:
174
+ xfeConfig = loadXfeConfig();
175
+ if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.jwt)) throw new Error("xfe.json 中未配置 jwt 信息,请检查配置文件。");
176
+ _xfeConfig_jwt = xfeConfig.jwt, _xfeConfig_jwt_aud = _xfeConfig_jwt.aud, aud = _xfeConfig_jwt_aud === void 0 ? "" : _xfeConfig_jwt_aud;
177
+ if (!aud) throw new Error("xfe.json 中的 jwt 配置不完整,请确保包含 aud 字段。");
178
+ return [
179
+ 4,
180
+ fetch("https://app.eshetang.com/jwk?appId=".concat(aud)).then(function(res) {
181
+ return res.json();
182
+ })
183
+ ];
184
+ case 1:
185
+ jwkRes = _state.sent();
186
+ _ref = (jwkRes === null || jwkRes === void 0 ? void 0 : jwkRes.data) || {}, keyId = _ref.keyId, privateKeyPkcs8 = _ref.privateKeyPkcs8;
187
+ if (!keyId || !privateKeyPkcs8) throw new Error("未获取到项目签名密钥, 请检查aud是否正确: ".concat(aud));
188
+ return [
189
+ 2,
190
+ {
191
+ XFE_JWT_AUD: aud,
192
+ XFE_JWT_KEY_ID: keyId,
193
+ XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
194
+ }
195
+ ];
196
+ }
197
+ });
198
+ });
199
+ return function getJwtEnv() {
200
+ return _ref.apply(this, arguments);
201
+ };
202
+ }();
203
+ export { loadXfeConfig, configDeploy, getJwtEnv };
package/dist/cli.js CHANGED
@@ -7,6 +7,48 @@ function _array_like_to_array(arr, len) {
7
7
  function _array_with_holes(arr) {
8
8
  if (Array.isArray(arr)) return arr;
9
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 _define_property(obj, key, value) {
40
+ if (key in obj) {
41
+ Object.defineProperty(obj, key, {
42
+ value: value,
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true
46
+ });
47
+ } else {
48
+ obj[key] = value;
49
+ }
50
+ return obj;
51
+ }
10
52
  function _iterable_to_array_limit(arr, i) {
11
53
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
12
54
  if (_i == null) return;
@@ -34,6 +76,21 @@ function _iterable_to_array_limit(arr, i) {
34
76
  function _non_iterable_rest() {
35
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.");
36
78
  }
79
+ function _object_spread(target) {
80
+ for(var i = 1; i < arguments.length; i++){
81
+ var source = arguments[i] != null ? arguments[i] : {};
82
+ var ownKeys = Object.keys(source);
83
+ if (typeof Object.getOwnPropertySymbols === "function") {
84
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
85
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
86
+ }));
87
+ }
88
+ ownKeys.forEach(function(key) {
89
+ _define_property(target, key, source[key]);
90
+ });
91
+ }
92
+ return target;
93
+ }
37
94
  function _sliced_to_array(arr, i) {
38
95
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
39
96
  }
@@ -45,6 +102,101 @@ function _unsupported_iterable_to_array(o, minLen) {
45
102
  if (n === "Map" || n === "Set") return Array.from(n);
46
103
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
47
104
  }
105
+ function _ts_generator(thisArg, body) {
106
+ var f, y, t, g, _ = {
107
+ label: 0,
108
+ sent: function() {
109
+ if (t[0] & 1) throw t[1];
110
+ return t[1];
111
+ },
112
+ trys: [],
113
+ ops: []
114
+ };
115
+ return g = {
116
+ next: verb(0),
117
+ "throw": verb(1),
118
+ "return": verb(2)
119
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
120
+ return this;
121
+ }), g;
122
+ function verb(n) {
123
+ return function(v) {
124
+ return step([
125
+ n,
126
+ v
127
+ ]);
128
+ };
129
+ }
130
+ function step(op) {
131
+ if (f) throw new TypeError("Generator is already executing.");
132
+ while(_)try {
133
+ 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;
134
+ if (y = 0, t) op = [
135
+ op[0] & 2,
136
+ t.value
137
+ ];
138
+ switch(op[0]){
139
+ case 0:
140
+ case 1:
141
+ t = op;
142
+ break;
143
+ case 4:
144
+ _.label++;
145
+ return {
146
+ value: op[1],
147
+ done: false
148
+ };
149
+ case 5:
150
+ _.label++;
151
+ y = op[1];
152
+ op = [
153
+ 0
154
+ ];
155
+ continue;
156
+ case 7:
157
+ op = _.ops.pop();
158
+ _.trys.pop();
159
+ continue;
160
+ default:
161
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
162
+ _ = 0;
163
+ continue;
164
+ }
165
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
166
+ _.label = op[1];
167
+ break;
168
+ }
169
+ if (op[0] === 6 && _.label < t[1]) {
170
+ _.label = t[1];
171
+ t = op;
172
+ break;
173
+ }
174
+ if (t && _.label < t[2]) {
175
+ _.label = t[2];
176
+ _.ops.push(op);
177
+ break;
178
+ }
179
+ if (t[2]) _.ops.pop();
180
+ _.trys.pop();
181
+ continue;
182
+ }
183
+ op = body.call(thisArg, _);
184
+ } catch (e) {
185
+ op = [
186
+ 6,
187
+ e
188
+ ];
189
+ y = 0;
190
+ } finally{
191
+ f = t = 0;
192
+ }
193
+ if (op[0] & 5) throw op[1];
194
+ return {
195
+ value: op[0] ? op[1] : void 0,
196
+ done: true
197
+ };
198
+ }
199
+ }
48
200
  var __create = Object.create;
49
201
  var __defProp = Object.defineProperty;
50
202
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -100,8 +252,16 @@ var import_path2 = __toESM(require("path"));
100
252
  var import_path = __toESM(require("path"));
101
253
  var import_fs = __toESM(require("fs"));
102
254
  var import_yaml = __toESM(require("yaml"));
255
+ var loadXfeConfig = function() {
256
+ var xfeConfigPath = "./xfe.json";
257
+ if (!import_fs.default.existsSync(xfeConfigPath)) {
258
+ throw new Error("xfe.json 配置文件不存在,请在项目根目录下创建该文件。");
259
+ }
260
+ var xfeConfigContent = import_fs.default.readFileSync(xfeConfigPath, "utf8");
261
+ return JSON.parse(xfeConfigContent);
262
+ };
103
263
  var configDeploy = function() {
104
- var xfeConfig = JSON.parse(import_fs.default.readFileSync("./xfe.json", "utf8"));
264
+ var xfeConfig = loadXfeConfig();
105
265
  if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.deploy)) return;
106
266
  var droneConfigFilePath = import_path.default.resolve(__dirname, "../deploy/.drone.yml");
107
267
  import_fs.default.cpSync(droneConfigFilePath, xfeConfig.deploy.droneConfigPath || "./.drone.yml");
@@ -131,22 +291,107 @@ var configDeploy = function() {
131
291
  });
132
292
  import_fs.default.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
133
293
  };
134
- var config = function() {
135
- configDeploy();
136
- };
294
+ var getJwtEnv = function() {
295
+ var _ref = _async_to_generator(function() {
296
+ var xfeConfig, _xfeConfig_jwt, _xfeConfig_jwt_aud, aud, jwkRes, _ref, keyId, privateKeyPkcs8;
297
+ return _ts_generator(this, function(_state) {
298
+ switch(_state.label){
299
+ case 0:
300
+ xfeConfig = loadXfeConfig();
301
+ if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.jwt)) throw new Error("xfe.json 中未配置 jwt 信息,请检查配置文件。");
302
+ _xfeConfig_jwt = xfeConfig.jwt, _xfeConfig_jwt_aud = _xfeConfig_jwt.aud, aud = _xfeConfig_jwt_aud === void 0 ? "" : _xfeConfig_jwt_aud;
303
+ if (!aud) throw new Error("xfe.json 中的 jwt 配置不完整,请确保包含 aud 字段。");
304
+ return [
305
+ 4,
306
+ fetch("https://app.eshetang.com/jwk?appId=".concat(aud)).then(function(res) {
307
+ return res.json();
308
+ })
309
+ ];
310
+ case 1:
311
+ jwkRes = _state.sent();
312
+ _ref = (jwkRes === null || jwkRes === void 0 ? void 0 : jwkRes.data) || {}, keyId = _ref.keyId, privateKeyPkcs8 = _ref.privateKeyPkcs8;
313
+ if (!keyId || !privateKeyPkcs8) throw new Error("未获取到项目签名密钥, 请检查aud是否正确: ".concat(aud));
314
+ return [
315
+ 2,
316
+ {
317
+ XFE_JWT_AUD: aud,
318
+ XFE_JWT_KEY_ID: keyId,
319
+ XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
320
+ }
321
+ ];
322
+ }
323
+ });
324
+ });
325
+ return function getJwtEnv() {
326
+ return _ref.apply(this, arguments);
327
+ };
328
+ }();
137
329
  // src/cli.ts
138
330
  var argv = (0, import_minimist.default)(process.argv.slice(2));
139
331
  var commands = argv._;
140
332
  var _commands = _sliced_to_array(commands, 1), command = _commands[0];
141
333
  var appPackageRoot = import_path2.default.resolve(__dirname, "../");
142
- if (command === "dev") {
143
- (0, import_child_process.execSync)("node ".concat(import_path2.default.join(appPackageRoot, "scripts/dev.js")), {
144
- stdio: "inherit"
145
- });
146
- } else if (command === "build") {
147
- (0, import_child_process.execSync)("node ".concat(import_path2.default.join(appPackageRoot, "scripts/build.js")), {
148
- stdio: "inherit"
334
+ function main() {
335
+ return _main.apply(this, arguments);
336
+ }
337
+ function _main() {
338
+ _main = _async_to_generator(function() {
339
+ var jwtEnv, jwtEnv1;
340
+ return _ts_generator(this, function(_state) {
341
+ switch(_state.label){
342
+ case 0:
343
+ if (!(command === "dev")) return [
344
+ 3,
345
+ 2
346
+ ];
347
+ return [
348
+ 4,
349
+ getJwtEnv()
350
+ ];
351
+ case 1:
352
+ jwtEnv = _state.sent();
353
+ (0, import_child_process.execSync)("node ".concat(import_path2.default.join(appPackageRoot, "scripts/dev.js")), {
354
+ stdio: "inherit",
355
+ env: _object_spread({}, process.env, jwtEnv)
356
+ });
357
+ return [
358
+ 3,
359
+ 5
360
+ ];
361
+ case 2:
362
+ if (!(command === "build")) return [
363
+ 3,
364
+ 4
365
+ ];
366
+ return [
367
+ 4,
368
+ getJwtEnv()
369
+ ];
370
+ case 3:
371
+ jwtEnv1 = _state.sent();
372
+ (0, import_child_process.execSync)("node ".concat(import_path2.default.join(appPackageRoot, "scripts/build.js")), {
373
+ stdio: "inherit",
374
+ env: _object_spread({}, process.env, jwtEnv1)
375
+ });
376
+ return [
377
+ 3,
378
+ 5
379
+ ];
380
+ case 4:
381
+ if (command === "config") {
382
+ configDeploy();
383
+ }
384
+ _state.label = 5;
385
+ case 5:
386
+ return [
387
+ 2
388
+ ];
389
+ }
390
+ });
149
391
  });
150
- } else if (command === "config") {
151
- config();
392
+ return _main.apply(this, arguments);
152
393
  }
394
+ main().catch(function(err) {
395
+ console.error("XFE Web CLI 执行出错:", err);
396
+ process.exit(1);
397
+ });
package/dist/cli.mjs CHANGED
@@ -6,6 +6,48 @@ function _array_like_to_array(arr, len) {
6
6
  function _array_with_holes(arr) {
7
7
  if (Array.isArray(arr)) return arr;
8
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 _define_property(obj, key, value) {
39
+ if (key in obj) {
40
+ Object.defineProperty(obj, key, {
41
+ value: value,
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true
45
+ });
46
+ } else {
47
+ obj[key] = value;
48
+ }
49
+ return obj;
50
+ }
9
51
  function _iterable_to_array_limit(arr, i) {
10
52
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
53
  if (_i == null) return;
@@ -33,6 +75,21 @@ function _iterable_to_array_limit(arr, i) {
33
75
  function _non_iterable_rest() {
34
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.");
35
77
  }
78
+ function _object_spread(target) {
79
+ for(var i = 1; i < arguments.length; i++){
80
+ var source = arguments[i] != null ? arguments[i] : {};
81
+ var ownKeys = Object.keys(source);
82
+ if (typeof Object.getOwnPropertySymbols === "function") {
83
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
84
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
85
+ }));
86
+ }
87
+ ownKeys.forEach(function(key) {
88
+ _define_property(target, key, source[key]);
89
+ });
90
+ }
91
+ return target;
92
+ }
36
93
  function _sliced_to_array(arr, i) {
37
94
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
95
  }
@@ -44,7 +101,102 @@ function _unsupported_iterable_to_array(o, minLen) {
44
101
  if (n === "Map" || n === "Set") return Array.from(n);
45
102
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
103
  }
47
- import { config } from "./chunk-EQD7HO6T.mjs";
104
+ function _ts_generator(thisArg, body) {
105
+ var f, y, t, g, _ = {
106
+ label: 0,
107
+ sent: function() {
108
+ if (t[0] & 1) throw t[1];
109
+ return t[1];
110
+ },
111
+ trys: [],
112
+ ops: []
113
+ };
114
+ return g = {
115
+ next: verb(0),
116
+ "throw": verb(1),
117
+ "return": verb(2)
118
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
119
+ return this;
120
+ }), g;
121
+ function verb(n) {
122
+ return function(v) {
123
+ return step([
124
+ n,
125
+ v
126
+ ]);
127
+ };
128
+ }
129
+ function step(op) {
130
+ if (f) throw new TypeError("Generator is already executing.");
131
+ while(_)try {
132
+ 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;
133
+ if (y = 0, t) op = [
134
+ op[0] & 2,
135
+ t.value
136
+ ];
137
+ switch(op[0]){
138
+ case 0:
139
+ case 1:
140
+ t = op;
141
+ break;
142
+ case 4:
143
+ _.label++;
144
+ return {
145
+ value: op[1],
146
+ done: false
147
+ };
148
+ case 5:
149
+ _.label++;
150
+ y = op[1];
151
+ op = [
152
+ 0
153
+ ];
154
+ continue;
155
+ case 7:
156
+ op = _.ops.pop();
157
+ _.trys.pop();
158
+ continue;
159
+ default:
160
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
161
+ _ = 0;
162
+ continue;
163
+ }
164
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
165
+ _.label = op[1];
166
+ break;
167
+ }
168
+ if (op[0] === 6 && _.label < t[1]) {
169
+ _.label = t[1];
170
+ t = op;
171
+ break;
172
+ }
173
+ if (t && _.label < t[2]) {
174
+ _.label = t[2];
175
+ _.ops.push(op);
176
+ break;
177
+ }
178
+ if (t[2]) _.ops.pop();
179
+ _.trys.pop();
180
+ continue;
181
+ }
182
+ op = body.call(thisArg, _);
183
+ } catch (e) {
184
+ op = [
185
+ 6,
186
+ e
187
+ ];
188
+ y = 0;
189
+ } finally{
190
+ f = t = 0;
191
+ }
192
+ if (op[0] & 5) throw op[1];
193
+ return {
194
+ value: op[0] ? op[1] : void 0,
195
+ done: true
196
+ };
197
+ }
198
+ }
199
+ import { configDeploy, getJwtEnv } from "./chunk-JNAYST2A.mjs";
48
200
  // src/cli.ts
49
201
  import minimist from "minimist";
50
202
  import { execSync } from "child_process";
@@ -53,14 +205,67 @@ var argv = minimist(process.argv.slice(2));
53
205
  var commands = argv._;
54
206
  var _commands = _sliced_to_array(commands, 1), command = _commands[0];
55
207
  var appPackageRoot = path.resolve(__dirname, "../");
56
- if (command === "dev") {
57
- execSync("node ".concat(path.join(appPackageRoot, "scripts/dev.js")), {
58
- stdio: "inherit"
59
- });
60
- } else if (command === "build") {
61
- execSync("node ".concat(path.join(appPackageRoot, "scripts/build.js")), {
62
- stdio: "inherit"
208
+ function main() {
209
+ return _main.apply(this, arguments);
210
+ }
211
+ function _main() {
212
+ _main = _async_to_generator(function() {
213
+ var jwtEnv, jwtEnv1;
214
+ return _ts_generator(this, function(_state) {
215
+ switch(_state.label){
216
+ case 0:
217
+ if (!(command === "dev")) return [
218
+ 3,
219
+ 2
220
+ ];
221
+ return [
222
+ 4,
223
+ getJwtEnv()
224
+ ];
225
+ case 1:
226
+ jwtEnv = _state.sent();
227
+ execSync("node ".concat(path.join(appPackageRoot, "scripts/dev.js")), {
228
+ stdio: "inherit",
229
+ env: _object_spread({}, process.env, jwtEnv)
230
+ });
231
+ return [
232
+ 3,
233
+ 5
234
+ ];
235
+ case 2:
236
+ if (!(command === "build")) return [
237
+ 3,
238
+ 4
239
+ ];
240
+ return [
241
+ 4,
242
+ getJwtEnv()
243
+ ];
244
+ case 3:
245
+ jwtEnv1 = _state.sent();
246
+ execSync("node ".concat(path.join(appPackageRoot, "scripts/build.js")), {
247
+ stdio: "inherit",
248
+ env: _object_spread({}, process.env, jwtEnv1)
249
+ });
250
+ return [
251
+ 3,
252
+ 5
253
+ ];
254
+ case 4:
255
+ if (command === "config") {
256
+ configDeploy();
257
+ }
258
+ _state.label = 5;
259
+ case 5:
260
+ return [
261
+ 2
262
+ ];
263
+ }
264
+ });
63
265
  });
64
- } else if (command === "config") {
65
- config();
266
+ return _main.apply(this, arguments);
66
267
  }
268
+ main().catch(function(err) {
269
+ console.error("XFE Web CLI 执行出错:", err);
270
+ process.exit(1);
271
+ });
package/dist/config.d.mts CHANGED
@@ -1,3 +1,9 @@
1
- declare const config: () => void;
1
+ declare const loadXfeConfig: () => Record<string, any>;
2
+ declare const configDeploy: () => void;
3
+ declare const getJwtEnv: () => Promise<{
4
+ XFE_JWT_AUD: any;
5
+ XFE_JWT_KEY_ID: string;
6
+ XFE_JWT_PRIVATE_KEY: string;
7
+ }>;
2
8
 
3
- export { config };
9
+ export { configDeploy, getJwtEnv, loadXfeConfig };
package/dist/config.d.ts CHANGED
@@ -1,3 +1,9 @@
1
- declare const config: () => void;
1
+ declare const loadXfeConfig: () => Record<string, any>;
2
+ declare const configDeploy: () => void;
3
+ declare const getJwtEnv: () => Promise<{
4
+ XFE_JWT_AUD: any;
5
+ XFE_JWT_KEY_ID: string;
6
+ XFE_JWT_PRIVATE_KEY: string;
7
+ }>;
2
8
 
3
- export { config };
9
+ export { configDeploy, getJwtEnv, loadXfeConfig };
package/dist/config.js CHANGED
@@ -1,4 +1,128 @@
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 _ts_generator(thisArg, body) {
32
+ var f, y, t, g, _ = {
33
+ label: 0,
34
+ sent: function() {
35
+ if (t[0] & 1) throw t[1];
36
+ return t[1];
37
+ },
38
+ trys: [],
39
+ ops: []
40
+ };
41
+ return g = {
42
+ next: verb(0),
43
+ "throw": verb(1),
44
+ "return": verb(2)
45
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
46
+ return this;
47
+ }), g;
48
+ function verb(n) {
49
+ return function(v) {
50
+ return step([
51
+ n,
52
+ v
53
+ ]);
54
+ };
55
+ }
56
+ function step(op) {
57
+ if (f) throw new TypeError("Generator is already executing.");
58
+ while(_)try {
59
+ 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;
60
+ if (y = 0, t) op = [
61
+ op[0] & 2,
62
+ t.value
63
+ ];
64
+ switch(op[0]){
65
+ case 0:
66
+ case 1:
67
+ t = op;
68
+ break;
69
+ case 4:
70
+ _.label++;
71
+ return {
72
+ value: op[1],
73
+ done: false
74
+ };
75
+ case 5:
76
+ _.label++;
77
+ y = op[1];
78
+ op = [
79
+ 0
80
+ ];
81
+ continue;
82
+ case 7:
83
+ op = _.ops.pop();
84
+ _.trys.pop();
85
+ continue;
86
+ default:
87
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
88
+ _ = 0;
89
+ continue;
90
+ }
91
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
92
+ _.label = op[1];
93
+ break;
94
+ }
95
+ if (op[0] === 6 && _.label < t[1]) {
96
+ _.label = t[1];
97
+ t = op;
98
+ break;
99
+ }
100
+ if (t && _.label < t[2]) {
101
+ _.label = t[2];
102
+ _.ops.push(op);
103
+ break;
104
+ }
105
+ if (t[2]) _.ops.pop();
106
+ _.trys.pop();
107
+ continue;
108
+ }
109
+ op = body.call(thisArg, _);
110
+ } catch (e) {
111
+ op = [
112
+ 6,
113
+ e
114
+ ];
115
+ y = 0;
116
+ } finally{
117
+ f = t = 0;
118
+ }
119
+ if (op[0] & 5) throw op[1];
120
+ return {
121
+ value: op[0] ? op[1] : void 0,
122
+ done: true
123
+ };
124
+ }
125
+ }
2
126
  var __create = Object.create;
3
127
  var __defProp = Object.defineProperty;
4
128
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -60,16 +184,30 @@ var __toCommonJS = function(mod) {
60
184
  // src/config.ts
61
185
  var config_exports = {};
62
186
  __export(config_exports, {
63
- config: function() {
64
- return config;
187
+ configDeploy: function() {
188
+ return configDeploy;
189
+ },
190
+ getJwtEnv: function() {
191
+ return getJwtEnv;
192
+ },
193
+ loadXfeConfig: function() {
194
+ return loadXfeConfig;
65
195
  }
66
196
  });
67
197
  module.exports = __toCommonJS(config_exports);
68
198
  var import_path = __toESM(require("path"));
69
199
  var import_fs = __toESM(require("fs"));
70
200
  var import_yaml = __toESM(require("yaml"));
201
+ var loadXfeConfig = function() {
202
+ var xfeConfigPath = "./xfe.json";
203
+ if (!import_fs.default.existsSync(xfeConfigPath)) {
204
+ throw new Error("xfe.json 配置文件不存在,请在项目根目录下创建该文件。");
205
+ }
206
+ var xfeConfigContent = import_fs.default.readFileSync(xfeConfigPath, "utf8");
207
+ return JSON.parse(xfeConfigContent);
208
+ };
71
209
  var configDeploy = function() {
72
- var xfeConfig = JSON.parse(import_fs.default.readFileSync("./xfe.json", "utf8"));
210
+ var xfeConfig = loadXfeConfig();
73
211
  if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.deploy)) return;
74
212
  var droneConfigFilePath = import_path.default.resolve(__dirname, "../deploy/.drone.yml");
75
213
  import_fs.default.cpSync(droneConfigFilePath, xfeConfig.deploy.droneConfigPath || "./.drone.yml");
@@ -99,10 +237,44 @@ var configDeploy = function() {
99
237
  });
100
238
  import_fs.default.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
101
239
  };
102
- var config = function() {
103
- configDeploy();
104
- };
240
+ var getJwtEnv = function() {
241
+ var _ref = _async_to_generator(function() {
242
+ var xfeConfig, _xfeConfig_jwt, _xfeConfig_jwt_aud, aud, jwkRes, _ref, keyId, privateKeyPkcs8;
243
+ return _ts_generator(this, function(_state) {
244
+ switch(_state.label){
245
+ case 0:
246
+ xfeConfig = loadXfeConfig();
247
+ if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.jwt)) throw new Error("xfe.json 中未配置 jwt 信息,请检查配置文件。");
248
+ _xfeConfig_jwt = xfeConfig.jwt, _xfeConfig_jwt_aud = _xfeConfig_jwt.aud, aud = _xfeConfig_jwt_aud === void 0 ? "" : _xfeConfig_jwt_aud;
249
+ if (!aud) throw new Error("xfe.json 中的 jwt 配置不完整,请确保包含 aud 字段。");
250
+ return [
251
+ 4,
252
+ fetch("https://app.eshetang.com/jwk?appId=".concat(aud)).then(function(res) {
253
+ return res.json();
254
+ })
255
+ ];
256
+ case 1:
257
+ jwkRes = _state.sent();
258
+ _ref = (jwkRes === null || jwkRes === void 0 ? void 0 : jwkRes.data) || {}, keyId = _ref.keyId, privateKeyPkcs8 = _ref.privateKeyPkcs8;
259
+ if (!keyId || !privateKeyPkcs8) throw new Error("未获取到项目签名密钥, 请检查aud是否正确: ".concat(aud));
260
+ return [
261
+ 2,
262
+ {
263
+ XFE_JWT_AUD: aud,
264
+ XFE_JWT_KEY_ID: keyId,
265
+ XFE_JWT_PRIVATE_KEY: privateKeyPkcs8
266
+ }
267
+ ];
268
+ }
269
+ });
270
+ });
271
+ return function getJwtEnv() {
272
+ return _ref.apply(this, arguments);
273
+ };
274
+ }();
105
275
  // Annotate the CommonJS export names for ESM import in node:
106
276
  0 && (module.exports = {
107
- config: config
277
+ configDeploy: configDeploy,
278
+ getJwtEnv: getJwtEnv,
279
+ loadXfeConfig: loadXfeConfig
108
280
  });
package/dist/config.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { config } from "./chunk-EQD7HO6T.mjs";
2
- export { config };
1
+ import { configDeploy, getJwtEnv, loadXfeConfig } from "./chunk-JNAYST2A.mjs";
2
+ export { configDeploy, getJwtEnv, loadXfeConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xfe-repo/web-app",
3
- "version": "1.3.11",
3
+ "version": "1.3.15",
4
4
  "bin": {
5
5
  "xfe-web": "./bin/index.js"
6
6
  },
@@ -1,39 +0,0 @@
1
- // src/config.ts
2
- import path from "path";
3
- import fs from "fs";
4
- import yaml from "yaml";
5
- var configDeploy = function() {
6
- var xfeConfig = JSON.parse(fs.readFileSync("./xfe.json", "utf8"));
7
- if (!(xfeConfig === null || xfeConfig === void 0 ? void 0 : xfeConfig.deploy)) return;
8
- var droneConfigFilePath = path.resolve(__dirname, "../deploy/.drone.yml");
9
- fs.cpSync(droneConfigFilePath, xfeConfig.deploy.droneConfigPath || "./.drone.yml");
10
- var valuesYamlFilePath = path.resolve(__dirname, "../deploy/helm/values.yaml");
11
- var valuesYamlFile = fs.readFileSync(valuesYamlFilePath, "utf8");
12
- var valuesYaml = yaml.parse(valuesYamlFile);
13
- if (!valuesYaml.virtualService) valuesYaml.virtualService = {};
14
- if (!valuesYaml.virtualService.hosts) valuesYaml.virtualService.hosts = {
15
- test: [],
16
- stage: [],
17
- prod: []
18
- };
19
- var _xfeConfig_deploy = xfeConfig.deploy, _xfeConfig_deploy_virtualServiceEnabled = _xfeConfig_deploy.virtualServiceEnabled, virtualServiceEnabled = _xfeConfig_deploy_virtualServiceEnabled === void 0 ? true : _xfeConfig_deploy_virtualServiceEnabled, _xfeConfig_deploy_hostsProd = _xfeConfig_deploy.hostsProd, hostsProd = _xfeConfig_deploy_hostsProd === void 0 ? [] : _xfeConfig_deploy_hostsProd, _xfeConfig_deploy_hostsStage = _xfeConfig_deploy.hostsStage, hostsStage = _xfeConfig_deploy_hostsStage === void 0 ? [] : _xfeConfig_deploy_hostsStage, _xfeConfig_deploy_hostsTest = _xfeConfig_deploy.hostsTest, hostsTest = _xfeConfig_deploy_hostsTest === void 0 ? [] : _xfeConfig_deploy_hostsTest, _xfeConfig_deploy_gateways = _xfeConfig_deploy.gateways, gateways = _xfeConfig_deploy_gateways === void 0 ? [
20
- "common-gateway-eshetang"
21
- ] : _xfeConfig_deploy_gateways;
22
- var _xfeConfig_deploy1 = xfeConfig.deploy, _xfeConfig_deploy_targetK8s = _xfeConfig_deploy1.targetK8s, targetK8s = _xfeConfig_deploy_targetK8s === void 0 ? "saas" : _xfeConfig_deploy_targetK8s, _xfeConfig_deploy_targetNamespace = _xfeConfig_deploy1.targetNamespace, targetNamespace = _xfeConfig_deploy_targetNamespace === void 0 ? "" : _xfeConfig_deploy_targetNamespace;
23
- valuesYaml.virtualService.enabled = virtualServiceEnabled;
24
- valuesYaml.virtualService.gateways = gateways;
25
- valuesYaml.virtualService.hosts.prod = hostsProd;
26
- valuesYaml.virtualService.hosts.stage = hostsStage;
27
- valuesYaml.virtualService.hosts.test = hostsTest;
28
- valuesYaml.targetK8s = targetK8s;
29
- valuesYaml.namespace = targetNamespace;
30
- var valuesYamlStr = yaml.stringify(valuesYaml, {
31
- defaultStringType: "QUOTE_SINGLE",
32
- defaultKeyType: "PLAIN"
33
- });
34
- fs.writeFileSync(valuesYamlFilePath, valuesYamlStr, "utf8");
35
- };
36
- var config = function() {
37
- configDeploy();
38
- };
39
- export { config };