jsgui3-server 0.0.89 → 0.0.90
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/bundler/css-bundler.js
CHANGED
|
@@ -9,6 +9,8 @@ const stream_to_array = require('stream-to-array');
|
|
|
9
9
|
const util = require('util');
|
|
10
10
|
const Stream = require('stream');
|
|
11
11
|
// Will put the JS together. Maybe images?
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
12
14
|
|
|
13
15
|
const JS_AST_Node = require('./../resources/jsbuilder/JS_AST/JS_AST_Node');
|
|
14
16
|
|
|
@@ -35,16 +37,31 @@ const JS_AST_Node = require('./../resources/jsbuilder/JS_AST/JS_AST_Node');
|
|
|
35
37
|
// maybe scan an AST or AST stream as it's coming in.
|
|
36
38
|
|
|
37
39
|
|
|
40
|
+
// Needs to be able to copy / access the basic.css from jsgui3-html.
|
|
41
|
+
// Maybe be able to find them on disk.
|
|
42
|
+
|
|
43
|
+
// Streaming does seem like the best meachanism for loading data etc.
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const stream_html_basic_css = () => {
|
|
47
|
+
const css_file_path = path.join(path.dirname(require.resolve('jsgui3-html')), 'css', 'basic.css');
|
|
48
|
+
console.log('css_file_path', css_file_path);
|
|
49
|
+
|
|
50
|
+
const res_stream = fs.createReadStream(css_file_path);
|
|
51
|
+
|
|
52
|
+
return res_stream;
|
|
53
|
+
|
|
54
|
+
}
|
|
38
55
|
|
|
39
56
|
const bundle_css_from_js_str = (js_str, options = {}) => {
|
|
40
57
|
|
|
41
|
-
console.log('js_str.length', js_str.length);
|
|
58
|
+
//console.log('js_str.length', js_str.length);
|
|
42
59
|
// Moving towards using observables as a matter of course for longer-running functions.
|
|
43
60
|
|
|
44
61
|
// Seems like this makes a settimeout as well???
|
|
45
62
|
return obs((next, complete, error) => {
|
|
46
63
|
|
|
47
|
-
console.log('js_str.length', js_str.length);
|
|
64
|
+
//console.log('js_str.length', js_str.length);
|
|
48
65
|
|
|
49
66
|
// Returning a Bundle object when done could be best...?
|
|
50
67
|
|
|
@@ -54,15 +71,15 @@ const bundle_css_from_js_str = (js_str, options = {}) => {
|
|
|
54
71
|
|
|
55
72
|
const js_ast_node = JS_AST_Node.from_spec(spec);
|
|
56
73
|
|
|
57
|
-
console.log('!!js_ast_node', !!js_ast_node);
|
|
74
|
+
//console.log('!!js_ast_node', !!js_ast_node);
|
|
58
75
|
|
|
59
|
-
console.log('Object.keys(js_ast_node)', Object.keys(js_ast_node));
|
|
76
|
+
//console.log('Object.keys(js_ast_node)', Object.keys(js_ast_node));
|
|
60
77
|
|
|
61
78
|
// count all
|
|
62
79
|
|
|
63
80
|
//console.log('js_ast_node.query("count all")', js_ast_node.query("count all"));
|
|
64
81
|
|
|
65
|
-
console.log('js_ast_node.query.count.all.exe()', js_ast_node.query.count.all.exe());
|
|
82
|
+
//console.log('js_ast_node.query.count.all.exe()', js_ast_node.query.count.all.exe());
|
|
66
83
|
|
|
67
84
|
// A filter iterate query....? filter_deep_iterate could work.
|
|
68
85
|
// but we are looking specifically for 'ClassName.css'
|
|
@@ -142,7 +159,7 @@ const bundle_css_from_js_str = (js_str, options = {}) => {
|
|
|
142
159
|
//console.log('css_ae_node.source', css_ae_node.source);
|
|
143
160
|
const tl = css_ae_node.child_nodes[1].child_nodes[0];
|
|
144
161
|
//console.log('tl', tl);
|
|
145
|
-
console.log('tl.source', tl.source);
|
|
162
|
+
//console.log('tl.source', tl.source);
|
|
146
163
|
arr_css.push(tl.source);
|
|
147
164
|
|
|
148
165
|
|
|
@@ -157,10 +174,6 @@ const bundle_css_from_js_str = (js_str, options = {}) => {
|
|
|
157
174
|
complete();
|
|
158
175
|
}
|
|
159
176
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
177
|
|
|
165
178
|
// Can then do query to get all .css properties that are string templates.
|
|
166
179
|
// is it a property of a Class object?
|
|
@@ -195,4 +208,5 @@ class CSS_Bundler extends Bundler {
|
|
|
195
208
|
}
|
|
196
209
|
|
|
197
210
|
CSS_Bundler.bundle_css_from_js_str = bundle_css_from_js_str;
|
|
211
|
+
CSS_Bundler.stream_html_basic_css = stream_html_basic_css;
|
|
198
212
|
module.exports = CSS_Bundler;
|
|
@@ -3,7 +3,7 @@ const Bundler = require('./bundler');
|
|
|
3
3
|
const JS_Bundler = require('./js-bundler');
|
|
4
4
|
const CSS_Bundler = require('./css-bundler');
|
|
5
5
|
|
|
6
|
-
const {bundle_css_from_js_str} = CSS_Bundler;
|
|
6
|
+
const {bundle_css_from_js_str, stream_html_basic_css} = CSS_Bundler;
|
|
7
7
|
|
|
8
8
|
const Bundle = require('./bundle');
|
|
9
9
|
const {obs, prom_or_cb} = require('fnl');
|
|
@@ -46,6 +46,40 @@ const stream_to_array = require('stream-to-array');
|
|
|
46
46
|
const {bundle_js} = JS_Bundler;
|
|
47
47
|
|
|
48
48
|
|
|
49
|
+
// Observable to load the basic CSS, or return it.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const get_basic_css_content_obj = () => {
|
|
53
|
+
return obs((next, complete, error) => {
|
|
54
|
+
|
|
55
|
+
const s_css = stream_html_basic_css();
|
|
56
|
+
|
|
57
|
+
const chunks = [];
|
|
58
|
+
let buf_css;
|
|
59
|
+
|
|
60
|
+
s_css.once('end', () => {
|
|
61
|
+
// create the final data Buffer from data chunks;
|
|
62
|
+
buf_css = Buffer.concat(chunks);
|
|
63
|
+
complete({
|
|
64
|
+
'value': buf_css,
|
|
65
|
+
'content-type': 'text/css'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Of course, you can do anything else you need to here, like emit an event!
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Data is flushed from fileStream in chunks,
|
|
72
|
+
// this callback will be executed for each chunk
|
|
73
|
+
s_css.on('data', (chunk) => {
|
|
74
|
+
chunks.push(chunk); // push data chunk to array
|
|
75
|
+
|
|
76
|
+
// We can perform actions on the partial data we have so far!
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
49
83
|
const bundle_web_page = (webpage, options = {}) => {
|
|
50
84
|
const {content} = webpage;
|
|
51
85
|
//console.log('bundle web page');
|
|
@@ -85,8 +119,16 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
85
119
|
const res = new Bundle();
|
|
86
120
|
|
|
87
121
|
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
88
125
|
(async () => {
|
|
89
126
|
|
|
127
|
+
const o_basic_css = await get_basic_css_content_obj();
|
|
128
|
+
//console.log('o_css', o_css);
|
|
129
|
+
//console.log('t_content', t_content);
|
|
130
|
+
//throw 'stop';
|
|
131
|
+
|
|
90
132
|
if (t_content === 'string') {
|
|
91
133
|
// Hardly anything to bundle. No JS required, so it seems.
|
|
92
134
|
// Maybe put it inside a basic JSGUI page control...?
|
|
@@ -327,9 +369,6 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
327
369
|
'babel': 'debug'
|
|
328
370
|
});
|
|
329
371
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
372
|
obs_bundle.on('next', data => {
|
|
334
373
|
//console.log('next data', data);
|
|
335
374
|
console.log('next Object.keys(data)', Object.keys(data));
|
|
@@ -361,14 +400,16 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
361
400
|
if (tof(obs_css_from_js_res) === 'string') {
|
|
362
401
|
// should be added to the page bundle.
|
|
363
402
|
|
|
403
|
+
const basic_and_app_css = Buffer.concat([o_basic_css.value, Buffer.from(obs_css_from_js_res)]);
|
|
404
|
+
|
|
364
405
|
res.push({
|
|
365
406
|
'path': webpage.path + 'css/app.css',
|
|
366
|
-
'value':
|
|
407
|
+
'value': basic_and_app_css,
|
|
367
408
|
'content-type': 'text/css'
|
|
368
409
|
});
|
|
369
410
|
|
|
370
411
|
waiting_for_css_extraction = false;
|
|
371
|
-
console.log('obs_css_from_js complete');
|
|
412
|
+
//console.log('obs_css_from_js complete');
|
|
372
413
|
|
|
373
414
|
if (handle_css_extraction_complete) {
|
|
374
415
|
handle_css_extraction_complete();
|
|
@@ -502,8 +543,9 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
502
543
|
}
|
|
503
544
|
})().catch(err => {
|
|
504
545
|
console.trace();
|
|
546
|
+
console.log('err', err);
|
|
505
547
|
|
|
506
|
-
throw
|
|
548
|
+
throw err;
|
|
507
549
|
//console.error(err);
|
|
508
550
|
});
|
|
509
551
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const jsgui = require('./color_palette_client');
|
|
2
|
+
|
|
3
|
+
const {Demo_UI} = jsgui.controls;
|
|
4
|
+
const Server = require('../server');
|
|
5
|
+
|
|
6
|
+
// Want to exclude this from the client bundle.
|
|
7
|
+
// Some kind of marking to say that it's server-side only?
|
|
8
|
+
|
|
9
|
+
// Autoresizing within the color palette not working properly.
|
|
10
|
+
// Should do more work on a grid that deals with the autoresizing properly.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if (require.main === module) {
|
|
16
|
+
|
|
17
|
+
const server = new Server({
|
|
18
|
+
Ctrl: Demo_UI,
|
|
19
|
+
// Giving it the Ctrl and disk path client js should enable to server to get the JS-bundled CSS from the file(s).
|
|
20
|
+
// Putting the JS files through proper parsing and into a syntax tree would be best.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
//'js_mode': 'debug',
|
|
24
|
+
'disk_path_client_js': require.resolve('./color_palette_client.js')
|
|
25
|
+
//js_client: require.resolve('./square_box.js')
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// A callback or event for when the bundling has been completed
|
|
29
|
+
// a 'ready' event.
|
|
30
|
+
|
|
31
|
+
// then start the server....
|
|
32
|
+
// be able to choose the port / ports?
|
|
33
|
+
console.log('waiting for server ready event');
|
|
34
|
+
server.on('ready', () => {
|
|
35
|
+
console.log('server ready');
|
|
36
|
+
|
|
37
|
+
// server start will change to observable?
|
|
38
|
+
|
|
39
|
+
server.start(8080, function (err, cb_start) {
|
|
40
|
+
if (err) {
|
|
41
|
+
throw err;
|
|
42
|
+
} else {
|
|
43
|
+
// Should have build it by now...
|
|
44
|
+
|
|
45
|
+
console.log('server started');
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const jsgui = require('jsgui3-client'); // and will replace this with jsgui-client, I presume.
|
|
2
|
+
|
|
3
|
+
const {controls, Control, mixins} = jsgui;
|
|
4
|
+
const { Color_Palette } = controls;
|
|
5
|
+
const {dragable} = mixins;
|
|
6
|
+
|
|
7
|
+
// Relies on extracting CSS from JS files.
|
|
8
|
+
|
|
9
|
+
class Demo_UI extends Control {
|
|
10
|
+
constructor(spec) {
|
|
11
|
+
spec.__type_name = spec.__type_name || 'demo_ui';
|
|
12
|
+
super(spec);
|
|
13
|
+
const {context} = this;
|
|
14
|
+
this.add_class('demo-ui');
|
|
15
|
+
|
|
16
|
+
const compose = () => {
|
|
17
|
+
|
|
18
|
+
// Have it resize itself to fit the available space it has?
|
|
19
|
+
// mixin resize-to-fit-space possibly.
|
|
20
|
+
// would measure the space available in its parent control or container.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
const pal = new Color_Palette({
|
|
26
|
+
context: context
|
|
27
|
+
})
|
|
28
|
+
this.add(pal);
|
|
29
|
+
}
|
|
30
|
+
if (!spec.el) {
|
|
31
|
+
compose();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
activate() {
|
|
35
|
+
if (!this.__active) {
|
|
36
|
+
super.activate();
|
|
37
|
+
const {context} = this;
|
|
38
|
+
|
|
39
|
+
console.log('activate color_palette Demo_UI');
|
|
40
|
+
// listen for the context events regarding frames, changes, resizing.
|
|
41
|
+
|
|
42
|
+
context.on('window-resize', e_resize => {
|
|
43
|
+
console.log('window-resize', e_resize);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Include this in bundling.
|
|
51
|
+
// Want CSS bundling so that styles are read out from the JS document and compiled to a stylesheet.
|
|
52
|
+
|
|
53
|
+
//controls.Demo_UI = Demo_UI;
|
|
54
|
+
Demo_UI.css = `
|
|
55
|
+
.demo-ui {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: column;
|
|
58
|
+
justify-content: center;
|
|
59
|
+
align-items: center;
|
|
60
|
+
text-align: center;
|
|
61
|
+
min-height: 100vh;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
.demo-ui .cell {
|
|
66
|
+
height: 24px;
|
|
67
|
+
width: 24px;
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
// then if running on the client...?
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
//controls.Square_Box = Square_Box;
|
|
76
|
+
// could export jsgui with the updated controls....
|
|
77
|
+
// so that they are in the correct Page Context.?
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
controls.Demo_UI = Demo_UI;
|
|
81
|
+
//controls.Square_Box = Square_Box;
|
|
82
|
+
|
|
83
|
+
module.exports = jsgui;
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
module.exports = {
|
|
87
|
+
Square_Box: Square_Box,
|
|
88
|
+
Demo_UI: Demo_UI
|
|
89
|
+
}
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
// Then if window...?
|
|
93
|
+
|
|
94
|
+
// Need to add the Square_Box control to the context or original map of controls...
|
|
95
|
+
|
package/package.json
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"cookies": "^0.8.0",
|
|
14
14
|
"fnl": "^0.0.22",
|
|
15
15
|
"fnlfs": "^0.0.25",
|
|
16
|
-
"jsgui3-client": "^0.0.
|
|
17
|
-
"jsgui3-html": "0.0.
|
|
16
|
+
"jsgui3-client": "^0.0.72",
|
|
17
|
+
"jsgui3-html": "0.0.99",
|
|
18
18
|
"multiparty": "^4.2.3",
|
|
19
19
|
"ncp": "^2.0.0",
|
|
20
20
|
"obext": "0.0.24",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"type": "git",
|
|
41
41
|
"url": "https://github.com/metabench/jsgui3-server.git"
|
|
42
42
|
},
|
|
43
|
-
"version": "0.0.
|
|
43
|
+
"version": "0.0.90"
|
|
44
44
|
}
|