vanilla-jet 1.0.31 → 1.0.33

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.
@@ -1,10 +1,9 @@
1
- console.log("Init Templete Compile/Rendering");
2
-
3
1
  // -- Add dependencies
4
2
  const path = require("path"),
5
3
  fs = require("fs"),
6
4
  nunjucks = require('nunjucks'),
7
- identifier = 'templates';
5
+ identifier = 'templates',
6
+ chalk = require('chalk');
8
7
 
9
8
  let Functions = require('../framework/functions.js');
10
9
  let Dipper = require('../framework/dipper.js');
@@ -21,7 +20,7 @@ let settings = Config.settings;
21
20
  settings['shared']['environment'] = env;
22
21
 
23
22
  let opts = settings[env] || {},
24
- shared = settings['shared'] || {};
23
+ shared = settings['shared'] || {};
25
24
  const dipper = new Dipper(opts, shared);
26
25
 
27
26
  // -- Hydrate dipper
@@ -30,7 +29,7 @@ Functions.hydrate(dipper);
30
29
  // -- Making nunjucks
31
30
  let nunjucksPath = path.join(processCwd(), '/assets');
32
31
  nunjucks.configure(nunjucksPath, {
33
- autoescape: false,
32
+ autoescape: false,
34
33
  throwOnUndefined: true,
35
34
  noCache: true
36
35
  });
@@ -44,98 +43,98 @@ main();
44
43
  // -- Define mainfunctions on other functions
