vanilla-jet 1.0.32 → 1.0.34

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