jsgui3-server 0.0.83 → 0.0.86

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.
@@ -23,13 +23,23 @@ if (require.main === module) {
23
23
 
24
24
  // then start the server....
25
25
  // be able to choose the port / ports?
26
+ console.log('waiting for server ready event');
27
+ server.on('ready', () => {
28
+ console.log('server ready');
26
29
 
27
- server.start(8080, function (err, cb_start) {
28
- if (err) {
29
- throw err;
30
- } else {
31
- console.log('server started');
32
- }
33
- });
30
+ // server start will change to observable?
31
+
32
+ server.start(8080, function (err, cb_start) {
33
+ if (err) {
34
+ throw err;
35
+ } else {
36
+ // Should have build it by now...
37
+
38
+ console.log('server started');
39
+ }
40
+ });
41
+ })
42
+
43
+
34
44
 
35
45
  }
@@ -1,7 +1,9 @@
1
- const jsgui = require('jsgui3-html'); // and will replace this with jsgui-client, I presume.
1
+ const jsgui = require('jsgui3-client'); // and will replace this with jsgui-client, I presume.
2
2
  const {controls, Control, mixins} = jsgui;
3
3
  const {dragable} = mixins;
4
4
 
5
+ // Relies on extracting CSS from JS files.
6
+
5
7
  class Demo_UI extends Control {
6
8
  constructor(spec) {
7
9
  spec.__type_name = spec.__type_name || 'demo_ui';
package/package.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "@babel/core": "^7.17.9",
7
- "@babel/parser": "7.17.9",
8
7
  "@babel/generator": "^7.17.9",
8
+ "@babel/parser": "7.17.9",
9
9
  "babel-plugin-transform-runtime": "^6.23.0",
10
10
  "babel-preset-minify": "^0.5.1",
11
11
  "browserify": "17.0.0",
@@ -13,9 +13,8 @@
13
13
  "cookies": "^0.8.0",
14
14
  "fnl": "^0.0.21",
15
15
  "fnlfs": "^0.0.24",
16
- "jsgui3-client": "^0.0.67",
17
- "jsgui3-html": "0.0.95",
18
-
16
+ "jsgui3-client": "^0.0.69",
17
+ "jsgui3-html": "0.0.96",
19
18
  "multiparty": "^4.2.3",
20
19
  "ncp": "^2.0.0",
21
20
  "obext": "0.0.23",
@@ -41,5 +40,5 @@
41
40
  "type": "git",
42
41
  "url": "https://github.com/metabench/jsgui3-server.git"
43
42
  },
44
- "version": "0.0.83"
43
+ "version": "0.0.86"
45
44
  }
@@ -5,12 +5,13 @@
5
5
  // This is going to take over some of the responsibilities of the old website resource, which was unfocused code that was
6
6
  // doing some of the main / most important parts of serving the website.
7
7
 
8
- const {each, Router} = require('jsgui3-html');
8
+ const {each, Router, tof} = require('jsgui3-html');
9
9
  const HTTP_Publisher = require('./http-publisher');
10
10
  const {obs} = require('fnl');
11
11
 
12
12
 
13
13
  const Webpage_Bundler = require('./../bundler/webpage-bundler');
14
+ const Bundle = require('./../bundler/bundle');
14
15
 
15
16
 
16
17
  // Now it's the very basics of a website publisher. Quite flexible but could do with more.
