vanilla-jet 1.0.7 → 1.0.9
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/.scripts/generate_packages_json.js +48 -0
- package/framework/dipper.js +30 -5
- package/framework/functions.js +98 -0
- package/framework/router.js +1 -1
- package/framework/server.js +11 -8
- package/package.json +2 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// -- Vars
|
|
2
|
+
const path = require("path"),
|
|
3
|
+
fs = require("fs");
|
|
4
|
+
|
|
5
|
+
// -- Call main
|
|
6
|
+
main();
|
|
7
|
+
|
|
8
|
+
// -- Main function
|
|
9
|
+
async function main() {
|
|
10
|
+
|
|
11
|
+
// -- Create the object to be write in the file
|
|
12
|
+
const json = {
|
|
13
|
+
coreDependencies: {
|
|
14
|
+
"modernizr": "//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js",
|
|
15
|
+
"respond": "//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js",
|
|
16
|
+
"jquery": "//cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js",
|
|
17
|
+
"underscore": "//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-min.js"
|
|
18
|
+
},
|
|
19
|
+
dependencies: {},
|
|
20
|
+
styles: {},
|
|
21
|
+
fonts: {}
|
|
22
|
+
};
|
|
23
|
+
//console.log(json);
|
|
24
|
+
console.log("Creating the package.json file...");
|
|
25
|
+
|
|
26
|
+
// -- Create the file
|
|
27
|
+
await createFileIfnotExists(JSON.stringify(json, null, 2));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// -- Step 0
|
|
31
|
+
async function createFileIfnotExists(content) {
|
|
32
|
+
|
|
33
|
+
const fileName = 'vanillaJet.package.json';
|
|
34
|
+
const filePath = path.join(processCwd(), '/' + fileName);
|
|
35
|
+
const exists = await fs.promises.access(filePath, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
36
|
+
|
|
37
|
+
if (!exists) {
|
|
38
|
+
// -- Create the file with the json content
|
|
39
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// -- Helpers
|
|
44
|
+
function processCwd() {
|
|
45
|
+
return process.cwd()
|
|
46
|
+
.replace('/.grunt', '')
|
|
47
|
+
.replace('/.scripts', '');
|
|
48
|
+
}
|
package/framework/dipper.js
CHANGED
|
@@ -32,11 +32,14 @@ function Dipper(options, shared) {
|
|
|
32
32
|
this.enqueued_scripts = [];
|
|
33
33
|
this.enqueued_styles = [];
|
|
34
34
|
|
|
35
|
-
// -- Base
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
// -- Base scripts
|
|
36
|
+
let vanillaJetJson = this.openJsonFile('vanillaJet.package.json');
|
|
37
|
+
if (vanillaJetJson) {
|
|
38
|
+
let coreDependencies = vanillaJetJson.coreDependencies;
|
|
39
|
+
for (let key in coreDependencies) {
|
|
40
|
+
this.registerScript(key, coreDependencies[key]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
Dipper.prototype.getPageTitle = function() {
|
|
@@ -519,4 +522,26 @@ Dipper.prototype.includeEnvironment = function() {
|
|
|
519
522
|
</script>`;
|
|
520
523
|
}
|
|
521
524
|
|
|
525
|
+
// -- Helpers
|
|
526
|
+
Dipper.prototype.processCwd = function() {
|
|
527
|
+
|
|
528
|
+
return process.cwd()
|
|
529
|
+
.replace('/.grunt', '')
|
|
530
|
+
.replace('/.scripts', '');
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
Dipper.prototype.openJsonFile = function(fileName) {
|
|
534
|
+
|
|
535
|
+
let data = null;
|
|
536
|
+
const fs = require('fs'),
|
|
537
|
+
path = require('path'),
|
|
538
|
+
filePath = path.join(this.processCwd(), '/' + fileName),
|
|
539
|
+
exists = fs.existsSync(filePath);
|
|
540
|
+
|
|
541
|
+
if (exists) {
|
|
542
|
+
data = fs.readFileSync(filePath, 'utf8');
|
|
543
|
+
}
|
|
544
|
+
return JSON.parse(data);
|
|
545
|
+
}
|
|
546
|
+
|
|
522
547
|
module.exports = Dipper;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
function Functions(endpoints) {
|
|
2
|
+
|
|
3
|
+
// Dipper
|
|
4
|
+
dipper = global.dipper;
|
|
5
|
+
|
|
6
|
+
// -- Hydrate
|
|
7
|
+
Functions.hydrate(dipper);
|
|
8
|
+
|
|
9
|
+
// Creating endpoints array
|
|
10
|
+
this.endpoints = endpoints || {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Functions.hydrate = function(dipper) {
|
|
14
|
+
|
|
15
|
+
// -- Get vanillaJet.package.json
|
|
16
|
+
let json = dipper.openJsonFile('vanillaJet.package.json');
|
|
17
|
+
|
|
18
|
+
// -- Google Fonts
|
|
19
|
+
if (json.fonts && json.fonts.length > 0) {
|
|
20
|
+
dipper.registerStyle('google-fonts', dipper.get_google_fonts(json.fonts));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// - Styles
|
|
24
|
+
let stylesKeys = [];
|
|
25
|
+
if (json.styles && json.styles.length > 0) {
|
|
26
|
+
|
|
27
|
+
// -- Gettign the keys
|
|
28
|
+
stylesKeys = Object.keys(json.styles);
|
|
29
|
+
|
|
30
|
+
// -- Add google-fonts to keys
|
|
31
|
+
stylesKeys.push('google-fonts');
|
|
32
|
+
|
|
33
|
+
// -- Adding styles
|
|
34
|
+
for (let key in json.styles) {
|
|
35
|
+
// -- Check if init with http or https
|
|
36
|
+
let url = json.styles[key];
|
|
37
|
+
if (!/^https?:\/\//.test(url)) {
|
|
38
|
+
dipper.registerStyle(key, dipper.style(url));
|
|
39
|
+
} else {
|
|
40
|
+
dipper.registerStyle(key, url);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
dipper.registerStyle('app', dipper.style('app.min.css'), stylesKeys);
|
|
45
|
+
dipper.enqueueStyle('app');
|
|
46
|
+
|
|
47
|
+
// -- Scripts
|
|
48
|
+
let scriptsKeys = [];
|
|
49
|
+
if (json.dependencies && json.dependencies.length > 0) {
|
|
50
|
+
|
|
51
|
+
// -- Adding scripts
|
|
52
|
+
for (let key in json.dependencies) {
|
|
53
|
+
|
|
54
|
+
// -- Key name and requires
|
|
55
|
+
let keyParts = key.split(':');
|
|
56
|
+
let keyName = keyParts[0];
|
|
57
|
+
let keyRequires = keyParts[1] || '';
|
|
58
|
+
|
|
59
|
+
// -- Add key to scriptsKeys
|
|
60
|
+
scriptsKeys.push(keyName);
|
|
61
|
+
|
|
62
|
+
// -- Check if init with http or https
|
|
63
|
+
let url = json.dependencies[key];
|
|
64
|
+
if (!/^https?:\/\//.test(url)) {
|
|
65
|
+
if (keyRequires !== '') {
|
|
66
|
+
dipper.registerScript(keyName, dipper.script(url), [keyRequires]);
|
|
67
|
+
} else {
|
|
68
|
+
dipper.registerScript(keyName, dipper.script(url));
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
if (keyRequires !== '') {
|
|
72
|
+
dipper.registerScript(keyName, url, [keyRequires]);
|
|
73
|
+
} else {
|
|
74
|
+
dipper.registerScript(key, url);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
dipper.registerScript('vanillaJet', dipper.script('core/vanillaJet.js'), scriptsKeys);
|
|
80
|
+
dipper.enqueueScript('vanillaJet');
|
|
81
|
+
|
|
82
|
+
// -- Main app
|
|
83
|
+
dipper.registerScript('vanilla', dipper.script('vanilla.js'));
|
|
84
|
+
dipper.enqueueScript('vanilla');
|
|
85
|
+
|
|
86
|
+
// Adding meta tags
|
|
87
|
+
dipper.addMeta('UTF-8', '', 'charset');
|
|
88
|
+
dipper.addMeta('viewport', 'width=device-width, minimum-scale=1');
|
|
89
|
+
dipper.addMeta('og:title', dipper.getPageTitle(), 'property');
|
|
90
|
+
dipper.addMeta('og:site_name', dipper.getSiteTitle(), 'property');
|
|
91
|
+
dipper.addMeta('og:description', dipper.getDescription(), 'property');
|
|
92
|
+
dipper.addMeta('og:image', dipper.img('logo.png'), 'property');
|
|
93
|
+
dipper.addMeta('og:type', 'website', 'property');
|
|
94
|
+
dipper.addMeta('og:url', dipper.urlTo(''), 'property');
|
|
95
|
+
dipper.addMeta('theme-color', '#ffffff', '');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = Functions;
|
package/framework/router.js
CHANGED
|
@@ -139,7 +139,7 @@ class Router {
|
|
|
139
139
|
var acceptEncoding = (req.headers['accept-encoding'] != undefined) ? req.headers['accept-encoding'] : '';
|
|
140
140
|
var fileStream = fs.createReadStream(filename);
|
|
141
141
|
|
|
142
|
-
if (ext === 'js' && !route.match(/vanilla\.min\.js$/)) {
|
|
142
|
+
if (ext === 'js' && !route.match(/(vanilla\.min\.js|vanillaJet\.min\.js)$/)) {
|
|
143
143
|
extHeader['Cache-Control'] = 'public, max-age=15552000';
|
|
144
144
|
extHeader['Expires'] = new Date(Date.now() + 15552000000).toUTCString();
|
|
145
145
|
}
|
package/framework/server.js
CHANGED
|
@@ -7,24 +7,27 @@ const path = require('path');
|
|
|
7
7
|
|
|
8
8
|
let Router = require('./router.js');
|
|
9
9
|
let Dipper = require('./dipper.js');
|
|
10
|
+
let Functions = require('./functions.js');
|
|
10
11
|
|
|
11
12
|
class Server {
|
|
12
13
|
|
|
13
|
-
constructor(options,
|
|
14
|
-
|
|
15
|
-
console.log(functionsModule);
|
|
14
|
+
constructor(options, endpoints) {
|
|
16
15
|
|
|
17
16
|
this.httpx = null;
|
|
18
17
|
this.verbose = true;
|
|
19
18
|
this.router = null;
|
|
20
19
|
this.functions = null;
|
|
21
20
|
this.dipper = null;
|
|
22
|
-
this.init(options,
|
|
21
|
+
this.init(options, endpoints);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
init(options,
|
|
24
|
+
init(options, endpoints) {
|
|
26
25
|
|
|
27
|
-
let obj = this,
|
|
26
|
+
let obj = this,
|
|
27
|
+
settings = options.settings,
|
|
28
|
+
opts = settings[options.profile] || {},
|
|
29
|
+
shared = settings['shared'] || {},
|
|
30
|
+
security = settings['security'] || {};
|
|
28
31
|
|
|
29
32
|
_.defaults(opts, {
|
|
30
33
|
base_url: '',
|
|
@@ -59,7 +62,7 @@ class Server {
|
|
|
59
62
|
|
|
60
63
|
} else if (/^((https):\/\/)/.test(obj.options.site_url)) {
|
|
61
64
|
|
|
62
|
-
certs = {
|
|
65
|
+
let certs = {
|
|
63
66
|
key: fs.readFileSync(obj.security.key, 'utf8'),
|
|
64
67
|
cert: fs.readFileSync(obj.security.cert, 'utf8'),
|
|
65
68
|
allowHTTP1: true
|
|
@@ -75,7 +78,7 @@ class Server {
|
|
|
75
78
|
obj.router = new Router(obj);
|
|
76
79
|
|
|
77
80
|
// Setting endpoints
|
|
78
|
-
obj.functions = new
|
|
81
|
+
obj.functions = new Functions(endpoints);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
start() {
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vanilla-jet",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "VannilaJet framework",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"setup": "node ./.scripts/generate_packages_json.js",
|
|
7
8
|
"dev": "grunt --env=development & nodemon index.js --ignore '**/public/**'",
|
|
8
9
|
"build:qa": "grunt build --env=qa",
|
|
9
10
|
"build:prod": "grunt build --env=production",
|