45
44
  function main() {
46
45
 
47
- // -- Get template files
48
- const templates = getTemplates(templatesDirectoryPath);
49
- //console.log(templates);
50
-
51
- // -- Get home.html
52
- let homePageName = 'home.html';
53
- getHtmlFromPage(homePageName).then((htmlContent) => {
54
- if (htmlContent) {
55
- // -- Divide content line by line
56
- const htmlContentLines = htmlContent.split('\n');
57
- let lines = Array.from(htmlContentLines);
58
- // -- Iterate over each line
59
- for (let line of htmlContentLines) {
60
- let originalLine = line;
61
- // -- Remove spaces and tabs
62
- line = cleanALine(line);
63
- // -- Check is not empty and not a tag
64
- if (line.length != 0 && !line.includes('<')) {
65
-
66
- // -- Get template name
67
- var templateName = line.replace('include::', '');
68
- // -- Check if its name "templates" add all templates if not add specific one
69
- if (templateName === identifier) {
70
-
71
- let allTemplatesCompiled = '';
72
- for (let templateName in templates) {
73
- if (templateName.includes('template.html')) {
74
- let templatePath = templates[templateName];
75
- let templateCompiled = compileTemplate(templatePath);
76
- allTemplatesCompiled += templateCompiled;
77
- }
78
- }
79
- lines = replaceInclude(lines, originalLine, allTemplatesCompiled);
80
-
81
- } else {
82
- let templatePath = templates[templateName];
83
- let templateCompiled = compileTemplate(templatePath);
84
- lines = replaceInclude(lines, originalLine, templateCompiled);
85
- }
86
- }
46
+ // -- Get template files
47
+ const templates = getTemplates(templatesDirectoryPath);
48
+ //console.log(templates);
49
+
50
+ // -- Get home.html
51
+ let homePageName = 'home.html';
52
+ getHtmlFromPage(homePageName).then((htmlContent) => {
53
+ if (htmlContent) {
54
+ // -- Divide content line by line
55
+ const htmlContentLines = htmlContent.split('\n');
56
+ let lines = Array.from(htmlContentLines);
57
+ // -- Iterate over each line
58
+ for (let line of htmlContentLines) {
59
+ let originalLine = line;
60
+ // -- Remove spaces and tabs
61
+ line = cleanALine(line);
62
+ // -- Check is not empty and not a tag
63
+ if (line.length != 0 && !line.includes('<')) {
64
+
65
+ // -- Get template name
66
+ var templateName = line.replace('include::', '');
67
+ // -- Check if its name "templates" add all templates if not add specific one
68
+ if (templateName === identifier) {
69
+
70
+ let allTemplatesCompiled = '';
71
+ for (let templateName in templates) {
72
+ if (templateName.includes('template.html')) {
73
+ let templatePath = templates[templateName];
74
+ let templateCompiled = compileTemplate(templatePath);
75
+ allTemplatesCompiled += templateCompiled;
76
+ }
87
77
  }
88
- // -- Join lines
89
- const newHtml = lines.join('\n');
90
- // -- Create HTML file
91
- createHTMLFile(newHtml, homePageName);
92
- // -- Console finish
93
- console.log("VanillaJet - Finish build");
78
+ lines = replaceInclude(lines, originalLine, allTemplatesCompiled);
79
+
80
+ } else {
81
+ let templatePath = templates[templateName];
82
+ let templateCompiled = compileTemplate(templatePath);
83
+ lines = replaceInclude(lines, originalLine, templateCompiled);
84
+ }
94
85
  }
95
- });
86
+ }
87
+ // -- Join lines
88
+ const newHtml = lines.join('\n');
89
+ // -- Create HTML file
90
+ createHTMLFile(newHtml, homePageName);
91
+ // -- Console finish
92
+ console.log(chalk.green("\n\nVanillaJet - Finish build"));
93
+ }
94
+ });
96
95
  }
97
96
 
98
97
  // -- Step 0
99
98
  function getTemplates(directory) {
100
99
 
101
- const results = {};
102
-
103
- // -- Sub functions
104
- function exploreDirectory(dir) {
105
- const files = fs.readdirSync(dir);
106
- files.forEach(function (file) {
107
- //console.log(file);
108
- if (!checkExcludes(file)) {
109
- const filePath = path.join(dir, file);
110
- //console.log(filePath);
111
- const stats = fs.statSync(filePath);
112
- if (stats.isFile()) {
113
- const extension = path.extname(file).toLowerCase();
114
- if (extension === '.html') {
115
- results[file] = filePath;
116
- }
117
- } else if (stats.isDirectory()) {
118
- exploreDirectory(filePath);
119
- }
120
- }
121
- });
122
- }
100
+ const results = {};
101
+
102
+ // -- Sub functions
103
+ function exploreDirectory(dir) {
104
+ const files = fs.readdirSync(dir);
105
+ files.forEach(function (file) {
106
+ //console.log(file);
107
+ if (!checkExcludes(file)) {
108
+ const filePath = path.join(dir, file);
109
+ //console.log(filePath);
110
+ const stats = fs.statSync(filePath);
111
+ if (stats.isFile()) {
112
+ const extension = path.extname(file).toLowerCase();
113
+ if (extension === '.html') {
114
+ results[file] = filePath;
115
+ }
116
+ } else if (stats.isDirectory()) {
117
+ exploreDirectory(filePath);
118
+ }
119
+ }
120
+ });
121
+ }
123
122
 
124
- function checkExcludes(file) {
123
+ function checkExcludes(file) {
125
124
 
126
- const excludes = ['.DS_Store'];
127
- for (const esclude of excludes) {
128
- if (file.includes(esclude)) {
129
- return true;
130
- }
131
- }
132
- return false;
125
+ const excludes = ['.DS_Store'];
126
+ for (const esclude of excludes) {
127
+ if (file.includes(esclude)) {
128
+ return true;
129
+ }
133
130
  }
131
+ return false;
132
+ }
134
133
 
135
- // -- Main code
136
- const templatesPath = path.join(processCwd(), directory);
137
- exploreDirectory(templatesPath);
138
- return results;
134
+ // -- Main code
135
+ const templatesPath = path.join(processCwd(), directory);
136
+ exploreDirectory(templatesPath);
137
+ return results;
139
138
  }
140
139
 
141
140
  // -- Step 1
@@ -144,19 +143,19 @@ async function getHtmlFromPage(page) {
144
143
  const filename = path.join(processCwd(), '/assets/');
145
144
  const exists = await fs.promises.access(filename, fs.constants.F_OK).then(() => true).catch(() => false);
146
145
  if (!exists) {
147
- console.log("Assets folder doesnt exists");
148
- return null;
146
+ console.log("Assets folder doesnt exists");
147
+ return null;
149
148
  }
150
149
 
151
150
  let fileContent;
152
151
  if (await fs.promises.stat(filename).then((stats) => stats.isDirectory())) {
153
- const filePath = path.join(filename, 'pages/' + page);
154
- try {
155
- fileContent = await fs.promises.readFile(filePath, { encoding: 'utf8' });
156
- } catch (err) {
157
- console.log("Error in Home");
158
- return null;
159
- }
152
+ const filePath = path.join(filename, 'pages/' + page);
153
+ try {
154
+ fileContent = await fs.promises.readFile(filePath, { encoding: 'utf8' });
155
+ } catch (err) {
156
+ console.log("Error in Home");
157
+ return null;
158
+ }
160
159
  }
161
160
  return fileContent;
162
161
  }
@@ -164,58 +163,58 @@ async function getHtmlFromPage(page) {
164
163
  // -- Step 2
165
164
  function compileTemplate(path) {
166
165
 
167
- // -- Data
168
- let data = { 'app': dipper }
169
-
170
- // -- Render
171
- return nunjucks.render(path, data);
166
+ // -- Data
167
+ let data = { 'app': dipper }
168
+
169
+ // -- Render
170
+ return nunjucks.render(path, data);
172
171
  }
173
172
 
174
173
  // -- Step 3
175
174
  function replaceInclude(lines, originalLine, templateCompiled) {
176
- const index = lines.indexOf(originalLine);
177
- if (index !== -1) {
178
- lines.splice(index, 1, templateCompiled);
179
- }
180
- return lines;
175
+ const index = lines.indexOf(originalLine);
176
+ if (index !== -1) {
177
+ lines.splice(index, 1, templateCompiled);
178
+ }
179
+ return lines;
181
180
  }
182
181
 
183
182
  // -- Step 4
184
183
  async function createHTMLFile(content, filePath) {
185
184
 
186
- //const { html } = require('js-beautify');
187
- ///content = html(content);
188
-
189
- const { minify } = require('html-minifier-terser');
190
- //console.log(typeof content);
191
- const minified = await minify(content, {
192
- collapseWhitespace: true,
193
- collapseInlineTagWhitespace: true,
194
- removeComments: true,
195
- collapseBooleanAttributes: true,
196
- useShortDoctype: true,
197
- removeEmptyAttributes: true,
198
- removeOptionalTags: true,
199
- minifyJS: true
200
- });
201
-
202
- const publicPath = path.join(processCwd(), '/public/pages');
203
- fs.mkdirSync(publicPath, { recursive: true });
204
- const absolutePath = path.join(publicPath, filePath);
205
- fs.writeFileSync(absolutePath, minified, 'utf8');
206
- //console.log(`Html :) file created at: ${absolutePath}`);
185
+ //const { html } = require('js-beautify');
186
+ ///content = html(content);
187
+
188
+ const { minify } = require('html-minifier-terser');
189
+ //console.log(typeof content);
190
+ const minified = await minify(content, {
191
+ collapseWhitespace: true,
192
+ collapseInlineTagWhitespace: true,
193
+ removeComments: true,
194
+ collapseBooleanAttributes: true,
195
+ useShortDoctype: true,
196
+ removeEmptyAttributes: true,
197
+ removeOptionalTags: true,
198
+ minifyJS: true
199
+ });
200
+
201
+ const publicPath = path.join(processCwd(), '/public/pages');
202
+ fs.mkdirSync(publicPath, { recursive: true });
203
+ const absolutePath = path.join(publicPath, filePath);
204
+ fs.writeFileSync(absolutePath, minified, 'utf8');
205
+ //console.log(`Html :) file created at: ${absolutePath}`);
207
206
  }
208
207
 
209
208
  // -- Helpers
210
209
  function cleanALine(line) {
211
- line = line.replaceAll(' ', '');
212
- line = line.replaceAll('\t', '');
213
- line = line.replaceAll('\n', '');
214
- return line;
210
+ line = line.replaceAll(' ', '');
211
+ line = line.replaceAll('\t', '');
212
+ line = line.replaceAll('\n', '');
213
+ return line;
215
214
  }
216
215
 
217
216
  function processCwd() {
218
- return process.cwd()
219
- .replace('/.grunt', '')
220
- .replace('/node_modules/vanilla-jet', '');
217
+ return process.cwd()
218
+ .replace('/.grunt', '')
219
+ .replace('/node_modules/vanilla-jet', '');
221
220
  }
package/bin.js CHANGED
@@ -3,10 +3,10 @@
3
3
  const path = require('path');
4
4
  const args = process.argv.slice(2);
5
5
  const { execSync } = require('child_process');
6
+ const chalk = require('chalk');
6
7
 
7
8
  const generatePackagesJson = require(path.join(__dirname, './.scripts/generate_packages_json.js'));
8
9
 
9
- console.log(args[0]);
10
10
  switch (args[0]) {
11
11
 
12
12
  case 'setup':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanilla-jet",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "description": "VannilaJet framework",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -29,14 +29,7 @@
29
29
  "homepage": "https://github.com/nalancer08/VanillaJet#readme",
30
30
  "dependencies": {
31
31
  "blueimp-md5": "2.8.0",
32
- "html-minifier-terser": "7.2.0",
33
- "js-beautify": "1.14.8",
34
- "jsrsasign": "11.0.0",
35
- "jwt-simple": "0.5.3",
36
- "minimist": "1.2.6",
37
- "nunjucks": "3.2.4",
38
- "underscore": ">= 1.12.x",
39
- "zlib": "1.0.5",
32
+ "chalk": "4.1.2",
40
33
  "grunt": "1.6.1",
41
34
  "grunt-cli": "1.4.3",
42
35
  "grunt-contrib-clean": "2.0.1",
@@ -48,7 +41,15 @@
48
41
  "grunt-contrib-watch": "1.1.0",
49
42
  "grunt-run": "0.8.1",
50
43
  "grunt-shell": "4.0.0",
44
+ "html-minifier-terser": "7.2.0",
51
45
  "jit-grunt": "0.10.0",
52
- "nodemon": "3.0.1"
46
+ "js-beautify": "1.14.8",
47
+ "jsrsasign": "11.0.0",
48
+ "jwt-simple": "0.5.3",
49
+ "minimist": "1.2.6",
50
+ "nodemon": "3.0.1",
51
+ "nunjucks": "3.2.4",
52
+ "underscore": ">= 1.12.x",
53
+ "zlib": "1.0.5"
53
54
  }
54
55
  }
File without changes