vanilla-jet 1.1.2 → 1.1.3
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/.github/workflows/deploy.yml +1 -1
- package/.scripts/generate_packages_json.js +4 -4
- package/framework/dipper.js +91 -58
- package/framework/functions.js +85 -90
- package/framework/request.js +8 -13
- package/framework/response.js +20 -14
- package/framework/router.js +46 -25
- package/framework/server.js +15 -16
- package/package.json +9 -9
|
@@ -8,10 +8,10 @@ async function main() {
|
|
|
8
8
|
// -- Create the object to be write in the file
|
|
9
9
|
const json = {
|
|
10
10
|
coreDependencies: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
"modernizr": "//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js",
|
|
12
|
+
"respond": "//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js",
|
|
13
|
+
"jquery": "//cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js",
|
|
14
|
+
"underscore": "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-min.js"
|
|
15
15
|
},
|
|
16
16
|
dependencies: {},
|
|
17
17
|
styles: {},
|
package/framework/dipper.js
CHANGED
|
@@ -32,70 +32,90 @@ function Dipper(options, shared) {
|
|
|
32
32
|
this.anims = [];
|
|
33
33
|
this.enqueued_scripts = [];
|
|
34
34
|
this.enqueued_styles = [];
|
|
35
|
+
|
|
36
|
+
// -- Base scripts
|
|
37
|
+
let vanillaJetJson = this.openJsonFile('vanillaJet.package.json');
|
|
38
|
+
if (vanillaJetJson) {
|
|
39
|
+
let coreDependencies = vanillaJetJson.coreDependencies;
|
|
40
|
+
for (let key in coreDependencies) {
|
|
41
|
+
this.registerScript(key, coreDependencies[key]);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
Dipper.prototype.getPageTitle = function() {
|
|
38
|
-
|
|
47
|
+
|
|
48
|
+
var obj = this;
|
|
39
49
|
return obj.site_title;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
Dipper.prototype.getSiteTitle = function() {
|
|
43
|
-
|
|
53
|
+
|
|
54
|
+
var obj = this;
|
|
44
55
|
return obj.page_title;
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
Dipper.prototype.getDescription = function() {
|
|
48
|
-
|
|
59
|
+
|
|
60
|
+
var obj = this;
|
|
49
61
|
return obj.description;
|
|
50
62
|
}
|
|
51
63
|
|
|
52
64
|
Dipper.prototype.getFbAppId = function() {
|
|
53
|
-
|
|
65
|
+
|
|
66
|
+
var obj = this;
|
|
54
67
|
return obj.fbAppId;
|
|
55
68
|
}
|
|
56
69
|
|
|
57
70
|
Dipper.prototype.addMeta = function(name, content, attribute) {
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
var obj = this;
|
|
60
73
|
attribute = attribute || 'name';
|
|
61
74
|
content = content || '';
|
|
62
|
-
|
|
75
|
+
var meta = [];
|
|
76
|
+
meta['name'] = name;
|
|
77
|
+
meta['content'] = content;
|
|
78
|
+
meta['attribute'] = attribute;
|
|
63
79
|
obj.metas[name] = meta;
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
Dipper.prototype.metaTags = function() {
|
|
67
83
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
var obj = this;
|
|
85
|
+
var _ = require('underscore');
|
|
86
|
+
var stringMeta = '';
|
|
71
87
|
|
|
72
|
-
|
|
88
|
+
var keys = Object.keys(obj.metas);
|
|
73
89
|
_.each(keys, function(key) {
|
|
74
90
|
|
|
75
|
-
|
|
91
|
+
var name = obj.metas[key]['name'],
|
|
76
92
|
content = obj.metas[key]['content'],
|
|
77
93
|
attribute = obj.metas[key]['attribute'];
|
|
78
94
|
|
|
79
95
|
stringMeta += obj.metas[key]['content'] != '' ?
|
|
80
|
-
'<meta ' + attribute + '
|
|
81
|
-
'<meta ' + attribute + '
|
|
96
|
+
'<meta ' + attribute + '=\"' + name + '\" content=\"' + content + '\">\n\t' :
|
|
97
|
+
'<meta ' + attribute + '=\"' + name + '\">\n\t';
|
|
82
98
|
});
|
|
83
99
|
return stringMeta;
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
Dipper.prototype.img = function(filename) {
|
|
87
103
|
|
|
88
|
-
|
|
89
|
-
|
|
104
|
+
var obj = this,
|
|
105
|
+
dir = this.getDir('images', false);
|
|
106
|
+
ret = this.urlTo(dir + filename);
|
|
90
107
|
return ret;
|
|
91
108
|
}
|
|
92
109
|
|
|
93
110
|
Dipper.prototype.script = function(filename) {
|
|
94
111
|
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
var obj = this,
|
|
113
|
+
dir = this.getDir('scripts', false);
|
|
114
|
+
|
|
115
|
+
var filenameParts = filename.split('.'),
|
|
97
116
|
length = filenameParts.length;
|
|
98
117
|
if (length > 0) {
|
|
118
|
+
|
|
99
119
|
let position = length - 1;
|
|
100
120
|
filenameParts[position] = 'min.' + filenameParts[position];
|
|
101
121
|
filename = filenameParts.join('.');
|
|
@@ -105,22 +125,26 @@ Dipper.prototype.script = function(filename) {
|
|
|
105
125
|
|
|
106
126
|
Dipper.prototype.style = function(filename) {
|
|
107
127
|
|
|
108
|
-
|
|
109
|
-
|
|
128
|
+
var obj = this,
|
|
129
|
+
dir = this.getDir('styles', false),
|
|
130
|
+
ret = this.urlTo(dir + filename);
|
|
110
131
|
return ret;
|
|
111
132
|
}
|
|
112
133
|
|
|
113
134
|
Dipper.prototype.pdf = function(filename) {
|
|
114
135
|
|
|
115
|
-
|
|
116
|
-
|
|
136
|
+
var obj = this,
|
|
137
|
+
dir = '/assets/pdf/'
|
|
138
|
+
ret = this.urlTo(dir + filename);
|
|
139
|
+
//console.log(ret);
|
|
117
140
|
return ret;
|
|
118
141
|
}
|
|
119
142
|
|
|
120
143
|
Dipper.prototype.getDir = function(dir, full) {
|
|
121
144
|
|
|
122
|
-
|
|
123
|
-
|
|
145
|
+
var obj = this,
|
|
146
|
+
full = (full == undefined) ? true : full;
|
|
147
|
+
|
|
124
148
|
if ( obj.dirs[dir] != undefined ) {
|
|
125
149
|
return (full == true ? obj.baseDir(obj.dirs[dir]) : obj.dirs[dir]);
|
|
126
150
|
}
|
|
@@ -129,14 +153,16 @@ Dipper.prototype.getDir = function(dir, full) {
|
|
|
129
153
|
|
|
130
154
|
Dipper.prototype.baseDir = function(path) {
|
|
131
155
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
156
|
+
var obj = this,
|
|
157
|
+
path = path || '',
|
|
158
|
+
ret = obj.base_dir + path;
|
|
159
|
+
return ret;
|
|
135
160
|
}
|
|
136
161
|
|
|
137
162
|
Dipper.prototype.isSecureRequest = function() {
|
|
138
163
|
|
|
139
|
-
|
|
164
|
+
var obj = this;
|
|
165
|
+
// Cheking for http or https
|
|
140
166
|
if (/^((http):\/\/)/.test(obj.options.site_url) || /^((localhost))/.test(obj.options.site_url)) {
|
|
141
167
|
return false;
|
|
142
168
|
} else if (/^((https):\/\/)/.test(obj.options.site_url)) {
|
|
@@ -146,8 +172,11 @@ Dipper.prototype.isSecureRequest = function() {
|
|
|
146
172
|
|
|
147
173
|
Dipper.prototype.urlTo = function(route, protocol) {
|
|
148
174
|
|
|
149
|
-
|
|
150
|
-
|
|
175
|
+
var obj = this,
|
|
176
|
+
protocol = protocol || undefined,
|
|
177
|
+
url = obj.base_url + route;
|
|
178
|
+
//url = obj.baseUrl(route, protocol);
|
|
179
|
+
return url;
|
|
151
180
|
}
|
|
152
181
|
|
|
153
182
|
Dipper.prototype.registerStyle = function(
|
|
@@ -155,7 +184,7 @@ Dipper.prototype.registerStyle = function(
|
|
|
155
184
|
cdn = false, async = false,
|
|
156
185
|
origin = '', integrity = '') {
|
|
157
186
|
|
|
158
|
-
|
|
187
|
+
var obj = this;
|
|
159
188
|
obj.styles[name] = {
|
|
160
189
|
'resource' : url,
|
|
161
190
|
'requires' : requires,
|
|
@@ -171,7 +200,7 @@ Dipper.prototype.registerScript = function(
|
|
|
171
200
|
cdn = false, async = false, defer = false,
|
|
172
201
|
origin = '', integrity = '') {
|
|
173
202
|
|
|
174
|
-
|
|
203
|
+
var obj = this;
|
|
175
204
|
obj.scripts[name] = {
|
|
176
205
|
|
|
177
206
|
'resource' : url,
|
|
@@ -195,13 +224,13 @@ Dipper.prototype.registerAnimation = function(name, url) {
|
|
|
195
224
|
|
|
196
225
|
Dipper.prototype.enqueueStyle = function(name) {
|
|
197
226
|
|
|
198
|
-
|
|
227
|
+
var obj = this,
|
|
199
228
|
_ = require('underscore');
|
|
200
229
|
|
|
201
230
|
if (obj.styles[name] != undefined) {
|
|
202
231
|
if (obj.enqueued_styles[name] == undefined) {
|
|
203
232
|
|
|
204
|
-
|
|
233
|
+
var item = obj.styles[name];
|
|
205
234
|
_.each(item.requires, function(dep) {
|
|
206
235
|
obj.enqueueStyle(dep);
|
|
207
236
|
});
|
|
@@ -212,13 +241,13 @@ Dipper.prototype.enqueueStyle = function(name) {
|
|
|
212
241
|
|
|
213
242
|
Dipper.prototype.enqueueScript = function(name) {
|
|
214
243
|
|
|
215
|
-
|
|
244
|
+
var obj = this,
|
|
216
245
|
_ = require('underscore');
|
|
217
246
|
|
|
218
247
|
if (obj.scripts[name] != undefined) {
|
|
219
248
|
if (obj.enqueued_scripts[name] == undefined) {
|
|
220
249
|
|
|
221
|
-
|
|
250
|
+
var item = obj.scripts[name];
|
|
222
251
|
_.each(item.requires, function(dep) {
|
|
223
252
|
obj.enqueueScript(dep);
|
|
224
253
|
});
|
|
@@ -229,13 +258,13 @@ Dipper.prototype.enqueueScript = function(name) {
|
|
|
229
258
|
|
|
230
259
|
Dipper.prototype.dequeueStyle = function(name, dependencies) {
|
|
231
260
|
|
|
232
|
-
|
|
261
|
+
var obj = this,
|
|
233
262
|
_ = require('underscore')
|
|
234
263
|
dependencies = (dependencies == undefined) ? false : dependencies;
|
|
235
264
|
|
|
236
265
|
if (obj.styles[name] != undefined) {
|
|
237
266
|
if (obj.enqueued_styles[name] != undefined) {
|
|
238
|
-
|
|
267
|
+
var item = obj.styles[name];
|
|
239
268
|
if (dependencies != undefined) {
|
|
240
269
|
_.each(item.require, function(dep) {
|
|
241
270
|
obj.dequeueStyle(dep);
|
|
@@ -248,13 +277,13 @@ Dipper.prototype.dequeueStyle = function(name, dependencies) {
|
|
|
248
277
|
|
|
249
278
|
Dipper.prototype.dequeueScript = function(name, dependencies) {
|
|
250
279
|
|
|
251
|
-
|
|
280
|
+
var obj = this,
|
|
252
281
|
_ = require('underscore')
|
|
253
282
|
dependencies = (dependencies == undefined) ? false : dependencies;
|
|
254
283
|
|
|
255
284
|
if (obj.scripts[name] != undefined) {
|
|
256
285
|
if (obj.enqueued_scripts[name] != undefined) {
|
|
257
|
-
|
|
286
|
+
var item = obj.scripts[name];
|
|
258
287
|
if (dependencies != undefined) {
|
|
259
288
|
_.each(item.require, function(dep) {
|
|
260
289
|
obj.dequeueScript(dep);
|
|
@@ -267,23 +296,23 @@ Dipper.prototype.dequeueScript = function(name, dependencies) {
|
|
|
267
296
|
|
|
268
297
|
Dipper.prototype.includeStyle = function(style) {
|
|
269
298
|
|
|
270
|
-
|
|
299
|
+
var obj = this;
|
|
271
300
|
if (obj.styles[style]) {
|
|
272
301
|
|
|
273
|
-
|
|
302
|
+
var item = obj.styles[style],
|
|
274
303
|
output = '',
|
|
275
304
|
//type = item['cdn'] ? "" : 'type=\"text/javascript\"',
|
|
276
305
|
resource = item['resource'],
|
|
277
306
|
isAsync = item['async'] ? 'preload' : 'stylesheet',
|
|
278
|
-
origin = item['origin'] != '' ? ' crossorigin
|
|
279
|
-
integrity = item['integrity'] != '' ? ' integrity
|
|
307
|
+
origin = item['origin'] != '' ? ' crossorigin=\"' + item['origin'] + '\"' : '',
|
|
308
|
+
integrity = item['integrity'] != '' ? ' integrity=\"' + item['integrity'] + '\"' : '';
|
|
280
309
|
|
|
281
310
|
if (item['async']) {
|
|
282
311
|
|
|
283
|
-
|
|
284
|
-
output = '<link rel
|
|
312
|
+
var a = " as=\"style\" onload=\"this.onload=null; this.rel='stylesheet'\"";
|
|
313
|
+
output = '<link rel=\"' + isAsync + '\" type=\"text/css\" href=\"' + resource + '\"' + a + integrity + origin + ">";
|
|
285
314
|
} else {
|
|
286
|
-
output = '<link rel
|
|
315
|
+
output = '<link rel=\"' + isAsync + '\" type=\"text/css\" href=\"' + resource + '\"' + integrity + origin + ">";
|
|
287
316
|
}
|
|
288
317
|
return output + "\n";
|
|
289
318
|
}
|
|
@@ -291,19 +320,20 @@ Dipper.prototype.includeStyle = function(style) {
|
|
|
291
320
|
|
|
292
321
|
Dipper.prototype.includeScript = function(script) {
|
|
293
322
|
|
|
294
|
-
|
|
323
|
+
var obj = this;
|
|
295
324
|
if (obj.scripts[script]) {
|
|
296
325
|
|
|
297
|
-
|
|
326
|
+
var item = obj.scripts[script],
|
|
298
327
|
output = '',
|
|
299
328
|
//type = item['cdn'] ? "" : 'type=\"text/javascript\"',
|
|
300
329
|
resource = item['resource'],
|
|
301
330
|
isAsync = item['async'] ? ' async' : '',
|
|
302
331
|
defer = item['defer'] ? ' defer' : '',
|
|
303
|
-
origin = item['origin'] != '' ? ' crossorigin
|
|
304
|
-
integrity = item['integrity'] != '' ? ' integrity
|
|
332
|
+
origin = item['origin'] != '' ? ' crossorigin=\"' + item['origin'] + '\"' : '',
|
|
333
|
+
integrity = item['integrity'] != '' ? ' integrity=\"' + item['integrity'] + '\"' : '';
|
|
305
334
|
|
|
306
|
-
output = '<script src
|
|
335
|
+
output = '<script src=\"' + resource + '\"' + defer + isAsync + integrity + origin + '></script>';
|
|
336
|
+
//console.log(output);
|
|
307
337
|
return output + "\n";
|
|
308
338
|
}
|
|
309
339
|
}
|
|
@@ -327,22 +357,25 @@ Dipper.prototype.includeAnimation = function(anim) {
|
|
|
327
357
|
|
|
328
358
|
Dipper.prototype.includeStyles = function() {
|
|
329
359
|
|
|
330
|
-
|
|
331
|
-
_ = require('underscore')
|
|
332
|
-
|
|
360
|
+
var obj = this,
|
|
361
|
+
_ = require('underscore')
|
|
362
|
+
stylesString = '',
|
|
333
363
|
keys = Object.keys(obj.enqueued_styles);
|
|
334
364
|
|
|
335
365
|
_.each(keys, function(style) {
|
|
336
366
|
stylesString += obj.includeStyle(style);
|
|
337
367
|
});
|
|
368
|
+
|
|
369
|
+
//console.log(stylesString);
|
|
370
|
+
//$site->executeHook('core.includeStyles');
|
|
338
371
|
return stylesString;
|
|
339
372
|
}
|
|
340
373
|
|
|
341
374
|
Dipper.prototype.includeScripts = function () {
|
|
342
375
|
|
|
343
|
-
|
|
376
|
+
var obj = this,
|
|
344
377
|
_ = require('underscore')
|
|
345
|
-
|
|
378
|
+
scriptsString = '',
|
|
346
379
|
keys = Object.keys(obj.enqueued_scripts);
|
|
347
380
|
|
|
348
381
|
_.each(keys, function(script) {
|
|
@@ -367,9 +400,9 @@ Dipper.prototype.includeAnimations = function() {
|
|
|
367
400
|
|
|
368
401
|
Dipper.prototype.includeManifest = function() {
|
|
369
402
|
|
|
370
|
-
|
|
403
|
+
var obj = this,
|
|
371
404
|
url = obj.urlTo('/public/manifest.json'),
|
|
372
|
-
tagString = '<link rel
|
|
405
|
+
tagString = '<link rel=\"manifest\" href=\"' + url + '\">';
|
|
373
406
|
return tagString;
|
|
374
407
|
}
|
|
375
408
|
|
package/framework/functions.js
CHANGED
|
@@ -2,103 +2,98 @@ class Functions {
|
|
|
2
2
|
|
|
3
3
|
constructor() {
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
// Dipper
|
|
6
|
+
dipper = global.dipper;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
// -- Hydrate
|
|
9
|
+
Functions.hydrate(dipper);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
static hydrate(dipper) {
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
14
|
+
// -- Get vanillaJet.package.json
|
|
15
|
+
let json = dipper.openJsonFile('vanillaJet.package.json');
|
|
16
|
+
|
|
17
|
+
// -- Google Fonts
|
|
18
|
+
if (json.fonts && json.fonts.length > 0) {
|
|
19
|
+
dipper.registerStyle('google-fonts', dipper.get_google_fonts(json.fonts));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// - Styles
|
|
23
|
+
let stylesKeys = [];
|
|
24
|
+
if (json.styles) {
|
|
25
|
+
|
|
26
|
+
// -- Gettign the keys
|
|
27
|
+
stylesKeys = Object.keys(json.styles);
|
|
28
|
+
|
|
29
|
+
// -- Add google-fonts to keys
|
|
30
|
+
stylesKeys.push('google-fonts');
|
|
31
|
+
|
|
32
|
+
// -- Adding styles
|
|
33
|
+
for (let key in json.styles) {
|
|
34
|
+
// -- Check if init with http or https
|
|
35
|
+
let url = json.styles[key];
|
|
36
|
+
if (!/^(https?:\/\/|\/\/)/.test(url)) {
|
|
37
|
+
dipper.registerStyle(key, dipper.style(url));
|
|
38
|
+
} else {
|
|
39
|
+
dipper.registerStyle(key, url);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
keyName,
|
|
77
|
-
url,
|
|
78
|
-
(keyRequires !== '') ? [keyRequires] : undefined
|
|
79
|
-
);
|
|
80
|
-
}
|
|
43
|
+
dipper.registerStyle('app', dipper.style('app.min.css'), stylesKeys);
|
|
44
|
+
dipper.enqueueStyle('app');
|
|
45
|
+
|
|
46
|
+
// -- Scripts
|
|
47
|
+
let scriptsKeys = [];
|
|
48
|
+
if (json.dependencies) {
|
|
49
|
+
|
|
50
|
+
// -- Adding scripts
|
|
51
|
+
for (let key in json.dependencies) {
|
|
52
|
+
|
|
53
|
+
// -- Key name and requires
|
|
54
|
+
let keyParts = key.split(':');
|
|
55
|
+
let keyName = keyParts[0];
|
|
56
|
+
let keyRequires = keyParts[1] || '';
|
|
57
|
+
|
|
58
|
+
// -- Add key to scriptsKeys
|
|
59
|
+
scriptsKeys.push(keyName);
|
|
60
|
+
|
|
61
|
+
// -- Check if init with http or https
|
|
62
|
+
let url = json.dependencies[key];
|
|
63
|
+
if (!/^(https?:\/\/|\/\/)/.test(url)) {
|
|
64
|
+
dipper.registerScript(
|
|
65
|
+
keyName,
|
|
66
|
+
dipper.script(url),
|
|
67
|
+
(keyRequires !== '') ? [keyRequires] : undefined
|
|
68
|
+
);
|
|
69
|
+
} else {
|
|
70
|
+
dipper.registerScript(
|
|
71
|
+
keyName,
|
|
72
|
+
url,
|
|
73
|
+
(keyRequires !== '') ? [keyRequires] : undefined
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
81
77
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
dipper.addMeta('theme-color', '#ffffff', '');
|
|
78
|
+
scriptsKeys.push('jquery');
|
|
79
|
+
scriptsKeys.push('underscore');
|
|
80
|
+
dipper.registerScript('vanillaJet', dipper.script('core/vanillaJet.js'), scriptsKeys);
|
|
81
|
+
dipper.enqueueScript('vanillaJet');
|
|
82
|
+
|
|
83
|
+
// -- Main app
|
|
84
|
+
dipper.registerScript('vanilla', dipper.script('vanilla.js'));
|
|
85
|
+
dipper.enqueueScript('vanilla');
|
|
86
|
+
|
|
87
|
+
// Adding meta tags
|
|
88
|
+
dipper.addMeta('UTF-8', '', 'charset');
|
|
89
|
+
dipper.addMeta('viewport', 'width=device-width, minimum-scale=1');
|
|
90
|
+
dipper.addMeta('og:title', dipper.getPageTitle(), 'property');
|
|
91
|
+
dipper.addMeta('og:site_name', dipper.getSiteTitle(), 'property');
|
|
92
|
+
dipper.addMeta('og:description', dipper.getDescription(), 'property');
|
|
93
|
+
dipper.addMeta('og:image', dipper.img('logo.png'), 'property');
|
|
94
|
+
dipper.addMeta('og:type', 'website', 'property');
|
|
95
|
+
dipper.addMeta('og:url', dipper.urlTo(''), 'property');
|
|
96
|
+
dipper.addMeta('theme-color', '#ffffff', '');
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
|
package/framework/request.js
CHANGED
|
@@ -22,10 +22,7 @@ class Request {
|
|
|
22
22
|
|
|
23
23
|
init(req, options) {
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
body = '',
|
|
27
|
-
parsed = url.parse(req.url, true);
|
|
28
|
-
options = options || {};
|
|
25
|
+
var obj = this, body = '', options = options || {}, parsed = url.parse(req.url, true);
|
|
29
26
|
|
|
30
27
|
// Save callbacks
|
|
31
28
|
obj.onDataReceived = options.onDataReceived || obj.onDataReceived;
|
|
@@ -46,7 +43,7 @@ class Request {
|
|
|
46
43
|
}
|
|
47
44
|
|
|
48
45
|
// Matches
|
|
49
|
-
|
|
46
|
+
var matches = (obj.id == null) ? null : obj.id.match(/\.([a-z0-9]+)$/);
|
|
50
47
|
if (matches) {
|
|
51
48
|
obj.format = matches[1] || 'html';
|
|
52
49
|
obj.id = obj.id.replace(/\.([a-z0-9]+)$/, '');
|
|
@@ -61,7 +58,7 @@ class Request {
|
|
|
61
58
|
req.on('end', function (chunk) {
|
|
62
59
|
obj.params.body = body;
|
|
63
60
|
obj.params.post = querystring.parse(body);
|
|
64
|
-
obj.onDataReceived(obj);
|
|
61
|
+
obj.onDataReceived.call(obj);
|
|
65
62
|
});
|
|
66
63
|
}
|
|
67
64
|
|
|
@@ -72,8 +69,7 @@ class Request {
|
|
|
72
69
|
**/
|
|
73
70
|
param(name, value) {
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
ret = value || '';
|
|
72
|
+
var obj = this, ret = value || '';
|
|
77
73
|
// Try to retrieve parameter from both, POST and GET objects
|
|
78
74
|
if (typeof obj.params.post[name] !== 'undefined') {
|
|
79
75
|
ret = obj.params.post[name];
|
|
@@ -85,8 +81,7 @@ class Request {
|
|
|
85
81
|
|
|
86
82
|
post(name, value) {
|
|
87
83
|
|
|
88
|
-
|
|
89
|
-
ret = value || '';
|
|
84
|
+
var obj = this, ret = value || '';
|
|
90
85
|
// Try to retrieve parameter from POST object
|
|
91
86
|
if (typeof obj.params.post[name] !== 'undefined') {
|
|
92
87
|
ret = obj.params.post[name];
|
|
@@ -96,8 +91,7 @@ class Request {
|
|
|
96
91
|
|
|
97
92
|
get(name, value) {
|
|
98
93
|
|
|
99
|
-
|
|
100
|
-
ret = value || '';
|
|
94
|
+
var obj = this, ret = value || '';
|
|
101
95
|
// Try to retrieve parameter from GET object
|
|
102
96
|
if (typeof obj.params.get[name] !== 'undefined') {
|
|
103
97
|
ret = obj.params.get[name];
|
|
@@ -106,7 +100,8 @@ class Request {
|
|
|
106
100
|
}
|
|
107
101
|
|
|
108
102
|
body() {
|
|
109
|
-
|
|
103
|
+
|
|
104
|
+
var obj = this;
|
|
110
105
|
return obj.params.body;
|
|
111
106
|
}
|
|
112
107
|
}
|
package/framework/response.js
CHANGED
|
@@ -10,26 +10,31 @@ class Response {
|
|
|
10
10
|
this.status = 200;
|
|
11
11
|
this.headers = [];
|
|
12
12
|
this.autoRespond = true;
|
|
13
|
+
// Call initialization callback
|
|
13
14
|
this.init(res);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
init(res) {
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
var obj = this;
|
|
18
20
|
obj.res = res;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
setBody(body) {
|
|
22
|
-
|
|
24
|
+
|
|
25
|
+
var obj = this;
|
|
23
26
|
obj.body = body;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
setStatus(status) {
|
|
27
|
-
|
|
30
|
+
|
|
31
|
+
var obj = this;
|
|
28
32
|
obj.status = status;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
setHeader(name, value) {
|
|
32
|
-
|
|
36
|
+
|
|
37
|
+
var obj = this;
|
|
33
38
|
obj.headers.push({
|
|
34
39
|
name: name,
|
|
35
40
|
value: value
|
|
@@ -37,18 +42,20 @@ class Response {
|
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
getBody() {
|
|
40
|
-
|
|
45
|
+
|
|
46
|
+
var obj = this;
|
|
41
47
|
return obj.body;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
getStatus() {
|
|
45
|
-
|
|
51
|
+
|
|
52
|
+
var obj = this;
|
|
46
53
|
return obj.status;
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
getHeader(name) {
|
|
50
|
-
|
|
51
|
-
|
|
57
|
+
|
|
58
|
+
var obj = this, ret = null;
|
|
52
59
|
ret = _.find(obj.headers, function (header) {
|
|
53
60
|
return header.name == name;
|
|
54
61
|
});
|
|
@@ -56,7 +63,8 @@ class Response {
|
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
respond() {
|
|
59
|
-
|
|
66
|
+
|
|
67
|
+
var obj = this;
|
|
60
68
|
this.setHeader('Access-Control-Allow-Origin', '*');
|
|
61
69
|
|
|
62
70
|
_.each(obj.headers, function (header) {
|
|
@@ -67,7 +75,8 @@ class Response {
|
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
error404() {
|
|
70
|
-
|
|
78
|
+
|
|
79
|
+
var obj = this;
|
|
71
80
|
obj.res.writeHead(404, { "Content-Type": "text/plain" });
|
|
72
81
|
obj.res.write("404 Not Found\n");
|
|
73
82
|
obj.res.end();
|
|
@@ -75,10 +84,7 @@ class Response {
|
|
|
75
84
|
|
|
76
85
|
render(template) {
|
|
77
86
|
|
|
78
|
-
|
|
79
|
-
path = require("path"),
|
|
80
|
-
fs = require("fs");
|
|
81
|
-
template = 'pages/' + template;
|
|
87
|
+
var obj = this, path = require("path"), fs = require("fs"), template = 'pages/' + template;
|
|
82
88
|
|
|
83
89
|
const filename = path.join(process.cwd(), 'public/' + template);
|
|
84
90
|
const fileStream = fs.createReadStream(filename);
|
package/framework/router.js
CHANGED
|
@@ -18,7 +18,8 @@ class Router {
|
|
|
18
18
|
|
|
19
19
|
routeToRegExp(route) {
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
var optionalParam = /\((.*?)\)/g, namedParam = /(\(\?)?:\w+/g, splatParam = /\*\w+/g, escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
|
|
22
|
+
// Convert route to regular expression, this was taken from Backbone's router
|
|
22
23
|
route = route.replace(escapeRegExp, '\\$&')
|
|
23
24
|
.replace(optionalParam, '(?:$1)?')
|
|
24
25
|
.replace(namedParam, function (match, optional) {
|
|
@@ -30,21 +31,20 @@ class Router {
|
|
|
30
31
|
|
|
31
32
|
addRoute(method, route, handler, insert) {
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
handler: handler
|
|
40
|
-
};
|
|
41
|
-
if (insert) {
|
|
34
|
+
var obj = this, insert = insert || false, method = method.toLowerCase(), prev = (obj.server.options.base_url && obj.server.options.base_url != '' && obj.server.options.base_url != '/') ? obj.server.options.base_url : '', instance = {
|
|
35
|
+
regexp: obj.routeToRegExp(prev + route),
|
|
36
|
+
handler: handler
|
|
37
|
+
};
|
|
38
|
+
// Add the route, may be at the beginning or at the end
|
|
39
|
+
if (insert) { // Adding the route at the beginning of the route's array
|
|
42
40
|
obj.routes[method].unshift(instance);
|
|
43
|
-
} else {
|
|
41
|
+
} else { // Adding the route at the end of the route's array
|
|
44
42
|
obj.routes[method].push(instance);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
|
|
46
|
+
removeRoute(method, route) {}
|
|
47
|
+
|
|
48
48
|
onRequest(req, res) {
|
|
49
49
|
|
|
50
50
|
let obj = this;
|
|
@@ -54,14 +54,19 @@ class Router {
|
|
|
54
54
|
let request = new Request(req, {
|
|
55
55
|
onDataReceived: function () {
|
|
56
56
|
|
|
57
|
+
//console.log(request.path);
|
|
57
58
|
if (request.path == obj.server.options.base_url) {
|
|
58
59
|
request.path = obj.server.options.base_url + obj.defaultRoute;
|
|
59
60
|
}
|
|
60
|
-
//
|
|
61
|
+
//console.log(request.path);
|
|
62
|
+
// Try with the routes for the current method (get or post)
|
|
61
63
|
_.each(obj.routes[request.type], function (route) {
|
|
62
64
|
if (request.path.match(route.regexp)) {
|
|
63
|
-
|
|
65
|
+
|
|
66
|
+
var parts = route.handler.split('.'), clazz = parts[0], method = parts[1], callback = obj.validateCallback(clazz, method);
|
|
67
|
+
|
|
64
68
|
if (callback && callback != undefined && callback != '') {
|
|
69
|
+
|
|
65
70
|
isMatch = true;
|
|
66
71
|
handled = callback(request, response, obj.server);
|
|
67
72
|
return;
|
|
@@ -72,9 +77,13 @@ class Router {
|
|
|
72
77
|
// If not handled yet, try with the wildcard ones
|
|
73
78
|
if (!handled) {
|
|
74
79
|
_.each(obj.routes['*'], function (route) {
|
|
80
|
+
|
|
75
81
|
if (request.path.match(route.regexp)) {
|
|
76
|
-
|
|
82
|
+
|
|
83
|
+
var parts = route.handler.split('.'), clazz = parts[0], method = parts[1], callback = obj.validateCallback(clazz, method);
|
|
84
|
+
|
|
77
85
|
if (callback && callback != undefined && callback != '') {
|
|
86
|
+
|
|
78
87
|
isMatch = true;
|
|
79
88
|
handled = callback(request, response, obj.server);
|
|
80
89
|
return;
|
|
@@ -87,8 +96,8 @@ class Router {
|
|
|
87
96
|
// or not handled? Well, at this point we call 404
|
|
88
97
|
if (handled == false && isMatch == false) {
|
|
89
98
|
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
var path = require('path'), ext = path.extname(req.url).replace('.', ''), extHandled = false, extHeader = {};
|
|
100
|
+
var mimes = {
|
|
92
101
|
'png': 'image/png',
|
|
93
102
|
'webp': 'image/webp',
|
|
94
103
|
'jpg': 'image/jpg',
|
|
@@ -102,13 +111,15 @@ class Router {
|
|
|
102
111
|
'pdf': 'application/pdf',
|
|
103
112
|
'json': 'application/json'
|
|
104
113
|
};
|
|
105
|
-
|
|
114
|
+
|
|
115
|
+
var compressionMimes = {
|
|
106
116
|
'css': 'text/css',
|
|
107
117
|
'js': 'text/javascript',
|
|
108
118
|
'gz': 'application/x-gzip'
|
|
109
119
|
};
|
|
110
120
|
|
|
111
121
|
if (mimes[ext] != undefined && mimes[ext] != 'undefined') {
|
|
122
|
+
|
|
112
123
|
extHandled = true;
|
|
113
124
|
extHeader = { 'Content-Type': mimes[ext] };
|
|
114
125
|
}
|
|
@@ -122,9 +133,12 @@ class Router {
|
|
|
122
133
|
filePrivate = obj.isProtectedFile(route);
|
|
123
134
|
|
|
124
135
|
fs.exists(filename, function (exists) {
|
|
136
|
+
|
|
125
137
|
if (exists && !filePrivate) {
|
|
126
|
-
|
|
127
|
-
|
|
138
|
+
|
|
139
|
+
var acceptEncoding = (req.headers['accept-encoding'] != undefined) ? req.headers['accept-encoding'] : '';
|
|
140
|
+
var fileStream = fs.createReadStream(filename);
|
|
141
|
+
|
|
128
142
|
if (ext === 'js' && !route.match(/(vanilla\.min\.js|vanillaJet\.min\.js)$/)) {
|
|
129
143
|
extHeader['Cache-Control'] = 'public, max-age=15552000';
|
|
130
144
|
extHeader['Expires'] = new Date(Date.now() + 15552000000).toUTCString();
|
|
@@ -141,6 +155,8 @@ class Router {
|
|
|
141
155
|
return;
|
|
142
156
|
|
|
143
157
|
} else {
|
|
158
|
+
|
|
159
|
+
// Return 404
|
|
144
160
|
obj.onNotFound(response);
|
|
145
161
|
}
|
|
146
162
|
});
|
|
@@ -154,20 +170,23 @@ class Router {
|
|
|
154
170
|
isProtectedFile(route) {
|
|
155
171
|
|
|
156
172
|
let protectedDirs = ['framework', 'external', 'node_mudules'];
|
|
157
|
-
|
|
173
|
+
var routeParts = route.split('/');
|
|
158
174
|
if (routeParts[1] != undefined && routeParts.length > 2) {
|
|
159
175
|
return protectedDirs.includes(routeParts[1]);
|
|
160
176
|
}
|
|
161
177
|
return true;
|
|
162
178
|
}
|
|
163
179
|
|
|
180
|
+
validateExtension(route) {}
|
|
181
|
+
|
|
164
182
|
validateCallback(clazz, method) {
|
|
165
183
|
|
|
166
|
-
|
|
167
|
-
endpoints = obj.server.endpoints;
|
|
184
|
+
var obj = this, endpoints = obj.server.endpoints;
|
|
168
185
|
|
|
169
186
|
if (endpoints[clazz] != undefined) {
|
|
187
|
+
|
|
170
188
|
clazz = endpoints[clazz];
|
|
189
|
+
|
|
171
190
|
if (typeof clazz[method] === 'function') {
|
|
172
191
|
return clazz[method];
|
|
173
192
|
}
|
|
@@ -181,17 +200,19 @@ class Router {
|
|
|
181
200
|
**/
|
|
182
201
|
setDefaultRoute(route) {
|
|
183
202
|
|
|
184
|
-
|
|
203
|
+
var obj = this;
|
|
185
204
|
obj.defaultRoute = route;
|
|
186
205
|
}
|
|
187
206
|
|
|
188
207
|
getDefaultRoute() {
|
|
189
|
-
|
|
190
|
-
|
|
208
|
+
|
|
209
|
+
var obj = this, prev = (obj.server.options.base_url && obj.server.options.base_url != '' && obj.server.options.base_url != '/') ? obj.server.options.base_url : '';
|
|
210
|
+
|
|
191
211
|
return (prev + obj.defaultRoute);
|
|
192
212
|
}
|
|
193
213
|
|
|
194
214
|
onNotFound(response) {
|
|
215
|
+
|
|
195
216
|
response.setStatus(404);
|
|
196
217
|
response.respond();
|
|
197
218
|
}
|
package/framework/server.js
CHANGED
|
@@ -41,7 +41,6 @@ class Server {
|
|
|
41
41
|
_.defaults(security, {
|
|
42
42
|
pass_salt: '1234567890',
|
|
43
43
|
token_salt: '0987654321',
|
|
44
|
-
self_managed_certs: false,
|
|
45
44
|
version: '1.0'
|
|
46
45
|
});
|
|
47
46
|
obj.security = security;
|
|
@@ -57,7 +56,7 @@ class Server {
|
|
|
57
56
|
// -- Create the server
|
|
58
57
|
obj.httpx = obj.createServer(obj.options, obj.security);
|
|
59
58
|
|
|
60
|
-
// --
|
|
59
|
+
// -- Not found callback
|
|
61
60
|
obj.onNotFound = opts.onNotFound;
|
|
62
61
|
|
|
63
62
|
// Initialize router
|
|
@@ -74,6 +73,20 @@ class Server {
|
|
|
74
73
|
obj.functions = new Functions();
|
|
75
74
|
}
|
|
76
75
|
|
|
76
|
+
start() {
|
|
77
|
+
|
|
78
|
+
let obj = this;
|
|
79
|
+
let port = (obj.options.port && obj.options.port != '') ? obj.options.port : 8080;
|
|
80
|
+
|
|
81
|
+
// Listen on the specified port
|
|
82
|
+
obj.httpx.listen(port);
|
|
83
|
+
|
|
84
|
+
// Logging
|
|
85
|
+
obj.log('__________________ VanillaJet server started ___________________');
|
|
86
|
+
obj.log(` > Listening on ${obj.options.site_url}:${obj.options.port}${obj.options.base_url} < `);
|
|
87
|
+
obj.log('-----------------------------------------------------------------');
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
createServer(options, security) {
|
|
78
91
|
|
|
79
92
|
let obj = this;
|
|
@@ -103,20 +116,6 @@ class Server {
|
|
|
103
116
|
});
|
|
104
117
|
}
|
|
105
118
|
|
|
106
|
-
start() {
|
|
107
|
-
|
|
108
|
-
let obj = this;
|
|
109
|
-
let port = (obj.options.port && obj.options.port != '') ? obj.options.port : 8080;
|
|
110
|
-
|
|
111
|
-
// Listen on the specified port
|
|
112
|
-
obj.httpx.listen(port);
|
|
113
|
-
|
|
114
|
-
// Logging
|
|
115
|
-
obj.log('__________________ VanillaJet server started ___________________');
|
|
116
|
-
obj.log(` > Listening on ${obj.options.site_url}:${obj.options.port}${obj.options.base_url} < `);
|
|
117
|
-
obj.log('-----------------------------------------------------------------');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
119
|
log(value) {
|
|
121
120
|
|
|
122
121
|
let obj = this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vanilla-jet",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "VannilaJet framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -29,26 +29,26 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/nalancer08/VanillaJet#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"blueimp-md5": "2.
|
|
32
|
+
"blueimp-md5": "2.8.0",
|
|
33
33
|
"chalk": "4.1.2",
|
|
34
34
|
"grunt": "1.6.1",
|
|
35
|
-
"grunt-cli": "1.
|
|
35
|
+
"grunt-cli": "1.4.3",
|
|
36
36
|
"grunt-contrib-clean": "2.0.1",
|
|
37
37
|
"grunt-contrib-compress": "2.0.0",
|
|
38
38
|
"grunt-contrib-concat": "2.1.0",
|
|
39
39
|
"grunt-contrib-cssmin": "5.0.0",
|
|
40
40
|
"grunt-contrib-less": "3.0.0",
|
|
41
|
-
"grunt-contrib-uglify": "5.
|
|
41
|
+
"grunt-contrib-uglify": "5.0.1",
|
|
42
42
|
"grunt-contrib-watch": "1.1.0",
|
|
43
43
|
"grunt-run": "0.8.1",
|
|
44
44
|
"grunt-shell": "4.0.0",
|
|
45
45
|
"html-minifier-terser": "7.2.0",
|
|
46
46
|
"jit-grunt": "0.10.0",
|
|
47
|
-
"js-beautify": "1.
|
|
48
|
-
"jsrsasign": "11.
|
|
49
|
-
"jwt-simple": "0.5.
|
|
50
|
-
"minimist": "1.2.
|
|
51
|
-
"nodemon": "3.1
|
|
47
|
+
"js-beautify": "1.14.8",
|
|
48
|
+
"jsrsasign": "11.0.0",
|
|
49
|
+
"jwt-simple": "0.5.3",
|
|
50
|
+
"minimist": "1.2.6",
|
|
51
|
+
"nodemon": "3.0.1",
|
|
52
52
|
"nunjucks": "3.2.4",
|
|
53
53
|
"underscore": ">= 1.12.x",
|
|
54
54
|
"zlib": "1.0.5"
|