@doracli/express-server 0.0.5 → 0.0.6
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/LICENSE +20 -20
- package/bin/enter.mjs +3 -3
- package/lib/cjs/index.js +2 -2
- package/lib/esm/index.js +2 -2
- package/lib/type/index.d.ts +29 -3
- package/package.json +14 -14
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020-2029 zhangzhiguo
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2029 zhangzhiguo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/bin/enter.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import entry from './entry-fun.mjs';
|
|
3
|
-
entry();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import entry from './entry-fun.mjs';
|
|
3
|
+
entry();
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var e=require("path"),t=require("@cclr/utils"),
|
|
1
|
+
"use strict";var e=require("path"),t=require("@cclr/utils"),r=require("@doracli/helper"),n=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){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t,r,n,o,i,a){try{var u=e[i](a),c=u.value}catch(e){return void r(e)}u.done?t(c):Promise.resolve(c).then(n,o)}function h(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var i=e.apply(t,r);function a(e){f(i,n,o,a,u,"next",e)}function u(e){f(i,n,o,a,u,"throw",e)}a(void 0)})}}function p(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function v(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,O(n.key),n)}}function g(e,t,r){return t&&v(e.prototype,t),r&&v(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(e,t,r){return(t=O(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function y(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function b(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?y(Object(r),!0).forEach(function(t){d(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):y(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function m(){
|
|
2
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()};
|
|
3
|
+
var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof u?n:u,l=Object.create(c.prototype);return w(l,"_invoke",function(r,n,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,r){return i=t,u=0,c=e,h.n=r,a}};function p(r,n){for(u=r,c=n,t=0;!f&&l&&!o&&t<s.length;t++){var o,i=s[t],p=h.p,v=i[2];r>3?(o=v===n)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=e):i[0]<=p&&((o=r<2&&p<i[1])?(u=0,h.v=n,h.n=i[1]):p<v&&(o=r<3||i[0]>n||n>v)&&(i[4]=r,i[5]=n,h.n=v,u=0))}if(o||r>1)return a;throw f=!0,n}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:r.call(n,h))!==a)break}catch(t){i=e,u=1,c=t}finally{l=1}}return{value:t,done:f}}}(r,o,i),!0),l}var a={};function u(){}function c(){}function l(){}t=Object.getPrototypeOf;var s=[][n]?t(t([][n]())):(w(t={},n,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,n,function(){return this}),w(f,"toString",function(){return"[object Generator]"}),(m=function(){return{w:i,m:h}})()}function w(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}w=function(e,t,r,n){function i(t,r){w(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},w(e,t,r,n)}function C(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}var k=function(e,n,o){var i=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],a=e.Controller,u=e.relativePath,c=e.pathRouteMap,l=new a,s=a.routeFunNameMap,f=a.funNameMethodMap,h=a.fileRoute,p=a.defaultHandlerType,v=Object.keys(c)[0]||"",g=i?function(e){var t;return(null===(t=e[Object.keys(e)[0]||""])||void 0===t?void 0:t.defs)||[""]}(c):[""],d=function(){switch(o){case"add":return function(e,t,o,i){n.add(e,t,o,i),r.cLog.log("ser","Mount","[".concat(t.toUpperCase(),"] ").concat(e))};case"update":return function(e,t,o,i){n.update(e,t,o,i),r.cLog.log("ser","Update","[".concat(t.toUpperCase(),"] ").concat(e))};case"remove":return function(e,t){n.remove(e,t),r.cLog.log("ser","remove","[".concat(t.toUpperCase(),"] ").concat(e))}}}();g.forEach(function(e){Object.keys(s).forEach(function(r){var n=s[r],i=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:["get","post"];return(e||{})[t]||r}(f,n,"remove"===o?["get"]:["get","post"]),a=function(e,r,n){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",a=i?(e||"").replace(o,i):e||"";return r?t.uriPathJoin("/",a,r,n):t.uriPathJoin("/",a,n)}(u,h,r,v,e);i.forEach(function(e){if("remove"===o)d(a,e);else{var t=function(e,t){return function(r,n){return e[t].bind(e)(r,n)}}(l,n);d(a,e,t,{handlerType:p})}})})})},P=function(e,t){k(e,t,"add",!0)},j=function(e,t){k(e,t,"remove",!1)},M=function(){var e=h(m().m(function e(t){var o,i;return m().w(function(e){for(;;)switch(e.p=e.n){case 0:return o=[],e.p=1,e.n=2,n.dirIterate(t,function(){var e=h(m().m(function e(t,r){return m().w(function(e){for(;;)switch(e.n){case 0:if(!r.isDirectory){e.n=1;break}return e.a(2);case 1:o.push(t);case 2:return e.a(2)}},e)}));return function(t,r){return e.apply(this,arguments)}}(),{recursive:!0});case 2:return e.a(2,o);case 3:return e.p=3,i=e.v,r.cLog.error("scan","error","扫描 ".concat(t," 目录失败\n")),r.cLog.debug("scan","error",i),e.a(2,o)}},e,null,[[1,3]])}));return function(t){return e.apply(this,arguments)}}(),x=function(){return g(function t(i,a){var u=this;p(this,t),this.ctx=i,this.controllerConfig=a,d(this,"compiler",void 0),d(this,"outdirAbsolute",void 0),d(this,"inputKeyMap",{}),d(this,"compilerCtxMap",new Map),d(this,"buildGroup",function(){var t=h(m().m(function t(r){var o,i,a;return m().w(function(t){for(;;)switch(t.p=t.n){case 0:return o=u.compilerCtxMap.get(r),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,r){return i.metafile.outputs[r].entryPoint?(t[e.join(n.getCwd(),i.metafile.outputs[r].entryPoint)]=e.join(n.getCwd(),r),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(r.getDependencies(i.configCtx.getPackageConfig())),metafile:!0,splitting:!0,bundle:!0,outdir:this.outdirAbsolute,entryNames:"[dir]/[name]/[hash]"}))},[{key:"build",value:(i=h(m().m(function e(r){var n,o,i,a,u,c,l=this;return m().w(function(e){for(;;)switch(e.n){case 0:if(n=new Set,o=[],i=t.uuid(8),a={},r.forEach(function(e){var t;if(".ts"===(null===(t=l.controllerConfig.getConfig(e))||void 0===t?void 0:t.fileExt)){var r=l.inputKeyMap[e];r?n.add(r):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}),n.add(i);case 2:return e.n=3,Promise.all(Array.from(n).map(function(e){return l.buildGroup(e)}));case 3:return c=e.v,e.a(2,c.reduce(function(e,t){return b(b({},e),t)},a))}},e,this)})),function(e){return i.apply(this,arguments)})},{key:"getOutputPath",value:function(t,r){var n=this.controllerConfig.getConfig(t),o=n.relativeFilePathOrigin,i=n.fileName;return e.join(r,e.dirname(o),i)}}]);var i}(),A=function(){return g(function e(){p(this,e),d(this,"map",new Map)},[{key:"update",value:function(e,t){this.map.set(e,b(b({},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)})}}])}(),D=function(){var t=h(m().m(function t(r){var n,o,a,u;return m().w(function(t){for(;;)switch(t.n){case 0:n=r.absoluteFilePath,a=e.extname(n),u=a,t.n=".js"===u||".mjs"===u?1:".json"===u?3:5;break;case 1:return t.n=2,i.loadJs(n);case 2:case 4:return o=t.v,t.a(3,6);case 3:return t.n=4,i.loadJson(n);case 5:return t.a(3,6);case 6:return r.orange=o.default||o,t.a(2,r)}},t)}));return function(e){return t.apply(this,arguments)}}(),E=function(e){return e.replace(/\\/g,"/")},S=function(){return g(function e(t,r){p(this,e),this.scanAbsolute=t,this.serverConfig=r},[{key:"getBaseConfigMult",value:function(e){var t=this;return e.map(function(e){return t.getBaseConfig(e)})}},{key:"getBaseConfig",value:function(r){var n,o,i,a,u,c,l,s=this,f=(n=r,o=this.scanAbsolute,i=e.relative(o,n),a=i.replace(/\\/g,"/").split("/"),u=a.pop()||"",c=t.uriPathJoin.apply(void 0,C(a)),(l=u.match(/^(.*?)(\..*)$/))?{relativePath:c,fileName:l[1],fileExt:l[2],relativeFilePathOrigin:i,absoluteFilePathOrigin:n}:{relativeFilePathOrigin:i,absoluteFilePathOrigin:n}),h={};if(f.relativePath){var p=E(f.relativePath);Object.keys(this.serverConfig.pathRouteMap).forEach(function(e){var t=E(e);p.startsWith(t)&&(h[f.relativePath]=s.serverConfig.pathRouteMap[e])})}return b(b({},f),{},{pathRouteMap:h})}},{key:"loadMult",value:function(e){return Promise.all(e.map(function(){var e=h(m().m(function e(t){return m().w(function(e){for(;;)if(0===e.n)return e.a(2,D(t))},e)}));return function(t){return e.apply(this,arguments)}}()))}},{key:"load",value:function(e){return D(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,r,n=e.fileExt,o=e.fileName,i=e.orange;if(!i)return e;if(null===(t=r=".json"===n?a.defineControllerFun(function(e,t){t.json(i)}):i)||void 0===t||!t.handlerServer)return e;"FUN"===r.defineType&&(r.routeFunNameMap=d({},o||"",a.DefaultHandlerName));return r.defineType="CLASS",r.fileRoute=r.fileRoute||"/",b(b({},e),{},{Controller:r})}(e)}}])}(),F=function(){function e(t){p(this,e),d(this,"watcher",void 0),d(this,"watcherOptions",{ignoreInitial:!0,persistent:!0}),d(this,"changeCb",u.noop),t&&(this.watcherOptions=b(b({},this.watcherOptions),t)),this.watcher=this.createWatcher([])}return g(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,r=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 r}}],[{key:"of",value:function(t){return e.watcher||(e.watcher=new e(t)),e.watcher}}])}();d(F,"watcher",void 0);var W=function(){return g(function e(){p(this,e),d(this,"fileWatcher",void 0),d(this,"onCreate",u.noop),d(this,"onUpdate",u.noop),d(this,"onDelete",u.noop),this.fileWatcher=new F},[{key:"handleChange",value:function(){var e=this;this.fileWatcher.onChange(function(){var t=h(m().m(function t(r,n){var o,i;return m().w(function(t){for(;;)switch(t.n){case 0:o=n.type,i=o,t.n="create"===i?1:"delete"===i?2:"update"===i?3:4;break;case 1:return e.onCreate(r),t.a(3,5);case 2:return e.onDelete(r),t.a(3,5);case 3:return e.onUpdate(r),t.a(3,5);case 4:return t.a(3,5);case 5:return t.a(2)}},t)}));return function(e,r){return t.apply(this,arguments)}}())}},{key:"listion",value:function(e){this.fileWatcher.add(e),this.handleChange()}}])}(),R=function(){return g(function t(r){p(this,t),d(this,"scanAbsolute",void 0),d(this,"controllerBuilder",void 0),d(this,"controllerConfig",void 0),d(this,"controllerDeal",void 0),d(this,"routeManager",void 0),d(this,"controllerWatcher",void 0);var n=r.envParams.workRootDir;this.scanAbsolute=e.join(n,r.serverConfig.scan),this.controllerConfig=new A,this.controllerBuilder=new x(r,this.controllerConfig),this.controllerDeal=new S(this.scanAbsolute,r.serverConfig),this.controllerWatcher=new W,this.routeManager=r.routeManager},[{key:"scan",value:(r=h(m().m(function e(){var t,r=this;return m().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,M(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=r.controllerConfig.getConfig(e);t.Controller&&P(t,r.routeManager)});case 3:return e.a(2)}},e,this)})),function(){return r.apply(this,arguments)})},{key:"listen",value:function(){var e=this;this.controllerWatcher.onCreate=function(){var t=h(m().m(function t(r){return m().w(function(t){for(;;)switch(t.n){case 0:return e.controllerConfig.updateMulti(e.controllerDeal.getBaseConfigMult([r])),t.n=1,e.buildResolve([r]);case 1:t.v.forEach(function(t){var r=e.controllerConfig.getConfig(t);r.Controller&&P(r,e.routeManager)});case 2:return t.a(2)}},t)}));return function(e){return t.apply(this,arguments)}}(),this.controllerWatcher.onUpdate=function(){var t=h(m().m(function t(r){return m().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,e.buildResolve([r]);case 1:t.v.forEach(function(t){var r,n,o=e.controllerConfig.getConfig(t);o.Controller&&(r=o,n=e.routeManager,k(r,n,"update",!0))});case 2:return t.a(2)}},t)}));return function(e){return t.apply(this,arguments)}}(),this.controllerWatcher.onDelete=function(){var t=h(m().m(function t(r){var n;return m().w(function(t){for(;;)switch(t.n){case 0:if(n=e.controllerConfig.getConfig(r)){t.n=1;break}return t.a(2);case 1:j(n,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=h(m().m(function e(t){var r,n,o;return m().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.controllerBuilder.build(t);case 1:return r=e.v,this.controllerConfig.updateAbsoluteFilePath(r),o=this.controllerDeal,e.n=2,this.controllerDeal.loadMult(this.controllerConfig.getConfigList(Object.keys(r)));case 2:return n=o.formatMult.call(o,e.v),this.controllerConfig.updateMulti(n),e.a(2,Object.keys(r))}},e,this)})),function(e){return t.apply(this,arguments)})}]);var t,r}(),T=function(){var e=h(m().m(function e(t,n,o){var i;return m().w(function(e){for(;;)switch(e.n){case 0:return(i=r.configCtxWorkflow(new r.ConfigCtx)).use(r.collectBaseConfigMw(t.workRootDir,n)),i.use(r.collectPackageJsonMw()),i.use(r.collectTsconfigJsonMw()),i.use(r.collectDoraConfigMw("development")),i.use(r.wholeDoraConfigMw(o)),e.n=1,i.getResult();case 1:return e.a(2,e.v)}},e)}));return function(t,r,n){return e.apply(this,arguments)}}();exports.ServerWorkflow=R,exports.getConfigCtx=T,exports.getServerCtx=function(e,t,n){var o,i=r.configCtxWorkflow(new l.Ctx(e,t));return i.use(l.envParamsMw(n)),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()};
|
package/lib/esm/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{join as t,dirname as e,relative as r,extname as n}from"path";import{uriPathJoin as o,uuid as i}from"@cclr/utils";import{cLog as a,getDependencies as u,configCtxWorkflow as c,ConfigCtx as l,collectBaseConfigMw as s,collectPackageJsonMw as f,collectTsconfigJsonMw as h,collectDoraConfigMw as p,wholeDoraConfigMw as v}from"@doracli/helper";import{dirIterate as d,getCwd as g}from"@dorabag/file-pro";import{createCompiler as y,getNodeBuildConfigPreset as m}from"@doracli/esbuild";import{loadJson as b,loadJs as w}from"@dorabag/config-loader";import{defineControllerFun as C,DefaultHandlerName as O}from"@doracli/define-server";import{noop as k}from"@cclr/lang";import P from"chokidar";import{Ctx as j,envParamsMw as M,serverPlainMw as
|
|
1
|
+
import{join as t,dirname as e,relative as r,extname as n}from"path";import{uriPathJoin as o,uuid as i}from"@cclr/utils";import{cLog as a,getDependencies as u,configCtxWorkflow as c,ConfigCtx as l,collectBaseConfigMw as s,collectPackageJsonMw as f,collectTsconfigJsonMw as h,collectDoraConfigMw as p,wholeDoraConfigMw as v}from"@doracli/helper";import{dirIterate as d,getCwd as g}from"@dorabag/file-pro";import{createCompiler as y,getNodeBuildConfigPreset as m}from"@doracli/esbuild";import{loadJson as b,loadJs as w}from"@dorabag/config-loader";import{defineControllerFun as C,DefaultHandlerName as O}from"@doracli/define-server";import{noop as k}from"@cclr/lang";import P from"chokidar";import{Ctx as j,envParamsMw as M,serverPlainMw as A,serverScanMw as E,serverCacheMw as S}from"@doracli/express";function D(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function F(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function x(t){return function(){var e=this,r=arguments;return new Promise(function(n,o){var i=t.apply(e,r);function a(t){F(i,n,o,a,u,"next",t)}function u(t){F(i,n,o,a,u,"throw",t)}a(void 0)})}}function R(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function T(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,K(n.key),n)}}function W(t,e,r){return e&&T(t.prototype,e),r&&T(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function N(t,e,r){return(e=K(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function U(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function B(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?U(Object(r),!0).forEach(function(e){N(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):U(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function G(){
|
|
2
2
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
-
var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof u?n:u,l=Object.create(c.prototype);return U(l,"_invoke",function(r,n,o){var i,u,c,l=0,s=o||[],f=!1,h={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,r){return i=e,u=0,c=t,h.n=r,a}};function p(r,n){for(u=r,c=n,e=0;!f&&l&&!o&&e<s.length;e++){var o,i=s[e],p=h.p,v=i[2];r>3?(o=v===n)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=t):i[0]<=p&&((o=r<2&&p<i[1])?(u=0,h.v=n,h.n=i[1]):p<v&&(o=r<3||i[0]>n||n>v)&&(i[4]=r,i[5]=n,h.n=v,u=0))}if(o||r>1)return a;throw f=!0,n}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;(e=u<2?t: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"),e=i[o]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,u<2&&(u=0)}else 1===u&&(e=i.return)&&e.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=t}else if((e=(f=h.n<0)?c:r.call(n,h))!==a)break}catch(e){i=t,u=1,c=e}finally{l=1}}return{value:e,done:f}}}(r,o,i),!0),l}var a={};function u(){}function c(){}function l(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(U(e={},n,function(){return this}),e),f=l.prototype=u.prototype=Object.create(s);function h(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,U(t,o,"GeneratorFunction")),t.prototype=Object.create(f),t}return c.prototype=l,U(f,"constructor",l),U(l,"constructor",c),c.displayName="GeneratorFunction",U(l,o,"GeneratorFunction"),U(f),U(f,o,"Generator"),U(f,n,function(){return this}),U(f,"toString",function(){return"[object Generator]"}),(G=function(){return{w:i,m:h}})()}function U(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}U=function(t,e,r,n){function i(e,r){U(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},U(t,e,r,n)}function _(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var K=function(t,e){var r=t.Controller,n=t.relativePath,i=new r,u=r.routeFunNameMap,c=r.funNameMethodMap,l=r.fileRoute,s=r.defaultHandlerType;Object.keys(u).forEach(function(t){var r=u[t],f=(c||{})[r]||["get","post"],h=o("/",n,l,t);f.forEach(function(t){e.add(h,t,function(t,e){return i[r].bind(i)(t,e)},{handlerType:s}),a.log("ser","Mount","[".concat(t.toUpperCase(),"] ").concat(h))})})},L=function(e,r){var n=e.relativePath,o=e.Controller,i=o.routeFunNameMap,u=o.funNameMethodMap;Object.keys(i).forEach(function(e){var o=i[e],c=(u||{})[o]||["get"],l=t("/",n,e);c.forEach(function(t){r.remove(l,t),a.log("ser","remove","[".concat(t.toUpperCase(),"] ").concat(l))})})},H=function(){var t=A(G().m(function t(e){var r,n;return G().w(function(t){for(;;)switch(t.p=t.n){case 0:return r=[],t.p=1,t.n=2,d(e,function(){var t=A(G().m(function t(e,n){return G().w(function(t){for(;;)switch(t.n){case 0:if(!n.isDirectory){t.n=1;break}return t.a(2);case 1:r.push(e);case 2:return t.a(2)}},t)}));return function(e,r){return t.apply(this,arguments)}}(),{recursive:!0});case 2:return t.a(2,r);case 3:return t.p=3,n=t.v,a.error("scan","error","扫描 ".concat(e," 目录失败\n")),a.debug("scan","error",n),t.a(2,r)}},t,null,[[1,3]])}));return function(e){return t.apply(this,arguments)}}(),I=function(){return S(function e(r,n){var o=this;N(this,e),this.ctx=r,this.controllerConfig=n,R(this,"compiler",void 0),R(this,"outdirAbsolute",void 0),R(this,"inputKeyMap",{}),R(this,"compilerCtxMap",new Map),R(this,"buildGroup",function(){var e=A(G().m(function e(r){var n,i,a;return G().w(function(e){for(;;)switch(e.p=e.n){case 0:return n=o.compilerCtxMap.get(r),e.p=1,e.n=2,n.rebuild();case 2:return i=e.v,e.a(2,Object.keys(i.metafile.outputs).reduce(function(e,r){return i.metafile.outputs[r].entryPoint?(e[t(g(),i.metafile.outputs[r].entryPoint)]=t(g(),r),e):e},{}));case 3:return e.p=3,a=e.v,console.error(a),e.a(2,{})}},e,null,[[1,3]])}));return function(t){return e.apply(this,arguments)}}()),this.outdirAbsolute=r.serverConfig.cacheDir,this.compiler=y(m({sourcemap:void 0,minify:!1,external:Object.keys(u(r.configCtx.getPackageConfig())),metafile:!0,splitting:!0,bundle:!0,outdir:this.outdirAbsolute,entryNames:"[dir]/[name]/[hash]"}))},[{key:"build",value:(r=A(G().m(function t(e){var r,n,o,a,u,c,l=this;return G().w(function(t){for(;;)switch(t.n){case 0:if(r=new Set,n=[],o=i(8),a={},e.forEach(function(t){var e;if(".ts"===(null===(e=l.controllerConfig.getConfig(t))||void 0===e?void 0:e.fileExt)){var i=l.inputKeyMap[t];i?r.add(i):n.push({in:t,out:l.getOutputPath(t,o)})}else a[t]=t}),!n.length){t.n=2;break}return t.n=1,this.compiler.context({entryPoints:n});case 1:u=t.v,this.compilerCtxMap.set(o,u),n.forEach(function(t){return l.inputKeyMap[t.in]=o}),r.add(o);case 2:return t.n=3,Promise.all(Array.from(r).map(function(t){return l.buildGroup(t)}));case 3:return c=t.v,t.a(2,c.reduce(function(t,e){return B(B({},t),e)},a))}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"getOutputPath",value:function(r,n){var o=this.controllerConfig.getConfig(r),i=o.relativeFilePathOrigin,a=o.fileName;return t(n,e(i),a)}}]);var r}(),$=function(){return S(function t(){N(this,t),R(this,"map",new Map)},[{key:"update",value:function(t,e){this.map.set(t,B(B({},this.map.get(t)),e))}},{key:"updateMulti",value:function(t){var e=this;t.forEach(function(t){return e.update(t.absoluteFilePathOrigin,t)})}},{key:"updateAbsoluteFilePath",value:function(t){for(var e in t)Object.hasOwn(t,e)&&this.update(e,{absoluteFilePath:t[e]})}},{key:"getConfig",value:function(t){return this.map.get(t)}},{key:"getConfigList",value:function(t){var e=this;return t.map(function(t){return e.getConfig(t)})}}])}(),q=function(){var t=A(G().m(function t(e){var r,o,i,a;return G().w(function(t){for(;;)switch(t.n){case 0:r=e.absoluteFilePath,i=n(r),a=i,t.n=".js"===a||".mjs"===a?1:".json"===a?3:5;break;case 1:return t.n=2,w(r);case 2:case 4:return o=t.v,t.a(3,6);case 3:return t.n=4,b(r);case 5:return t.a(3,6);case 6:return e.orange=o.default||o,t.a(2,e)}},t)}));return function(e){return t.apply(this,arguments)}}(),z=function(){return S(function t(e){N(this,t),this.scanAbsolute=e},[{key:"getBaseConfigMult",value:function(t){var e=this;return t.map(function(t){return e.getBaseConfig(t)})}},{key:"getBaseConfig",value:function(t){return e=t,n=this.scanAbsolute,o=r(n,e),i=o.split("/"),a=i.pop()||"",u=i.join("/"),(c=a.match(/^(.*?)(\..*)$/))?{relativePath:u,fileName:c[1],fileExt:c[2],relativeFilePathOrigin:o,absoluteFilePathOrigin:e}:{relativeFilePathOrigin:o,absoluteFilePathOrigin:e};var e,n,o,i,a,u,c}},{key:"loadMult",value:function(t){return Promise.all(t.map(function(){var t=A(G().m(function t(e){return G().w(function(t){for(;;)if(0===t.n)return t.a(2,q(e))},t)}));return function(e){return t.apply(this,arguments)}}()))}},{key:"load",value:function(t){return q(t)}},{key:"formatMult",value:function(t){var e=this;return t.map(function(t){return e.format(t)})}},{key:"format",value:function(t){return function(t){var e,r,n=t.fileExt,o=t.fileName,i=t.orange;if(!i)return t;if(null===(e=r=".json"===n?C(function(t,e){e.json(i)}):i)||void 0===e||!e.handlerServer)return t;"FUN"===r.defineType&&(r.routeFunNameMap=R({},o||"",O));return r.defineType="CLASS",r.fileRoute=r.fileRoute||"/",B(B({},t),{},{Controller:r})}(t)}}])}(),J=function(){function t(e){N(this,t),R(this,"watcher",void 0),R(this,"watcherOptions",{ignoreInitial:!0,persistent:!0}),R(this,"changeCb",k),e&&(this.watcherOptions=B(B({},this.watcherOptions),e)),this.watcher=this.createWatcher([])}return S(t,[{key:"onChange",value:function(t){this.changeCb=t}},{key:"add",value:function(t){var e;null===(e=this.watcher)||void 0===e||e.add(t)}},{key:"unwatch",value:function(t){var e;null===(e=this.watcher)||void 0===e||e.unwatch(t)}},{key:"close",value:function(){this.watcher&&this.watcher.close()}},{key:"createWatcher",value:function(t){var e=this;return P.watch(t,this.watcherOptions).on("change",function(t){return e.changeCb(t,{type:"update"})}).on("add",function(t){return e.changeCb(t,{type:"create"})}).on("unlink",function(t){return e.changeCb(t,{type:"delete"})})}}],[{key:"of",value:function(e){return t.watcher||(t.watcher=new t(e)),t.watcher}}])}();R(J,"watcher",void 0);var Q=function(){return S(function t(){N(this,t),R(this,"fileWatcher",void 0),R(this,"onCreate",k),R(this,"onUpdate",k),R(this,"onDelete",k),this.fileWatcher=new J},[{key:"handleChange",value:function(){var t=this;this.fileWatcher.onChange(function(){var e=A(G().m(function e(r,n){var o,i;return G().w(function(e){for(;;)switch(e.n){case 0:o=n.type,i=o,e.n="create"===i?1:"delete"===i?2:"update"===i?3:4;break;case 1:return t.onCreate(r),e.a(3,5);case 2:return t.onDelete(r),e.a(3,5);case 3:return t.onUpdate(r),e.a(3,5);case 4:return e.a(3,5);case 5:return e.a(2)}},e)}));return function(t,r){return e.apply(this,arguments)}}())}},{key:"listion",value:function(t){this.fileWatcher.add(t),this.handleChange()}}])}(),V=function(){return S(function e(r){N(this,e),R(this,"scanAbsolute",void 0),R(this,"controllerBuilder",void 0),R(this,"controllerConfig",void 0),R(this,"controllerDeal",void 0),R(this,"routeManager",void 0),R(this,"controllerWatcher",void 0);var n=r.envParams.workRootDir;this.scanAbsolute=t(n,r.serverConfig.scan),this.controllerConfig=new $,this.controllerBuilder=new I(r,this.controllerConfig),this.controllerDeal=new z(this.scanAbsolute),this.controllerWatcher=new Q,this.routeManager=r.routeManager},[{key:"scan",value:(r=A(G().m(function t(){var e,r=this;return G().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,H(this.scanAbsolute);case 1:return e=t.v,this.controllerConfig.updateMulti(this.controllerDeal.getBaseConfigMult(e)),t.n=2,this.buildResolve(e);case 2:t.v.forEach(function(t){var e=r.controllerConfig.getConfig(t);e.Controller&&K(e,r.routeManager)});case 3:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"listen",value:function(){var e=this;this.controllerWatcher.onCreate=function(){var t=A(G().m(function t(r){return G().w(function(t){for(;;)switch(t.n){case 0:return e.controllerConfig.updateMulti(e.controllerDeal.getBaseConfigMult([r])),t.n=1,e.buildResolve([r]);case 1:t.v.forEach(function(t){var r=e.controllerConfig.getConfig(t);r.Controller&&K(r,e.routeManager)});case 2:return t.a(2)}},t)}));return function(e){return t.apply(this,arguments)}}(),this.controllerWatcher.onUpdate=function(){var r=A(G().m(function r(n){return G().w(function(r){for(;;)switch(r.n){case 0:return r.n=1,e.buildResolve([n]);case 1:r.v.forEach(function(r){var n,o,i,u,c,l,s,f,h,p=e.controllerConfig.getConfig(r);p.Controller&&(n=p,o=e.routeManager,i=n.relativePath,u=n.Controller,c=new u,l=u.routeFunNameMap,s=u.fileRoute,f=u.funNameMethodMap,h=u.defaultHandlerType,Object.keys(l).forEach(function(e){var r=l[e],n=(f||{})[r]||["get","post"],u=t("/",i,s,e);n.forEach(function(t){o.update(u,t,function(t,e){return c[r].bind(c)(t,e)},{handlerType:h}),a.log("ser","Update","[".concat(t.toUpperCase(),"] ").concat(u))})}))});case 2:return r.a(2)}},r)}));return function(t){return r.apply(this,arguments)}}(),this.controllerWatcher.onDelete=function(){var t=A(G().m(function t(r){var n;return G().w(function(t){for(;;)switch(t.n){case 0:if(n=e.controllerConfig.getConfig(r)){t.n=1;break}return t.a(2);case 1:L(n,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:(e=A(G().m(function t(e){var r,n,o;return G().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.controllerBuilder.build(e);case 1:return r=t.v,this.controllerConfig.updateAbsoluteFilePath(r),o=this.controllerDeal,t.n=2,this.controllerDeal.loadMult(this.controllerConfig.getConfigList(Object.keys(r)));case 2:return n=o.formatMult.call(o,t.v),this.controllerConfig.updateMulti(n),t.a(2,Object.keys(r))}},t,this)})),function(t){return e.apply(this,arguments)})}]);var e,r}(),X=function(){var t=A(G().m(function t(e,r,n){var o;return G().w(function(t){for(;;)switch(t.n){case 0:return(o=c(new l)).use(s(e.workRootDir,r)),o.use(f()),o.use(h()),o.use(p("development")),o.use(v(n)),t.n=1,o.getResult();case 1:return t.a(2,t.v)}},t)}));return function(e,r,n){return t.apply(this,arguments)}}(),Y=function(t,e,r){var n,o=c(new j(t,e));return o.use(M(r)),o.use(E()),o.use(F(null===(n=t.getCmd())||void 0===n?void 0:n.scan)),o.use(D()),o.getResult()};export{V as ServerWorkflow,X as getConfigCtx,Y as getServerCtx};
|
|
3
|
+
var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var c=n&&n.prototype instanceof u?n:u,l=Object.create(c.prototype);return _(l,"_invoke",function(r,n,o){var i,u,c,l=0,s=o||[],f=!1,h={p:0,n:0,v:t,a:p,f:p.bind(t,4),d:function(e,r){return i=e,u=0,c=t,h.n=r,a}};function p(r,n){for(u=r,c=n,e=0;!f&&l&&!o&&e<s.length;e++){var o,i=s[e],p=h.p,v=i[2];r>3?(o=v===n)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=t):i[0]<=p&&((o=r<2&&p<i[1])?(u=0,h.v=n,h.n=i[1]):p<v&&(o=r<3||i[0]>n||n>v)&&(i[4]=r,i[5]=n,h.n=v,u=0))}if(o||r>1)return a;throw f=!0,n}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;(e=u<2?t: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"),e=i[o]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,u<2&&(u=0)}else 1===u&&(e=i.return)&&e.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=t}else if((e=(f=h.n<0)?c:r.call(n,h))!==a)break}catch(e){i=t,u=1,c=e}finally{l=1}}return{value:e,done:f}}}(r,o,i),!0),l}var a={};function u(){}function c(){}function l(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(_(e={},n,function(){return this}),e),f=l.prototype=u.prototype=Object.create(s);function h(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,_(t,o,"GeneratorFunction")),t.prototype=Object.create(f),t}return c.prototype=l,_(f,"constructor",l),_(l,"constructor",c),c.displayName="GeneratorFunction",_(l,o,"GeneratorFunction"),_(f),_(f,o,"Generator"),_(f,n,function(){return this}),_(f,"toString",function(){return"[object Generator]"}),(G=function(){return{w:i,m:h}})()}function _(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}_=function(t,e,r,n){function i(e,r){_(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},_(t,e,r,n)}function I(t){return function(t){if(Array.isArray(t))return D(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return D(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?D(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function K(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var L=function(t,e,r){var n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=t.Controller,u=t.relativePath,c=t.pathRouteMap,l=new i,s=i.routeFunNameMap,f=i.funNameMethodMap,h=i.fileRoute,p=i.defaultHandlerType,v=Object.keys(c)[0]||"",d=n?function(t){var e;return(null===(e=t[Object.keys(t)[0]||""])||void 0===e?void 0:e.defs)||[""]}(c):[""],g=function(){switch(r){case"add":return function(t,r,n,o){e.add(t,r,n,o),a.log("ser","Mount","[".concat(r.toUpperCase(),"] ").concat(t))};case"update":return function(t,r,n,o){e.update(t,r,n,o),a.log("ser","Update","[".concat(r.toUpperCase(),"] ").concat(t))};case"remove":return function(t,r){e.remove(t,r),a.log("ser","remove","[".concat(r.toUpperCase(),"] ").concat(t))}}}();d.forEach(function(t){Object.keys(s).forEach(function(e){var n=s[e],i=function(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:["get","post"];return(t||{})[e]||r}(f,n,"remove"===r?["get"]:["get","post"]),a=function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"",a=i?(t||"").replace(n,i):t||"";return e?o("/",a,e,r):o("/",a,r)}(u,h,e,v,t);i.forEach(function(t){if("remove"===r)g(a,t);else{var e=function(t,e){return function(r,n){return t[e].bind(t)(r,n)}}(l,n);g(a,t,e,{handlerType:p})}})})})},$=function(t,e){L(t,e,"add",!0)},H=function(t,e){L(t,e,"remove",!1)},q=function(){var t=x(G().m(function t(e){var r,n;return G().w(function(t){for(;;)switch(t.p=t.n){case 0:return r=[],t.p=1,t.n=2,d(e,function(){var t=x(G().m(function t(e,n){return G().w(function(t){for(;;)switch(t.n){case 0:if(!n.isDirectory){t.n=1;break}return t.a(2);case 1:r.push(e);case 2:return t.a(2)}},t)}));return function(e,r){return t.apply(this,arguments)}}(),{recursive:!0});case 2:return t.a(2,r);case 3:return t.p=3,n=t.v,a.error("scan","error","扫描 ".concat(e," 目录失败\n")),a.debug("scan","error",n),t.a(2,r)}},t,null,[[1,3]])}));return function(e){return t.apply(this,arguments)}}(),z=function(){return W(function e(r,n){var o=this;R(this,e),this.ctx=r,this.controllerConfig=n,N(this,"compiler",void 0),N(this,"outdirAbsolute",void 0),N(this,"inputKeyMap",{}),N(this,"compilerCtxMap",new Map),N(this,"buildGroup",function(){var e=x(G().m(function e(r){var n,i,a;return G().w(function(e){for(;;)switch(e.p=e.n){case 0:return n=o.compilerCtxMap.get(r),e.p=1,e.n=2,n.rebuild();case 2:return i=e.v,e.a(2,Object.keys(i.metafile.outputs).reduce(function(e,r){return i.metafile.outputs[r].entryPoint?(e[t(g(),i.metafile.outputs[r].entryPoint)]=t(g(),r),e):e},{}));case 3:return e.p=3,a=e.v,console.error(a),e.a(2,{})}},e,null,[[1,3]])}));return function(t){return e.apply(this,arguments)}}()),this.outdirAbsolute=r.serverConfig.cacheDir,this.compiler=y(m({sourcemap:void 0,minify:!1,external:Object.keys(u(r.configCtx.getPackageConfig())),metafile:!0,splitting:!0,bundle:!0,outdir:this.outdirAbsolute,entryNames:"[dir]/[name]/[hash]"}))},[{key:"build",value:(r=x(G().m(function t(e){var r,n,o,a,u,c,l=this;return G().w(function(t){for(;;)switch(t.n){case 0:if(r=new Set,n=[],o=i(8),a={},e.forEach(function(t){var e;if(".ts"===(null===(e=l.controllerConfig.getConfig(t))||void 0===e?void 0:e.fileExt)){var i=l.inputKeyMap[t];i?r.add(i):n.push({in:t,out:l.getOutputPath(t,o)})}else a[t]=t}),!n.length){t.n=2;break}return t.n=1,this.compiler.context({entryPoints:n});case 1:u=t.v,this.compilerCtxMap.set(o,u),n.forEach(function(t){return l.inputKeyMap[t.in]=o}),r.add(o);case 2:return t.n=3,Promise.all(Array.from(r).map(function(t){return l.buildGroup(t)}));case 3:return c=t.v,t.a(2,c.reduce(function(t,e){return B(B({},t),e)},a))}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"getOutputPath",value:function(r,n){var o=this.controllerConfig.getConfig(r),i=o.relativeFilePathOrigin,a=o.fileName;return t(n,e(i),a)}}]);var r}(),J=function(){return W(function t(){R(this,t),N(this,"map",new Map)},[{key:"update",value:function(t,e){this.map.set(t,B(B({},this.map.get(t)),e))}},{key:"updateMulti",value:function(t){var e=this;t.forEach(function(t){return e.update(t.absoluteFilePathOrigin,t)})}},{key:"updateAbsoluteFilePath",value:function(t){for(var e in t)Object.hasOwn(t,e)&&this.update(e,{absoluteFilePath:t[e]})}},{key:"getConfig",value:function(t){return this.map.get(t)}},{key:"getConfigList",value:function(t){var e=this;return t.map(function(t){return e.getConfig(t)})}}])}(),Q=function(){var t=x(G().m(function t(e){var r,o,i,a;return G().w(function(t){for(;;)switch(t.n){case 0:r=e.absoluteFilePath,i=n(r),a=i,t.n=".js"===a||".mjs"===a?1:".json"===a?3:5;break;case 1:return t.n=2,w(r);case 2:case 4:return o=t.v,t.a(3,6);case 3:return t.n=4,b(r);case 5:return t.a(3,6);case 6:return e.orange=o.default||o,t.a(2,e)}},t)}));return function(e){return t.apply(this,arguments)}}(),V=function(t){return t.replace(/\\/g,"/")},X=function(){return W(function t(e,r){R(this,t),this.scanAbsolute=e,this.serverConfig=r},[{key:"getBaseConfigMult",value:function(t){var e=this;return t.map(function(t){return e.getBaseConfig(t)})}},{key:"getBaseConfig",value:function(t){var e,n,i,a,u,c,l,s=this,f=(e=t,n=this.scanAbsolute,i=r(n,e),a=i.replace(/\\/g,"/").split("/"),u=a.pop()||"",c=o.apply(void 0,I(a)),(l=u.match(/^(.*?)(\..*)$/))?{relativePath:c,fileName:l[1],fileExt:l[2],relativeFilePathOrigin:i,absoluteFilePathOrigin:e}:{relativeFilePathOrigin:i,absoluteFilePathOrigin:e}),h={};if(f.relativePath){var p=V(f.relativePath);Object.keys(this.serverConfig.pathRouteMap).forEach(function(t){var e=V(t);p.startsWith(e)&&(h[f.relativePath]=s.serverConfig.pathRouteMap[t])})}return B(B({},f),{},{pathRouteMap:h})}},{key:"loadMult",value:function(t){return Promise.all(t.map(function(){var t=x(G().m(function t(e){return G().w(function(t){for(;;)if(0===t.n)return t.a(2,Q(e))},t)}));return function(e){return t.apply(this,arguments)}}()))}},{key:"load",value:function(t){return Q(t)}},{key:"formatMult",value:function(t){var e=this;return t.map(function(t){return e.format(t)})}},{key:"format",value:function(t){return function(t){var e,r,n=t.fileExt,o=t.fileName,i=t.orange;if(!i)return t;if(null===(e=r=".json"===n?C(function(t,e){e.json(i)}):i)||void 0===e||!e.handlerServer)return t;"FUN"===r.defineType&&(r.routeFunNameMap=N({},o||"",O));return r.defineType="CLASS",r.fileRoute=r.fileRoute||"/",B(B({},t),{},{Controller:r})}(t)}}])}(),Y=function(){function t(e){R(this,t),N(this,"watcher",void 0),N(this,"watcherOptions",{ignoreInitial:!0,persistent:!0}),N(this,"changeCb",k),e&&(this.watcherOptions=B(B({},this.watcherOptions),e)),this.watcher=this.createWatcher([])}return W(t,[{key:"onChange",value:function(t){this.changeCb=t}},{key:"add",value:function(t){var e;null===(e=this.watcher)||void 0===e||e.add(t)}},{key:"unwatch",value:function(t){var e;null===(e=this.watcher)||void 0===e||e.unwatch(t)}},{key:"close",value:function(){this.watcher&&this.watcher.close()}},{key:"createWatcher",value:function(t){var e=this;return P.watch(t,this.watcherOptions).on("change",function(t){return e.changeCb(t,{type:"update"})}).on("add",function(t){return e.changeCb(t,{type:"create"})}).on("unlink",function(t){return e.changeCb(t,{type:"delete"})})}}],[{key:"of",value:function(e){return t.watcher||(t.watcher=new t(e)),t.watcher}}])}();N(Y,"watcher",void 0);var Z=function(){return W(function t(){R(this,t),N(this,"fileWatcher",void 0),N(this,"onCreate",k),N(this,"onUpdate",k),N(this,"onDelete",k),this.fileWatcher=new Y},[{key:"handleChange",value:function(){var t=this;this.fileWatcher.onChange(function(){var e=x(G().m(function e(r,n){var o,i;return G().w(function(e){for(;;)switch(e.n){case 0:o=n.type,i=o,e.n="create"===i?1:"delete"===i?2:"update"===i?3:4;break;case 1:return t.onCreate(r),e.a(3,5);case 2:return t.onDelete(r),e.a(3,5);case 3:return t.onUpdate(r),e.a(3,5);case 4:return e.a(3,5);case 5:return e.a(2)}},e)}));return function(t,r){return e.apply(this,arguments)}}())}},{key:"listion",value:function(t){this.fileWatcher.add(t),this.handleChange()}}])}(),tt=function(){return W(function e(r){R(this,e),N(this,"scanAbsolute",void 0),N(this,"controllerBuilder",void 0),N(this,"controllerConfig",void 0),N(this,"controllerDeal",void 0),N(this,"routeManager",void 0),N(this,"controllerWatcher",void 0);var n=r.envParams.workRootDir;this.scanAbsolute=t(n,r.serverConfig.scan),this.controllerConfig=new J,this.controllerBuilder=new z(r,this.controllerConfig),this.controllerDeal=new X(this.scanAbsolute,r.serverConfig),this.controllerWatcher=new Z,this.routeManager=r.routeManager},[{key:"scan",value:(r=x(G().m(function t(){var e,r=this;return G().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,q(this.scanAbsolute);case 1:return e=t.v,this.controllerConfig.updateMulti(this.controllerDeal.getBaseConfigMult(e)),t.n=2,this.buildResolve(e);case 2:t.v.forEach(function(t){var e=r.controllerConfig.getConfig(t);e.Controller&&$(e,r.routeManager)});case 3:return t.a(2)}},t,this)})),function(){return r.apply(this,arguments)})},{key:"listen",value:function(){var t=this;this.controllerWatcher.onCreate=function(){var e=x(G().m(function e(r){return G().w(function(e){for(;;)switch(e.n){case 0:return t.controllerConfig.updateMulti(t.controllerDeal.getBaseConfigMult([r])),e.n=1,t.buildResolve([r]);case 1:e.v.forEach(function(e){var r=t.controllerConfig.getConfig(e);r.Controller&&$(r,t.routeManager)});case 2:return e.a(2)}},e)}));return function(t){return e.apply(this,arguments)}}(),this.controllerWatcher.onUpdate=function(){var e=x(G().m(function e(r){return G().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,t.buildResolve([r]);case 1:e.v.forEach(function(e){var r,n,o=t.controllerConfig.getConfig(e);o.Controller&&(r=o,n=t.routeManager,L(r,n,"update",!0))});case 2:return e.a(2)}},e)}));return function(t){return e.apply(this,arguments)}}(),this.controllerWatcher.onDelete=function(){var e=x(G().m(function e(r){var n;return G().w(function(e){for(;;)switch(e.n){case 0:if(n=t.controllerConfig.getConfig(r)){e.n=1;break}return e.a(2);case 1:H(n,t.routeManager);case 2:return e.a(2)}},e)}));return function(t){return e.apply(this,arguments)}}(),this.controllerWatcher.listion(this.scanAbsolute)}},{key:"buildResolve",value:(e=x(G().m(function t(e){var r,n,o;return G().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.controllerBuilder.build(e);case 1:return r=t.v,this.controllerConfig.updateAbsoluteFilePath(r),o=this.controllerDeal,t.n=2,this.controllerDeal.loadMult(this.controllerConfig.getConfigList(Object.keys(r)));case 2:return n=o.formatMult.call(o,t.v),this.controllerConfig.updateMulti(n),t.a(2,Object.keys(r))}},t,this)})),function(t){return e.apply(this,arguments)})}]);var e,r}(),et=function(){var t=x(G().m(function t(e,r,n){var o;return G().w(function(t){for(;;)switch(t.n){case 0:return(o=c(new l)).use(s(e.workRootDir,r)),o.use(f()),o.use(h()),o.use(p("development")),o.use(v(n)),t.n=1,o.getResult();case 1:return t.a(2,t.v)}},t)}));return function(e,r,n){return t.apply(this,arguments)}}(),rt=function(t,e,r){var n,o=c(new j(t,e));return o.use(M(r)),o.use(A()),o.use(E(null===(n=t.getCmd())||void 0===n?void 0:n.scan)),o.use(S()),o.getResult()};export{tt as ServerWorkflow,et as getConfigCtx,rt as getServerCtx};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Ctx, RouteManager, TEnvParams } from '@doracli/express';
|
|
1
|
+
import { Ctx, TServerConfig, RouteManager, TEnvParams } from '@doracli/express';
|
|
2
2
|
import { Compiler } from '@doracli/esbuild';
|
|
3
3
|
import { TPlainObject, TAny, PartialRecursive } from '@cclr/lang';
|
|
4
4
|
import { TController } from '@doracli/define-server';
|
|
5
|
+
import { TDoraConfigService, TDoraConfig } from '@doracli/type';
|
|
5
6
|
import { ConfigCtx } from '@doracli/helper';
|
|
6
|
-
import { TDoraConfig } from '@doracli/type';
|
|
7
7
|
import { Application } from 'express';
|
|
8
8
|
|
|
9
9
|
type TControllerConfig = {
|
|
@@ -13,6 +13,11 @@ type TControllerConfig = {
|
|
|
13
13
|
relativeFilePathOrigin: string;
|
|
14
14
|
/** 处理后文件绝对路径 */
|
|
15
15
|
absoluteFilePath: string;
|
|
16
|
+
/**
|
|
17
|
+
* pathRouteMap
|
|
18
|
+
* 路径前段 => 文件对应的路由,同一个文件可以对应多个路由
|
|
19
|
+
*/
|
|
20
|
+
pathRouteMap: TDoraConfigService['pathRouteMap'];
|
|
16
21
|
/** 路由前缀 */
|
|
17
22
|
route: string;
|
|
18
23
|
/** 文件相对路径 - 路径部分 */
|
|
@@ -67,15 +72,26 @@ declare class ControllerBuilder {
|
|
|
67
72
|
*/
|
|
68
73
|
declare class ControllerDeal {
|
|
69
74
|
private scanAbsolute;
|
|
70
|
-
|
|
75
|
+
private serverConfig;
|
|
76
|
+
constructor(scanAbsolute: string, serverConfig: TServerConfig);
|
|
71
77
|
/** 收集路径中的参数 多个 */
|
|
72
78
|
getBaseConfigMult(absolutePathList: string[]): ({
|
|
79
|
+
pathRouteMap: {
|
|
80
|
+
[dirPath: string]: {
|
|
81
|
+
defs: string[];
|
|
82
|
+
};
|
|
83
|
+
};
|
|
73
84
|
relativeFilePathOrigin: string;
|
|
74
85
|
absoluteFilePathOrigin: string;
|
|
75
86
|
relativePath?: undefined;
|
|
76
87
|
fileName?: undefined;
|
|
77
88
|
fileExt?: undefined;
|
|
78
89
|
} | {
|
|
90
|
+
pathRouteMap: {
|
|
91
|
+
[dirPath: string]: {
|
|
92
|
+
defs: string[];
|
|
93
|
+
};
|
|
94
|
+
};
|
|
79
95
|
relativePath: string;
|
|
80
96
|
fileName: string;
|
|
81
97
|
fileExt: string;
|
|
@@ -84,12 +100,22 @@ declare class ControllerDeal {
|
|
|
84
100
|
})[];
|
|
85
101
|
/** 收集路径中的参数 */
|
|
86
102
|
getBaseConfig(absolutePath: string): {
|
|
103
|
+
pathRouteMap: {
|
|
104
|
+
[dirPath: string]: {
|
|
105
|
+
defs: string[];
|
|
106
|
+
};
|
|
107
|
+
};
|
|
87
108
|
relativeFilePathOrigin: string;
|
|
88
109
|
absoluteFilePathOrigin: string;
|
|
89
110
|
relativePath?: undefined;
|
|
90
111
|
fileName?: undefined;
|
|
91
112
|
fileExt?: undefined;
|
|
92
113
|
} | {
|
|
114
|
+
pathRouteMap: {
|
|
115
|
+
[dirPath: string]: {
|
|
116
|
+
defs: string[];
|
|
117
|
+
};
|
|
118
|
+
};
|
|
93
119
|
relativePath: string;
|
|
94
120
|
fileName: string;
|
|
95
121
|
fileExt: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doracli/express-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "use server",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -32,21 +32,21 @@
|
|
|
32
32
|
"g:build": "drr build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@cclr/lang": "^0.1.
|
|
36
|
-
"@cclr/utils": "^0.1.
|
|
37
|
-
"@dorabag/config-loader": "^1.0.
|
|
38
|
-
"@dorabag/file-pro": "^1.0.
|
|
39
|
-
"@dorabag/open-browser": "^1.0.
|
|
40
|
-
"@dorabag/srv-tool": "^1.0.
|
|
41
|
-
"@doracli/commander": "0.0.
|
|
42
|
-
"@doracli/define-server": "0.0.
|
|
43
|
-
"@doracli/esbuild": "0.0.
|
|
44
|
-
"@doracli/express": "0.0.
|
|
45
|
-
"@doracli/helper": "0.0.
|
|
46
|
-
"@doracli/type": "0.0.
|
|
35
|
+
"@cclr/lang": "^0.1.50",
|
|
36
|
+
"@cclr/utils": "^0.1.50",
|
|
37
|
+
"@dorabag/config-loader": "^1.0.17",
|
|
38
|
+
"@dorabag/file-pro": "^1.0.18",
|
|
39
|
+
"@dorabag/open-browser": "^1.0.18",
|
|
40
|
+
"@dorabag/srv-tool": "^1.0.17",
|
|
41
|
+
"@doracli/commander": "0.0.6",
|
|
42
|
+
"@doracli/define-server": "0.0.6",
|
|
43
|
+
"@doracli/esbuild": "0.0.6",
|
|
44
|
+
"@doracli/express": "0.0.6",
|
|
45
|
+
"@doracli/helper": "0.0.6",
|
|
46
|
+
"@doracli/type": "0.0.6",
|
|
47
47
|
"@types/express": "^5.0.6",
|
|
48
48
|
"chokidar": "^4.0.3",
|
|
49
49
|
"express": "^5.2.1"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "b387668fa2986c56f245bc53bcb7072fd53b62e1"
|
|
52
52
|
}
|