@@ -73,125 +74,276 @@ class HTTP_Website_Publisher extends HTTP_Publisher {
73
74
  console.log('http-website-publisher disk_path_client_js', disk_path_client_js);
74
75
  //throw 'stop';
75
76
 
77
+ // This could be an observable that acts sequentially and async.
78
+
76
79
  const setup_website_publishing = (website) => {
77
- // put pages into a router here...
78
- // however, may need to be on the lookout for other content that needs to be bundled with each page in the site.
79
80
 
80
- // Now let's try bundling an active JS client.
81
- // May need to compile / render JSGUI Controls to HTML / full HTML pages.
81
+ //console.log('website', website);
82
+ //console.log('website.pages', website.pages);
83
+ //console.log('website.pages.length()', website.pages.length());
84
+ //throw 'stop';
82
85
 
83
- // And unspecified pages such as admin pages?
86
+ // should the website have a 'main' or 'front' or 'first' page, with it having its HTML rendered?
84
87
 
85
- each(website.pages, (page => {
86
- //console.log('page', page);
87
- //console.log('page.name', page.name);
88
- //console.log('page.url', page.url);
89
- //console.log('page.path', page.path);
90
- // Need a common client js file for all of them I think.
91
-
92
- const opts_bundling = {};
93
- if (disk_path_client_js) opts_bundling.disk_path_client_js = disk_path_client_js;
94
-
95
- const obs_bundling = Webpage_Bundler.bundle_web_page(page, opts_bundling);
96
- //console.log('doing bundling');
97
- //console.log('obs_bundling', obs_bundling);
98
-
99
- obs_bundling.on('complete', res => {
100
- //console.log('obs_bundling res', res);
101
- const bundle = res;
102
- console.log('bundle._arr.length', bundle._arr.length);
103
- console.log('Object.keys(bundle)', Object.keys(bundle));
104
-
105
- if (bundle._arr.length === 1) {
106
- // And check it's HTML inside...?
107
-
108
- const bundled_item = bundle._arr[0];
109
- console.log('bundled_item', bundled_item);
110
-
111
- if (bundled_item['content-type']) {
112
- const ct = bundled_item['content-type'];
113
- if (ct === 'text/html') {
114
- const http_serve_html = (req, res) => {
115
- res.writeHead(200, {
116
- 'Content-Type': 'text/html'
117
- });
118
- res.end(bundled_item.value, 'utf-8');
119
- }
120
- router.set_route(bundled_item.path, (req, res) => {
121
- http_serve_html(req, res);
122
- });
123
- } else {
124
- throw 'NYI';
125
- }
126
88
 
127
- } else {
128
- throw 'NYI';
129
- }
89
+ return obs((next, complete, error) => {
130
90
 
131
- // need to create / use the handler for it here.
132
- // will have various http handler functions to reference and use.
133
- // will have details of http handling in other files.
91
+ (async () => {
134
92
 
135
- // Maybe use an HTML publisher for this? (if it's HTML).
136
- // Or publisher by mime type (lookup).
137
93
 
138
- // create http handler function....
94
+ // not iterating properly through the collection without ._arr.
139
95
 
140
-
96
+ // May make more sense to have 2 versions,
97
+ // for 1 page
98
+ // for 2+ pages
99
+ const opts_bundling = {};
100
+ if (disk_path_client_js) opts_bundling.disk_path_client_js = disk_path_client_js;
141
101
 
142
- } else {
102
+ if (website.pages._arr.length === 0) {
103
+ throw 'NYI';
104
+ } else if (website.pages._arr.length === 1) {
105
+ const page = website.pages._arr[0];
106
+ const obs_bundling = Webpage_Bundler.bundle_web_page(page, opts_bundling);
107
+ //console.log('doing bundling');
108
+ //console.log('obs_bundling', obs_bundling);
109
+
110
+ //throw 'stop';
111
+
112
+ obs_bundling.on('complete', obs_bundling_res => {
113
+ // Should be a Bundle rather than a Buffer?
114
+
115
+ //console.log('obs_bundling res', obs_bundling_res);
116
+
117
+ // Need to have the HTML rendering and HTTP serving here as well.
118
+
119
+
120
+
121
+
122
+ //const page_bundle = res;
123
+
124
+ if (obs_bundling_res instanceof Bundle) {
125
+ //console.log('1) obs_bundling_res._arr.length', obs_bundling_res._arr.length);
126
+
127
+ // then need to handle the page construction and routing of http requests.
128
+
129
+ console.log('obs_bundling_res._arr.length', obs_bundling_res._arr.length);
130
+
131
+ each(obs_bundling_res, item => {
132
+ //console.log('item', item);
133
+ //console.log('item.path', item.path, item['content-type']);
134
+
135
+ if (item['content-type']) {
136
+ const ct = item['content-type'];
137
+ if (ct === 'text/html') {
138
+ const http_serve_html = (req, res) => {
139
+ res.writeHead(200, {
140
+ 'Content-Type': 'text/html'
141
+ });
142
+ res.end(item.value, 'utf-8');
143
+ }
144
+ router.set_route(item.path, (req, res) => {
145
+ http_serve_html(req, res);
146
+ });
147
+ } else {
148
+ const http_serve_any = (req, res) => {
149
+ res.writeHead(200, {
150
+ 'Content-Type': ct
151
+ });
152
+ res.end(item.value, 'utf-8');
153
+ }
154
+ router.set_route(item.path, (req, res) => {
155
+ http_serve_any(req, res);
156
+ });
157
+
158
+ //throw 'NYI';
159
+ }
160
+
161
+ } else {
162
+ throw 'NYI';
163
+ }
164
+
165
+ })
143
166
 
144
- // Multiple items at multiple paths....
167
+ //console.trace();
168
+ //throw 'stop';
145
169
 
146
- each(bundle, item => {
147
- //console.log('item', item);
148
- console.log('item.path', item.path, item['content-type']);
149
170
 
150
- if (item['content-type']) {
151
- const ct = item['content-type'];
152
- if (ct === 'text/html') {
153
- const http_serve_html = (req, res) => {
154
- res.writeHead(200, {
155
- 'Content-Type': 'text/html'
156
- });
157
- res.end(item.value, 'utf-8');
158
- }
159
- router.set_route(item.path, (req, res) => {
160
- http_serve_html(req, res);
161
- });
162
- } else {
163
- const http_serve_any = (req, res) => {
164
- res.writeHead(200, {
165
- 'Content-Type': ct
166
- });
167
- res.end(item.value, 'utf-8');
168
- }
169
- router.set_route(item.path, (req, res) => {
170
- http_serve_any(req, res);
171
- });
172
171
 
173
- //throw 'NYI';
174
- }
175
-
172
+ complete(obs_bundling_res);
176
173
  } else {
177
- throw 'NYI';
174
+
175
+ console.log('tof(obs_bundling_res)', tof(obs_bundling_res));
176
+
177
+ console.trace();
178
+ throw 'stop';
178
179
  }
179
180
 
180
- })
181
+
182
+
183
+ });
184
+
185
+ } else if (website.pages._arr.length > 1) {
186
+ throw 'NYI';
187
+ for (const page in website.pages._arr) {
188
+
189
+
190
+
191
+ // With multiple pages, add page to bundle.
192
+
193
+ const obs_bundling = Webpage_Bundler.bundle_web_page(page, opts_bundling);
194
+ //console.log('doing bundling');
195
+ //console.log('obs_bundling', obs_bundling);
196
+
197
+ //throw 'stop';
198
+
199
+ obs_bundling.on('complete', res => {
200
+ //console.log('obs_bundling res', res);
201
+ const page_bundle = res;
202
+
203
+ console.log('page_bundle._arr.length', page_bundle._arr.length);
204
+
205
+ //complete(bundle);
206
+
207
+ });
208
+
209
+
210
+ const old = () => {
211
+ obs_bundling.on('complete', res => {
212
+ //console.log('obs_bundling res', res);
213
+ const bundle = res;
214
+ //console.log('bundle._arr.length', bundle._arr.length);
215
+ //console.log('Object.keys(bundle)', Object.keys(bundle));
216
+
217
+ if (bundle._arr.length === 1) {
218
+ // And check it's HTML inside...?
219
+
220
+ const bundled_item = bundle._arr[0];
221
+ //console.log('bundled_item', bundled_item);
222
+
223
+ if (bundled_item['content-type']) {
224
+ const ct = bundled_item['content-type'];
225
+ if (ct === 'text/html') {
226
+ const http_serve_html = (req, res) => {
227
+ res.writeHead(200, {
228
+ 'Content-Type': 'text/html'
229
+ });
230
+ res.end(bundled_item.value, 'utf-8');
231
+ }
232
+ router.set_route(bundled_item.path, (req, res) => {
233
+ http_serve_html(req, res);
234
+ });
235
+ } else {
236
+ throw 'NYI';
237
+ }
238
+
239
+ } else {
240
+ throw 'NYI';
241
+ }
242
+
243
+ // need to create / use the handler for it here.
244
+ // will have various http handler functions to reference and use.
245
+ // will have details of http handling in other files.
246
+
247
+ // Maybe use an HTML publisher for this? (if it's HTML).
248
+ // Or publisher by mime type (lookup).
249
+
250
+ // create http handler function....
251
+
252
+
253
+
254
+ } else {
255
+
256
+ // Multiple items at multiple paths....
257
+
258
+ each(bundle, item => {
259
+ //console.log('item', item);
260
+ //console.log('item.path', item.path, item['content-type']);
261
+
262
+ if (item['content-type']) {
263
+ const ct = item['content-type'];
264
+ if (ct === 'text/html') {
265
+ const http_serve_html = (req, res) => {
266
+ res.writeHead(200, {
267
+ 'Content-Type': 'text/html'
268
+ });
269
+ res.end(item.value, 'utf-8');
270
+ }
271
+ router.set_route(item.path, (req, res) => {
272
+ http_serve_html(req, res);
273
+ });
274
+ } else {
275
+ const http_serve_any = (req, res) => {
276
+ res.writeHead(200, {
277
+ 'Content-Type': ct
278
+ });
279
+ res.end(item.value, 'utf-8');
280
+ }
281
+ router.set_route(item.path, (req, res) => {
282
+ http_serve_any(req, res);
283
+ });
284
+
285
+ //throw 'NYI';
286
+ }
287
+
288
+ } else {
289
+ throw 'NYI';
290
+ }
291
+
292
+ })
293
+
294
+ //console.trace();
295
+ //throw 'NYI';
296
+ }
297
+ })
298
+ }
299
+
300
+
301
+
302
+
303
+
304
+
305
+ //console.log(`${property}: ${object[property]}`);
306
+ }
307
+ }
181
308
 
182
- //console.trace();
183
- //throw 'NYI';
184
- }
185
- })
186
309
 
187
- }));
310
+
188
311
 
312
+
313
+
314
+ })().catch(err => {
315
+ console.error(err);
316
+ });
317
+
318
+
319
+
320
+
321
+ });
322
+ // put pages into a router here...
323
+ // however, may need to be on the lookout for other content that needs to be bundled with each page in the site.
324
+
325
+ // Now let's try bundling an active JS client.
326
+ // May need to compile / render JSGUI Controls to HTML / full HTML pages.
327
+
328
+ // And unspecified pages such as admin pages?
329
+
330
+
189
331
  //throw 'NYI';
190
332
  }
191
-
192
333
  if (website) {
193
- setup_website_publishing(website);
334
+ const obs_setup = setup_website_publishing(website);
335
+ obs_setup.on('complete', res_complete => {
336
+ console.log('setup complete');
194
337
 
338
+
339
+ this.raise('ready');
340
+
341
+ //complete(res_complete);
342
+
343
+
344
+ })
345
+ } else {
346
+ this.raise('ready');
195
347
  }
196
348
 
197
349
  // Create a router for the website if it does not already have one.
@@ -200,7 +352,6 @@ class HTTP_Website_Publisher extends HTTP_Publisher {
200
352
  // Do we already know all of the pages in the website?
201
353
  // Maybe there are dynamic pages.
202
354
 
203
-
204
355
  // Probably best to come up with a bundle here, or at an early stage.
205
356
 
206
357
  // .prepare_bundle?
@@ -227,6 +378,13 @@ class HTTP_Website_Publisher extends HTTP_Publisher {
227
378
  const accept_encoding = req.headers['accept-encoding'];
228
379
  const {host} = req.headers;
229
380
 
381
+ // count of routes in the router?
382
+
383
+ // router.routes.length?
384
+ // router.num_routes?
385
+
386
+
387
+
230
388
  //console.log('[httpVersion, host, url, statusCode, method, accept_endoding]', [httpVersion, host, url, statusCode, method, accept_encoding]);
231
389
 
232
390
 
@@ -247,10 +405,6 @@ class HTTP_Website_Publisher extends HTTP_Publisher {
247
405
 
248
406
  // Possibly the publisher has the router for the website.
249
407
 
250
-
251
-
252
-
253
-
254
408
  // May have bundle already prepared anyway.
255
409
  // Possibly the Website or the Website_Resource could do the bundling / building.
256
410
  // Could even bundle into a ZIP file :)
@@ -15,6 +15,8 @@ class JS_AST_Node_Type extends JS_AST_Node_Category_Statement {
15
15
  Object.defineProperty(this, 'abbreviated_type', {
16
16
  get() {
17
17
  const abb = type_abbreviations[this.babel.node.type];
18
+ // Maybe need a load more abbreviations now there are more babel types.
19
+
18
20
  if (abb) {
19
21
  return abb;
20
22
  } else {
@@ -8,17 +8,22 @@ const type_abbreviations = {
8
8
  'ArrayPattern': 'ArP',
9
9
  'BinaryExpression': 'BE',
10
10
  'BlockStatement': 'BS',
11
+ 'BreakStatement': 'BkS',
11
12
  'BooleanLiteral': 'BL',
12
13
  'CallExpression': 'CE', // change to CaE? Need to change sigs being looked for.
13
14
  'ClassBody': 'CB',
15
+ 'CatchClause': 'CC',
14
16
  'ClassDeclaration': 'CD',
17
+ 'ClassExpression': 'CE',
15
18
  'ClassMethod': 'CM',
16
19
  'ConditionalExpression': 'CoE',
17
20
  'EmptyStatement': '__',
18
21
  'ExpressionStatement': 'ES',
19
22
  'File': 'F',
20
23
  'ForStatement': 'FS',
24
+ 'ForInStatement': 'FIS',
21
25
  'FunctionExpression': 'FE',
26
+ 'FunctionDeclaration': 'FD',
22
27
  'Identifier': 'ID',
23
28
  'IfStatement': 'IS',
24
29
  'LogicalExpression': 'LE',
@@ -32,10 +37,18 @@ const type_abbreviations = {
32
37
  'ObjectProperty': 'OPr',
33
38
  'Program': 'P',
34
39
  'ReturnStatement': 'RS',
40
+ 'RestElement': 'RE',
41
+ 'RegExpLiteral': 'RxL',
42
+ 'SequenceExpression': 'SE',
35
43
  'StringLiteral': 'SL',
44
+ 'SwitchCase': 'SC',
45
+ 'SwitchStatement': 'SS',
36
46
  'Super': 'S',
37
- 'ThisExpression': 'TE',
47
+ 'ThisExpression': 'ThE',
48
+ 'TemplateElement': 'TE',
49
+ 'TemplateLiteral': 'TL',
38
50
  'ThrowStatement': 'TS',
51
+ 'TryStatement': 'TryS',
39
52
  'UnaryExpression': 'UnE',
40
53
  'UpdateExpression': 'UpE',
41
54
  'VariableDeclaration': 'VDn',