@makano/rew 1.2.85 → 1.2.87
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/rew/modules/context.js +10 -0
- package/lib/rew/pkgs/serve.js +17 -0
- package/package.json +1 -1
|
@@ -149,6 +149,16 @@ module.exports.prepareContext = function (
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
if(!context.app){
|
|
153
|
+
context.appPackage = (packageName) => context.app = { config: { manifest: { package: packageName } } }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
Object.defineProperty(context, 'packageName', {
|
|
157
|
+
get: () => context.app?.config?.manifest?.package,
|
|
158
|
+
enumerable: true,
|
|
159
|
+
configurable: true
|
|
160
|
+
});
|
|
161
|
+
|
|
152
162
|
if (
|
|
153
163
|
context.module.main ||
|
|
154
164
|
(options.fromMain == true && options.as == "main")
|
package/lib/rew/pkgs/serve.js
CHANGED
|
@@ -6,6 +6,7 @@ const { run } = require('../main');
|
|
|
6
6
|
const { runPath } = require('../modules/runtime');
|
|
7
7
|
const { cleanCache } = require('../functions/import');
|
|
8
8
|
const { REW_FILE_TYPE } = require('../const/ext');
|
|
9
|
+
const { Usage } = require('../const/usage');
|
|
9
10
|
|
|
10
11
|
const lookUpFiles = ['route', 'page', 'page.s'];
|
|
11
12
|
|
|
@@ -85,6 +86,17 @@ module.exports = (context) => {
|
|
|
85
86
|
return this;
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
onFetch(fn, override = false){
|
|
90
|
+
if(this.options.fetch && !override){
|
|
91
|
+
const originalFn = fn;
|
|
92
|
+
fn = (...args) => {
|
|
93
|
+
return originalFn(...args, this.options.fetch(...args));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this.options.fetch = fn;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
|
|
88
100
|
port(port){
|
|
89
101
|
this.listen = port;
|
|
90
102
|
return this;
|
|
@@ -301,6 +313,11 @@ module.exports = (context) => {
|
|
|
301
313
|
return new Server(options);
|
|
302
314
|
}
|
|
303
315
|
|
|
316
|
+
service = Usage.prototype.create('svr.service', (cb) => {
|
|
317
|
+
const server = Svr.prototype.create();
|
|
318
|
+
cb(server);
|
|
319
|
+
});
|
|
320
|
+
|
|
304
321
|
router({ id = '/', type = 'normal', ...options }){
|
|
305
322
|
let router;
|
|
306
323
|
if(type == 'default') router = SvrRouter.new(IttyRouter, {...options}, { id });
|