jsgui3-server 0.0.98 → 0.0.100
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/examples/box/{square_box_client.js → 1) square box/client.js } +40 -5
- package/examples/box/{square_box.js → 1) square box/server.js } +10 -3
- package/examples/box/2) twenty square boxes/css flex wrap/client.js +248 -0
- package/examples/box/2) twenty square boxes/css flex wrap/server.js +113 -0
- package/examples/controls/1) window/client.js +184 -0
- package/examples/controls/1) window/server.js +114 -0
- package/examples/controls/{_html-server-color-palette.js → __old/_html-server-color-palette.js} +2 -2
- package/examples/controls/{scs-month-view.js → __old/scs-month-view.js} +0 -1
- package/http/responders/HTTP_Responder.js +16 -0
- package/http/responders/static/Static_Route_HTTP_Responder.js +106 -0
- package/package.json +9 -8
- package/page-context.js +15 -0
- package/publishers/helpers/assigners/Assigner.js +11 -0
- package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +150 -0
- package/publishers/helpers/assigners/static-headers/Single_Control_Webpage_Server_Static_Headers_Assigner.js +110 -0
- package/publishers/helpers/assigners/static-routes/Single_Control_Webpage_Server_Static_Routes_Assigner.js +92 -0
- package/publishers/helpers/assigners/static-uncompressed-response-buffers/Single_Control_Webpage_Server_Static_Uncompressed_Response_Buffers_Assigner.js +104 -0
- package/publishers/helpers/preparers/static/bundle/Ready_To_Serve_Preparer.js +19 -0
- package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +45 -0
- package/publishers/http-webpage-publisher.js +483 -3
- package/publishers/http-webpageorsite-publisher.js +343 -0
- package/publishers/http-website-publisher.js +51 -2
- package/resources/compile/server-resource-compilation.js +2 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +26 -0
- package/resources/processors/bundlers/css-bundler.js +24 -1
- package/resources/processors/bundlers/js/JS_Bundler.js +52 -0
- package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +389 -0
- package/resources/processors/bundlers/js/esbuild/Bundler_Using_ESBuild.js +9 -0
- package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +186 -0
- package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +191 -0
- package/resources/processors/bundlers/js/esbuild/_Old_CSS_Extractor.js +240 -0
- package/resources/processors/bundlers/js-bundler.js +201 -193
- package/resources/processors/bundlers/webpage-bundler.js +15 -0
- package/resources/processors/extractors/Extractor.js +10 -0
- package/resources/processors/extractors/js/css_and_js/AST_Node/CSS_And_JS_From_JS_String_Using_AST_Node_Extractor.js +239 -0
- package/resources/processors/extractors/js/css_and_js/CSS_And_JS_From_JS_String_Extractor.js +4 -0
- package/resources/processors/extractors/string/Pos_Span_String_Extractor.js +94 -0
- package/server.js +188 -5
- package/static-page-context.js +14 -0
- package/examples/box/box.css +0 -8
- package/examples/box/out_square_box_client.js +0 -48
- /package/examples/controls/{html-server-combo-box.js → __old/html-server-combo-box.js} +0 -0
- /package/examples/controls/{html-server-list.js → __old/html-server-list.js} +0 -0
- /package/examples/controls/{html-server-popup-menu-button.js → __old/html-server-popup-menu-button.js} +0 -0
- /package/examples/controls/{html-server-start-stop-toggle-button.js → __old/html-server-start-stop-toggle-button.js} +0 -0
- /package/examples/controls/{scs-arrow-button.js → __old/scs-arrow-button.js} +0 -0
- /package/examples/controls/{scs-date-picker.js → __old/scs-date-picker.js} +0 -0
- /package/examples/controls/{scs-file-browser.js → __old/scs-file-browser.js} +0 -0
- /package/examples/controls/{scs-item.js → __old/scs-item.js} +0 -0
- /package/examples/controls/{scs-month-arrow-selector.js → __old/scs-month-arrow-selector.js} +0 -0
- /package/examples/controls/{scs-start-stop-toggle-button.js → __old/scs-start-stop-toggle-button.js} +0 -0
- /package/examples/controls/{scs-tree.js → __old/scs-tree.js} +0 -0
- /package/examples/controls/{scs-year-arrow-selector.js → __old/scs-year-arrow-selector.js} +0 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
// This won't deal with CSS, maybe will have some options for it.
|
|
5
|
+
|
|
6
|
+
const {obs} = require('fnl');
|
|
7
|
+
const esbuild = require('esbuild')
|
|
8
|
+
|
|
9
|
+
const Bundle = require('../../bundle');
|
|
10
|
+
const Bundler_Using_ESBuild = require('./Bundler_Using_ESBuild');
|
|
11
|
+
// extends Bundler ???
|
|
12
|
+
// extends Core_Bundler?
|
|
13
|
+
// exends Base_Bundler???
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Core_JS_Single_File_Minifying_Bundler_Using_ESBuild extends Bundler_Using_ESBuild {
|
|
19
|
+
constructor(spec) {
|
|
20
|
+
super(spec);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// And the options....
|
|
24
|
+
|
|
25
|
+
// May want to have it do minification by default?
|
|
26
|
+
// Or even call a specific minifier class later on....
|
|
27
|
+
|
|
28
|
+
// Making classes with very specific responsibilities to do very specific things may help.
|
|
29
|
+
|
|
30
|
+
// Core_JS_Non_Minifying_Bundler_Using_ESBuild for example....
|
|
31
|
+
|
|
32
|
+
// Really specific class names for specific functionality to call reqlly quickly and interchange really quickly.
|
|
33
|
+
|
|
34
|
+
// Probably use the non-minifying bundler, and then use a minifier afterwards.
|
|
35
|
+
// And here the minifier is ESBuild, as is the bundler.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
bundle(str_js) {
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
const res_obs = obs(async(next, complete, error) => {
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
//console.log('Core_JS_Bundler_Using_ESBuild bundle js_file_path:', js_file_path);
|
|
51
|
+
|
|
52
|
+
// Looks like we need better linking build options....
|
|
53
|
+
|
|
54
|
+
let result = await esbuild.build({
|
|
55
|
+
stdin: {
|
|
56
|
+
contents: str_js,
|
|
57
|
+
|
|
58
|
+
// These are all optional:
|
|
59
|
+
//resolveDir: './src',
|
|
60
|
+
//sourcefile: 'imaginary-file.js',
|
|
61
|
+
//loader: 'ts',
|
|
62
|
+
},
|
|
63
|
+
//bundle: true,
|
|
64
|
+
|
|
65
|
+
// Possibly no minification here....
|
|
66
|
+
// Want to use non-minified or only partially minified version to separate the JS and the CSS.
|
|
67
|
+
|
|
68
|
+
treeShaking: true,
|
|
69
|
+
minify: true,
|
|
70
|
+
|
|
71
|
+
//sourcemap: 'external',
|
|
72
|
+
write: false,
|
|
73
|
+
outdir: 'out',
|
|
74
|
+
})
|
|
75
|
+
//console.log('result.outputFiles:\n\n');
|
|
76
|
+
for (let out of result.outputFiles) {
|
|
77
|
+
//console.log('out.path, out.contents, out.hash, out.text', out.path, out.contents, out.hash, out.text)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
console.log('result.outputFiles.length', result.outputFiles.length);
|
|
81
|
+
|
|
82
|
+
//console.trace();
|
|
83
|
+
//throw 'stop';
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if (result.outputFiles.length === 1) {
|
|
87
|
+
|
|
88
|
+
const output_file = result.outputFiles[0];
|
|
89
|
+
|
|
90
|
+
//console.log('output_file', output_file);
|
|
91
|
+
|
|
92
|
+
console.log('output_file.text.length', output_file.text.length);
|
|
93
|
+
//console.log('output_file.text', output_file.text);
|
|
94
|
+
|
|
95
|
+
console.log('Object.keys(output_file)', Object.keys(output_file));
|
|
96
|
+
|
|
97
|
+
// The Bundle is a subclass of Collection.
|
|
98
|
+
// Maybe its better to make it an Object class that assigns all properties from spec.
|
|
99
|
+
|
|
100
|
+
// May be much simpler and more flexible for the moment.
|
|
101
|
+
// Or an array (or collection) of BundleItem instances???
|
|
102
|
+
|
|
103
|
+
// Maybe don't have the Bundle extend Collection?
|
|
104
|
+
// Maybe overhaul Collection?
|
|
105
|
+
|
|
106
|
+
// Or use Collection and possibly get onto improving it.
|
|
107
|
+
// Need to be careful as Collection is integral to Controls.
|
|
108
|
+
|
|
109
|
+
// The Bundle should have items, like a collection.
|
|
110
|
+
// Maybe indexed by paths???
|
|
111
|
+
|
|
112
|
+
const res_bundle = new Bundle();
|
|
113
|
+
|
|
114
|
+
// Really flexible Bundle_Item perhaps....?
|
|
115
|
+
// The Bundle_Item will need to be able to represent data in different stages of preparation.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
// Just the text?
|
|
119
|
+
const o_bundle_item = {
|
|
120
|
+
type: 'JavaScript',
|
|
121
|
+
extension: 'js',
|
|
122
|
+
text: output_file.text
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
res_bundle.push(o_bundle_item);
|
|
126
|
+
|
|
127
|
+
next(res_bundle);
|
|
128
|
+
complete();
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
// Spec_Property_Assigner class???
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
// Think we do have the (full?) output here.
|
|
141
|
+
|
|
142
|
+
// prob leave out the hash???
|
|
143
|
+
|
|
144
|
+
//console.log('output_file.contents', output_file.contents);
|
|
145
|
+
|
|
146
|
+
//const
|
|
147
|
+
|
|
148
|
+
// Bundle_Result or Bundle class?
|
|
149
|
+
|
|
150
|
+
// always have Bundlers return a Bundle?
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
//console.trace();
|
|
160
|
+
//throw 'NYI';
|
|
161
|
+
|
|
162
|
+
} else {
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
console.trace();
|
|
166
|
+
throw 'NYI';
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
// The core bundler....
|
|
172
|
+
// Maybe later even use a Static_Response_Preparer???
|
|
173
|
+
// And have the relevant Publisher use it?
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
});
|
|
181
|
+
return res_obs;
|
|
182
|
+
|
|
183
|
+
// The bundle result should have a few things, makes sense to make it an object or class, not too complicated.
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
module.exports = Core_JS_Single_File_Minifying_Bundler_Using_ESBuild;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// Could split the CSS from JS here.
|
|
4
|
+
// Extractors are a different thing to bundlers.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// Probably better to remove this / use the specific extractor that's named / available / gets used.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const {bundle_css_from_js_str} = require('../../css-bundler');
|
|
15
|
+
|
|
16
|
+
const {obs} = require('fnl');
|
|
17
|
+
|
|
18
|
+
const Core_JS_Non_Minifying_Bundler_Using_ESBuild = require('./Core_JS_Non_Minifying_Bundler_Using_ESBuild');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
// It is a Bundler though....
|
|
22
|
+
|
|
23
|
+
// Or not???
|
|
24
|
+
|
|
25
|
+
// And Extractor?
|
|
26
|
+
// Separator???
|
|
27
|
+
|
|
28
|
+
// An Extractor processor I think.
|
|
29
|
+
|
|
30
|
+
const Extractor = require('../../../extractors/Extractor');
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class _Old_CSS_Extractor extends Extractor {
|
|
34
|
+
|
|
35
|
+
// Maybe should use a reference to the file itself?
|
|
36
|
+
// Maybe needs to use jsdom even?
|
|
37
|
+
|
|
38
|
+
// Will first try with existing code and then see about optimisations.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
constructor(spec) {
|
|
44
|
+
super();
|
|
45
|
+
|
|
46
|
+
console.trace();
|
|
47
|
+
throw 'Deprecating this particular class, use other extractor classes in the extractors dir.'
|
|
48
|
+
|
|
49
|
+
this.core_js_non_minifying_bundler = new Core_JS_Non_Minifying_Bundler_Using_ESBuild();
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
separate_css_and_js(js_file_path) {
|
|
54
|
+
|
|
55
|
+
const {core_js_non_minifying_bundler} = this;
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
console.log('js_file_path', js_file_path);
|
|
59
|
+
|
|
60
|
+
const obs_res = obs(async(next, complete, error) => {
|
|
61
|
+
|
|
62
|
+
// Then we need to use the core js bundler....
|
|
63
|
+
|
|
64
|
+
const core_js_non_minifying_bundler_obs_res = core_js_non_minifying_bundler.bundle(js_file_path);
|
|
65
|
+
|
|
66
|
+
// Only one piece of data...?
|
|
67
|
+
|
|
68
|
+
const arr_no_minifying_bundler_data = [];
|
|
69
|
+
|
|
70
|
+
core_js_non_minifying_bundler_obs_res.on('next', data => {
|
|
71
|
+
|
|
72
|
+
//console.log('core js (non-minifying) bundler next event data:', data);
|
|
73
|
+
|
|
74
|
+
arr_no_minifying_bundler_data.push(data);
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
core_js_non_minifying_bundler_obs_res.on('complete', async() => {
|
|
82
|
+
// This overall function not yet complete though....
|
|
83
|
+
|
|
84
|
+
console.log('arr_no_minifying_bundler_data', arr_no_minifying_bundler_data);
|
|
85
|
+
|
|
86
|
+
// Then use that Bundle object....
|
|
87
|
+
// Should represent a single JS file I think.
|
|
88
|
+
|
|
89
|
+
// Have plenty of checks in these various classes, though keep the overall code simple, but the
|
|
90
|
+
// structure will be somewhat complex, like the inner working of the app which it represents.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if (arr_no_minifying_bundler_data.length === 1) {
|
|
94
|
+
const bundle_item = arr_no_minifying_bundler_data[0]._arr[0];
|
|
95
|
+
|
|
96
|
+
console.log('bundle_item', bundle_item);
|
|
97
|
+
|
|
98
|
+
if (bundle_item.type === 'JavaScript') {
|
|
99
|
+
|
|
100
|
+
const {text} = bundle_item;
|
|
101
|
+
|
|
102
|
+
// Then run it through the CSS extraction algorithm.
|
|
103
|
+
// Having that code in the relevant class would help.
|
|
104
|
+
|
|
105
|
+
console.log('pre extract css from bundled unminified js');
|
|
106
|
+
|
|
107
|
+
// Reimplementing it as an Extractor that uses ESBuild will / may help.
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
// Would be worth making an AST_Node version of this though, as that's what it uses.
|
|
111
|
+
// May well be possible / better to use other methods / regexes / parser and AST.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
const r1 = await bundle_css_from_js_str(text);
|
|
121
|
+
console.log('post extract css from bundled unminified js');
|
|
122
|
+
|
|
123
|
+
// That bundle algorithm is a little slow.
|
|
124
|
+
// It does work well though.
|
|
125
|
+
|
|
126
|
+
// Maybe using regexes on the JS would work better.
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
console.log('r1', r1);
|
|
130
|
+
|
|
131
|
+
console.trace();
|
|
132
|
+
throw 'NYI';
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
// Then run it through the CSS extractor function / class.
|
|
137
|
+
|
|
138
|
+
// Perhaps we should make and use an ESBuild specific CSS extractor???
|
|
139
|
+
// Should the current extractor function be too slow....
|
|
140
|
+
|
|
141
|
+
// Including the standard / default jsgui3 css as well....
|
|
142
|
+
// May be worth making more classes to do individual parts of it.
|
|
143
|
+
// And have overall bundling class(es) join them together with simple syntax using the relevant classes to do the job.
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// Worth making the code somewhat longwinded / complex if it makes it easy to follow
|
|
147
|
+
// Since it's doing some complex things (at least complex considering all eventual options) the structure
|
|
148
|
+
// representing that and being able to accommodate it will help.
|
|
149
|
+
|
|
150
|
+
// The Publisher should (probably) do the reference insertion.
|
|
151
|
+
// Though a JS_And_CSS_References_Inserter may be useful structurally to see what's going on.
|
|
152
|
+
// Would insert the references within the HTML JSGUI3 Control within the right place(s).
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
} else {
|
|
169
|
+
console.trace();
|
|
170
|
+
throw 'Unexpected bundle item type: ' + bundle_item.type;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
} else {
|
|
177
|
+
console.trace();
|
|
178
|
+
throw 'NYI';
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Then when it is complete...???
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
return obs_res;
|
|
195
|
+
|
|
196
|
+
/*
|
|
197
|
+
obs_res.on('next', data => {
|
|
198
|
+
console.log('data', data);
|
|
199
|
+
})
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
///const res_core_bundle =
|
|
204
|
+
|
|
205
|
+
// Maybe should compile / bundle the file with esbuild.
|
|
206
|
+
// Want it to look through all the CSS throughout JSGUI JS and include it in the CSS for the client.
|
|
207
|
+
// Should be very convenient for including CSS in the JS. Sensible defaults.
|
|
208
|
+
|
|
209
|
+
// ESBuild_Wrapper perhaps.
|
|
210
|
+
|
|
211
|
+
// Core_JS_Bundler_Using_ESBuild
|
|
212
|
+
|
|
213
|
+
// JS_Bundler_Using_ESBuild
|
|
214
|
+
|
|
215
|
+
// Make it async or observable....
|
|
216
|
+
|
|
217
|
+
// Observable may be the best thing to use, maybe will improve observable API, possibly specifying how it combines results.
|
|
218
|
+
|
|
219
|
+
// Looks like we first need to get the JS all as a bundle.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
module.exports = _Old_CSS_Extractor;
|