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.
- package/.grunt/compile_html.js +132 -133
- package/bin.js +1 -1
- package/package.json +11 -10
- package/public/scripts/vanilla.min.js +0 -0
package/.grunt/compile_html.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
123
|
+
function checkExcludes(file) {
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
148
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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.
|
|
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
|
-
"
|
|
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
|
-
"
|
|
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
|