@webqit/webflo 0.8.77 → 0.9.1
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/package.json +5 -12
- package/src/Cli.js +131 -0
- package/src/Configurator.js +97 -0
- package/src/Context.js +76 -0
- package/src/config-pi/deployment/Env.js +69 -0
- package/src/config-pi/deployment/Layout.js +65 -0
- package/src/config-pi/deployment/Origins.js +133 -0
- package/src/config-pi/deployment/Virtualization.js +65 -0
- package/src/config-pi/deployment/index.js +18 -0
- package/src/config-pi/index.js +16 -0
- package/src/config-pi/runtime/Client.js +59 -0
- package/src/config-pi/runtime/Server.js +174 -0
- package/src/config-pi/runtime/client/Worker.js +117 -0
- package/src/config-pi/runtime/client/index.js +12 -0
- package/src/config-pi/runtime/index.js +18 -0
- package/src/config-pi/runtime/server/Headers.js +90 -0
- package/src/config-pi/runtime/server/Redirects.js +108 -0
- package/src/config-pi/runtime/server/index.js +14 -0
- package/src/config-pi/static/Manifest.js +321 -0
- package/src/config-pi/static/Ssg.js +72 -0
- package/src/config-pi/static/index.js +14 -0
- package/src/deployment-pi/index.js +10 -0
- package/src/{services → deployment-pi}/origins/index.js +88 -58
- package/src/index.js +14 -147
- package/src/{runtime → runtime-pi}/Router.js +19 -19
- package/src/runtime-pi/client/Context.js +7 -0
- package/src/{runtime → runtime-pi}/client/Router.js +2 -2
- package/src/{runtime/client/Navigator.js → runtime-pi/client/Runtime.js} +148 -103
- package/src/runtime-pi/client/RuntimeClient.js +114 -0
- package/src/{runtime → runtime-pi}/client/Storage.js +1 -1
- package/src/{runtime → runtime-pi}/client/Url.js +2 -6
- package/src/{runtime/client/WorkerClient.js → runtime-pi/client/WorkerComm.js} +2 -2
- package/src/runtime-pi/client/generate.js +242 -0
- package/src/runtime-pi/client/generate.oohtml.js +7 -0
- package/src/runtime-pi/client/index.js +18 -0
- package/src/runtime-pi/client/whatwag.js +27 -0
- package/src/runtime-pi/client/worker/Context.js +7 -0
- package/src/runtime-pi/client/worker/Worker.js +243 -0
- package/src/runtime-pi/client/worker/WorkerClient.js +46 -0
- package/src/runtime-pi/client/worker/index.js +18 -0
- package/src/runtime-pi/index.js +14 -0
- package/src/runtime-pi/server/Context.js +16 -0
- package/src/{runtime → runtime-pi}/server/Router.js +6 -6
- package/src/runtime-pi/server/Runtime.js +531 -0
- package/src/runtime-pi/server/RuntimeClient.js +103 -0
- package/src/runtime-pi/server/index.js +41 -0
- package/src/runtime-pi/server/whatwag.js +35 -0
- package/src/{runtime → runtime-pi}/util.js +0 -0
- package/src/{runtime/_FormData.js → runtime-pi/xFormData.js} +2 -2
- package/src/{runtime/_Headers.js → runtime-pi/xHeaders.js} +4 -4
- package/src/runtime-pi/xHttpEvent.js +93 -0
- package/src/runtime-pi/xHttpMessage.js +179 -0
- package/src/runtime-pi/xRequest.js +67 -0
- package/src/runtime-pi/xRequestHeaders.js +95 -0
- package/src/runtime-pi/xResponse.js +62 -0
- package/src/{runtime/_ResponseHeaders.js → runtime-pi/xResponseHeaders.js} +38 -18
- package/src/{runtime/_URL.js → runtime-pi/xURL.js} +4 -4
- package/src/runtime-pi/xfetch.js +7 -0
- package/src/{services → services-pi}/certbot/http-auth-hook.js +0 -0
- package/src/{services → services-pi}/certbot/http-cleanup-hook.js +0 -0
- package/src/{services → services-pi}/certbot/index.js +21 -15
- package/src/services-pi/index.js +9 -0
- package/src/static-pi/index.js +11 -0
- package/src/webflo.js +33 -0
- package/test/index.test.js +26 -0
- package/src/build/client/index.js +0 -261
- package/src/build/index.js +0 -5
- package/src/config/client.js +0 -191
- package/src/config/headers.js +0 -121
- package/src/config/index.js +0 -14
- package/src/config/layout.js +0 -83
- package/src/config/manifest.js +0 -341
- package/src/config/origins.js +0 -165
- package/src/config/prerendering.js +0 -100
- package/src/config/redirects.js +0 -137
- package/src/config/server.js +0 -201
- package/src/config/variables.js +0 -102
- package/src/config/vhosts.js +0 -93
- package/src/runtime/_MessageStream.js +0 -195
- package/src/runtime/_NavigationEvent.js +0 -91
- package/src/runtime/_Request.js +0 -59
- package/src/runtime/_RequestHeaders.js +0 -72
- package/src/runtime/_Response.js +0 -56
- package/src/runtime/client/NavigationEvent.js +0 -21
- package/src/runtime/client/Runtime.js +0 -126
- package/src/runtime/client/Worker.js +0 -317
- package/src/runtime/client/archive/Cache.js +0 -38
- package/src/runtime/client/archive/Http.js +0 -225
- package/src/runtime/client/archive/StdRequest.js +0 -74
- package/src/runtime/client/archive/WorkerComm.js +0 -183
- package/src/runtime/client/effects/sounds.js +0 -64
- package/src/runtime/index.js +0 -5
- package/src/runtime/server/NavigationEvent.js +0 -39
- package/src/runtime/server/Runtime.js +0 -593
- package/src/runtime/server/index.js +0 -183
- package/src/runtime/server/index.mjs +0 -10
- package/src/services/index.js +0 -6
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import { Observer } from './Runtime.js';
|
|
6
|
+
import WorkerComm from './WorkerComm.js';
|
|
7
|
+
import Router from './Router.js';
|
|
8
|
+
|
|
9
|
+
export default class RuntimeClient {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* RuntimeClient
|
|
13
|
+
*
|
|
14
|
+
* @param Context cx
|
|
15
|
+
*/
|
|
16
|
+
constructor(cx) {
|
|
17
|
+
this.cx = cx;
|
|
18
|
+
const workerComm = new WorkerComm('/worker.js', { startMessages: true });
|
|
19
|
+
Observer.observe(workerComm, changes => {
|
|
20
|
+
//console.log('SERVICE_WORKER_STATE_CHANGE', changes[0].name, changes[0].value);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Handles HTTP events.
|
|
26
|
+
*
|
|
27
|
+
* @param HttpEvent httpEvent
|
|
28
|
+
* @param Function remoteFetch
|
|
29
|
+
*
|
|
30
|
+
* @return Response
|
|
31
|
+
*/
|
|
32
|
+
async handle(httpEvent, remoteFetch) {
|
|
33
|
+
// The app router
|
|
34
|
+
const router = new Router(this.cx, httpEvent.url.pathname);
|
|
35
|
+
const handle = async () => {
|
|
36
|
+
// --------
|
|
37
|
+
// ROUTE FOR DATA
|
|
38
|
+
// --------
|
|
39
|
+
let httpMethodName = httpEvent.request.method.toLowerCase();
|
|
40
|
+
let response = await router.route([httpMethodName === 'delete' ? 'del' : httpMethodName, 'default'], httpEvent, {}, async event => {
|
|
41
|
+
return remoteFetch(event.request);
|
|
42
|
+
}, remoteFetch);
|
|
43
|
+
if (!(response instanceof httpEvent.Response)) {
|
|
44
|
+
response = new httpEvent.Response(response);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// --------
|
|
48
|
+
// Rendering
|
|
49
|
+
// --------
|
|
50
|
+
if (response.ok && response.headers.contentType === 'application/json') {
|
|
51
|
+
await this.render(httpEvent, response, router);
|
|
52
|
+
await this.scrollIntoView(httpEvent);
|
|
53
|
+
} else if (!response.ok) {
|
|
54
|
+
await this.unrender();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return response;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// --------
|
|
61
|
+
// PIPE THROUGH MIDDLEWARES
|
|
62
|
+
// --------
|
|
63
|
+
return (this.cx.middlewares || []).concat(handle).reverse().reduce((next, fn) => {
|
|
64
|
+
return () => fn.call(this.cx, httpEvent, router, next);
|
|
65
|
+
}, null)();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Renderer
|
|
69
|
+
async render(httpEvent, response, router) {
|
|
70
|
+
let data = await response.json();
|
|
71
|
+
return router.route('render', httpEvent, data, async (httpEvent, data) => {
|
|
72
|
+
// --------
|
|
73
|
+
// OOHTML would waiting for DOM-ready in order to be initialized
|
|
74
|
+
await new Promise(res => window.WebQit.DOM.ready(res));
|
|
75
|
+
if (!window.document.state.env) {
|
|
76
|
+
window.document.setState({
|
|
77
|
+
env: 'client',
|
|
78
|
+
onHydration: (httpEvent.detail || {}).srcType === 'init',
|
|
79
|
+
network: this.cx.runtime.network,
|
|
80
|
+
url: this.cx.runtime.location,
|
|
81
|
+
}, { update: true });
|
|
82
|
+
}
|
|
83
|
+
window.document.setState({ page: data }, { update: 'merge' });
|
|
84
|
+
window.document.body.setAttribute('template', 'page/' + httpEvent.url.pathname.split('/').filter(a => a).map(a => a + '+-').join('/'));
|
|
85
|
+
await new Promise(res => (window.document.templatesReadyState === 'complete' && res(), window.document.addEventListener('templatesreadystatechange', res)));
|
|
86
|
+
return window;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Unrender
|
|
91
|
+
async unrender() {
|
|
92
|
+
window.document.setState({ page: {} }, { update: 'merge' });
|
|
93
|
+
window.document.body.setAttribute('template', '');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Normalize scroll position
|
|
97
|
+
async scrollIntoView(httpEvent) {
|
|
98
|
+
if (!(httpEvent.detail.src instanceof Element)) return;
|
|
99
|
+
await new Promise(res => setTimeout(res, 10));
|
|
100
|
+
let viewportTop, urlTarget;
|
|
101
|
+
if (httpEvent.url.hash && (urlTarget = document.querySelector(httpEvent.url.hash))) {
|
|
102
|
+
urlTarget.scrollIntoView();
|
|
103
|
+
} else if (viewportTop = Array.from(document.querySelectorAll('[data-viewport-top]')).pop()) {
|
|
104
|
+
viewportTop.focus();
|
|
105
|
+
} else {
|
|
106
|
+
document.documentElement.classList.add('scroll-reset');
|
|
107
|
+
document.body.scrollIntoView();
|
|
108
|
+
await new Promise(res => setTimeout(res, 600));
|
|
109
|
+
document.documentElement.classList.remove('scroll-reset');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { _isString, _isUndefined } from '@webqit/util/js/index.js';
|
|
7
7
|
import { Observer } from './Runtime.js';
|
|
8
8
|
|
|
9
|
-
export default function(
|
|
9
|
+
export default function(namespace = null, persistent = false) {
|
|
10
10
|
|
|
11
11
|
const storeType = persistent ? 'localStorage' : 'sessionStorage';
|
|
12
12
|
if (!window[storeType]) {
|
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* @imports
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
6
|
-
import _isObject from '@webqit/util/js/
|
|
7
|
-
import _isTypeObject from '@webqit/util/js/isTypeObject.js';
|
|
8
|
-
import _isString from '@webqit/util/js/isString.js';
|
|
9
|
-
import _isEmpty from '@webqit/util/js/isEmpty.js';
|
|
10
|
-
import _with from '@webqit/util/obj/with.js';
|
|
5
|
+
import { _with } from '@webqit/util/obj/index.js';
|
|
6
|
+
import { _isArray, _isObject, _isTypeObject, _isString, _isEmpty } from '@webqit/util/js/index.js';
|
|
11
7
|
import { wwwFormUnserialize, wwwFormSerialize } from '../util.js';
|
|
12
8
|
import { Observer } from './Runtime.js';
|
|
13
9
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { _isFunction } from '@webqit/util/js/index.js';
|
|
7
7
|
import { Observer } from './Runtime.js';
|
|
8
8
|
|
|
9
|
-
export default class
|
|
9
|
+
export default class WorkerComm {
|
|
10
10
|
|
|
11
11
|
constructor(file, params = {}) {
|
|
12
12
|
this.ready = navigator.serviceWorker.ready;
|
|
@@ -73,7 +73,7 @@ export default class WorkerClient {
|
|
|
73
73
|
}
|
|
74
74
|
return this.post;
|
|
75
75
|
},
|
|
76
|
-
receive:
|
|
76
|
+
receive: callback => {
|
|
77
77
|
navigator.serviceWorker.addEventListener('message', callback);
|
|
78
78
|
return this.post;
|
|
79
79
|
},
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* imports
|
|
4
|
+
*/
|
|
5
|
+
import Fs from 'fs';
|
|
6
|
+
import Url from 'url';
|
|
7
|
+
import Path from 'path';
|
|
8
|
+
import Webpack from 'webpack';
|
|
9
|
+
import { _beforeLast } from '@webqit/util/str/index.js';
|
|
10
|
+
import { _isObject, _isArray } from '@webqit/util/js/index.js';
|
|
11
|
+
import * as DotJs from '@webqit/backpack/src/dotfiles/DotJs.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @generate
|
|
15
|
+
*/
|
|
16
|
+
export async function generate() {
|
|
17
|
+
const cx = this || {};
|
|
18
|
+
// -----------
|
|
19
|
+
if (!cx.config.runtime?.Client) {
|
|
20
|
+
throw new Error(`The Client configurator "config.runtime.Client" is required in context.`);
|
|
21
|
+
}
|
|
22
|
+
const clientConfig = await (new cx.config.runtime.Client(cx)).read();
|
|
23
|
+
if (clientConfig.support_service_worker && !cx.config.runtime.client?.Worker) {
|
|
24
|
+
throw new Error(`The Service Worker configurator "config.runtime.client.Worker" is required in context.`);
|
|
25
|
+
}
|
|
26
|
+
const workerConfig = await (new cx.config.runtime.client.Worker(cx)).read();
|
|
27
|
+
// -----------
|
|
28
|
+
if (!cx.config.deployment?.Layout) {
|
|
29
|
+
throw new Error(`The Layout configurator "config.deployment.Layout" is required in context.`);
|
|
30
|
+
}
|
|
31
|
+
const layoutConfig = await (new cx.config.deployment.Layout(cx)).read();
|
|
32
|
+
const bundleOutput = { path: Path.resolve(cx.CWD || '', layoutConfig.PUBLIC_DIR), };
|
|
33
|
+
const dirSelf = Path.dirname(Url.fileURLToPath(import.meta.url)).replace(/\\/g, '/');
|
|
34
|
+
// -----------
|
|
35
|
+
// Generate client build
|
|
36
|
+
let genClient = getGen.call(cx, dirSelf, layoutConfig.CLIENT_DIR, clientConfig, `The Client Build.`);
|
|
37
|
+
if (clientConfig.support_oohtml) {
|
|
38
|
+
genClient.imports = { [`${dirSelf}/generate.oohtml.js`]: null, ...genClient.imports };
|
|
39
|
+
}
|
|
40
|
+
await bundle.call(cx, genClient, { ...bundleOutput, filename: 'bundle.js', }, true/* asModule */);
|
|
41
|
+
cx.logger && cx.logger.log('');
|
|
42
|
+
// -----------
|
|
43
|
+
// Generate worker build
|
|
44
|
+
if (clientConfig.support_service_worker) {
|
|
45
|
+
let genWorker = getGen.call(cx, `${dirSelf}/worker`, layoutConfig.WORKER_DIR, workerConfig, `The Worker Build.`);
|
|
46
|
+
await bundle.call(cx, genWorker, { ...bundleOutput, filename: 'worker.js', });
|
|
47
|
+
cx.logger && cx.logger.log('');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Compile routes.
|
|
53
|
+
*
|
|
54
|
+
* @param string modulesDir
|
|
55
|
+
* @param string routesDir
|
|
56
|
+
* @param object paramsObj
|
|
57
|
+
* @param string desc
|
|
58
|
+
*
|
|
59
|
+
* @return Object
|
|
60
|
+
*/
|
|
61
|
+
function getGen(modulesDir, routesDir, paramsObj, desc) {
|
|
62
|
+
const cx = this || {};
|
|
63
|
+
if (cx.logger) {
|
|
64
|
+
cx.logger.log(cx.logger.style.comment(`-----------------`));
|
|
65
|
+
cx.logger.log(desc);
|
|
66
|
+
cx.logger.log(cx.logger.style.comment(`-----------------`));
|
|
67
|
+
cx.logger.log('');
|
|
68
|
+
}
|
|
69
|
+
// ------------------
|
|
70
|
+
const gen = { imports: {}, code: [], };
|
|
71
|
+
// ------------------
|
|
72
|
+
// >> Modules import
|
|
73
|
+
gen.imports[`${modulesDir}/index.js`] = `{ start }`;
|
|
74
|
+
gen.code.push(``);
|
|
75
|
+
// ------------------
|
|
76
|
+
// >> Routes mapping
|
|
77
|
+
gen.code.push(`// >> Routes`);
|
|
78
|
+
declareRoutesObj.call(cx, gen, routesDir, 'layout', '');
|
|
79
|
+
gen.code.push(``);
|
|
80
|
+
// ------------------
|
|
81
|
+
// >> Params
|
|
82
|
+
gen.code.push(`// >> Params`);
|
|
83
|
+
declareParamsObj.call(cx, gen, paramsObj, 'params');
|
|
84
|
+
gen.code.push(``);
|
|
85
|
+
// ------------------
|
|
86
|
+
// >> Startup
|
|
87
|
+
gen.code.push(`// >> Startup`);
|
|
88
|
+
gen.code.push(`start.call({ layout, params })`);
|
|
89
|
+
return gen;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Compile routes.
|
|
94
|
+
*
|
|
95
|
+
* @param object gen
|
|
96
|
+
* @param string routesDir
|
|
97
|
+
* @param string varName
|
|
98
|
+
*
|
|
99
|
+
* @return void
|
|
100
|
+
*/
|
|
101
|
+
function declareRoutesObj(gen, routesDir, varName) {
|
|
102
|
+
const cx = this || {};
|
|
103
|
+
cx.logger && cx.logger.log(`> Declaring routes...`);
|
|
104
|
+
// ----------------
|
|
105
|
+
// Directory walker
|
|
106
|
+
const walk = (dir, callback) => {
|
|
107
|
+
Fs.readdirSync(dir).forEach(f => {
|
|
108
|
+
let resource = Path.join(dir, f);
|
|
109
|
+
if (Fs.statSync(resource).isDirectory()) {
|
|
110
|
+
walk(resource, callback);
|
|
111
|
+
} else {
|
|
112
|
+
let ext = Path.extname(resource) || '';
|
|
113
|
+
callback(resource, ext);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
// ----------------
|
|
118
|
+
// >> Routes mapping
|
|
119
|
+
gen.code.push(`const ${varName} = {};`);
|
|
120
|
+
let indexCount = 0;
|
|
121
|
+
if (routesDir && Fs.existsSync(routesDir)) {
|
|
122
|
+
let clientDirname = routesDir.replace(/\\/g, '/').split('/').pop();
|
|
123
|
+
walk(routesDir, (file, ext) => {
|
|
124
|
+
//relativePath = relativePath.replace(/\\/g, '/');
|
|
125
|
+
if (file.replace(/\\/g, '/').endsWith('/index.js')) {
|
|
126
|
+
let relativePath = Path.relative(routesDir, file).replace(/\\/g, '/');
|
|
127
|
+
// Import code
|
|
128
|
+
let routeName = 'index' + (++ indexCount);
|
|
129
|
+
// IMPORTANT: we;re taking a step back here so that the parent-child relationship for
|
|
130
|
+
// the directories be involved
|
|
131
|
+
gen.imports[`../${clientDirname}/${relativePath}`] = '* as ' + routeName;
|
|
132
|
+
// Definition code
|
|
133
|
+
let routePath = _beforeLast('/' + relativePath, '/index.js');
|
|
134
|
+
gen.code.push(`${varName}['${routePath || '/'}'] = ${routeName};`);
|
|
135
|
+
// Show
|
|
136
|
+
cx.logger && cx.logger.log(`> ./${relativePath}`);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (!indexCount) {
|
|
141
|
+
cx.logger && cx.logger.log(`> (none)`);
|
|
142
|
+
}
|
|
143
|
+
cx.logger && cx.logger.log(``);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Compile params.
|
|
148
|
+
*
|
|
149
|
+
* @param object gen
|
|
150
|
+
* @param object paramsObj
|
|
151
|
+
* @param string varName
|
|
152
|
+
*
|
|
153
|
+
* @return void
|
|
154
|
+
*/
|
|
155
|
+
function declareParamsObj(gen, paramsObj, varName = null, indentation = 0) {
|
|
156
|
+
const cx = this || {};
|
|
157
|
+
// ----------------
|
|
158
|
+
// Params compilation
|
|
159
|
+
if (varName) gen.code.push(`const ${varName} = {`);
|
|
160
|
+
_isArray(paramsObj)
|
|
161
|
+
Object.keys(paramsObj).forEach(name => {
|
|
162
|
+
let _name = ` ${' '.repeat(indentation)}${(_isArray(paramsObj) ? '' : (name.includes(' ') ? `'${name}'` : name) + ': ')}`;
|
|
163
|
+
if ([ 'boolean', 'number' ].includes(typeof paramsObj[name])) {
|
|
164
|
+
gen.code.push(`${_name}${paramsObj[name]},`);
|
|
165
|
+
} else if (_isArray(paramsObj[name])) {
|
|
166
|
+
gen.code.push(`${_name}[`);
|
|
167
|
+
declareParamsObj.call(cx, gen, paramsObj[name], null, indentation + 1);
|
|
168
|
+
gen.code.push(` ${' '.repeat(indentation)}],`);
|
|
169
|
+
} else if (_isObject(paramsObj[name])) {
|
|
170
|
+
gen.code.push(`${_name}{`);
|
|
171
|
+
declareParamsObj.call(cx, gen, paramsObj[name], null, indentation + 1);
|
|
172
|
+
gen.code.push(` ${' '.repeat(indentation)}},`);
|
|
173
|
+
} else {
|
|
174
|
+
gen.code.push(`${_name}'${paramsObj[name]}',`);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
if (varName) gen.code.push(`};`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Bundle generated file
|
|
182
|
+
*
|
|
183
|
+
* @param object gen
|
|
184
|
+
* @param object output
|
|
185
|
+
* @param boolean asModule
|
|
186
|
+
*
|
|
187
|
+
* @return Promise
|
|
188
|
+
*/
|
|
189
|
+
function bundle(gen, output, asModule = false) {
|
|
190
|
+
const cx = this || {};
|
|
191
|
+
const moduleFile = Path.join(output.path, `${_beforeLast(output.filename, '.')}.esm.js`);
|
|
192
|
+
// ------------------
|
|
193
|
+
// >> Show waiting...
|
|
194
|
+
if (cx.logger) {
|
|
195
|
+
let waiting = cx.logger.waiting(cx.logger.f`Writing the ES module file: ${moduleFile}`);
|
|
196
|
+
waiting.start();
|
|
197
|
+
DotJs.write(gen, moduleFile, 'ES Module file');
|
|
198
|
+
waiting.stop();
|
|
199
|
+
cx.logger.info(cx.logger.f`The module file: ${moduleFile}`);
|
|
200
|
+
} else {
|
|
201
|
+
DotJs.write(gen, moduleFile, 'ES Module file');
|
|
202
|
+
}
|
|
203
|
+
// ----------------
|
|
204
|
+
// >> Webpack config
|
|
205
|
+
const bundlingConfig = { entry: moduleFile, output };
|
|
206
|
+
if (asModule) {
|
|
207
|
+
bundlingConfig.experiments = { outputModule: true, };
|
|
208
|
+
bundlingConfig.output.environment = bundlingConfig.output.environment || {};
|
|
209
|
+
if (!('module' in bundlingConfig.output)) {
|
|
210
|
+
bundlingConfig.output.module = true;
|
|
211
|
+
bundlingConfig.output.environment.module = true;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// ----------------
|
|
215
|
+
// The bundling process
|
|
216
|
+
return new Promise(resolve => {
|
|
217
|
+
let waiting;
|
|
218
|
+
if (cx.logger) {
|
|
219
|
+
waiting = cx.logger.waiting(`Bundling...`);
|
|
220
|
+
cx.logger.log('');
|
|
221
|
+
cx.logger.log('> Bundling...');
|
|
222
|
+
cx.logger.info(cx.logger.f`FROM: ${bundlingConfig.entry}`);
|
|
223
|
+
cx.logger.info(cx.logger.f`TO: ${bundlingConfig.output.path + '/' + bundlingConfig.output.filename}`);
|
|
224
|
+
cx.logger.log('');
|
|
225
|
+
waiting.start();
|
|
226
|
+
}
|
|
227
|
+
// Run
|
|
228
|
+
let compiler = Webpack(bundlingConfig);
|
|
229
|
+
compiler.run((err, stats) => {
|
|
230
|
+
waiting.stop();
|
|
231
|
+
if (err) {
|
|
232
|
+
cx.logger.title(`Errors!`);
|
|
233
|
+
cx.logger.error(err);
|
|
234
|
+
}
|
|
235
|
+
let log = stats.toString({ colors: true, });
|
|
236
|
+
cx.logger && cx.logger.log(log);
|
|
237
|
+
// Remove moduleFile build
|
|
238
|
+
//Fs.unlinkSync(bundlingConfig.entry);
|
|
239
|
+
resolve(log);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @imports
|
|
4
|
+
*/
|
|
5
|
+
import Context from './Context.js';
|
|
6
|
+
import RuntimeClient from './RuntimeClient.js';
|
|
7
|
+
import Runtime from './Runtime.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @start
|
|
11
|
+
*/
|
|
12
|
+
export async function start(clientCallback = null) {
|
|
13
|
+
const cx = this || {};
|
|
14
|
+
const defaultClientCallback = _cx => new RuntimeClient(_cx);
|
|
15
|
+
return new Runtime(Context.create(cx), ( ...args ) => {
|
|
16
|
+
return clientCallback ? clientCallback( ...args.concat( defaultClientCallback ) ) : defaultClientCallback( ...args );
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
const {
|
|
3
|
+
URL,
|
|
4
|
+
fetch,
|
|
5
|
+
Headers,
|
|
6
|
+
Request,
|
|
7
|
+
Response,
|
|
8
|
+
FormData,
|
|
9
|
+
ReadableStream,
|
|
10
|
+
File,
|
|
11
|
+
Blob
|
|
12
|
+
} = globalThis;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @exports
|
|
16
|
+
*/
|
|
17
|
+
export {
|
|
18
|
+
URL,
|
|
19
|
+
fetch,
|
|
20
|
+
Headers,
|
|
21
|
+
Request,
|
|
22
|
+
Response,
|
|
23
|
+
FormData,
|
|
24
|
+
ReadableStream,
|
|
25
|
+
File,
|
|
26
|
+
Blob,
|
|
27
|
+
}
|