jsgui3-server 0.0.85 → 0.0.86

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,12 +36,152 @@ const Stream = require('stream');
34
36
 
35
37
 
36
38
 
37
- const bundle_css_from_js = (js_file_path, options = {}) => {
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
+ }
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
+
38
162
 
39
- return obs(async (next, complete, error) => {
40
163
 
41
- // Go through each file? Just the first?
42
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
+
43
185
  });
44
186
 
45
187
  }
@@ -52,5 +194,5 @@ class CSS_Bundler extends Bundler {
52
194
  }
53
195
  }
54
196
 
55
- CSS_Bundler.bundle_css_from_js = bundle_css_from_js;
197
+ CSS_Bundler.bundle_css_from_js_str = bundle_css_from_js_str;
56
198
  module.exports = CSS_Bundler;
@@ -130,9 +130,22 @@ const bundle_js = (js_file_path, options = {}, callback) => {
130
130
  let buf_js = Buffer.concat(buffers);
131
131
  let str_js = buf_js.toString();
132
132
 
133
+ next({
134
+ 'lang': 'JavaScript',
135
+ 'operation': 'bundle',
136
+ 'compress': false,
137
+ 'type': 'single-string',
138
+ 'value': str_js
139
+ });
140
+
133
141
  // full browserified (client) js app.
134
142
 
135
143
  let babel_option = options.babel
144
+
145
+
146
+ // could send str_js to a CSS extractor / bundler.
147
+
148
+
136
149
  //console.log('babel_option', babel_option);
137
150
  if (babel_option === 'es5') {
138
151
 
@@ -177,7 +190,6 @@ const bundle_js = (js_file_path, options = {}, callback) => {
177
190
  //plugins: ["minify-dead-code-elimination"]
178
191
  };
179
192
  if (options.include_sourcemaps) o_transform.sourceMaps = 'inline';
180
-
181
193
  let res_transform = babel.transform(str_js, o_transform);
182
194
  buf_js = Buffer.from(res_transform.code);
183
195
  } else {