jsgui3-server 0.0.84 → 0.0.85
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 +9 -1
- package/bundler/js-bundler.js +10 -1
- package/bundler/webpage-bundler.js +11 -9
- package/examples/square_box.js +13 -7
- package/package.json +3 -3
- package/publishing/http-website-publisher.js +112 -95
- package/roadmap.md +4 -0
- package/server.js +13 -0
- package/website/website.js +26 -0
package/bundler/css-bundler.js
CHANGED
|
@@ -34,7 +34,15 @@ const Stream = require('stream');
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
|
|
37
|
+
const bundle_css_from_js = (js_file_path, options = {}) => {
|
|
37
38
|
|
|
39
|
+
return obs(async (next, complete, error) => {
|
|
40
|
+
|
|
41
|
+
// Go through each file? Just the first?
|
|
42
|
+
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
}
|
|
38
46
|
|
|
39
47
|
|
|
40
48
|
|
|
@@ -44,5 +52,5 @@ class CSS_Bundler extends Bundler {
|
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
|
|
55
|
+
CSS_Bundler.bundle_css_from_js = bundle_css_from_js;
|
|
48
56
|
module.exports = CSS_Bundler;
|
package/bundler/js-bundler.js
CHANGED
|
@@ -33,6 +33,11 @@ const Stream = require('stream');
|
|
|
33
33
|
|
|
34
34
|
const bundle_js = (js_file_path, options = {}, callback) => {
|
|
35
35
|
|
|
36
|
+
// Could even split a file into its server and client components.
|
|
37
|
+
// Maybe providing found css would work well here.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
36
41
|
// Returning an observable and not using a callback would work best.
|
|
37
42
|
|
|
38
43
|
const res = obs((next, complete, error) => {
|
|
@@ -58,6 +63,9 @@ const bundle_js = (js_file_path, options = {}, callback) => {
|
|
|
58
63
|
|
|
59
64
|
let fileContents = await fnlfs.load(js_file_path);
|
|
60
65
|
|
|
66
|
+
|
|
67
|
+
// Maybe do that post browserify - can read through whole thing to find the css template literals.
|
|
68
|
+
|
|
61
69
|
// Could use the CSS bundler to scan_js_for_css
|
|
62
70
|
// Seems as though it would be best as an observable.
|
|
63
71
|
|
|
@@ -122,6 +130,8 @@ const bundle_js = (js_file_path, options = {}, callback) => {
|
|
|
122
130
|
let buf_js = Buffer.concat(buffers);
|
|
123
131
|
let str_js = buf_js.toString();
|
|
124
132
|
|
|
133
|
+
// full browserified (client) js app.
|
|
134
|
+
|
|
125
135
|
let babel_option = options.babel
|
|
126
136
|
//console.log('babel_option', babel_option);
|
|
127
137
|
if (babel_option === 'es5') {
|
|
@@ -173,7 +183,6 @@ const bundle_js = (js_file_path, options = {}, callback) => {
|
|
|
173
183
|
} else {
|
|
174
184
|
buf_js = Buffer.from(str_js);
|
|
175
185
|
}
|
|
176
|
-
|
|
177
186
|
complete(buf_js);
|
|
178
187
|
})();
|
|
179
188
|
|
|
@@ -36,6 +36,15 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
36
36
|
const {content} = webpage;
|
|
37
37
|
|
|
38
38
|
let {disk_path_client_js} = options;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// Could use the CSS bundler to extract the css from the JS.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// Could look for the css within disk_path_client_js.
|
|
46
|
+
|
|
47
|
+
|
|
39
48
|
//if (options.js_client) js_client_disk_path =
|
|
40
49
|
|
|
41
50
|
// Then depending on the content type
|
|
@@ -76,9 +85,6 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
76
85
|
// Or render it with a temporary context?
|
|
77
86
|
|
|
78
87
|
// Controls with temportary contexts could be useful.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
88
|
if (content instanceof Control) {
|
|
83
89
|
//console.log('content is control');
|
|
84
90
|
//console.log('content.constructor.name', content.constructor.name);
|
|
@@ -111,7 +117,6 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
111
117
|
|
|
112
118
|
//console.log('cloned_content', cloned_content);
|
|
113
119
|
|
|
114
|
-
|
|
115
120
|
// The page context may not have a request and response.
|
|
116
121
|
// For bundling, won't have one (unless one were made).
|
|
117
122
|
|
|
@@ -135,10 +140,6 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
135
140
|
// So when it finds CSS, it can output that.
|
|
136
141
|
// A Control's CSS property, within the JS definition.
|
|
137
142
|
// That can be output to a CSS file, copied or removed from the JS file.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
143
|
bundle_js(diskpath_js_client, {
|
|
143
144
|
'js_mode': 'mini',
|
|
144
145
|
'babel': 'mini'
|
|
@@ -149,6 +150,7 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
149
150
|
} else {
|
|
150
151
|
//console.log('res_bundle_js', res_bundle_js);
|
|
151
152
|
|
|
153
|
+
// Could search at this point for class.css properties.
|
|
152
154
|
res.push({
|
|
153
155
|
'path': webpage.path + 'js/app.js',
|
|
154
156
|
'value': res_bundle_js,
|
|
@@ -197,7 +199,7 @@ const bundle_web_page = (webpage, options = {}) => {
|
|
|
197
199
|
}
|
|
198
200
|
} else {
|
|
199
201
|
|
|
200
|
-
console.log('t_content', t_content);
|
|
202
|
+
//console.log('t_content', t_content);
|
|
201
203
|
|
|
202
204
|
if (t_content === 'function') {
|
|
203
205
|
|
package/examples/square_box.js
CHANGED
|
@@ -23,13 +23,19 @@ 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
|
+
server.start(8080, function (err, cb_start) {
|
|
29
|
+
if (err) {
|
|
30
|
+
throw err;
|
|
31
|
+
} else {
|
|
32
|
+
// Should have build it by now...
|
|
33
|
+
|
|
34
|
+
console.log('server started');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
})
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
if (err) {
|
|
29
|
-
throw err;
|
|
30
|
-
} else {
|
|
31
|
-
console.log('server started');
|
|
32
|
-
}
|
|
33
|
-
});
|
|
39
|
+
|
|
34
40
|
|
|
35
41
|
}
|
package/package.json
CHANGED
|
@@ -13,8 +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.
|
|
17
|
-
"jsgui3-html": "0.0.
|
|
16
|
+
"jsgui3-client": "^0.0.68",
|
|
17
|
+
"jsgui3-html": "0.0.96",
|
|
18
18
|
"multiparty": "^4.2.3",
|
|
19
19
|
"ncp": "^2.0.0",
|
|
20
20
|
"obext": "0.0.23",
|
|
@@ -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.85"
|
|
44
44
|
}
|
|
@@ -73,122 +73,139 @@ class HTTP_Website_Publisher extends HTTP_Publisher {
|
|
|
73
73
|
console.log('http-website-publisher disk_path_client_js', disk_path_client_js);
|
|
74
74
|
//throw 'stop';
|
|
75
75
|
|
|
76
|
+
// This could be an observable that acts sequentially and async.
|
|
77
|
+
|
|
76
78
|
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
79
|
|
|
80
|
-
|
|
81
|
-
// May need to compile / render JSGUI Controls to HTML / full HTML pages.
|
|
80
|
+
return obs(async(next, complete, error) => {
|
|
82
81
|
|
|
83
|
-
|
|
82
|
+
for (const page in website.pages) {
|
|
83
|
+
|
|
84
|
+
const opts_bundling = {};
|
|
85
|
+
if (disk_path_client_js) opts_bundling.disk_path_client_js = disk_path_client_js;
|
|
86
|
+
|
|
87
|
+
const obs_bundling = await Webpage_Bundler.bundle_web_page(page, opts_bundling);
|
|
88
|
+
//console.log('doing bundling');
|
|
89
|
+
console.log('obs_bundling', obs_bundling);
|
|
90
|
+
|
|
91
|
+
throw 'stop';
|
|
92
|
+
|
|
84
93
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
'Content-Type': 'text/html'
|
|
117
|
-
});
|
|
118
|
-
res.end(bundled_item.value, 'utf-8');
|
|
94
|
+
const old = () => {
|
|
95
|
+
obs_bundling.on('complete', res => {
|
|
96
|
+
//console.log('obs_bundling res', res);
|
|
97
|
+
const bundle = res;
|
|
98
|
+
//console.log('bundle._arr.length', bundle._arr.length);
|
|
99
|
+
//console.log('Object.keys(bundle)', Object.keys(bundle));
|
|
100
|
+
|
|
101
|
+
if (bundle._arr.length === 1) {
|
|
102
|
+
// And check it's HTML inside...?
|
|
103
|
+
|
|
104
|
+
const bundled_item = bundle._arr[0];
|
|
105
|
+
//console.log('bundled_item', bundled_item);
|
|
106
|
+
|
|
107
|
+
if (bundled_item['content-type']) {
|
|
108
|
+
const ct = bundled_item['content-type'];
|
|
109
|
+
if (ct === 'text/html') {
|
|
110
|
+
const http_serve_html = (req, res) => {
|
|
111
|
+
res.writeHead(200, {
|
|
112
|
+
'Content-Type': 'text/html'
|
|
113
|
+
});
|
|
114
|
+
res.end(bundled_item.value, 'utf-8');
|
|
115
|
+
}
|
|
116
|
+
router.set_route(bundled_item.path, (req, res) => {
|
|
117
|
+
http_serve_html(req, res);
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
throw 'NYI';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
} else {
|
|
124
|
+
throw 'NYI';
|
|
119
125
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
126
|
+
|
|
127
|
+
// need to create / use the handler for it here.
|
|
128
|
+
// will have various http handler functions to reference and use.
|
|
129
|
+
// will have details of http handling in other files.
|
|
130
|
+
|
|
131
|
+
// Maybe use an HTML publisher for this? (if it's HTML).
|
|
132
|
+
// Or publisher by mime type (lookup).
|
|
133
|
+
|
|
134
|
+
// create http handler function....
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
123
138
|
} else {
|
|
124
|
-
|
|
139
|
+
|
|
140
|
+
// Multiple items at multiple paths....
|
|
141
|
+
|
|
142
|
+
each(bundle, item => {
|
|
143
|
+
//console.log('item', item);
|
|
144
|
+
//console.log('item.path', item.path, item['content-type']);
|
|
145
|
+
|
|
146
|
+
if (item['content-type']) {
|
|
147
|
+
const ct = item['content-type'];
|
|
148
|
+
if (ct === 'text/html') {
|
|
149
|
+
const http_serve_html = (req, res) => {
|
|
150
|
+
res.writeHead(200, {
|
|
151
|
+
'Content-Type': 'text/html'
|
|
152
|
+
});
|
|
153
|
+
res.end(item.value, 'utf-8');
|
|
154
|
+
}
|
|
155
|
+
router.set_route(item.path, (req, res) => {
|
|
156
|
+
http_serve_html(req, res);
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
const http_serve_any = (req, res) => {
|
|
160
|
+
res.writeHead(200, {
|
|
161
|
+
'Content-Type': ct
|
|
162
|
+
});
|
|
163
|
+
res.end(item.value, 'utf-8');
|
|
164
|
+
}
|
|
165
|
+
router.set_route(item.path, (req, res) => {
|
|
166
|
+
http_serve_any(req, res);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
//throw 'NYI';
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
} else {
|
|
173
|
+
throw 'NYI';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
//console.trace();
|
|
179
|
+
//throw 'NYI';
|
|
125
180
|
}
|
|
181
|
+
})
|
|
182
|
+
}
|
|
126
183
|
|
|
127
|
-
|
|
128
|
-
throw 'NYI';
|
|
129
|
-
}
|
|
130
|
-
|
|
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.
|
|
134
|
-
|
|
135
|
-
// Maybe use an HTML publisher for this? (if it's HTML).
|
|
136
|
-
// Or publisher by mime type (lookup).
|
|
137
|
-
|
|
138
|
-
// create http handler function....
|
|
184
|
+
|
|
139
185
|
|
|
140
|
-
|
|
141
186
|
|
|
142
|
-
} else {
|
|
143
187
|
|
|
144
|
-
// Multiple items at multiple paths....
|
|
145
188
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
//console.log('item.path', item.path, item['content-type']);
|
|
189
|
+
//console.log(`${property}: ${object[property]}`);
|
|
190
|
+
}
|
|
149
191
|
|
|
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
192
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
} else {
|
|
177
|
-
throw 'NYI';
|
|
178
|
-
}
|
|
193
|
+
});
|
|
194
|
+
// put pages into a router here...
|
|
195
|
+
// however, may need to be on the lookout for other content that needs to be bundled with each page in the site.
|
|
179
196
|
|
|
180
|
-
|
|
197
|
+
// Now let's try bundling an active JS client.
|
|
198
|
+
// May need to compile / render JSGUI Controls to HTML / full HTML pages.
|
|
181
199
|
|
|
182
|
-
|
|
183
|
-
//throw 'NYI';
|
|
184
|
-
}
|
|
185
|
-
})
|
|
200
|
+
// And unspecified pages such as admin pages?
|
|
186
201
|
|
|
187
|
-
|
|
202
|
+
|
|
188
203
|
//throw 'NYI';
|
|
189
204
|
}
|
|
190
205
|
if (website) {
|
|
191
206
|
setup_website_publishing(website);
|
|
207
|
+
} else {
|
|
208
|
+
this.raise('ready');
|
|
192
209
|
}
|
|
193
210
|
|
|
194
211
|
// Create a router for the website if it does not already have one.
|
package/roadmap.md
CHANGED
package/server.js
CHANGED
|
@@ -236,9 +236,19 @@ class JSGUI_Server extends Evented_Class {
|
|
|
236
236
|
|
|
237
237
|
|
|
238
238
|
const ws_publisher = new HTTP_Website_Publisher(opts_ws_publisher);
|
|
239
|
+
|
|
240
|
+
// but need to wait until that website publisher is ready.
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
239
245
|
// ws publisher could have website admin (web) tools.
|
|
240
246
|
// website admin web interface.
|
|
241
247
|
|
|
248
|
+
ws_publisher.on('ready', () => {
|
|
249
|
+
|
|
250
|
+
});
|
|
251
|
+
|
|
242
252
|
|
|
243
253
|
|
|
244
254
|
|
|
@@ -254,6 +264,9 @@ class JSGUI_Server extends Evented_Class {
|
|
|
254
264
|
// ws_publisher.start();
|
|
255
265
|
}
|
|
256
266
|
current();
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
257
270
|
}
|
|
258
271
|
|
|
259
272
|
// a 'router' property that returns the server router.
|
package/website/website.js
CHANGED
|
@@ -3,6 +3,32 @@ const {tof, HTML_Document} = jsgui;
|
|
|
3
3
|
|
|
4
4
|
const oext = require('obext');
|
|
5
5
|
|
|
6
|
+
// Should maybe become its own module.
|
|
7
|
+
|
|
8
|
+
// jsgui3-website and jsgui3-webpage
|
|
9
|
+
// jsgui3-application
|
|
10
|
+
// jsgui3-ui-app
|
|
11
|
+
// jsgui3-app may be enough
|
|
12
|
+
// could build / deploy it to phonegap / other native app wrapper.
|
|
13
|
+
// And could deploy a jsgui3-app as a website...?
|
|
14
|
+
// Deploy same app to other platforms?
|
|
15
|
+
// possibly jsgui3-bundler could bundle a website for different uses and formats.
|
|
16
|
+
// could have some kind of non-node server operating on client-side apps.
|
|
17
|
+
|
|
18
|
+
// jsgui3-coming-soon could itself be a website.
|
|
19
|
+
// or a webpage?
|
|
20
|
+
|
|
21
|
+
// website with a single page.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
6
32
|
const Webpage = require('./webpage');
|
|
7
33
|
// Website is a Publisher?
|
|
8
34
|
|