vanilla-jet 1.0.8 → 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.
@@ -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
+ }
@@ -32,11 +32,14 @@ function Dipper(options, shared) {
32
32
  this.enqueued_scripts = [];
33
33
  this.enqueued_styles = [];
34
34
 
35
- // -- Base
36
- this.registerScript('modernizr', '//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js');
37
- this.registerScript('respond', '//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js');
38
- this.registerScript('jquery', '//cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js');
39
- this.registerScript('underscore', '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-min.js');
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;
@@ -7,22 +7,21 @@ 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, functionsModule) {
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, functionsModule);
21
+ this.init(options, endpoints);
23
22
  }
24
23
 
25
- init(options, functionsModule) {
24
+ init(options, endpoints) {
26
25
 
27
26
  let obj = this,
28
27
  settings = options.settings,
@@ -79,7 +78,7 @@ class Server {
79
78
  obj.router = new Router(obj);
80
79
 
81
80
  // Setting endpoints
82
- obj.functions = new functionsModule(obj);
81
+ obj.functions = new Functions(endpoints);
83
82
  }
84
83
 
85
84
  start() {
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "vanilla-jet",
3
- "version": "1.0.8",
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",