jsgui3-server 0.0.97 → 0.0.99

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.
Files changed (54) hide show
  1. package/examples/box/{square_box_client.js → 1) square box/client.js } +40 -5
  2. package/examples/box/{square_box.js → 1) square box/server.js } +10 -3
  3. package/examples/box/2) twenty square boxes/css flex wrap/client.js +248 -0
  4. package/examples/box/2) twenty square boxes/css flex wrap/server.js +113 -0
  5. package/examples/controls/1) window/client.js +183 -0
  6. package/examples/controls/1) window/server.js +113 -0
  7. package/examples/controls/{scs-month-view.js → __old/scs-month-view.js} +0 -1
  8. package/http/responders/HTTP_Responder.js +16 -0
  9. package/http/responders/static/Static_Route_HTTP_Responder.js +106 -0
  10. package/package.json +9 -8
  11. package/page-context.js +15 -0
  12. package/publishers/helpers/assigners/Assigner.js +11 -0
  13. package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +150 -0
  14. package/publishers/helpers/assigners/static-headers/Single_Control_Webpage_Server_Static_Headers_Assigner.js +110 -0
  15. package/publishers/helpers/assigners/static-routes/Single_Control_Webpage_Server_Static_Routes_Assigner.js +92 -0
  16. package/publishers/helpers/assigners/static-uncompressed-response-buffers/Single_Control_Webpage_Server_Static_Uncompressed_Response_Buffers_Assigner.js +104 -0
  17. package/publishers/helpers/preparers/static/bundle/Ready_To_Serve_Preparer.js +19 -0
  18. package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +38 -0
  19. package/publishers/http-publisher.js +4 -2
  20. package/publishers/http-webpage-publisher.js +480 -3
  21. package/publishers/http-webpageorsite-publisher.js +336 -0
  22. package/publishers/http-website-publisher.js +51 -2
  23. package/resources/compile/server-resource-compilation.js +2 -0
  24. package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +26 -0
  25. package/resources/processors/bundlers/css-bundler.js +24 -1
  26. package/resources/processors/bundlers/js/JS_Bundler.js +52 -0
  27. package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +329 -0
  28. package/resources/processors/bundlers/js/esbuild/Bundler_Using_ESBuild.js +9 -0
  29. package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +174 -0
  30. package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +191 -0
  31. package/resources/processors/bundlers/js/esbuild/_Old_CSS_Extractor.js +240 -0
  32. package/resources/processors/bundlers/js-bundler.js +201 -193
  33. package/resources/processors/bundlers/webpage-bundler.js +15 -0
  34. package/resources/processors/extractors/Extractor.js +10 -0
  35. package/resources/processors/extractors/js/css_and_js/AST_Node/CSS_And_JS_From_JS_String_Using_AST_Node_Extractor.js +239 -0
  36. package/resources/processors/extractors/js/css_and_js/CSS_And_JS_From_JS_String_Extractor.js +4 -0
  37. package/resources/processors/extractors/string/Pos_Span_String_Extractor.js +94 -0
  38. package/server.js +176 -5
  39. package/static-page-context.js +14 -0
  40. package/examples/box/box.css +0 -8
  41. package/examples/box/out_square_box_client.js +0 -28862
  42. /package/examples/controls/{_html-server-color-palette.js → __old/_html-server-color-palette.js} +0 -0
  43. /package/examples/controls/{html-server-combo-box.js → __old/html-server-combo-box.js} +0 -0
  44. /package/examples/controls/{html-server-list.js → __old/html-server-list.js} +0 -0
  45. /package/examples/controls/{html-server-popup-menu-button.js → __old/html-server-popup-menu-button.js} +0 -0
  46. /package/examples/controls/{html-server-start-stop-toggle-button.js → __old/html-server-start-stop-toggle-button.js} +0 -0
  47. /package/examples/controls/{scs-arrow-button.js → __old/scs-arrow-button.js} +0 -0
  48. /package/examples/controls/{scs-date-picker.js → __old/scs-date-picker.js} +0 -0
  49. /package/examples/controls/{scs-file-browser.js → __old/scs-file-browser.js} +0 -0
  50. /package/examples/controls/{scs-item.js → __old/scs-item.js} +0 -0
  51. /package/examples/controls/{scs-month-arrow-selector.js → __old/scs-month-arrow-selector.js} +0 -0
  52. /package/examples/controls/{scs-start-stop-toggle-button.js → __old/scs-start-stop-toggle-button.js} +0 -0
  53. /package/examples/controls/{scs-tree.js → __old/scs-tree.js} +0 -0
  54. /package/examples/controls/{scs-year-arrow-selector.js → __old/scs-year-arrow-selector.js} +0 -0
