jsgui3-server 0.0.80 → 0.0.83

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/README.md +8 -1
  2. package/bundler/bundle.js +11 -0
  3. package/bundler/bundler.js +9 -0
  4. package/bundler/js-bundler.js +189 -0
  5. package/bundler/webpage-bundler.js +284 -0
  6. package/bundler/website-bundler.js +23 -0
  7. package/controls/README.md +8 -0
  8. package/controls/page/admin.js +75 -0
  9. package/controls/panel/admin.js +11 -0
  10. package/examples/controls/html-server-combo-box.js +5 -5
  11. package/examples/html-server.js +3 -0
  12. package/examples/square_box.js +35 -0
  13. package/examples/square_box_client.js +91 -0
  14. package/module.js +8 -0
  15. package/{single-control-server.js → old/_single-control-server.js} +157 -96
  16. package/old/single-control-server.js +108 -158
  17. package/{single-page-app.js → old/single-page-app.js} +2 -0
  18. package/{examples/demos → old}/square_box.js +1 -1
  19. package/package.json +10 -9
  20. package/page-context.js +1 -1
  21. package/publishing/http-css-publisher.js +0 -0
  22. package/publishing/{function-publisher.js → http-function-publisher.js} +12 -2
  23. package/publishing/http-html-page-publisher.js +5 -0
  24. package/publishing/http-html-publisher.js +25 -0
  25. package/publishing/http-jpeg-publisher.js +0 -0
  26. package/publishing/http-js-publisher.js +25 -0
  27. package/publishing/{observable-publisher.js → http-observable-publisher.js} +12 -6
  28. package/publishing/http-png-publisher.js +0 -0
  29. package/publishing/http-publisher.js +52 -0
  30. package/publishing/{resource-publisher.js → http-resource-publisher.js} +20 -1
  31. package/publishing/http-svg-publisher.js +0 -0
  32. package/publishing/http-webpage-publisher.js +112 -0
  33. package/publishing/http-website-publisher.js +262 -0
  34. package/publishing/notes.md +1 -0
  35. package/resources/README.md +16 -0
  36. package/resources/_old_website-resource.js +507 -0
  37. package/resources/compile/server-resource-compilation.js +41 -0
  38. package/resources/data-resource.js +14 -0
  39. package/resources/fs-resource.js +2 -4
  40. package/resources/jsbuilder/test/test_ast_node.js +0 -63
  41. package/resources/jsbuilder/test/test_project.js +1 -0
  42. package/resources/notes.txt +11 -0
  43. package/resources/server-installed-tools.js +29 -0
  44. package/resources/server-resource-pool.js +1 -44
  45. package/resources/website-css-resource.js +1 -1
  46. package/resources/website-javascript-resource.js +165 -34
  47. package/resources/website-resource.js +62 -294
  48. package/resources/website-static-html-resource.js +19 -16
  49. package/resources/website-template-html-resource.js +231 -0
  50. package/roadmap.md +46 -0
  51. package/server.js +711 -18
  52. package/website/webpage.js +169 -0
  53. package/website/website-group.js +16 -0
  54. package/website/website.js +227 -0
