jsgui3-server 0.0.95 → 0.0.97
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/controls/Active_HTML_Document.js +90 -0
- package/examples/box/box.css +8 -0
- package/examples/box/out_square_box_client.js +28862 -0
- package/examples/box/square_box.js +63 -1
- package/examples/box/square_box_client.js +42 -5
- package/examples/boxes/square_boxes_client.js +1 -1
- package/package.json +11 -8
- package/publishers/http-js-publisher.js +136 -0
- package/{publishing → publishers}/http-webpage-publisher.js +27 -0
- package/{publishing → publishers}/http-website-publisher.js +245 -8
- package/{publishing → publishers}/notes.md +3 -0
- package/resources/_old_website-javascript-resource.js +995 -0
- package/resources/process-js.js +5 -0
- package/{bundler → resources/processors/bundlers}/bundle.js +11 -0
- package/resources/processors/bundlers/bundler.js +24 -0
- package/{bundler → resources/processors/bundlers}/css-bundler.js +3 -3
- package/{bundler → resources/processors/bundlers}/js-bundler.js +28 -0
- package/{bundler → resources/processors/bundlers}/webpage-bundler.js +71 -1
- package/resources/website-audio-resource.js +3 -0
- package/resources/website-javascript-resource-processor.js +909 -0
- package/resources/website-javascript-resource.js +138 -162
- package/resources/website-resource-processor.js +11 -0
- package/resources/website-resource.js +5 -3
- package/roadmap.md +6 -0
- package/server.js +123 -14
- package/website/webpage.js +36 -1
- package/website/website.js +9 -1
- package/bundler/bundler.js +0 -9
- package/publishing/http-js-publisher.js +0 -25
- /package/{publishing → publishers}/http-css-publisher.js +0 -0
- /package/{publishing → publishers}/http-function-publisher.js +0 -0
- /package/{publishing → publishers}/http-html-page-publisher.js +0 -0
- /package/{publishing → publishers}/http-html-publisher.js +0 -0
- /package/{publishing → publishers}/http-jpeg-publisher.js +0 -0
- /package/{publishing → publishers}/http-observable-publisher.js +0 -0
- /package/{publishing → publishers}/http-png-publisher.js +0 -0
- /package/{publishing → publishers}/http-publisher.js +0 -0
- /package/{publishing → publishers}/http-resource-publisher.js +0 -0
- /package/{publishing → publishers}/http-svg-publisher.js +0 -0
- /package/{bundler → resources/processors/bundlers}/test_ast.js +0 -0
- /package/{bundler → resources/processors/bundlers}/website-bundler.js +0 -0
|
@@ -3,10 +3,72 @@ const jsgui = require('./square_box_client');
|
|
|
3
3
|
const {Demo_UI, Square_Box} = jsgui.controls;
|
|
4
4
|
const Server = require('../../server');
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
|
|
6
8
|
// Want to exclude this from the client bundle.
|
|
7
9
|
// Some kind of marking to say that it's server-side only?
|
|
8
10
|
|
|
11
|
+
// Need to include JSGUI3 js within the client document.
|
|
12
|
+
// Seems like an earlier code simplification removed this functionality?
|
|
13
|
+
// Just specifying a Ctrl for the server - and giving it the 'disk_path_client_js'.
|
|
14
|
+
// May as well fix that....
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
9
18
|
if (require.main === module) {
|
|
19
|
+
|
|
20
|
+
// By default should include the JS and the CSS.
|
|
21
|
+
// By reference, serving them from their respective paths.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
// This API is not working right now.
|
|
25
|
+
|
|
26
|
+
// A very simple syntax for running a single control would be great.
|
|
27
|
+
|
|
28
|
+
// Need to in the default (server) configuration build and serve the client-side app.
|
|
29
|
+
// Want to be able to make interactive apps quickly with minimal server side code that needs to be written as boilerplate to
|
|
30
|
+
// get the app running.
|
|
31
|
+
|
|
32
|
+
// Though maybe defining a webpage, that serves the client js, and renders the control on the server, and activates it on the client,
|
|
33
|
+
// would be the right approach.
|
|
34
|
+
|
|
35
|
+
// Want to make the code really explicit, in a simple way.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// eg { '/': Demo_UI }
|
|
39
|
+
// eg { '*': Demo_UI }
|
|
40
|
+
// as at least it explicitly assigns it to the '/' route
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// But worth keeping the '/' Ctrl property?
|
|
44
|
+
// Could change it to explicitly setting the route(s).
|
|
45
|
+
|
|
46
|
+
// Do want it to build the client js on start.
|
|
47
|
+
|
|
48
|
+
// Could extract the CSS from the file itself, or maybe better reading it from the classes and objects that are loaded / referenced.
|
|
49
|
+
// All kinds of complex server program structures exist already, so could use Publishers if needed for some things.
|
|
50
|
+
// But need to keep the surface-level API really simple.
|
|
51
|
+
|
|
52
|
+
// Maybe define a Webpage and maybe use / define an HTML_Webpage_Publisher for example too.
|
|
53
|
+
// The clearest code would be really explicit about what it does, but in terms of almost English idioms
|
|
54
|
+
// and on the surface-level not spelling out in great detail what it's doing, but referencing objects and
|
|
55
|
+
// instructions with clear purposes, though details could be obscure at the top level. Eg it's the publisher's responsibility
|
|
56
|
+
// to include the CSS and JS that's needed to get it to run. A publisher is referenced and used, and it does its thing.
|
|
57
|
+
|
|
58
|
+
// The Server could automatically involk the use of a Publisher.
|
|
59
|
+
// May be better to either require or recommend more explicit code, have them in the examples,
|
|
60
|
+
// but also to document some shortcuts, defaults, and abbreviations (though they may omit some essential info, so not recommended for beginners)
|
|
61
|
+
|
|
62
|
+
// Could have a tabbed view for examples for 'explicit' and 'short' notations when there are multiple.
|
|
63
|
+
|
|
64
|
+
// jsgui3-html-suite may be of use, for some more extended controls that are built on top of jsgui3-html, but not specifically
|
|
65
|
+
// client or server.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
10
72
|
const server = new Server({
|
|
11
73
|
Ctrl: Demo_UI,
|
|
12
74
|
// Giving it the Ctrl and disk path client js should enable to server to get the JS-bundled CSS from the file(s).
|
|
@@ -14,7 +76,7 @@ if (require.main === module) {
|
|
|
14
76
|
|
|
15
77
|
|
|
16
78
|
//'js_mode': 'debug',
|
|
17
|
-
'
|
|
79
|
+
'src_path_client_js': require.resolve('./square_box_client.js')
|
|
18
80
|
//js_client: require.resolve('./square_box.js')
|
|
19
81
|
});
|
|
20
82
|
// A callback or event for when the bundling has been completed
|
|
@@ -2,20 +2,33 @@ const jsgui = require('jsgui3-client');
|
|
|
2
2
|
const {controls, Control, mixins} = jsgui;
|
|
3
3
|
const {dragable} = mixins;
|
|
4
4
|
|
|
5
|
+
const Active_HTML_Document = require('../../controls/Active_HTML_Document');
|
|
6
|
+
|
|
7
|
+
// Maybe better to include it within an Active_HTML_Document.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
5
12
|
// Relies on extracting CSS from JS files.
|
|
6
13
|
|
|
7
|
-
class Demo_UI extends
|
|
8
|
-
constructor(spec) {
|
|
14
|
+
class Demo_UI extends Active_HTML_Document {
|
|
15
|
+
constructor(spec = {}) {
|
|
9
16
|
spec.__type_name = spec.__type_name || 'demo_ui';
|
|
10
17
|
super(spec);
|
|
11
18
|
const {context} = this;
|
|
12
|
-
|
|
19
|
+
|
|
20
|
+
// Make sure it requires the correct CSS.
|
|
21
|
+
// Though making that 'effortless' on the server may help more.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
this.body.add_class('demo-ui');
|
|
13
26
|
|
|
14
27
|
const compose = () => {
|
|
15
28
|
const box = new Square_Box({
|
|
16
29
|
context: context
|
|
17
30
|
})
|
|
18
|
-
this.add(box);
|
|
31
|
+
this.body.add(box);
|
|
19
32
|
}
|
|
20
33
|
if (!spec.el) {
|
|
21
34
|
compose();
|
|
@@ -41,6 +54,30 @@ class Demo_UI extends Control {
|
|
|
41
54
|
// Want CSS bundling so that styles are read out from the JS document and compiled to a stylesheet.
|
|
42
55
|
|
|
43
56
|
//controls.Demo_UI = Demo_UI;
|
|
57
|
+
|
|
58
|
+
// A css file may be an easier way to get started...?
|
|
59
|
+
// Want to support but not require css in js.
|
|
60
|
+
|
|
61
|
+
// But need to set up the serving of the CSS both on the server, and on the client.
|
|
62
|
+
// Ofc setting it up on the server first is important - then can that stage set it up in the doc sent to the client?
|
|
63
|
+
|
|
64
|
+
// Including the CSS from the JS like before.
|
|
65
|
+
// Needs to extract the CSS and serve it as a separate CSS file.
|
|
66
|
+
// Should also have end-to-end regression tests so this does not break again in the future.
|
|
67
|
+
// The code was kind of clunky and got refactored away.
|
|
68
|
+
//
|
|
69
|
+
|
|
70
|
+
// Would need to parse the JS files to extract the CSS.
|
|
71
|
+
// Maybe could do it an easier way???
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
44
81
|
Demo_UI.css = `
|
|
45
82
|
.demo-ui {
|
|
46
83
|
display: flex;
|
|
@@ -69,7 +106,7 @@ class Square_Box extends Control {
|
|
|
69
106
|
|
|
70
107
|
console.log('dragable mixin applied to square');
|
|
71
108
|
this.dragable = true;
|
|
72
|
-
console.log('this.dragable = true;');
|
|
109
|
+
//console.log('this.dragable = true;');
|
|
73
110
|
|
|
74
111
|
this.on('dragend', e => {
|
|
75
112
|
console.log('square box dragend e', e);
|
package/package.json
CHANGED
|
@@ -3,21 +3,24 @@
|
|
|
3
3
|
"main": "module.js",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@babel/core": "^7.20
|
|
7
|
-
"@babel/generator": "^7.
|
|
8
|
-
"@babel/parser": "7.
|
|
6
|
+
"@babel/core": "^7.22.20",
|
|
7
|
+
"@babel/generator": "^7.22.15",
|
|
8
|
+
"@babel/parser": "7.22.16",
|
|
9
9
|
"babel-plugin-transform-runtime": "^6.23.0",
|
|
10
10
|
"babel-preset-minify": "^0.5.2",
|
|
11
11
|
"browserify": "17.0.0",
|
|
12
12
|
"child-process": "^1.0.2",
|
|
13
13
|
"cookies": "^0.8.0",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
14
|
+
"esbuild": "^0.19.3",
|
|
15
|
+
"fnl": "^0.0.27",
|
|
16
|
+
"fnlfs": "^0.0.28",
|
|
17
|
+
"jsgui3-client": "^0.0.79",
|
|
18
|
+
"jsgui3-webpage": "^0.0.3",
|
|
19
|
+
"jsgui3-website": "^0.0.3",
|
|
17
20
|
|
|
18
21
|
"multiparty": "^4.2.3",
|
|
19
22
|
"ncp": "^2.0.0",
|
|
20
|
-
"obext": "0.0.
|
|
23
|
+
"obext": "^0.0.25",
|
|
21
24
|
"rimraf": "^3.0.2",
|
|
22
25
|
"stream-to-array": "^2.3.0",
|
|
23
26
|
"url-parse": "^1.5.10"
|
|
@@ -41,5 +44,5 @@
|
|
|
41
44
|
"type": "git",
|
|
42
45
|
"url": "https://github.com/metabench/jsgui3-server.git"
|
|
43
46
|
},
|
|
44
|
-
"version": "0.0.
|
|
47
|
+
"version": "0.0.97"
|
|
45
48
|
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// Publishes the HTML format.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const HTTP_Publisher = require('./http-publisher');
|
|
7
|
+
|
|
8
|
+
// This part will process the requests and responses, not the JS resource itself.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class HTTP_JS_Publisher extends HTTP_Publisher {
|
|
13
|
+
constructor(spec) {
|
|
14
|
+
|
|
15
|
+
// Should probably take one or more JS Resources.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
super(spec);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Will publish HTML documents over HTTP, but seems as though it would need to be configured / called with
|
|
23
|
+
// something to render as well as a rendering engine and parameters.
|
|
24
|
+
|
|
25
|
+
// compilation = rendering? not exactly.
|
|
26
|
+
|
|
27
|
+
// handle_http()
|
|
28
|
+
|
|
29
|
+
'handle_http'(req, res) {
|
|
30
|
+
|
|
31
|
+
// Will the resource itself process the requests? Maybe only the Resource Publisher should do that.
|
|
32
|
+
// A greater level of abstraction there, more splitting of responsibilities.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
console.log('HTTP_JS_Publisher processing req.url', req.url);
|
|
39
|
+
var remoteAddress = req.connection.remoteAddress;
|
|
40
|
+
var custom_paths = this.custom_paths;
|
|
41
|
+
var rurl = req.url.replace(/\./g, '☺');
|
|
42
|
+
var custom_response_entry = custom_paths[rurl];
|
|
43
|
+
var pool = this.pool;
|
|
44
|
+
if (custom_response_entry) {
|
|
45
|
+
const ae = req.headers['accept-encoding'];
|
|
46
|
+
let data_to_serve;
|
|
47
|
+
let o_head = {
|
|
48
|
+
'Content-Type': 'text/javascript'
|
|
49
|
+
}
|
|
50
|
+
if (ae.includes('gzip')) {
|
|
51
|
+
o_head['Content-Encoding'] = 'gzip';
|
|
52
|
+
data_to_serve = custom_response_entry._.gzip;
|
|
53
|
+
} else {
|
|
54
|
+
data_to_serve = custom_response_entry._.raw;
|
|
55
|
+
}
|
|
56
|
+
res.writeHead(200, o_head);
|
|
57
|
+
res.end(data_to_serve);
|
|
58
|
+
} else {
|
|
59
|
+
//var served_directories = this.served_directories;
|
|
60
|
+
//console.log('served_directories', served_directories);
|
|
61
|
+
var url_parts = url.parse(req.url, true);
|
|
62
|
+
//console.log('url_parts ' + stringify(url_parts));
|
|
63
|
+
var splitPath = url_parts.path.substr(1).split('/');
|
|
64
|
+
|
|
65
|
+
var wildcard_value = req.params.wildcard_value;
|
|
66
|
+
//console.log('*** wildcard_value', wildcard_value);
|
|
67
|
+
|
|
68
|
+
if (wildcard_value == 'web/require.js') {
|
|
69
|
+
|
|
70
|
+
} else {
|
|
71
|
+
var disk_path = path.dirname(require.main.filename) + '/' + 'js/' + wildcard_value;
|
|
72
|
+
var compress = false;
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
//console.log('disk_path', disk_path);
|
|
76
|
+
|
|
77
|
+
if (compress) {
|
|
78
|
+
throw 'NYI with Babel';
|
|
79
|
+
|
|
80
|
+
} else {
|
|
81
|
+
// try to load it from the project's js path.
|
|
82
|
+
//console.log('disk_path', disk_path);
|
|
83
|
+
var project_js_path = 'js/' + wildcard_value;
|
|
84
|
+
//console.log('project_js_path', project_js_path);
|
|
85
|
+
|
|
86
|
+
fs2.load_file_as_string(disk_path, function (err, str_js) {
|
|
87
|
+
if (err) {
|
|
88
|
+
console.log('error loading from project_js_path: ', project_js_path);
|
|
89
|
+
console.log(err);
|
|
90
|
+
} else {
|
|
91
|
+
// Have loaded the js from the project path, we can serve it.
|
|
92
|
+
console.log('have loaded js');
|
|
93
|
+
// serve the js.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
//res.writeHead(200, {'Content-Type': 'text/javascript'});
|
|
97
|
+
// Could possibly stream it from disk instead, that would likely be more efficient.
|
|
98
|
+
console.log('str_js.length', str_js.length);
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
// use gzip in many cases.
|
|
102
|
+
// want to support that.
|
|
103
|
+
|
|
104
|
+
// a streaming middleware fn could work...?
|
|
105
|
+
|
|
106
|
+
zlib.deflate(str_js, function (err, buffer) {
|
|
107
|
+
console.log('deflated buffer.length', buffer.length);
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if (err) throw err;
|
|
111
|
+
res.writeHead(200, {
|
|
112
|
+
'Content-Encoding': 'deflate',
|
|
113
|
+
'Content-Type': 'text/javascript'
|
|
114
|
+
});
|
|
115
|
+
res.end(buffer);
|
|
116
|
+
//res.writeHead(200, {'Content-Type': 'text/javascript'});
|
|
117
|
+
//response.end(servableJs);
|
|
118
|
+
//res.end(minified.code);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
//response.end(servableJs);
|
|
123
|
+
//res.end(str_js);
|
|
124
|
+
//throw 'stop';
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
module.exports = HTTP_JS_Publisher;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
// Want to get it (back) working as a server easily serving simple controls and pages and sites.
|
|
2
|
+
// Need to tame some of the more complex layers inside it to get it to easily serve the app.
|
|
3
|
+
// Then should work on making / improving some of the specific controls.
|
|
4
|
+
// Make the code idiomatic and DRY. The more complex lower and middle level abstractions will help with that.
|
|
5
|
+
// Use polymorphism and run-time checks to allow for some more flexibility.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
1
9
|
|
|
2
10
|
|
|
3
11
|
// A publisher handles HTTP requests.
|
|
@@ -9,6 +17,14 @@
|
|
|
9
17
|
const HTTP_Publisher = require('./http-publisher');
|
|
10
18
|
const {obs} = require('fnl');
|
|
11
19
|
|
|
20
|
+
// May want / need to more carefully and specifically define APIs.
|
|
21
|
+
// It's nice to have classes for specific things like this, but need to make them do what is needed.
|
|
22
|
+
// Maybe get a 'Website' object or control ready to be served.
|
|
23
|
+
//
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
12
28
|
// Named observables?
|
|
13
29
|
/*
|
|
14
30
|
|
|
@@ -48,12 +64,23 @@ obs((next, complete, error) => {
|
|
|
48
64
|
//
|
|
49
65
|
|
|
50
66
|
|
|
67
|
+
// Should include or use various other publishers, such as html or js?
|
|
51
68
|
|
|
52
69
|
|
|
53
70
|
class HTTP_Webpage_Publisher extends HTTP_Publisher {
|
|
54
71
|
|
|
55
72
|
// Website generally serves JS from a single address.
|
|
56
73
|
// Webpage could have its specific JS.
|
|
74
|
+
// This component may need to handle the JS building.
|
|
75
|
+
// webpage-bundler within the 'bundler' directory.
|
|
76
|
+
|
|
77
|
+
// But not sure if babel or esbuild is better here.
|
|
78
|
+
// Babel has obviously improved since I had to switch to esbuild years ago.
|
|
79
|
+
// Being able to use either would help.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
57
84
|
|
|
58
85
|
constructor(spec = {}) {
|
|
59
86
|
super(spec)
|