jsgui3-server 0.0.84 → 0.0.87

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/bundle.js CHANGED
@@ -1,5 +1,13 @@
1
1
  // Could make this a Collection?
2
2
 
3
+ // jsgui3-bundle possibly?
4
+ // Could save the whole thing as a ZIP file, or in-memory buffer in ZIP format?
5
+
6
+
7
+
8
+
9
+
10
+
3
11
  const {Collection} = require('jsgui3-html');
4
12
 
5
13
  class Bundle extends Collection {
@@ -1,7 +1,7 @@
1
1
  const Bundler = require('./bundler');
2
2
  const Bundle = require('./bundle');
3
3
  const {obs, prom_or_cb} = require('fnl');
4
- const {tof} = require('jsgui3-html');
4
+ const {tof, each} = require('jsgui3-html');
5
5
  const fnlfs = require('fnlfs');
6
6
  const browserify = require('browserify');
7
7
  const babel = require('@babel/core');
@@ -10,6 +10,8 @@ const util = require('util');
10
10
  const Stream = require('stream');
11
11
  // Will put the JS together. Maybe images?
12
12
 
13
+ const JS_AST_Node = require('./../resources/jsbuilder/JS_AST/JS_AST_Node');
14
+
13
15
  // Will put the JS together. Maybe images?
14
16
  // Get everything ready to serve.
15
17
 
@@ -34,7 +36,155 @@ const Stream = require('stream');
34
36
 
35
37
 
36
38
 
39
+ const bundle_css_from_js_str = (js_str, options = {}) => {
40
+
41
+ console.log('js_str.length', js_str.length);
42
+ // Moving towards using observables as a matter of course for longer-running functions.
43
+
44
+ // Seems like this makes a settimeout as well???
45
+ return obs((next, complete, error) => {
46
+
47
+ console.log('js_str.length', js_str.length);
48
+
49
+ // Returning a Bundle object when done could be best...?
50
+
51
+ const spec = {
52
+ source: js_str
53
+ };
54
+
55
+ const js_ast_node = JS_AST_Node.from_spec(spec);
56
+
57
+ console.log('!!js_ast_node', !!js_ast_node);
58
+
59
+ console.log('Object.keys(js_ast_node)', Object.keys(js_ast_node));
60
+
61
+ // count all
62
+
63
+ //console.log('js_ast_node.query("count all")', js_ast_node.query("count all"));
64
+
65
+ console.log('js_ast_node.query.count.all.exe()', js_ast_node.query.count.all.exe());
66
+
67
+ // A filter iterate query....? filter_deep_iterate could work.
68
+ // but we are looking specifically for 'ClassName.css'
69
+ // .css property assignments.
70
+
71
+ const ae_nodes = [];
72
+
73
+
74
+ // Just assigning a template literal to .css?
75
+ const css_ae_nodes = [];
76
+
77
+ js_ast_node.deep_iterate(node => {
78
+ //console.log('node', node);
79
+ //console.log('Object.keys(node)', Object.keys(node));
80
+ //console.log('node.type_signature', node.type_signature);
81
+ //console.log('node.signature', node.signature);
82
+ //console.log('node.type', node.type);
83
+ //console.log('node.abbreviated_type', node.abbreviated_type);
84
+
85
+ if (node.type === 'AssignmentExpression') {
86
+ //return true;
87
+ ae_nodes.push(node);
88
+ //console.log('node.source', node.source);
89
+
90
+ //console.log('Object.keys(node)', Object.keys(node));
91
+
92
+ //console.log('node.child_nodes.length', node.child_nodes.length);
93
+
94
+ const [node_assigned_to, node_assigned] = node.child_nodes;
95
+ //console.log('node_assigned_to.source', node_assigned_to.source);
96
+ //console.log('node_assigned_to.type', node_assigned_to.type);
97
+ //console.log('node_assigned.type', node_assigned.type);
98
+
99
+ if (node_assigned.type === 'TemplateLiteral') {
100
+
101
+ if (node_assigned_to.type === 'MemberExpression') {
102
+
103
+ //console.log('node_assigned_to', node_assigned_to);
104
+
105
+ // the last ID being .css?
106
+ const last_me_child = node_assigned_to.child_nodes[node_assigned_to.child_nodes.length - 1];
107
+ //console.log('last_me_child', last_me_child);
108
+ //console.log('last_me_child.source', last_me_child.source);
109
+
110
+ if (last_me_child.source === 'css') {
111
+ css_ae_nodes.push(node);
112
+ }
113
+
114
+
115
+
116
+ // does it end '.css'?
117
+ // break it down further?
118
+
119
+ }
37
120
 
121
+ ///console.log('node.source', node.source);
122
+ //throw 'stop';
123
+
124
+ }
125
+
126
+ //console.log('');
127
+ // look at the left part...
128
+ }
129
+
130
+ //throw 'stop';
131
+ });
132
+ //console.log('ae_nodes', ae_nodes);
133
+ //console.log('ae_nodes.length', ae_nodes.length);
134
+ //console.log('css_ae_nodes.length', css_ae_nodes.length);
135
+
136
+ const arr_css = [];
137
+
138
+ if (css_ae_nodes.length > 0) {
139
+ //console.log('css_ae_nodes', css_ae_nodes);
140
+
141
+ each(css_ae_nodes, css_ae_node => {
142
+ //console.log('css_ae_node.source', css_ae_node.source);
143
+ const tl = css_ae_node.child_nodes[1].child_nodes[0];
144
+ //console.log('tl', tl);
145
+ console.log('tl.source', tl.source);
146
+ arr_css.push(tl.source);
147
+
148
+
149
+ })
150
+ }
151
+
152
+ if (arr_css.length > 0) {
153
+ const str_css = arr_css.join('\n');
154
+
155
+ complete(str_css);
156
+ } else {
157
+ complete();
158
+ }
159
+
160
+
161
+
162
+
163
+
164
+
165
+ // Can then do query to get all .css properties that are string templates.
166
+ // is it a property of a Class object?
167
+
168
+
169
+
170
+
171
+
172
+ // Need to get an AST from it....
173
+ // Or could simply search (regex?) for .css = `...`?
174
+
175
+
176
+
177
+
178
+ // Go through each file? Just the first?
179
+
180
+ // Or should the whole bundled (browserified) JS be consulted?
181
+
182
+ const [stop, pause, resume] = [() => {}, () => {}, () => {}];
183
+ return [stop, pause, resume];
184
+
185
+ });
186
+
187
+ }
38
188
 
39
189
 
40
190
 
@@ -44,5 +194,5 @@ class CSS_Bundler extends Bundler {
44
194
  }
45
195
  }
