@doracli/express-server 0.0.4 → 0.0.5
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/lib/cjs/index.js +3 -1037
- package/lib/esm/index.js +3 -1033
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1,1037 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var path = require('path');
|
|
4
|
-
var helper = require('@doracli/helper');
|
|
5
|
-
var filePro = require('@dorabag/file-pro');
|
|
6
|
-
var utils = require('@cclr/utils');
|
|
7
|
-
var esbuild = require('@doracli/esbuild');
|
|
8
|
-
var configLoader = require('@dorabag/config-loader');
|
|
9
|
-
var defineServer = require('@doracli/define-server');
|
|
10
|
-
var lang = require('@cclr/lang');
|
|
11
|
-
var chokidar = require('chokidar');
|
|
12
|
-
var express = require('@doracli/express');
|
|
13
|
-
|
|
14
|
-
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
15
|
-
try {
|
|
16
|
-
var i = n[a](c),
|
|
17
|
-
u = i.value;
|
|
18
|
-
} catch (n) {
|
|
19
|
-
return void e(n);
|
|
20
|
-
}
|
|
21
|
-
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
22
|
-
}
|
|
23
|
-
function _asyncToGenerator(n) {
|
|
24
|
-
return function () {
|
|
25
|
-
var t = this,
|
|
26
|
-
e = arguments;
|
|
27
|
-
return new Promise(function (r, o) {
|
|
28
|
-
var a = n.apply(t, e);
|
|
29
|
-
function _next(n) {
|
|
30
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
31
|
-
}
|
|
32
|
-
function _throw(n) {
|
|
33
|
-
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
34
|
-
}
|
|
35
|
-
_next(void 0);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function _classCallCheck(a, n) {
|
|
40
|
-
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
41
|
-
}
|
|
42
|
-
function _defineProperties(e, r) {
|
|
43
|
-
for (var t = 0; t < r.length; t++) {
|
|
44
|
-
var o = r[t];
|
|
45
|
-
o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function _createClass(e, r, t) {
|
|
49
|
-
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
50
|
-
writable: false
|
|
51
|
-
}), e;
|
|
52
|
-
}
|
|
53
|
-
function _defineProperty(e, r, t) {
|
|
54
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
55
|
-
value: t,
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true
|
|
59
|
-
}) : e[r] = t, e;
|
|
60
|
-
}
|
|
61
|
-
function ownKeys(e, r) {
|
|
62
|
-
var t = Object.keys(e);
|
|
63
|
-
if (Object.getOwnPropertySymbols) {
|
|
64
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
65
|
-
r && (o = o.filter(function (r) {
|
|
66
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
67
|
-
})), t.push.apply(t, o);
|
|
68
|
-
}
|
|
69
|
-
return t;
|
|
70
|
-
}
|
|
71
|
-
function _objectSpread2(e) {
|
|
72
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
73
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
74
|
-
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
75
|
-
_defineProperty(e, r, t[r]);
|
|
76
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
77
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
return e;
|
|
81
|
-
}
|
|
82
|
-
function _regenerator() {
|
|
83
|
-
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
84
|
-
var e,
|
|
85
|
-
t,
|
|
86
|
-
r = "function" == typeof Symbol ? Symbol : {},
|
|
87
|
-
n = r.iterator || "@@iterator",
|
|
88
|
-
o = r.toStringTag || "@@toStringTag";
|
|
89
|
-
function i(r, n, o, i) {
|
|
90
|
-
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
91
|
-
u = Object.create(c.prototype);
|
|
92
|
-
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
93
|
-
var i,
|
|
94
|
-
c,
|
|
95
|
-
u,
|
|
96
|
-
f = 0,
|
|
97
|
-
p = o || [],
|
|
98
|
-
y = false,
|
|
99
|
-
G = {
|
|
100
|
-
p: 0,
|
|
101
|
-
n: 0,
|
|
102
|
-
v: e,
|
|
103
|
-
a: d,
|
|
104
|
-
f: d.bind(e, 4),
|
|
105
|
-
d: function (t, r) {
|
|
106
|
-
return i = t, c = 0, u = e, G.n = r, a;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
function d(r, n) {
|
|
110
|
-
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
111
|
-
var o,
|
|
112
|
-
i = p[t],
|
|
113
|
-
d = G.p,
|
|
114
|
-
l = i[2];
|
|
115
|
-
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
116
|
-
}
|
|
117
|
-
if (o || r > 1) return a;
|
|
118
|
-
throw y = true, n;
|
|
119
|
-
}
|
|
120
|
-
return function (o, p, l) {
|
|
121
|
-
if (f > 1) throw TypeError("Generator is already running");
|
|
122
|
-
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
123
|
-
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
124
|
-
try {
|
|
125
|
-
if (f = 2, i) {
|
|
126
|
-
if (c || (o = "next"), t = i[o]) {
|
|
127
|
-
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
128
|
-
if (!t.done) return t;
|
|
129
|
-
u = t.value, c < 2 && (c = 0);
|
|
130
|
-
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
131
|
-
i = e;
|
|
132
|
-
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
133
|
-
} catch (t) {
|
|
134
|
-
i = e, c = 1, u = t;
|
|
135
|
-
} finally {
|
|
136
|
-
f = 1;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
value: t,
|
|
141
|
-
done: y
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
}(r, o, i), true), u;
|
|
145
|
-
}
|
|
146
|
-
var a = {};
|
|
147
|
-
function Generator() {}
|
|
148
|
-
function GeneratorFunction() {}
|
|
149
|
-
function GeneratorFunctionPrototype() {}
|
|
150
|
-
t = Object.getPrototypeOf;
|
|
151
|
-
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
152
|
-
return this;
|
|
153
|
-
}), t),
|
|
154
|
-
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
155
|
-
function f(e) {
|
|
156
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
157
|
-
}
|
|
158
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
159
|
-
return this;
|
|
160
|
-
}), _regeneratorDefine(u, "toString", function () {
|
|
161
|
-
return "[object Generator]";
|
|
162
|
-
}), (_regenerator = function () {
|
|
163
|
-
return {
|
|
164
|
-
w: i,
|
|
165
|
-
m: f
|
|
166
|
-
};
|
|
167
|
-
})();
|
|
168
|
-
}
|
|
169
|
-
function _regeneratorDefine(e, r, n, t) {
|
|
170
|
-
var i = Object.defineProperty;
|
|
171
|
-
try {
|
|
172
|
-
i({}, "", {});
|
|
173
|
-
} catch (e) {
|
|
174
|
-
i = 0;
|
|
175
|
-
}
|
|
176
|
-
_regeneratorDefine = function (e, r, n, t) {
|
|
177
|
-
function o(r, n) {
|
|
178
|
-
_regeneratorDefine(e, r, function (e) {
|
|
179
|
-
return this._invoke(r, n, e);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
r ? i ? i(e, r, {
|
|
183
|
-
value: n,
|
|
184
|
-
enumerable: !t,
|
|
185
|
-
configurable: !t,
|
|
186
|
-
writable: !t
|
|
187
|
-
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
188
|
-
}, _regeneratorDefine(e, r, n, t);
|
|
189
|
-
}
|
|
190
|
-
function _toPrimitive(t, r) {
|
|
191
|
-
if ("object" != typeof t || !t) return t;
|
|
192
|
-
var e = t[Symbol.toPrimitive];
|
|
193
|
-
if (void 0 !== e) {
|
|
194
|
-
var i = e.call(t, r);
|
|
195
|
-
if ("object" != typeof i) return i;
|
|
196
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
197
|
-
}
|
|
198
|
-
return ("string" === r ? String : Number)(t);
|
|
199
|
-
}
|
|
200
|
-
function _toPropertyKey(t) {
|
|
201
|
-
var i = _toPrimitive(t, "string");
|
|
202
|
-
return "symbol" == typeof i ? i : i + "";
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* 挂载单个路由
|
|
207
|
-
* @param controllerConfig
|
|
208
|
-
* @param manager
|
|
209
|
-
*/
|
|
210
|
-
var mountServerSingle = function mountServerSingle(controllerConfig, manager) {
|
|
211
|
-
var Controller = controllerConfig.Controller,
|
|
212
|
-
relativePath = controllerConfig.relativePath;
|
|
213
|
-
var controller = new Controller();
|
|
214
|
-
var routeFunNameMap = Controller.routeFunNameMap,
|
|
215
|
-
funNameMethodMap = Controller.funNameMethodMap,
|
|
216
|
-
fileRoute = Controller.fileRoute,
|
|
217
|
-
defaultHandlerType = Controller.defaultHandlerType;
|
|
218
|
-
Object.keys(routeFunNameMap).forEach(function (childRoute) {
|
|
219
|
-
var funName = routeFunNameMap[childRoute];
|
|
220
|
-
var methods = (funNameMethodMap || {})[funName] || ['get', 'post'];
|
|
221
|
-
var routeStr = path.join('/', relativePath, fileRoute, childRoute);
|
|
222
|
-
methods.forEach(function (method) {
|
|
223
|
-
manager.add(routeStr, method, function (req, res) {
|
|
224
|
-
return controller[funName].bind(controller)(req, res);
|
|
225
|
-
}, {
|
|
226
|
-
handlerType: defaultHandlerType
|
|
227
|
-
});
|
|
228
|
-
helper.cLog.log('ser', 'Mount', "[".concat(method.toUpperCase(), "] ").concat(routeStr));
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* 更新单个路由
|
|
235
|
-
* @param controllerConfig
|
|
236
|
-
* @param manager
|
|
237
|
-
*/
|
|
238
|
-
var updateServerSingle = function updateServerSingle(controllerConfig, manager) {
|
|
239
|
-
var relativePath = controllerConfig.relativePath,
|
|
240
|
-
Controller = controllerConfig.Controller;
|
|
241
|
-
var controller = new Controller();
|
|
242
|
-
var routeFunNameMap = Controller.routeFunNameMap,
|
|
243
|
-
fileRoute = Controller.fileRoute,
|
|
244
|
-
funNameMethodMap = Controller.funNameMethodMap,
|
|
245
|
-
defaultHandlerType = Controller.defaultHandlerType;
|
|
246
|
-
Object.keys(routeFunNameMap).forEach(function (childRoute) {
|
|
247
|
-
var funName = routeFunNameMap[childRoute];
|
|
248
|
-
var methods = (funNameMethodMap || {})[funName] || ['get', 'post'];
|
|
249
|
-
var routeStr = path.join('/', relativePath, fileRoute, childRoute);
|
|
250
|
-
methods.forEach(function (method) {
|
|
251
|
-
manager.update(routeStr, method, function (req, res) {
|
|
252
|
-
return controller[funName].bind(controller)(req, res);
|
|
253
|
-
}, {
|
|
254
|
-
handlerType: defaultHandlerType
|
|
255
|
-
});
|
|
256
|
-
helper.cLog.log('ser', 'Update', "[".concat(method.toUpperCase(), "] ").concat(routeStr));
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 删除单个路由
|
|
263
|
-
* @param controllerConfig
|
|
264
|
-
* @param manager
|
|
265
|
-
*/
|
|
266
|
-
var removeServerSingle = function removeServerSingle(controllerConfig, manager) {
|
|
267
|
-
var relativePath = controllerConfig.relativePath,
|
|
268
|
-
Controller = controllerConfig.Controller;
|
|
269
|
-
var routeFunNameMap = Controller.routeFunNameMap,
|
|
270
|
-
funNameMethodMap = Controller.funNameMethodMap;
|
|
271
|
-
Object.keys(routeFunNameMap).forEach(function (childRoute) {
|
|
272
|
-
var funName = routeFunNameMap[childRoute];
|
|
273
|
-
var methods = (funNameMethodMap || {})[funName] || ['get'];
|
|
274
|
-
var routeStr = path.join('/', relativePath, childRoute);
|
|
275
|
-
methods.forEach(function (method) {
|
|
276
|
-
manager.remove(routeStr, method);
|
|
277
|
-
helper.cLog.log('ser', 'remove', "[".concat(method.toUpperCase(), "] ").concat(routeStr));
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* 搜索控制器文件
|
|
284
|
-
* @returns
|
|
285
|
-
*/
|
|
286
|
-
var scanControllerHelp = /*#__PURE__*/function () {
|
|
287
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(targetPath) {
|
|
288
|
-
var controllerPathList, _t;
|
|
289
|
-
return _regenerator().w(function (_context2) {
|
|
290
|
-
while (1) switch (_context2.p = _context2.n) {
|
|
291
|
-
case 0:
|
|
292
|
-
controllerPathList = [];
|
|
293
|
-
_context2.p = 1;
|
|
294
|
-
_context2.n = 2;
|
|
295
|
-
return filePro.dirIterate(targetPath, /*#__PURE__*/function () {
|
|
296
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(dir, _ref2) {
|
|
297
|
-
var isDirectory;
|
|
298
|
-
return _regenerator().w(function (_context) {
|
|
299
|
-
while (1) switch (_context.n) {
|
|
300
|
-
case 0:
|
|
301
|
-
isDirectory = _ref2.isDirectory;
|
|
302
|
-
if (!isDirectory) {
|
|
303
|
-
_context.n = 1;
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
return _context.a(2);
|
|
307
|
-
case 1:
|
|
308
|
-
controllerPathList.push(dir);
|
|
309
|
-
case 2:
|
|
310
|
-
return _context.a(2);
|
|
311
|
-
}
|
|
312
|
-
}, _callee);
|
|
313
|
-
}));
|
|
314
|
-
return function (_x2, _x3) {
|
|
315
|
-
return _ref3.apply(this, arguments);
|
|
316
|
-
};
|
|
317
|
-
}(), {
|
|
318
|
-
recursive: true
|
|
319
|
-
});
|
|
320
|
-
case 2:
|
|
321
|
-
return _context2.a(2, controllerPathList);
|
|
322
|
-
case 3:
|
|
323
|
-
_context2.p = 3;
|
|
324
|
-
_t = _context2.v;
|
|
325
|
-
helper.cLog.error('scan', 'error', "\u626B\u63CF ".concat(targetPath, " \u76EE\u5F55\u5931\u8D25\n"));
|
|
326
|
-
helper.cLog.debug('scan', 'error', _t);
|
|
327
|
-
return _context2.a(2, controllerPathList);
|
|
328
|
-
}
|
|
329
|
-
}, _callee2, null, [[1, 3]]);
|
|
330
|
-
}));
|
|
331
|
-
return function scanControllerHelp(_x) {
|
|
332
|
-
return _ref.apply(this, arguments);
|
|
333
|
-
};
|
|
334
|
-
}();
|
|
335
|
-
|
|
336
|
-
var ControllerBuilder = /*#__PURE__*/function () {
|
|
337
|
-
function ControllerBuilder(ctx, controllerConfig) {
|
|
338
|
-
var _this = this;
|
|
339
|
-
_classCallCheck(this, ControllerBuilder);
|
|
340
|
-
this.ctx = ctx;
|
|
341
|
-
this.controllerConfig = controllerConfig;
|
|
342
|
-
_defineProperty(this, "compiler", void 0);
|
|
343
|
-
_defineProperty(this, "outdirAbsolute", void 0);
|
|
344
|
-
/**
|
|
345
|
-
* absoluteFilePathOrigin => ctxKey
|
|
346
|
-
*/
|
|
347
|
-
_defineProperty(this, "inputKeyMap", {});
|
|
348
|
-
/**
|
|
349
|
-
* ctxKey => compilerCtx
|
|
350
|
-
*/
|
|
351
|
-
_defineProperty(this, "compilerCtxMap", new Map());
|
|
352
|
-
/**
|
|
353
|
-
* 根据编译上下文分组构建
|
|
354
|
-
* @param groupkey
|
|
355
|
-
* @returns {input => output}[]
|
|
356
|
-
*/
|
|
357
|
-
_defineProperty(this, "buildGroup", /*#__PURE__*/function () {
|
|
358
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(groupkey) {
|
|
359
|
-
var ctx, buildRes, _t;
|
|
360
|
-
return _regenerator().w(function (_context) {
|
|
361
|
-
while (1) switch (_context.p = _context.n) {
|
|
362
|
-
case 0:
|
|
363
|
-
ctx = _this.compilerCtxMap.get(groupkey);
|
|
364
|
-
_context.p = 1;
|
|
365
|
-
_context.n = 2;
|
|
366
|
-
return ctx.rebuild();
|
|
367
|
-
case 2:
|
|
368
|
-
buildRes = _context.v;
|
|
369
|
-
return _context.a(2, Object.keys(buildRes.metafile.outputs).reduce(function (pre, output) {
|
|
370
|
-
/** 公共依赖也会是输出,忽略掉 */
|
|
371
|
-
if (!buildRes.metafile.outputs[output].entryPoint) {
|
|
372
|
-
return pre;
|
|
373
|
-
}
|
|
374
|
-
pre[path.join(filePro.getCwd(), buildRes.metafile.outputs[output].entryPoint)] = path.join(filePro.getCwd(), output);
|
|
375
|
-
return pre;
|
|
376
|
-
}, {}));
|
|
377
|
-
case 3:
|
|
378
|
-
_context.p = 3;
|
|
379
|
-
_t = _context.v;
|
|
380
|
-
console.error(_t);
|
|
381
|
-
return _context.a(2, {});
|
|
382
|
-
}
|
|
383
|
-
}, _callee, null, [[1, 3]]);
|
|
384
|
-
}));
|
|
385
|
-
return function (_x) {
|
|
386
|
-
return _ref.apply(this, arguments);
|
|
387
|
-
};
|
|
388
|
-
}());
|
|
389
|
-
this.outdirAbsolute = ctx.serverConfig.cacheDir;
|
|
390
|
-
this.compiler = esbuild.createCompiler(esbuild.getNodeBuildConfigPreset({
|
|
391
|
-
sourcemap: undefined,
|
|
392
|
-
minify: false,
|
|
393
|
-
external: Object.keys(helper.getDependencies(ctx.configCtx.getPackageConfig())),
|
|
394
|
-
metafile: true,
|
|
395
|
-
splitting: true,
|
|
396
|
-
// 启用代码分割
|
|
397
|
-
bundle: true,
|
|
398
|
-
// 启用打包
|
|
399
|
-
outdir: this.outdirAbsolute,
|
|
400
|
-
entryNames: '[dir]/[name]/[hash]'
|
|
401
|
-
}));
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/** 批量构建 */
|
|
405
|
-
return _createClass(ControllerBuilder, [{
|
|
406
|
-
key: "build",
|
|
407
|
-
value: (function () {
|
|
408
|
-
var _build = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(absoluteFilePathOriginList) {
|
|
409
|
-
var _this2 = this;
|
|
410
|
-
var cacheBuildCtx, inOutList, newCacheKey, resInOutMap, _ctx, buildResList;
|
|
411
|
-
return _regenerator().w(function (_context2) {
|
|
412
|
-
while (1) switch (_context2.n) {
|
|
413
|
-
case 0:
|
|
414
|
-
cacheBuildCtx = new Set();
|
|
415
|
-
inOutList = [];
|
|
416
|
-
newCacheKey = utils.uuid(8);
|
|
417
|
-
resInOutMap = {}; // 1. 先检查已有的编译上下文
|
|
418
|
-
absoluteFilePathOriginList.forEach(function (absoluteFilePathOrigin) {
|
|
419
|
-
var _this2$controllerConf;
|
|
420
|
-
if (((_this2$controllerConf = _this2.controllerConfig.getConfig(absoluteFilePathOrigin)) === null || _this2$controllerConf === void 0 ? void 0 : _this2$controllerConf.fileExt) !== '.ts') {
|
|
421
|
-
resInOutMap[absoluteFilePathOrigin] = absoluteFilePathOrigin;
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
var ctxKey = _this2.inputKeyMap[absoluteFilePathOrigin];
|
|
425
|
-
if (ctxKey) {
|
|
426
|
-
cacheBuildCtx.add(ctxKey);
|
|
427
|
-
} else {
|
|
428
|
-
inOutList.push({
|
|
429
|
-
in: absoluteFilePathOrigin,
|
|
430
|
-
out: _this2.getOutputPath(absoluteFilePathOrigin, newCacheKey)
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
// 2. 没有缓存的编译上下文,全部新建,写入缓存
|
|
436
|
-
if (!inOutList.length) {
|
|
437
|
-
_context2.n = 2;
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
_context2.n = 1;
|
|
441
|
-
return this.compiler.context({
|
|
442
|
-
entryPoints: inOutList
|
|
443
|
-
});
|
|
444
|
-
case 1:
|
|
445
|
-
_ctx = _context2.v;
|
|
446
|
-
this.compilerCtxMap.set(newCacheKey, _ctx);
|
|
447
|
-
inOutList.forEach(function (o) {
|
|
448
|
-
return _this2.inputKeyMap[o.in] = newCacheKey;
|
|
449
|
-
});
|
|
450
|
-
cacheBuildCtx.add(newCacheKey);
|
|
451
|
-
case 2:
|
|
452
|
-
_context2.n = 3;
|
|
453
|
-
return Promise.all(Array.from(cacheBuildCtx).map(function (groupkey) {
|
|
454
|
-
return _this2.buildGroup(groupkey);
|
|
455
|
-
}));
|
|
456
|
-
case 3:
|
|
457
|
-
buildResList = _context2.v;
|
|
458
|
-
return _context2.a(2, buildResList.reduce(function (pre, cur) {
|
|
459
|
-
return _objectSpread2(_objectSpread2({}, pre), cur);
|
|
460
|
-
}, resInOutMap));
|
|
461
|
-
}
|
|
462
|
-
}, _callee2, this);
|
|
463
|
-
}));
|
|
464
|
-
function build(_x2) {
|
|
465
|
-
return _build.apply(this, arguments);
|
|
466
|
-
}
|
|
467
|
-
return build;
|
|
468
|
-
}())
|
|
469
|
-
}, {
|
|
470
|
-
key: "getOutputPath",
|
|
471
|
-
value: /** 获取输出文件路径 */
|
|
472
|
-
function getOutputPath(key, ctxHash) {
|
|
473
|
-
var config = this.controllerConfig.getConfig(key);
|
|
474
|
-
var relativeFilePathOrigin = config.relativeFilePathOrigin,
|
|
475
|
-
fileName = config.fileName;
|
|
476
|
-
return path.join(ctxHash, path.dirname(relativeFilePathOrigin), fileName);
|
|
477
|
-
}
|
|
478
|
-
}]);
|
|
479
|
-
}();
|
|
480
|
-
|
|
481
|
-
var ControllerConfig = /*#__PURE__*/function () {
|
|
482
|
-
function ControllerConfig() {
|
|
483
|
-
_classCallCheck(this, ControllerConfig);
|
|
484
|
-
_defineProperty(this, "map", new Map());
|
|
485
|
-
}
|
|
486
|
-
return _createClass(ControllerConfig, [{
|
|
487
|
-
key: "update",
|
|
488
|
-
value: function update(absoluteFilePathOrigin, config) {
|
|
489
|
-
this.map.set(absoluteFilePathOrigin, _objectSpread2(_objectSpread2({}, this.map.get(absoluteFilePathOrigin)), config));
|
|
490
|
-
}
|
|
491
|
-
}, {
|
|
492
|
-
key: "updateMulti",
|
|
493
|
-
value: function updateMulti(configs) {
|
|
494
|
-
var _this = this;
|
|
495
|
-
configs.forEach(function (config) {
|
|
496
|
-
return _this.update(config.absoluteFilePathOrigin, config);
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
|
-
}, {
|
|
500
|
-
key: "updateAbsoluteFilePath",
|
|
501
|
-
value: function updateAbsoluteFilePath(inOutMap) {
|
|
502
|
-
for (var absoluteFilePathOrigin in inOutMap) {
|
|
503
|
-
if (!Object.hasOwn(inOutMap, absoluteFilePathOrigin)) continue;
|
|
504
|
-
this.update(absoluteFilePathOrigin, {
|
|
505
|
-
absoluteFilePath: inOutMap[absoluteFilePathOrigin]
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}, {
|
|
510
|
-
key: "getConfig",
|
|
511
|
-
value: function getConfig(absoluteFilePathOrigin) {
|
|
512
|
-
return this.map.get(absoluteFilePathOrigin);
|
|
513
|
-
}
|
|
514
|
-
}, {
|
|
515
|
-
key: "getConfigList",
|
|
516
|
-
value: function getConfigList(absoluteFilePathOriginList) {
|
|
517
|
-
var _this2 = this;
|
|
518
|
-
return absoluteFilePathOriginList.map(function (absoluteFilePathOrigin) {
|
|
519
|
-
return _this2.getConfig(absoluteFilePathOrigin);
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
}]);
|
|
523
|
-
}();
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* 解析文件名
|
|
527
|
-
* @param controllerConfig
|
|
528
|
-
* @returns
|
|
529
|
-
*/
|
|
530
|
-
var parseControllerPath = function parseControllerPath(absoluteFilePathOrigin, scanPath) {
|
|
531
|
-
var relativeFilePathOrigin = path.relative(scanPath, absoluteFilePathOrigin);
|
|
532
|
-
var parts = relativeFilePathOrigin.split('/');
|
|
533
|
-
var fileName = parts.pop() || '';
|
|
534
|
-
var relativePath = parts.join('/');
|
|
535
|
-
|
|
536
|
-
// 正则提取
|
|
537
|
-
var match = fileName.match(/^(.*?)(\..*)$/);
|
|
538
|
-
if (!match) {
|
|
539
|
-
return {
|
|
540
|
-
relativeFilePathOrigin: relativeFilePathOrigin,
|
|
541
|
-
absoluteFilePathOrigin: absoluteFilePathOrigin
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
return {
|
|
545
|
-
relativePath: relativePath,
|
|
546
|
-
fileName: match[1],
|
|
547
|
-
fileExt: match[2],
|
|
548
|
-
relativeFilePathOrigin: relativeFilePathOrigin,
|
|
549
|
-
absoluteFilePathOrigin: absoluteFilePathOrigin
|
|
550
|
-
};
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* 加载控制器文件
|
|
555
|
-
* @param controllerConfig
|
|
556
|
-
* @returns
|
|
557
|
-
*/
|
|
558
|
-
var loadControllerFile = /*#__PURE__*/function () {
|
|
559
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(controllerConfig) {
|
|
560
|
-
var absoluteFilePath, fileOrange, ext, _t;
|
|
561
|
-
return _regenerator().w(function (_context) {
|
|
562
|
-
while (1) switch (_context.n) {
|
|
563
|
-
case 0:
|
|
564
|
-
absoluteFilePath = controllerConfig.absoluteFilePath;
|
|
565
|
-
ext = path.extname(absoluteFilePath);
|
|
566
|
-
_t = ext;
|
|
567
|
-
_context.n = _t === '.js' ? 1 : _t === '.mjs' ? 1 : _t === '.json' ? 3 : 5;
|
|
568
|
-
break;
|
|
569
|
-
case 1:
|
|
570
|
-
_context.n = 2;
|
|
571
|
-
return configLoader.loadJs(absoluteFilePath);
|
|
572
|
-
case 2:
|
|
573
|
-
fileOrange = _context.v;
|
|
574
|
-
return _context.a(3, 6);
|
|
575
|
-
case 3:
|
|
576
|
-
_context.n = 4;
|
|
577
|
-
return configLoader.loadJson(absoluteFilePath);
|
|
578
|
-
case 4:
|
|
579
|
-
fileOrange = _context.v;
|
|
580
|
-
return _context.a(3, 6);
|
|
581
|
-
case 5:
|
|
582
|
-
return _context.a(3, 6);
|
|
583
|
-
case 6:
|
|
584
|
-
controllerConfig.orange = fileOrange.default || fileOrange;
|
|
585
|
-
return _context.a(2, controllerConfig);
|
|
586
|
-
}
|
|
587
|
-
}, _callee);
|
|
588
|
-
}));
|
|
589
|
-
return function loadControllerFile(_x) {
|
|
590
|
-
return _ref.apply(this, arguments);
|
|
591
|
-
};
|
|
592
|
-
}();
|
|
593
|
-
|
|
594
|
-
/**
|
|
595
|
-
* 格式化控制器
|
|
596
|
-
* @param controllerConfig
|
|
597
|
-
* @returns
|
|
598
|
-
*/
|
|
599
|
-
var formatController = function formatController(controllerConfig) {
|
|
600
|
-
var _Controller;
|
|
601
|
-
var fileExt = controllerConfig.fileExt,
|
|
602
|
-
fileName = controllerConfig.fileName,
|
|
603
|
-
orange = controllerConfig.orange;
|
|
604
|
-
if (!orange) return controllerConfig;
|
|
605
|
-
var Controller;
|
|
606
|
-
if (fileExt === '.json') {
|
|
607
|
-
Controller = defineServer.defineControllerFun(function (_req, res) {
|
|
608
|
-
res.json(orange);
|
|
609
|
-
});
|
|
610
|
-
} else {
|
|
611
|
-
Controller = orange;
|
|
612
|
-
}
|
|
613
|
-
if (!((_Controller = Controller) !== null && _Controller !== void 0 && _Controller.handlerServer)) return controllerConfig;
|
|
614
|
-
switch (Controller.defineType) {
|
|
615
|
-
case 'FUN':
|
|
616
|
-
Controller.routeFunNameMap = _defineProperty({}, fileName || '', defineServer.DefaultHandlerName);
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
Controller.defineType = 'CLASS';
|
|
620
|
-
Controller.fileRoute = Controller.fileRoute || '/';
|
|
621
|
-
return _objectSpread2(_objectSpread2({}, controllerConfig), {}, {
|
|
622
|
-
Controller: Controller
|
|
623
|
-
});
|
|
624
|
-
};
|
|
625
|
-
|
|
626
|
-
/**
|
|
627
|
-
* 控制器处理类
|
|
628
|
-
*/
|
|
629
|
-
var ControllerDeal = /*#__PURE__*/function () {
|
|
630
|
-
function ControllerDeal(scanAbsolute) {
|
|
631
|
-
_classCallCheck(this, ControllerDeal);
|
|
632
|
-
this.scanAbsolute = scanAbsolute;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
/** 收集路径中的参数 多个 */
|
|
636
|
-
return _createClass(ControllerDeal, [{
|
|
637
|
-
key: "getBaseConfigMult",
|
|
638
|
-
value: function getBaseConfigMult(absolutePathList) {
|
|
639
|
-
var _this = this;
|
|
640
|
-
return absolutePathList.map(function (absolutePath) {
|
|
641
|
-
return _this.getBaseConfig(absolutePath);
|
|
642
|
-
});
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
/** 收集路径中的参数 */
|
|
646
|
-
}, {
|
|
647
|
-
key: "getBaseConfig",
|
|
648
|
-
value: function getBaseConfig(absolutePath) {
|
|
649
|
-
return parseControllerPath(absolutePath, this.scanAbsolute);
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
/** 加载多个配置 */
|
|
653
|
-
}, {
|
|
654
|
-
key: "loadMult",
|
|
655
|
-
value: function loadMult(configs) {
|
|
656
|
-
return Promise.all(configs.map(/*#__PURE__*/function () {
|
|
657
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(config) {
|
|
658
|
-
return _regenerator().w(function (_context) {
|
|
659
|
-
while (1) switch (_context.n) {
|
|
660
|
-
case 0:
|
|
661
|
-
return _context.a(2, loadControllerFile(config));
|
|
662
|
-
}
|
|
663
|
-
}, _callee);
|
|
664
|
-
}));
|
|
665
|
-
return function (_x) {
|
|
666
|
-
return _ref.apply(this, arguments);
|
|
667
|
-
};
|
|
668
|
-
}()));
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
/** 加载单个配置 */
|
|
672
|
-
}, {
|
|
673
|
-
key: "load",
|
|
674
|
-
value: function load(config) {
|
|
675
|
-
return loadControllerFile(config);
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
/** 格式化多个配置 */
|
|
679
|
-
}, {
|
|
680
|
-
key: "formatMult",
|
|
681
|
-
value: function formatMult(configs) {
|
|
682
|
-
var _this2 = this;
|
|
683
|
-
return configs.map(function (config) {
|
|
684
|
-
return _this2.format(config);
|
|
685
|
-
});
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
/** 格式化配置 */
|
|
689
|
-
}, {
|
|
690
|
-
key: "format",
|
|
691
|
-
value: function format(config) {
|
|
692
|
-
return formatController(config);
|
|
693
|
-
}
|
|
694
|
-
}]);
|
|
695
|
-
}();
|
|
696
|
-
|
|
697
|
-
var FileWatcher = /*#__PURE__*/function () {
|
|
698
|
-
function FileWatcher(options) {
|
|
699
|
-
_classCallCheck(this, FileWatcher);
|
|
700
|
-
_defineProperty(this, "watcher", void 0);
|
|
701
|
-
_defineProperty(this, "watcherOptions", {
|
|
702
|
-
ignoreInitial: true,
|
|
703
|
-
persistent: true
|
|
704
|
-
});
|
|
705
|
-
_defineProperty(this, "changeCb", lang.noop);
|
|
706
|
-
if (options) {
|
|
707
|
-
this.watcherOptions = _objectSpread2(_objectSpread2({}, this.watcherOptions), options);
|
|
708
|
-
}
|
|
709
|
-
this.watcher = this.createWatcher([]);
|
|
710
|
-
}
|
|
711
|
-
return _createClass(FileWatcher, [{
|
|
712
|
-
key: "onChange",
|
|
713
|
-
value: function onChange(cb) {
|
|
714
|
-
this.changeCb = cb;
|
|
715
|
-
}
|
|
716
|
-
}, {
|
|
717
|
-
key: "add",
|
|
718
|
-
value: function add(path) {
|
|
719
|
-
var _this$watcher;
|
|
720
|
-
(_this$watcher = this.watcher) === null || _this$watcher === void 0 || _this$watcher.add(path);
|
|
721
|
-
}
|
|
722
|
-
}, {
|
|
723
|
-
key: "unwatch",
|
|
724
|
-
value: function unwatch(path) {
|
|
725
|
-
var _this$watcher2;
|
|
726
|
-
(_this$watcher2 = this.watcher) === null || _this$watcher2 === void 0 || _this$watcher2.unwatch(path);
|
|
727
|
-
}
|
|
728
|
-
}, {
|
|
729
|
-
key: "close",
|
|
730
|
-
value: function close() {
|
|
731
|
-
if (this.watcher) {
|
|
732
|
-
this.watcher.close();
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
}, {
|
|
736
|
-
key: "createWatcher",
|
|
737
|
-
value: function createWatcher(dir) {
|
|
738
|
-
var _this = this;
|
|
739
|
-
var watcher = chokidar.watch(dir, this.watcherOptions).on('change', function (path) {
|
|
740
|
-
return _this.changeCb(path, {
|
|
741
|
-
type: 'update'
|
|
742
|
-
});
|
|
743
|
-
}).on('add', function (path) {
|
|
744
|
-
return _this.changeCb(path, {
|
|
745
|
-
type: 'create'
|
|
746
|
-
});
|
|
747
|
-
}).on('unlink', function (path) {
|
|
748
|
-
return _this.changeCb(path, {
|
|
749
|
-
type: 'delete'
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
return watcher;
|
|
753
|
-
}
|
|
754
|
-
}], [{
|
|
755
|
-
key: "of",
|
|
756
|
-
value: function of(options) {
|
|
757
|
-
if (!FileWatcher.watcher) {
|
|
758
|
-
FileWatcher.watcher = new FileWatcher(options);
|
|
759
|
-
}
|
|
760
|
-
return FileWatcher.watcher;
|
|
761
|
-
}
|
|
762
|
-
}]);
|
|
763
|
-
}();
|
|
764
|
-
_defineProperty(FileWatcher, "watcher", void 0);
|
|
765
|
-
|
|
766
|
-
var ControllerWatcher = /*#__PURE__*/function () {
|
|
767
|
-
function ControllerWatcher() {
|
|
768
|
-
_classCallCheck(this, ControllerWatcher);
|
|
769
|
-
_defineProperty(this, "fileWatcher", void 0);
|
|
770
|
-
_defineProperty(this, "onCreate", lang.noop);
|
|
771
|
-
_defineProperty(this, "onUpdate", lang.noop);
|
|
772
|
-
_defineProperty(this, "onDelete", lang.noop);
|
|
773
|
-
this.fileWatcher = new FileWatcher();
|
|
774
|
-
}
|
|
775
|
-
return _createClass(ControllerWatcher, [{
|
|
776
|
-
key: "handleChange",
|
|
777
|
-
value: function handleChange() {
|
|
778
|
-
var _this = this;
|
|
779
|
-
this.fileWatcher.onChange(/*#__PURE__*/function () {
|
|
780
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(path, _ref) {
|
|
781
|
-
var type, _t;
|
|
782
|
-
return _regenerator().w(function (_context) {
|
|
783
|
-
while (1) switch (_context.n) {
|
|
784
|
-
case 0:
|
|
785
|
-
type = _ref.type;
|
|
786
|
-
_t = type;
|
|
787
|
-
_context.n = _t === 'create' ? 1 : _t === 'delete' ? 2 : _t === 'update' ? 3 : 4;
|
|
788
|
-
break;
|
|
789
|
-
case 1:
|
|
790
|
-
_this.onCreate(path);
|
|
791
|
-
return _context.a(3, 5);
|
|
792
|
-
case 2:
|
|
793
|
-
_this.onDelete(path);
|
|
794
|
-
return _context.a(3, 5);
|
|
795
|
-
case 3:
|
|
796
|
-
_this.onUpdate(path);
|
|
797
|
-
return _context.a(3, 5);
|
|
798
|
-
case 4:
|
|
799
|
-
return _context.a(3, 5);
|
|
800
|
-
case 5:
|
|
801
|
-
return _context.a(2);
|
|
802
|
-
}
|
|
803
|
-
}, _callee);
|
|
804
|
-
}));
|
|
805
|
-
return function (_x, _x2) {
|
|
806
|
-
return _ref2.apply(this, arguments);
|
|
807
|
-
};
|
|
808
|
-
}());
|
|
809
|
-
}
|
|
810
|
-
}, {
|
|
811
|
-
key: "listion",
|
|
812
|
-
value: function listion(path) {
|
|
813
|
-
this.fileWatcher.add(path);
|
|
814
|
-
this.handleChange();
|
|
815
|
-
}
|
|
816
|
-
}]);
|
|
817
|
-
}();
|
|
818
|
-
|
|
819
|
-
var ServerWorkflow = /*#__PURE__*/function () {
|
|
820
|
-
function ServerWorkflow(ctx) {
|
|
821
|
-
_classCallCheck(this, ServerWorkflow);
|
|
822
|
-
_defineProperty(this, "scanAbsolute", void 0);
|
|
823
|
-
_defineProperty(this, "controllerBuilder", void 0);
|
|
824
|
-
_defineProperty(this, "controllerConfig", void 0);
|
|
825
|
-
_defineProperty(this, "controllerDeal", void 0);
|
|
826
|
-
_defineProperty(this, "routeManager", void 0);
|
|
827
|
-
_defineProperty(this, "controllerWatcher", void 0);
|
|
828
|
-
var workRootDir = ctx.envParams.workRootDir;
|
|
829
|
-
this.scanAbsolute = path.join(workRootDir, ctx.serverConfig.scan);
|
|
830
|
-
this.controllerConfig = new ControllerConfig();
|
|
831
|
-
this.controllerBuilder = new ControllerBuilder(ctx, this.controllerConfig);
|
|
832
|
-
this.controllerDeal = new ControllerDeal(this.scanAbsolute);
|
|
833
|
-
this.controllerWatcher = new ControllerWatcher();
|
|
834
|
-
this.routeManager = ctx.routeManager;
|
|
835
|
-
}
|
|
836
|
-
return _createClass(ServerWorkflow, [{
|
|
837
|
-
key: "scan",
|
|
838
|
-
value: function () {
|
|
839
|
-
var _scan = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
840
|
-
var _this = this;
|
|
841
|
-
var filesList, absoluteFilePathOriginList;
|
|
842
|
-
return _regenerator().w(function (_context) {
|
|
843
|
-
while (1) switch (_context.n) {
|
|
844
|
-
case 0:
|
|
845
|
-
_context.n = 1;
|
|
846
|
-
return scanControllerHelp(this.scanAbsolute);
|
|
847
|
-
case 1:
|
|
848
|
-
filesList = _context.v;
|
|
849
|
-
// 2. 初始化控制器对象
|
|
850
|
-
this.controllerConfig.updateMulti(this.controllerDeal.getBaseConfigMult(filesList));
|
|
851
|
-
// 3. buildResolve
|
|
852
|
-
_context.n = 2;
|
|
853
|
-
return this.buildResolve(filesList);
|
|
854
|
-
case 2:
|
|
855
|
-
absoluteFilePathOriginList = _context.v;
|
|
856
|
-
// 4. 挂载路由
|
|
857
|
-
absoluteFilePathOriginList.forEach(function (absoluteFilePathOrigin) {
|
|
858
|
-
var config = _this.controllerConfig.getConfig(absoluteFilePathOrigin);
|
|
859
|
-
if (config.Controller) {
|
|
860
|
-
mountServerSingle(config, _this.routeManager);
|
|
861
|
-
}
|
|
862
|
-
});
|
|
863
|
-
case 3:
|
|
864
|
-
return _context.a(2);
|
|
865
|
-
}
|
|
866
|
-
}, _callee, this);
|
|
867
|
-
}));
|
|
868
|
-
function scan() {
|
|
869
|
-
return _scan.apply(this, arguments);
|
|
870
|
-
}
|
|
871
|
-
return scan;
|
|
872
|
-
}() // 监听文件变化
|
|
873
|
-
}, {
|
|
874
|
-
key: "listen",
|
|
875
|
-
value: function listen() {
|
|
876
|
-
var _this2 = this;
|
|
877
|
-
// 2.1 新建文件
|
|
878
|
-
this.controllerWatcher.onCreate = /*#__PURE__*/function () {
|
|
879
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(path) {
|
|
880
|
-
var absoluteFilePathOriginList;
|
|
881
|
-
return _regenerator().w(function (_context2) {
|
|
882
|
-
while (1) switch (_context2.n) {
|
|
883
|
-
case 0:
|
|
884
|
-
// 2.1.1 初始化控制器对象
|
|
885
|
-
_this2.controllerConfig.updateMulti(_this2.controllerDeal.getBaseConfigMult([path]));
|
|
886
|
-
// 2.1.2 buildResolve
|
|
887
|
-
_context2.n = 1;
|
|
888
|
-
return _this2.buildResolve([path]);
|
|
889
|
-
case 1:
|
|
890
|
-
absoluteFilePathOriginList = _context2.v;
|
|
891
|
-
// 2.1.3 挂载路由
|
|
892
|
-
absoluteFilePathOriginList.forEach(function (absoluteFilePathOrigin) {
|
|
893
|
-
var config = _this2.controllerConfig.getConfig(absoluteFilePathOrigin);
|
|
894
|
-
if (config.Controller) {
|
|
895
|
-
mountServerSingle(config, _this2.routeManager);
|
|
896
|
-
}
|
|
897
|
-
});
|
|
898
|
-
case 2:
|
|
899
|
-
return _context2.a(2);
|
|
900
|
-
}
|
|
901
|
-
}, _callee2);
|
|
902
|
-
}));
|
|
903
|
-
return function (_x) {
|
|
904
|
-
return _ref.apply(this, arguments);
|
|
905
|
-
};
|
|
906
|
-
}();
|
|
907
|
-
// 2.2 更新文件
|
|
908
|
-
this.controllerWatcher.onUpdate = /*#__PURE__*/function () {
|
|
909
|
-
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(path) {
|
|
910
|
-
var absoluteFilePathOriginList;
|
|
911
|
-
return _regenerator().w(function (_context3) {
|
|
912
|
-
while (1) switch (_context3.n) {
|
|
913
|
-
case 0:
|
|
914
|
-
_context3.n = 1;
|
|
915
|
-
return _this2.buildResolve([path]);
|
|
916
|
-
case 1:
|
|
917
|
-
absoluteFilePathOriginList = _context3.v;
|
|
918
|
-
// 2.2.1 挂载路由
|
|
919
|
-
absoluteFilePathOriginList.forEach(function (absoluteFilePathOrigin) {
|
|
920
|
-
var config = _this2.controllerConfig.getConfig(absoluteFilePathOrigin);
|
|
921
|
-
if (config.Controller) {
|
|
922
|
-
updateServerSingle(config, _this2.routeManager);
|
|
923
|
-
}
|
|
924
|
-
});
|
|
925
|
-
case 2:
|
|
926
|
-
return _context3.a(2);
|
|
927
|
-
}
|
|
928
|
-
}, _callee3);
|
|
929
|
-
}));
|
|
930
|
-
return function (_x2) {
|
|
931
|
-
return _ref2.apply(this, arguments);
|
|
932
|
-
};
|
|
933
|
-
}();
|
|
934
|
-
// 2.3 删除文件
|
|
935
|
-
this.controllerWatcher.onDelete = /*#__PURE__*/function () {
|
|
936
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(path) {
|
|
937
|
-
var config;
|
|
938
|
-
return _regenerator().w(function (_context4) {
|
|
939
|
-
while (1) switch (_context4.n) {
|
|
940
|
-
case 0:
|
|
941
|
-
config = _this2.controllerConfig.getConfig(path);
|
|
942
|
-
if (config) {
|
|
943
|
-
_context4.n = 1;
|
|
944
|
-
break;
|
|
945
|
-
}
|
|
946
|
-
return _context4.a(2);
|
|
947
|
-
case 1:
|
|
948
|
-
removeServerSingle(config, _this2.routeManager);
|
|
949
|
-
case 2:
|
|
950
|
-
return _context4.a(2);
|
|
951
|
-
}
|
|
952
|
-
}, _callee4);
|
|
953
|
-
}));
|
|
954
|
-
return function (_x3) {
|
|
955
|
-
return _ref3.apply(this, arguments);
|
|
956
|
-
};
|
|
957
|
-
}();
|
|
958
|
-
|
|
959
|
-
// 3. 监听文件变化
|
|
960
|
-
this.controllerWatcher.listion(this.scanAbsolute);
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
/**
|
|
964
|
-
* 1. 构建
|
|
965
|
-
* 2. 加载
|
|
966
|
-
* 3. 格式化
|
|
967
|
-
* @param absoluteFilePathOriginList 更新的文件
|
|
968
|
-
* @returns 更新的文件列表
|
|
969
|
-
*/
|
|
970
|
-
}, {
|
|
971
|
-
key: "buildResolve",
|
|
972
|
-
value: (function () {
|
|
973
|
-
var _buildResolve = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(absoluteFilePathOriginList) {
|
|
974
|
-
var inOutMap, list, _t;
|
|
975
|
-
return _regenerator().w(function (_context5) {
|
|
976
|
-
while (1) switch (_context5.n) {
|
|
977
|
-
case 0:
|
|
978
|
-
_context5.n = 1;
|
|
979
|
-
return this.controllerBuilder.build(absoluteFilePathOriginList);
|
|
980
|
-
case 1:
|
|
981
|
-
inOutMap = _context5.v;
|
|
982
|
-
this.controllerConfig.updateAbsoluteFilePath(inOutMap);
|
|
983
|
-
_t = this.controllerDeal;
|
|
984
|
-
_context5.n = 2;
|
|
985
|
-
return this.controllerDeal.loadMult(this.controllerConfig.getConfigList(Object.keys(inOutMap)));
|
|
986
|
-
case 2:
|
|
987
|
-
list = _t.formatMult.call(_t, _context5.v);
|
|
988
|
-
this.controllerConfig.updateMulti(list);
|
|
989
|
-
return _context5.a(2, Object.keys(inOutMap));
|
|
990
|
-
}
|
|
991
|
-
}, _callee5, this);
|
|
992
|
-
}));
|
|
993
|
-
function buildResolve(_x4) {
|
|
994
|
-
return _buildResolve.apply(this, arguments);
|
|
995
|
-
}
|
|
996
|
-
return buildResolve;
|
|
997
|
-
}())
|
|
998
|
-
}]);
|
|
999
|
-
}();
|
|
1000
|
-
|
|
1001
|
-
var getConfigCtx = /*#__PURE__*/function () {
|
|
1002
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(envParams, cmd, defaultDora) {
|
|
1003
|
-
var workflow;
|
|
1004
|
-
return _regenerator().w(function (_context) {
|
|
1005
|
-
while (1) switch (_context.n) {
|
|
1006
|
-
case 0:
|
|
1007
|
-
workflow = helper.configCtxWorkflow(new helper.ConfigCtx());
|
|
1008
|
-
workflow.use(helper.collectBaseConfigMw(envParams.workRootDir, cmd));
|
|
1009
|
-
workflow.use(helper.collectPackageJsonMw());
|
|
1010
|
-
workflow.use(helper.collectTsconfigJsonMw());
|
|
1011
|
-
workflow.use(helper.collectDoraConfigMw('development'));
|
|
1012
|
-
workflow.use(helper.wholeDoraConfigMw(defaultDora));
|
|
1013
|
-
_context.n = 1;
|
|
1014
|
-
return workflow.getResult();
|
|
1015
|
-
case 1:
|
|
1016
|
-
return _context.a(2, _context.v);
|
|
1017
|
-
}
|
|
1018
|
-
}, _callee);
|
|
1019
|
-
}));
|
|
1020
|
-
return function getConfigCtx(_x, _x2, _x3) {
|
|
1021
|
-
return _ref.apply(this, arguments);
|
|
1022
|
-
};
|
|
1023
|
-
}();
|
|
1024
|
-
|
|
1025
|
-
var getServerCtx = function getServerCtx(configCtx, app, envParams) {
|
|
1026
|
-
var _configCtx$getCmd;
|
|
1027
|
-
var workflow = helper.configCtxWorkflow(new express.Ctx(configCtx, app));
|
|
1028
|
-
workflow.use(express.envParamsMw(envParams));
|
|
1029
|
-
workflow.use(express.serverPlainMw());
|
|
1030
|
-
workflow.use(express.serverScanMw((_configCtx$getCmd = configCtx.getCmd()) === null || _configCtx$getCmd === void 0 ? void 0 : _configCtx$getCmd.scan));
|
|
1031
|
-
workflow.use(express.serverCacheMw());
|
|
1032
|
-
return workflow.getResult();
|
|
1033
|
-
};
|
|
1034
|
-
|
|
1035
|
-
exports.ServerWorkflow = ServerWorkflow;
|
|
1036
|
-
exports.getConfigCtx = getConfigCtx;
|
|
1037
|
-
exports.getServerCtx = getServerCtx;
|
|
1
|
+
"use strict";var e=require("path"),t=require("@cclr/utils"),n=require("@doracli/helper"),r=require("@dorabag/file-pro"),o=require("@doracli/esbuild"),i=require("@dorabag/config-loader"),a=require("@doracli/define-server"),u=require("@cclr/lang"),c=require("chokidar"),l=require("@doracli/express");function s(e,t,n,r,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void n(e)}u.done?t(c):Promise.resolve(c).then(r,o)}function f(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var i=e.apply(t,n);function a(e){s(i,r,o,a,u,"next",e)}function u(e){s(i,r,o,a,u,"throw",e)}a(void 0)})}}function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,m(r.key),r)}}function v(e,t,n){return t&&p(e.prototype,t),n&&p(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function g(e,t,n){return(t=m(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?d(Object(n),!0).forEach(function(t){g(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):d(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function b(){
|
|
2
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
+
var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",o=n.toStringTag||"@@toStringTag";function i(n,r,o,i){var c=r&&r.prototype instanceof u?r:u,l=Object.create(c.prototype);return w(l,"_invoke",function(n,r,o){var i,u,c,l=0,s=o||[],f=!1,h={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return i=t,u=0,c=e,h.n=n,a}};function p(n,r){for(u=n,c=r,t=0;!f&&l&&!o&&t<s.length;t++){var o,i=s[t],p=h.p,v=i[2];n>3?(o=v===r)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=n<2&&p<i[1])?(u=0,h.v=r,h.n=i[1]):p<v&&(o=n<3||i[0]>r||r>v)&&(i[4]=n,i[5]=r,h.n=v,u=0))}if(o||n>1)return a;throw f=!0,r}return function(o,s,v){if(l>1)throw TypeError("Generator is already running");for(f&&1===s&&p(s,v),u=s,c=v;(t=u<2?e:c)||!f;){i||(u?u<3?(u>1&&(h.n=-1),p(u,c)):h.n=c:h.v=c);try{if(l=2,i){if(u||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,u<2&&(u=0)}else 1===u&&(t=i.return)&&t.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=e}else if((t=(f=h.n<0)?c:n.call(r,h))!==a)break}catch(t){i=e,u=1,c=t}finally{l=1}}return{value:t,done:f}}}(n,o,i),!0),l}var a={};function u(){}function c(){}function l(){}t=Object.getPrototypeOf;var s=[][r]?t(t([][r]())):(w(t={},r,function(){return this}),t),f=l.prototype=u.prototype=Object.create(s);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,w(e,o,"GeneratorFunction")),e.prototype=Object.create(f),e}return c.prototype=l,w(f,"constructor",l),w(l,"constructor",c),c.displayName="GeneratorFunction",w(l,o,"GeneratorFunction"),w(f),w(f,o,"Generator"),w(f,r,function(){return this}),w(f,"toString",function(){return"[object Generator]"}),(b=function(){return{w:i,m:h}})()}function w(e,t,n,r){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}w=function(e,t,n,r){function i(t,n){w(e,t,function(e){return this._invoke(t,n,e)})}t?o?o(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(i("next",0),i("throw",1),i("return",2))},w(e,t,n,r)}function m(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}var C=function(e,r){var o=e.Controller,i=e.relativePath,a=new o,u=o.routeFunNameMap,c=o.funNameMethodMap,l=o.fileRoute,s=o.defaultHandlerType;Object.keys(u).forEach(function(e){var o=u[e],f=(c||{})[o]||["get","post"],h=t.uriPathJoin("/",i,l,e);f.forEach(function(e){r.add(h,e,function(e,t){return a[o].bind(a)(e,t)},{handlerType:s}),n.cLog.log("ser","Mount","[".concat(e.toUpperCase(),"] ").concat(h))})})},O=function(t,r){var o=t.relativePath,i=t.Controller,a=new i,u=i.routeFunNameMap,c=i.fileRoute,l=i.funNameMethodMap,s=i.defaultHandlerType;Object.keys(u).forEach(function(t){var i=u[t],f=(l||{})[i]||["get","post"],h=e.join("/",o,c,t);f.forEach(function(e){r.update(h,e,function(e,t){return a[i].bind(a)(e,t)},{handlerType:s}),n.cLog.log("ser","Update","[".concat(e.toUpperCase(),"] ").concat(h))})})},k=function(t,r){var o=t.relativePath,i=t.Controller,a=i.routeFunNameMap,u=i.funNameMethodMap;Object.keys(a).forEach(function(t){var i=a[t],c=(u||{})[i]||["get"],l=e.join("/",o,t);c.forEach(function(e){r.remove(l,e),n.cLog.log("ser","remove","[".concat(e.toUpperCase(),"] ").concat(l))})})},P=function(){var e=f(b().m(function e(t){var o,i;return b().w(function(e){for(;;)switch(e.p=e.n){case 0:return o=[],e.p=1,e.n=2,r.dirIterate(t,function(){var e=f(b().m(function e(t,n){return b().w(function(e){for(;;)switch(e.n){case 0:if(!n.isDirectory){e.n=1;break}return e.a(2);case 1:o.push(t);case 2:return e.a(2)}},e)}));return function(t,n){return e.apply(this,arguments)}}(),{recursive:!0});case 2:return e.a(2,o);case 3:return e.p=3,i=e.v,n.cLog.error("scan","error","扫描 ".concat(t," 目录失败\n")),n.cLog.debug("scan","error",i),e.a(2,o)}},e,null,[[1,3]])}));return function(t){return e.apply(this,arguments)}}(),M=function(){return v(function t(i,a){var u=this;h(this,t),this.ctx=i,this.controllerConfig=a,g(this,"compiler",void 0),g(this,"outdirAbsolute",void 0),g(this,"inputKeyMap",{}),g(this,"compilerCtxMap",new Map),g(this,"buildGroup",function(){var t=f(b().m(function t(n){var o,i,a;return b().w(function(t){for(;;)switch(t.p=t.n){case 0:return o=u.compilerCtxMap.get(n),t.p=1,t.n=2,o.rebuild();case 2:return i=t.v,t.a(2,Object.keys(i.metafile.outputs).reduce(function(t,n){return i.metafile.outputs[n].entryPoint?(t[e.join(r.getCwd(),i.metafile.outputs[n].entryPoint)]=e.join(r.getCwd(),n),t):t},{}));case 3:return t.p=3,a=t.v,console.error(a),t.a(2,{})}},t,null,[[1,3]])}));return function(e){return t.apply(this,arguments)}}()),this.outdirAbsolute=i.serverConfig.cacheDir,this.compiler=o.createCompiler(o.getNodeBuildConfigPreset({sourcemap:void 0,minify:!1,external:Object.keys(n.getDependencies(i.configCtx.getPackageConfig())),metafile:!0,splitting:!0,bundle:!0,outdir:this.outdirAbsolute,entryNames:"[dir]/[name]/[hash]"}))},[{key:"build",value:(i=f(b().m(function e(n){var r,o,i,a,u,c,l=this;return b().w(function(e){for(;;)switch(e.n){case 0:if(r=new Set,o=[],i=t.uuid(8),a={},n.forEach(function(e){var t;if(".ts"===(null===(t=l.controllerConfig.getConfig(e))||void 0===t?void 0:t.fileExt)){var n=l.inputKeyMap[e];n?r.add(n):o.push({in:e,out:l.getOutputPath(e,i)})}else a[e]=e}),!o.length){e.n=2;break}return e.n=1,this.compiler.context({entryPoints:o});case 1:u=e.v,this.compilerCtxMap.set(i,u),o.forEach(function(e){return l.inputKeyMap[e.in]=i}),r.add(i);case 2:return e.n=3,Promise.all(Array.from(r).map(function(e){return l.buildGroup(e)}));case 3:return c=e.v,e.a(2,c.reduce(function(e,t){return y(y({},e),t)},a))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"getOutputPath",value:function(t,n){var r=this.controllerConfig.getConfig(t),o=r.relativeFilePathOrigin,i=r.fileName;return e.join(n,e.dirname(o),i)}}]);var i}(),j=function(){return v(function e(){h(this,e),g(this,"map",new Map)},[{key:"update",value:function(e,t){this.map.set(e,y(y({},this.map.get(e)),t))}},{key:"updateMulti",value:function(e){var t=this;e.forEach(function(e){return t.update(e.absoluteFilePathOrigin,e)})}},{key:"updateAbsoluteFilePath",value:function(e){for(var t in e)Object.hasOwn(e,t)&&this.update(t,{absoluteFilePath:e[t]})}},{key:"getConfig",value:function(e){return this.map.get(e)}},{key:"getConfigList",value:function(e){var t=this;return e.map(function(e){return t.getConfig(e)})}}])}(),x=function(){var t=f(b().m(function t(n){var r,o,a,u;return b().w(function(t){for(;;)switch(t.n){case 0:r=n.absoluteFilePath,a=e.extname(r),u=a,t.n=".js"===u||".mjs"===u?1:".json"===u?3:5;break;case 1:return t.n=2,i.loadJs(r);case 2:case 4:return o=t.v,t.a(3,6);case 3:return t.n=4,i.loadJson(r);case 5:return t.a(3,6);case 6:return n.orange=o.default||o,t.a(2,n)}},t)}));return function(e){return t.apply(this,arguments)}}(),E=function(){return v(function e(t){h(this,e),this.scanAbsolute=t},[{key:"getBaseConfigMult",value:function(e){var t=this;return e.map(function(e){return t.getBaseConfig(e)})}},{key:"getBaseConfig",value:function(t){return n=t,r=this.scanAbsolute,o=e.relative(r,n),i=o.split("/"),a=i.pop()||"",u=i.join("/"),(c=a.match(/^(.*?)(\..*)$/))?{relativePath:u,fileName:c[1],fileExt:c[2],relativeFilePathOrigin:o,absoluteFilePathOrigin:n}:{relativeFilePathOrigin:o,absoluteFilePathOrigin:n};var n,r,o,i,a,u,c}},{key:"loadMult",value:function(e){return Promise.all(e.map(function(){var e=f(b().m(function e(t){return b().w(function(e){for(;;)if(0===e.n)return e.a(2,x(t))},e)}));return function(t){return e.apply(this,arguments)}}()))}},{key:"load",value:function(e){return x(e)}},{key:"formatMult",value:function(e){var t=this;return e.map(function(e){return t.format(e)})}},{key:"format",value:function(e){return function(e){var t,n,r=e.fileExt,o=e.fileName,i=e.orange;if(!i)return e;if(null===(t=n=".json"===r?a.defineControllerFun(function(e,t){t.json(i)}):i)||void 0===t||!t.handlerServer)return e;"FUN"===n.defineType&&(n.routeFunNameMap=g({},o||"",a.DefaultHandlerName));return n.defineType="CLASS",n.fileRoute=n.fileRoute||"/",y(y({},e),{},{Controller:n})}(e)}}])}(),D=function(){function e(t){h(this,e),g(this,"watcher",void 0),g(this,"watcherOptions",{ignoreInitial:!0,persistent:!0}),g(this,"changeCb",u.noop),t&&(this.watcherOptions=y(y({},this.watcherOptions),t)),this.watcher=this.createWatcher([])}return v(e,[{key:"onChange",value:function(e){this.changeCb=e}},{key:"add",value:function(e){var t;null===(t=this.watcher)||void 0===t||t.add(e)}},{key:"unwatch",value:function(e){var t;null===(t=this.watcher)||void 0===t||t.unwatch(e)}},{key:"close",value:function(){this.watcher&&this.watcher.close()}},{key:"createWatcher",value:function(e){var t=this,n=c.watch(e,this.watcherOptions).on("change",function(e){return t.changeCb(e,{type:"update"})}).on("add",function(e){return t.changeCb(e,{type:"create"})}).on("unlink",function(e){return t.changeCb(e,{type:"delete"})});return n}}],[{key:"of",value:function(t){return e.watcher||(e.watcher=new e(t)),e.watcher}}])}();g(D,"watcher",void 0);var F=function(){return v(function e(){h(this,e),g(this,"fileWatcher",void 0),g(this,"onCreate",u.noop),g(this,"onUpdate",u.noop),g(this,"onDelete",u.noop),this.fileWatcher=new D},[{key:"handleChange",value:function(){var e=this;this.fileWatcher.onChange(function(){var t=f(b().m(function t(n,r){var o,i;return b().w(function(t){for(;;)switch(t.n){case 0:o=r.type,i=o,t.n="create"===i?1:"delete"===i?2:"update"===i?3:4;break;case 1:return e.onCreate(n),t.a(3,5);case 2:return e.onDelete(n),t.a(3,5);case 3:return e.onUpdate(n),t.a(3,5);case 4:return t.a(3,5);case 5:return t.a(2)}},t)}));return function(e,n){return t.apply(this,arguments)}}())}},{key:"listion",value:function(e){this.fileWatcher.add(e),this.handleChange()}}])}(),N=function(){return v(function t(n){h(this,t),g(this,"scanAbsolute",void 0),g(this,"controllerBuilder",void 0),g(this,"controllerConfig",void 0),g(this,"controllerDeal",void 0),g(this,"routeManager",void 0),g(this,"controllerWatcher",void 0);var r=n.envParams.workRootDir;this.scanAbsolute=e.join(r,n.serverConfig.scan),this.controllerConfig=new j,this.controllerBuilder=new M(n,this.controllerConfig),this.controllerDeal=new E(this.scanAbsolute),this.controllerWatcher=new F,this.routeManager=n.routeManager},[{key:"scan",value:(n=f(b().m(function e(){var t,n=this;return b().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,P(this.scanAbsolute);case 1:return t=e.v,this.controllerConfig.updateMulti(this.controllerDeal.getBaseConfigMult(t)),e.n=2,this.buildResolve(t);case 2:e.v.forEach(function(e){var t=n.controllerConfig.getConfig(e);t.Controller&&C(t,n.routeManager)});case 3:return e.a(2)}},e,this)})),function(){return n.apply(this,arguments)})},{key:"listen",value:function(){var e=this;this.controllerWatcher.onCreate=function(){var t=f(b().m(function t(n){return b().w(function(t){for(;;)switch(t.n){case 0:return e.controllerConfig.updateMulti(e.controllerDeal.getBaseConfigMult([n])),t.n=1,e.buildResolve([n]);case 1:t.v.forEach(function(t){var n=e.controllerConfig.getConfig(t);n.Controller&&C(n,e.routeManager)});case 2:return t.a(2)}},t)}));return function(e){return t.apply(this,arguments)}}(),this.controllerWatcher.onUpdate=function(){var t=f(b().m(function t(n){return b().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,e.buildResolve([n]);case 1:t.v.forEach(function(t){var n=e.controllerConfig.getConfig(t);n.Controller&&O(n,e.routeManager)});case 2:return t.a(2)}},t)}));return function(e){return t.apply(this,arguments)}}(),this.controllerWatcher.onDelete=function(){var t=f(b().m(function t(n){var r;return b().w(function(t){for(;;)switch(t.n){case 0:if(r=e.controllerConfig.getConfig(n)){t.n=1;break}return t.a(2);case 1:k(r,e.routeManager);case 2:return t.a(2)}},t)}));return function(e){return t.apply(this,arguments)}}(),this.controllerWatcher.listion(this.scanAbsolute)}},{key:"buildResolve",value:(t=f(b().m(function e(t){var n,r,o;return b().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.controllerBuilder.build(t);case 1:return n=e.v,this.controllerConfig.updateAbsoluteFilePath(n),o=this.controllerDeal,e.n=2,this.controllerDeal.loadMult(this.controllerConfig.getConfigList(Object.keys(n)));case 2:return r=o.formatMult.call(o,e.v),this.controllerConfig.updateMulti(r),e.a(2,Object.keys(n))}},e,this)})),function(e){return t.apply(this,arguments)})}]);var t,n}(),S=function(){var e=f(b().m(function e(t,r,o){var i;return b().w(function(e){for(;;)switch(e.n){case 0:return(i=n.configCtxWorkflow(new n.ConfigCtx)).use(n.collectBaseConfigMw(t.workRootDir,r)),i.use(n.collectPackageJsonMw()),i.use(n.collectTsconfigJsonMw()),i.use(n.collectDoraConfigMw("development")),i.use(n.wholeDoraConfigMw(o)),e.n=1,i.getResult();case 1:return e.a(2,e.v)}},e)}));return function(t,n,r){return e.apply(this,arguments)}}();exports.ServerWorkflow=N,exports.getConfigCtx=S,exports.getServerCtx=function(e,t,r){var o,i=n.configCtxWorkflow(new l.Ctx(e,t));return i.use(l.envParamsMw(r)),i.use(l.serverPlainMw()),i.use(l.serverScanMw(null===(o=e.getCmd())||void 0===o?void 0:o.scan)),i.use(l.serverCacheMw()),i.getResult()};
|