@@ -0,0 +1,231 @@
1
+ var path = require('path'), fs = require('fs'),
2
+ url = require('url'), jsgui = require('jsgui3-html'), os = require('os'), http = require('http'), libUrl = require('url'),
3
+ Resource = jsgui.Resource,
4
+ Cookies = require('cookies'), fs2 = require('../fs2');
5
+
6
+ var stringify = jsgui.stringify, each = jsgui.each, arrayify = jsgui.arrayify, tof = jsgui.tof;
7
+ var filter_map_by_regex = jsgui.filter_map_by_regex;
8
+ var Class = jsgui.Class, Data_Object = jsgui.Data_Object, Enhanced_Data_Object = jsgui.Enhanced_Data_Object;
9
+ var fp = jsgui.fp, is_defined = jsgui.is_defined;
10
+ var Collection = jsgui.Collection;
11
+
12
+ // Extends AutoStart_Resource?
13
+ // May need to change around a fair few references to make it workable.
14
+ // May need some more complicated logic to change it to the path for service.
15
+
16
+ // Maybe this will be / need a Compiler.
17
+
18
+ // website-html-resource....
19
+ // may be useful to have / use a Resource for the HTML servinh=g / compilation.
20
+
21
+ // Consider the server as an HTML compiler? Or a more complex compiler?
22
+
23
+ // Seems more like loading server-side compilers is the way.
24
+ // Load them into jsgui.
25
+
26
+ // lang.load_compiler
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+ var serve_fn_html_template_from_disk = function(filePath, fn_template, obj_data, response) {
35
+
36
+ // serve templated file as html...
37
+
38
+ fs2.load_file_as_string(filePath, function (err, data) {
39
+
40
+
41
+ if (err) {
42
+ throw err;
43
+ } else {
44
+ const templated = fn_template(data, obj_data);
45
+
46
+
47
+
48
+
49
+ //var servableJs = updateReferencesForServing(data);
50
+ response.writeHead(200, {'Content-Type': 'text/html'});
51
+ response.end(templated);
52
+ }
53
+ });
54
+ }
55
+
56
+
57
+ // File_Server_Resource?
58
+ // So the resource has code to route to the file and then serve it.
59
+
60
+ // Also a Templated_HTML resource?
61
+ // Connects to HTML_Template
62
+ // Connects to Data_Resource
63
+ // Populates the HTML_Template data from the Data_Resource
64
+
65
+ // HTML_Template being a Data_Transformation / Data_Transformation_Resource / Transformation_Resource
66
+ // Codecs could be another type of Transformation_Resource
67
+
68
+ // Transformation Resource could / should appear in jsgui3-client. Makes sense on the client too.
69
+
70
+ // Separate loading of transformation resource, data resource, and template (resource)
71
+ // The transformation resource can itself load / be provided with the data resource and template resource.
72
+
73
+ // jsx processing may be the best way (by far)?
74
+
75
+ // or jsui templates?
76
+ // jsx may seem / be easiest at this stage for long term expansion and integration.
77
+
78
+
79
+
80
+ class Site_Template_HTML extends Resource {
81
+
82
+ constructor(spec) {
83
+ super(spec);
84
+
85
+ this.meta.set('custom_paths', new Data_Object({}));
86
+ // Those are custom file paths.
87
+
88
+ // could have a collection of directories, indexed by name, that get served.
89
+
90
+ // Index the collection by string value?
91
+ this.meta.set('served_directories', new Collection({'index_by': 'name'}));
92
+ }
93
+ 'start'(callback) {
94
+ callback(null, true);
95
+ }
96
+ 'set_custom_path'(url, file_path) {
97
+ // But change the URL to have a smiley face instead of fullstops
98
+ //console.log('url', url);
99
+ var escaped_url = url.replace(/\./g, '☺');
100
+ //console.log('escaped_url', escaped_url);
101
+
102
+ //this.meta.set('custom_paths.' + escaped_url, file_path);
103
+ var custom_paths = this.meta.get('custom_paths');
104
+ //console.log('custom_paths', custom_paths);
105
+ custom_paths.set(escaped_url, file_path);
106
+
107
+ }
108
+ 'serve_directory'(path) {
109
+ // Serves that directory, as any files given in that directory can be served from /js
110
+ var served_directories = this.meta.get('served_directories');
111
+ //console.log('served_directories ' + stringify(served_directories));
112
+ //served_directories.push(path);
113
+ served_directories.push({
114
+ 'name': path
115
+ });
116
+ //console.log('served_directories ' + stringify(served_directories));
117
+ //console.log('path ' + path);
118
+
119
+ //throw 'stop';
120
+
121
+ }
122
+ 'process'(req, res) {
123
+ //console.log('Site_Static_HTML processing');
124
+ var remoteAddress = req.connection.remoteAddress;
125
+ var custom_paths = this.custom_paths;
126
+ var rurl = req.url;
127
+ var pool = this.pool;
128
+ // should have a bunch of resources from the pool.
129
+ //var pool_resources = pool.resources();
130
+ //console.log('pool_resources ' + stringify(pool_resources));
131
+
132
+ var url_parts = url.parse(req.url, true);
133
+ //console.log('url_parts ' + stringify(url_parts));
134
+ var splitPath = url_parts.path.substr(1).split('/');
135
+ //console.log('resource site css splitPath ' + stringify(splitPath));
136
+
137
+ if (rurl.substr(0, 1) == '/') rurl = rurl.substr(1);
138
+ rurl = rurl.replace(/\./g, '☺');
139
+ //console.log('rurl ' + rurl);
140
+
141
+ if (rurl == '') rurl = '/';
142
+ var custom_response_entry = custom_paths.get(rurl);
143
+ //console.log('Static HTML Resource process url', req.url);
144
+
145
+
146
+ //console.log('custom_response_entry ' + stringify(custom_response_entry));
147
+
148
+ if (custom_response_entry) {
149
+ var tcr = tof(custom_response_entry);
150
+ //console.log('tcr ' + tcr);
151
+ if (tcr == 'data_value') {
152
+ var val = custom_response_entry.value();
153
+ //console.log('val ' + val);
154
+ var tval = tof(val);
155
+ if (tval === 'string') {
156
+ // then it should be a local file path, serve it.
157
+ // need to specify a template resource / algorithm.
158
+
159
+ serve_html_file_from_disk(val, res);
160
+ }
161
+ }
162
+ //throw 'stop';
163
+ } else {
164
+ //console.log('splitPath', splitPath);
165
+ //console.log('splitPath.length', splitPath.length);
166
+
167
+ if (splitPath.length > 0) {
168
+
169
+ // Can check for /js folder.
170
+ // There will be some fixed resources for the site.
171
+ // They will be served by Resource objects.
172
+ // There may be some overlap of resources, with there being some very fixed purpose
173
+ // specific resources that could duplicate some features of the more general ones.
174
+ // Eventually, some of the code from the more specific resources will be
175
+ // replacable with code from the more general ones.
176
+
177
+ // Site_JavaScript resource
178
+ // Will serve JavaScript files needed for the site.
179
+ // Could become more advanced at some points, serving particular builds.
180
+
181
+ if (splitPath.length == 1) {
182
+ if (splitPath[0] == '') {
183
+ // Serve the default page.
184
+ // serve index.html
185
+ //serve_html_file_from_disk('./index.html', res);
186
+ serve_html_file_from_disk('index.html', res);
187
+
188
+
189
+
190
+
191
+ }
192
+ } else {
193
+ if (splitPath[0] == 'html') {
194
+ //var sjs = pool.get_resource('Site JavaScript');
195
+ //console.log('sjs ' + sjs);
196
+
197
+ //throw 'stop';
198
+
199
+ // determine the name of the file to serve, serve that file
200
+ // Could use some more general kind of file server.
201
+
202
+ if (splitPath.length > 1) {
203
+ if (splitPath.length == 2) {
204
+ var fileName = splitPath[1];
205
+ //console.log('url_parts.path ' + url_parts.path);
206
+ var filePath = url_parts.path.substr(1);
207
+ //console.log('module.uri ' + module.uri);
208
+
209
+ // No, need the current module's relative path....
210
+
211
+ //var val2 = path.dirname(module.uri);
212
+ //console.log('val2 ' + val2);
213
+ //throw '9) stop';
214
+
215
+ //var diskPath = val2 + '/../css/' + fileName;
216
+ var diskPath = '../../ws/css/' + fileName;
217
+
218
+ serve_html_file_from_disk(diskPath, res);
219
+ } else {
220
+ if (splitPath.length == 3) {
221
+
222
+ }
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }
230
+ }
231
+ module.exports = Site_Template_HTML;
package/roadmap.md ADDED
@@ -0,0 +1,46 @@
1
+ Make it work as a stand-alone application.
2
+ Start it, get it serving a directory easily.
3
+ Start it, access it through admin pages.
4
+ Admin interface showing by default.
5
+
6
+ Admin web interfaces seem like a piece of progress that the groundwork is in place for.
7
+
8
+ node server start 80
9
+ node server stop 80
10
+
11
+ Command line interfaces to interact with a jsgui server
12
+
13
+ node server modify 80 upload \[path\] as index.html
14
+ or similar?
15
+
16
+ node server get 80
17
+
18
+ node server 80
19
+ starts it
20
+ shows a cli for it...
21
+ a cli app?
22
+ a terminal app?
23
+
24
+
25
+ Server will start with a default holding page.
26
+ Server will be in a very simple configuration.
27
+ Single html response for all requests...?
28
+
29
+
30
+ Server with admin interface available, and admin interface allowing it to bundle / serve selected content.
31
+ Also want to make use of simple and stable API.
32
+
33
+ Want to make the server admin page(s) with panels.
34
+ Would be a nice place for a decent web ui.
35
+
36
+ More advanced and user-friendly functionality out-of-the-box.
37
+ A file manager interface would be cool.
38
+ Maybe would need to use file system resource
39
+ Could work on remote file system too.
40
+
41
+
42
+
43
+
44
+
45
+
46
+