46
196
 
47
- //CSS_Bundler.bundle_css = bundle_css;
197
+ CSS_Bundler.bundle_css_from_js_str = bundle_css_from_js_str;
48
198
  module.exports = CSS_Bundler;
@@ -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
 
@@ -72,6 +80,8 @@ const bundle_js = (js_file_path, options = {}, callback) => {
72
80
  // are there any replacements to do?
73
81
  // options.replacements
74
82
 
83
+
84
+
75
85
  if (options.js_mode === 'debug') {
76
86
  options.include_sourcemaps = true;
77
87
  }
@@ -122,7 +132,22 @@ const bundle_js = (js_file_path, options = {}, callback) => {
122
132
  let buf_js = Buffer.concat(buffers);
123
133
  let str_js = buf_js.toString();
124
134
 
135
+ next({
136
+ 'lang': 'JavaScript',
137
+ 'operation': 'bundle',
138
+ 'compress': false,
139
+ 'type': 'single-string',
140
+ 'value': str_js
141
+ });
142
+
143
+ // full browserified (client) js app.
144
+
125
145
  let babel_option = options.babel
146
+
147
+
148
+ // could send str_js to a CSS extractor / bundler.
149
+
150
+
126
151
  //console.log('babel_option', babel_option);
127
152
  if (babel_option === 'es5') {
128
153
 
@@ -167,13 +192,11 @@ const bundle_js = (js_file_path, options = {}, callback) => {
167
192
  //plugins: ["minify-dead-code-elimination"]
168
193
  };
169
194
  if (options.include_sourcemaps) o_transform.sourceMaps = 'inline';
170
-
171
195
  let res_transform = babel.transform(str_js, o_transform);
172
196
  buf_js = Buffer.from(res_transform.code);
173
197
  } else {
174
198
  buf_js = Buffer.from(str_js);
175
199
  }
176
-
177
200
  complete(buf_js);
178
201
  })();
179
202