vanilla-jet 1.0.32 → 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 +130 -132
- package/bin.js +1 -0
- package/package.json +2 -2
- package/public/scripts/vanilla.min.js +0 -0
package/.grunt/compile_html.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
123
|
+
function checkExcludes(file) {
|
|
126
124
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
149
|
-
|
|
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
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
return process.cwd()
|
|
218
|
+
.replace('/.grunt', '')
|
|
219
|
+
.replace('/node_modules/vanilla-jet', '');
|
|
222
220
|
}
|
package/bin.js
CHANGED
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,7 +29,7 @@
|
|
|
29
29
|
"homepage": "https://github.com/nalancer08/VanillaJet#readme",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"blueimp-md5": "2.8.0",
|
|
32
|
-
"chalk": "
|
|
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
|