@@ -3,55 +3,56 @@
3
3
 
4
4
 
5
5
 
6
+ const all_old_bundler_implementation = () => {
6
7
 
7
8
 
8
- const Bundler = require('./bundler');
9
- const Bundle = require('./bundle');
10
- const {obs, prom_or_cb} = require('fnl');
11
- const {tof} = require('jsgui3-html');
12
- const fnlfs = require('fnlfs');
9
+ const Bundler = require('./bundler');
10
+ const Bundle = require('./bundle');
11
+ const {obs, prom_or_cb} = require('fnl');
12
+ const {tof} = require('jsgui3-html');
13
+ const fnlfs = require('fnlfs');
13
14
 
14
- // May want a more base JS_Bundler class, and then subclasses will use specific modules like Babel or ESBuild to bundle.
15
- // That way can go for nice defaults and provide flexibility too. Plus interchangability of some inner components, eg if someone
16
- //
15
+ // May want a more base JS_Bundler class, and then subclasses will use specific modules like Babel or ESBuild to bundle.
16
+ // That way can go for nice defaults and provide flexibility too. Plus interchangability of some inner components, eg if someone
17
+ //
17
18
 
18
19
 
19
20
 
20
- const browserify = require('browserify');
21
- const babel = require('@babel/core');
21
+ const browserify = require('browserify');
22
+ const babel = require('@babel/core');
22
23
 
23
24
 
24
- const stream_to_array = require('stream-to-array');
25
- const util = require('util');
26
- const Stream = require('stream');
27
- // Will put the JS together. Maybe images?
25
+ const stream_to_array = require('stream-to-array');
26
+ const util = require('util');
27
+ const Stream = require('stream');
28
+ // Will put the JS together. Maybe images?
28
29
 
29
- // Will put the JS together. Maybe images?
30
- // Get everything ready to serve.
30
+ // Will put the JS together. Maybe images?
31
+ // Get everything ready to serve.
31
32
 
32
- // Would need a JS file that contains refs to all of the components used.
33
- // Examine what is in the website and what JS it needs.
33
+ // Would need a JS file that contains refs to all of the components used.
34
+ // Examine what is in the website and what JS it needs.
34
35
 
35
- // Should be customisable which system gets used to make the bundle.
36
- // eg babel or esbuild. Browserify still seems to work on code here at least, but esbuild seems better.
36
+ // Should be customisable which system gets used to make the bundle.
37
+ // eg babel or esbuild. Browserify still seems to work on code here at least, but esbuild seems better.
37
38
 
38
- // JS bundling will become a bit more advanced in this server. Similar principles.
39
+ // JS bundling will become a bit more advanced in this server. Similar principles.
39
40
 
40
- // JS_Bundler reporting css that gets found while bundling JS would make sense.
41
+ // JS_Bundler reporting css that gets found while bundling JS would make sense.
41
42
 
42
- // jsgui3-jsbuilder could be a separate project too.
43
- // or jsgui3-js-builder even.
43
+ // jsgui3-jsbuilder could be a separate project too.
44
+ // or jsgui3-js-builder even.
44
45
 
45
46
 
46
47
 
47
48
 
48
- // A JS Bundler or JS Packager class will probably be best.
49
+ // A JS Bundler or JS Packager class will probably be best.
49
50
 
50
- // This seems more like a babel specific JS Bundler.
51
- // Or even compiler???
52
- // Source_Compiler????
51
+ // This seems more like a babel specific JS Bundler.
52
+ // Or even compiler???
53
+ // Source_Compiler????
53
54
 
54
- // Giving the classes simple and intuitive APIs, allowing for them to be nicely interchangable.
55
+ // Giving the classes simple and intuitive APIs, allowing for them to be nicely interchangable.
55
56
 
56
57
 
57
58
 
@@ -59,198 +60,205 @@ const Stream = require('stream');
59
60
 
60
61
 
61
62
 
62
- const bundle_js = (js_file_path, options = {}, callback) => {
63
+ const bundle_js = (js_file_path, options = {}, callback) => {
63
64
 
64
- // Could even split a file into its server and client components.
65
- // Maybe providing found css would work well here.
65
+ // Could even split a file into its server and client components.
66
+ // Maybe providing found css would work well here.
66
67
 
67
68
 
68
69
 
69
- // Returning an observable and not using a callback would work best.
70
+ // Returning an observable and not using a callback would work best.
70
71
 
71
- const res = obs((next, complete, error) => {
72
+ const res = obs((next, complete, error) => {
72
73
 
73
74
 
74
75
 
75
- let a = arguments;
76
- if (typeof a[2] === 'function') {
77
- callback = a[2];
76
+ let a = arguments;
77
+ if (typeof a[2] === 'function') {
78
+ callback = a[2];
78
79
 
79
- options.include_sourcemaps = true;
80
- }
80
+ options.include_sourcemaps = true;
81
+ }
81
82
 
82
- (async () => {
83
- // options
84
- // may want a replacement within the client-side code.
85
- // Can we call browserify on the code string?
86
- // Creating a modified copy of the file would do.
87
- // Load the file, modify it, save it under a different name
83
+ (async () => {
84
+ // options
85
+ // may want a replacement within the client-side code.
86
+ // Can we call browserify on the code string?
87
+ // Creating a modified copy of the file would do.
88
+ // Load the file, modify it, save it under a different name
88
89
 
89
- let s = new Stream.Readable(),
90
- path = require('path').parse(js_file_path);
90
+ let s = new Stream.Readable(),
91
+ path = require('path').parse(js_file_path);
91
92
 
92
- let fileContents = await fnlfs.load(js_file_path);
93
+ let fileContents = await fnlfs.load(js_file_path);
93
94
 
94
95
 
95
- // Maybe do that post browserify - can read through whole thing to find the css template literals.
96
+ // Maybe do that post browserify - can read through whole thing to find the css template literals.
96
97
 
97
- // Could use the CSS bundler to scan_js_for_css
98
- // Seems as though it would be best as an observable.
98
+ // Could use the CSS bundler to scan_js_for_css
99
+ // Seems as though it would be best as an observable.
99
100
 
100
101
 
101
- // Could first get own system AST of the JS file.
102
+ // Could first get own system AST of the JS file.
102
103
 
103
- // Modify the original file contents so that only client-side parts appear?
104
- // Could be done by programatically removing a whole code block, what to do if it is run on the server.
104
+ // Modify the original file contents so that only client-side parts appear?
105
+ // Could be done by programatically removing a whole code block, what to do if it is run on the server.
105
106
 
106
107
 
107
- //console.log('1) fileContents.length', fileContents.length);
108
- // are there any replacements to do?
109
- // options.replacements
108
+ //console.log('1) fileContents.length', fileContents.length);
109
+ // are there any replacements to do?
110
+ // options.replacements
111
+
112
+
113
+
114
+ if (options.js_mode === 'debug') {
115
+ options.include_sourcemaps = true;
116
+ }
117
+ if (options.js_mode === 'compress' || options.js_mode === 'mini') {
118
+ options.include_sourcemaps = false;
119
+ options.babel = 'mini';
120
+ }
121
+
122
+ //console.log('options.babel', options.babel);
123
+
124
+ if (options.replace) {
125
+ let s_file_contents = fileContents.toString();
126
+ //console.log('s_file_contents', s_file_contents);
127
+ each(options.replace, (text, key) => {
128
+ //console.log('key', key);
129
+ //console.log('text', text);
130
+ let running_fn = '(' + text + ')();'
131
+ //console.log('running_fn', running_fn);
132
+ s_file_contents = s_file_contents.split(key).join(running_fn);
133
+ })
134
+ fileContents = Buffer.from(s_file_contents);
135
+ //console.log('2) fileContents.length', fileContents.length);
136
+ }
137
+ // Then we can replace some of the file contents with specific content given when we tall it to serve that file.
138
+ // We have a space for client-side activation.
139
+ s.push(fileContents);
140
+ s.push(null);
141
+
142
+ //let include_sourcemaps = true;
143
+
144
+ let b = browserify(s, {
145
+ basedir: path.dir,
146
+ //builtins: false,
147
+ builtins: ['buffer', 'process'],
148
+ 'debug': options.include_sourcemaps
149
+ });
150
+
151
+ // May be able to better put the bundle stream info into the observable results.
152
+ // Browserify gets given the stream.
153
+
154
+ // Nice if this function could output a stream as well.
155
+
156
+
157
+ let parts = await stream_to_array(b.bundle());
158
+
159
+ const buffers = parts
160
+ .map(part => util.isBuffer(part) ? part : Buffer.from(part));
161
+ let buf_js = Buffer.concat(buffers);
162
+ let str_js = buf_js.toString();
163
+
164
+ next({
165
+ 'lang': 'JavaScript',
166
+ 'operation': 'bundle',
167
+ 'compress': false,
168
+ 'type': 'single-string',
169
+ 'value': str_js
170
+ });
171
+
172
+ // full browserified (client) js app.
173
+
174
+ let babel_option = options.babel
175
+
176
+
177
+ // could send str_js to a CSS extractor / bundler.
178
+
179
+
180
+ //console.log('babel_option', babel_option);
181
+ if (babel_option === 'es5') {
182
+
183
+ let o_transform = {
184
+ "presets": [
185
+ "es2015",
186
+ "es2017"
187
+ ],
188
+ "plugins": [
189
+ "transform-runtime"
190
+ ] //,
191
+ //'sourceMaps': 'inline'
192
+ };
193
+
194
+ if (options.include_sourcemaps) o_transform.sourceMaps = 'inline';
195
+ let res_transform = babel.transform(str_js, o_transform);
196
+ //console.log('res_transform', res_transform);
197
+ //console.log('Object.keys(res_transform)', Object.keys(res_transform));
198
+ let jst_es5 = res_transform.code;
199
+ //let {jst_es5, map, ast} = babel.transform(str_js);
200
+ //console.log('jst_es5.length', jst_es5.length);
201
+ buf_js = Buffer.from(jst_es5);
202
+ } else if (babel_option === 'mini') {
203
+ /*
204
+ let o_transform = {
205
+ presets: ["minify"]//,
206
+ //'sourceMaps': 'inline'
207
+ };
208
+ */
209
+ let o_transform = {
210
+ "presets": [
211
+ ["minify", {
212
+ //"mangle": {
213
+ //"exclude": ["MyCustomError"]
214
+ //},
215
+ //"unsafe": {
216
+ // "typeConstructors": false
217
+ //},
218
+ //"keepFnName": true
219
+ }]
220
+ ],
221
+ //plugins: ["minify-dead-code-elimination"]
222
+ };
223
+ if (options.include_sourcemaps) o_transform.sourceMaps = 'inline';
224
+ let res_transform = babel.transform(str_js, o_transform);
225
+ buf_js = Buffer.from(res_transform.code);
226
+ } else {
227
+ buf_js = Buffer.from(str_js);
228
+ }
229
+ complete(buf_js);
230
+ })();
110
231
 
111
-
112
-
113
- if (options.js_mode === 'debug') {
114
- options.include_sourcemaps = true;
115
- }
116
- if (options.js_mode === 'compress' || options.js_mode === 'mini') {
117
- options.include_sourcemaps = false;
118
- options.babel = 'mini';
119
- }
120
-
121
- //console.log('options.babel', options.babel);
122
-
123
- if (options.replace) {
124
- let s_file_contents = fileContents.toString();
125
- //console.log('s_file_contents', s_file_contents);
126
- each(options.replace, (text, key) => {
127
- //console.log('key', key);
128
- //console.log('text', text);
129
- let running_fn = '(' + text + ')();'
130
- //console.log('running_fn', running_fn);
131
- s_file_contents = s_file_contents.split(key).join(running_fn);
132
- })
133
- fileContents = Buffer.from(s_file_contents);
134
- //console.log('2) fileContents.length', fileContents.length);
135
- }
136
- // Then we can replace some of the file contents with specific content given when we tall it to serve that file.
137
- // We have a space for client-side activation.
138
- s.push(fileContents);
139
- s.push(null);
140
-
141
- //let include_sourcemaps = true;
142
-
143
- let b = browserify(s, {
144
- basedir: path.dir,
145
- //builtins: false,
146
- builtins: ['buffer', 'process'],
147
- 'debug': options.include_sourcemaps
232
+ })
233
+ if (callback) {
234
+ res.on('complete', (value) => {
235
+ callback(null, value);
148
236
  });
237
+ res.on('error', err => {
238
+ callback(err);
239
+ })
240
+ } else {
241
+ return res;
242
+ }
243
+ // An observable would be better as result could include status messages (with their timings).
149
244
 
150
- // May be able to better put the bundle stream info into the observable results.
151
- // Browserify gets given the stream.
152
-
153
- // Nice if this function could output a stream as well.
154
-
245
+ //return prom_or_cb((resolve, reject) => {
246
+
247
+ //}, callback);
248
+ }
155
249
 
156
- let parts = await stream_to_array(b.bundle());
250
+ class JS_Bundler extends Bundler {
251
+ constructor(spec = {}) {
252
+ super(spec);
253
+ }
254
+ }
157
255
 
158
- const buffers = parts
159
- .map(part => util.isBuffer(part) ? part : Buffer.from(part));
160
- let buf_js = Buffer.concat(buffers);
161
- let str_js = buf_js.toString();
256
+ JS_Bundler.bundle_js = bundle_js;
162
257
 
163
- next({
164
- 'lang': 'JavaScript',
165
- 'operation': 'bundle',
166
- 'compress': false,
167
- 'type': 'single-string',
168
- 'value': str_js
169
- });
258
+ }
170
259
 
171
- // full browserified (client) js app.
172
-
173
- let babel_option = options.babel
174
-
175
-
176
- // could send str_js to a CSS extractor / bundler.
177
-
178
-
179
- //console.log('babel_option', babel_option);
180
- if (babel_option === 'es5') {
181
-
182
- let o_transform = {
183
- "presets": [
184
- "es2015",
185
- "es2017"
186
- ],
187
- "plugins": [
188
- "transform-runtime"
189
- ] //,
190
- //'sourceMaps': 'inline'
191
- };
192
-
193
- if (options.include_sourcemaps) o_transform.sourceMaps = 'inline';
194
- let res_transform = babel.transform(str_js, o_transform);
195
- //console.log('res_transform', res_transform);
196
- //console.log('Object.keys(res_transform)', Object.keys(res_transform));
197
- let jst_es5 = res_transform.code;
198
- //let {jst_es5, map, ast} = babel.transform(str_js);
199
- //console.log('jst_es5.length', jst_es5.length);
200
- buf_js = Buffer.from(jst_es5);
201
- } else if (babel_option === 'mini') {
202
- /*
203
- let o_transform = {
204
- presets: ["minify"]//,
205
- //'sourceMaps': 'inline'
206
- };
207
- */
208
- let o_transform = {
209
- "presets": [
210
- ["minify", {
211
- //"mangle": {
212
- //"exclude": ["MyCustomError"]
213
- //},
214
- //"unsafe": {
215
- // "typeConstructors": false
216
- //},
217
- //"keepFnName": true
218
- }]
219
- ],
220
- //plugins: ["minify-dead-code-elimination"]
221
- };
222
- if (options.include_sourcemaps) o_transform.sourceMaps = 'inline';
223
- let res_transform = babel.transform(str_js, o_transform);
224
- buf_js = Buffer.from(res_transform.code);
225
- } else {
226
- buf_js = Buffer.from(str_js);
227
- }
228
- complete(buf_js);
229
- })();
230
-
231
- })
232
- if (callback) {
233
- res.on('complete', (value) => {
234
- callback(null, value);
235
- });
236
- res.on('error', err => {
237
- callback(err);
238
- })
239
- } else {
240
- return res;
241
- }
242
- // An observable would be better as result could include status messages (with their timings).
243
260
 
244
- //return prom_or_cb((resolve, reject) => {
245
-
246
- //}, callback);
247
- }
261
+ const JS_Bundler = require('./js/JS_Bundler');
248
262
 
249
- class JS_Bundler extends Bundler {
250
- constructor(spec = {}) {
251
- super(spec);
252
- }
253
- }
254
263
 
255
- JS_Bundler.bundle_js = bundle_js;
256
264
  module.exports = JS_Bundler;
@@ -7,6 +7,21 @@
7
7
  // Maybe even JS from JS.
8
8
 
9
9
 
10
+ // Late 2023 - Looks best to retire this one, make it really flexible in terms of what it does internally, with (many?) more classes doing
11
+ // specific things. It looks like ESBuild is the fastest option, may need to mix that with some very specific pieces of functionality
12
+ // for things like splitting / extracting CSS.
13
+
14
+ // Will identify the various parts of the tasks involved in bundling (and then serving) assets on the web.
15
+ // Will make classes that are named 1st in terms of that they do, but then there will be directories with different implementations
16
+ // of that functionality.
17
+
18
+ // May well be worth having this link to (require and export) an improved and specific version of the Webpage_Bundler class.
19
+
20
+
21
+
22
+
23
+
24
+
10
25
  const Bundler = require('./bundler');
11
26
 
12
27
  const JS_Bundler = require('./js-bundler');
@@ -0,0 +1,10 @@
1
+
2
+ const {Evented_Class} = require('lang-tools');
3
+
4
+ class Extractor extends Evented_Class {
5
+ constructor(spec) {
6
+ super();
7
+ }
8
+ }
9
+
10
+ module.exports = Extractor;