-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a002053
commit 9aefdef
Showing
6,268 changed files
with
1,079 additions
and
686,227 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
Binary file renamed
BIN
+4.05 KB
...node_modules/fsevents/build/Release/.node → .DS_Store
100755 → 100644
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = function(grunt) { | ||
grunt.registerTask('buildLess', 'Compile admin.less and add .section.less', function() { | ||
let adminContent = grunt.file.read('assets/styles/less/admin.less'); | ||
let sectionFiles = grunt.file.expand([ | ||
'assets/styles/less/sections/**/*.section.less', | ||
'assets/styles/less/sections/*.section.less' | ||
]); | ||
|
||
let combinedContent = adminContent + '\n'; | ||
sectionFiles.forEach(function(filePath) { | ||
let sectionContent = grunt.file.read(filePath); | ||
combinedContent += `\n/* ${filePath} */\n` + sectionContent; | ||
}); | ||
|
||
// -- New file | ||
grunt.file.write('assets/styles/less/admin_build.less', combinedContent); | ||
grunt.task.run(['less']); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
console.log("Init Templete Compile/Rendering"); | ||
|
||
// -- Add dependencies | ||
const path = require("path"), | ||
fs = require("fs"), | ||
nunjucks = require('nunjucks'), | ||
identifier = 'templates'; | ||
|
||
let Functions = require('../core/external/functions.js'); | ||
let Dipper = require('../core/framework/dipper.js'); | ||
let Config = require('../core/external/config.js'); | ||
|
||
// -- Init Dipper | ||
const env = process.argv[2] || 'development'; | ||
let settings = Config.settings; | ||
settings['shared']['environment'] = env; | ||
|
||
let opts = settings[env] || {}, | ||
shared = settings['shared'] || {}; | ||
const dipper = new Dipper(opts, shared); | ||
|
||
// -- Hydrate dipper | ||
Functions.hydrate(dipper); | ||
|
||
// -- Making nunjucks | ||
let nunjucksPath = path.join(processCwd(), '/assets'); | ||
nunjucks.configure(nunjucksPath, { | ||
autoescape: false, | ||
throwOnUndefined: true, | ||
noCache: true | ||
}); | ||
|
||
// -- Template directory | ||
const templatesDirectoryPath = '../assets/templates/'; | ||
|
||
// -- Call main function | ||
main(); | ||
|
||
// -- Define mainfunctions on other functions | ||
function main() { | ||
|
||
// -- Get template files | ||
const templates = getTemplates(templatesDirectoryPath); | ||
//console.log(templates); | ||
|
||
// -- Get home.html | ||
let homePageName = 'home.html'; | ||
getHtmlFromPage(homePageName).then((htmlContent) => { | ||
if (htmlContent) { | ||
// -- Divide content line by line | ||
const htmlContentLines = htmlContent.split('\n'); | ||
let lines = Array.from(htmlContentLines); | ||
// -- Iterate over each line | ||
for (let line of htmlContentLines) { | ||
let originalLine = line; | ||
// -- Remove spaces and tabs | ||
line = cleanALine(line); | ||
// -- Check is not empty and not a tag | ||
if (line.length != 0 && !line.includes('<')) { | ||
|
||
// -- Get template name | ||
var templateName = line.replace('include::', ''); | ||
// -- Check if its name "templates" add all templates if not add specific one | ||
if (templateName === identifier) { | ||
|
||
let allTemplatesCompiled = ''; | ||
for (let templateName in templates) { | ||
if (templateName.includes('template.html')) { | ||
let templatePath = templates[templateName]; | ||
let templateCompiled = compileTemplate(templatePath); | ||
allTemplatesCompiled += templateCompiled; | ||
} | ||
} | ||
lines = replaceInclude(lines, originalLine, allTemplatesCompiled); | ||
|
||
} else { | ||
let templatePath = templates[templateName]; | ||
let templateCompiled = compileTemplate(templatePath); | ||
lines = replaceInclude(lines, originalLine, templateCompiled); | ||
} | ||
} | ||
} | ||
// -- Join lines | ||
const newHtml = lines.join('\n'); | ||
// -- Create HTML file | ||
createHTMLFile(newHtml, homePageName); | ||
} | ||
}); | ||
} | ||
|
||
// -- Step 0 | ||
function getTemplates(directory) { | ||
|
||
const results = {}; | ||
|
||
// -- Sub functions | ||
function exploreDirectory(dir) { | ||
const files = fs.readdirSync(dir); | ||
files.forEach(function (file) { | ||
//console.log(file); | ||
if (!checkExcludes(file)) { | ||
const filePath = path.join(dir, file); | ||
//console.log(filePath); | ||
const stats = fs.statSync(filePath); | ||
if (stats.isFile()) { | ||
const extension = path.extname(file).toLowerCase(); | ||
if (extension === '.html') { | ||
results[file] = filePath; | ||
} | ||
} else if (stats.isDirectory()) { | ||
exploreDirectory(filePath); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
function checkExcludes(file) { | ||
|
||
const excludes = ['.DS_Store']; | ||
for (const esclude of excludes) { | ||
if (file.includes(esclude)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
// -- Main code | ||
const templatesPath = path.join(__dirname, directory); | ||
exploreDirectory(templatesPath); | ||
return results; | ||
} | ||
|
||
// -- Step 1 | ||
async function getHtmlFromPage(page) { | ||
|
||
const filename = path.join(processCwd(), '/assets/'); | ||
const exists = await fs.promises.access(filename, fs.constants.F_OK).then(() => true).catch(() => false); | ||
if (!exists) { | ||
console.log("Assets folder doesnt exists"); | ||
return null; | ||
} | ||
|
||
let fileContent; | ||
if (await fs.promises.stat(filename).then((stats) => stats.isDirectory())) { | ||
const filePath = path.join(filename, 'pages/' + page); | ||
try { | ||
fileContent = await fs.promises.readFile(filePath, { encoding: 'utf8' }); | ||
} catch (err) { | ||
console.log("Error in Home"); | ||
return null; | ||
} | ||
} | ||
return fileContent; | ||
} | ||
|
||
// -- Step 2 | ||
function compileTemplate(path) { | ||
|
||
// -- Data | ||
let data = { 'app': dipper } | ||
|
||
// -- Render | ||
return nunjucks.render(path, data); | ||
} | ||
|
||
// -- Step 3 | ||
function replaceInclude(lines, originalLine, templateCompiled) { | ||
const index = lines.indexOf(originalLine); | ||
if (index !== -1) { | ||
lines.splice(index, 1, templateCompiled); | ||
} | ||
return lines; | ||
} | ||
|
||
// -- Step 4 | ||
async function createHTMLFile(content, filePath) { | ||
|
||
//const { html } = require('js-beautify'); | ||
///content = html(content); | ||
|
||
const { minify } = require('html-minifier-terser'); | ||
//console.log(typeof content); | ||
const minified = await minify(content, { | ||
collapseWhitespace: true, | ||
collapseInlineTagWhitespace: true, | ||
removeComments: true, | ||
collapseBooleanAttributes: true, | ||
useShortDoctype: true, | ||
removeEmptyAttributes: true, | ||
removeOptionalTags: true, | ||
minifyJS: true | ||
}); | ||
|
||
const publicPath = path.join(processCwd(), '/public/pages'); | ||
fs.mkdirSync(publicPath, { recursive: true }); | ||
const absolutePath = path.join(publicPath, filePath); | ||
fs.writeFileSync(absolutePath, minified, 'utf8'); | ||
console.log(`Html file created at: ${absolutePath}`); | ||
} | ||
|
||
// -- Helpers | ||
function cleanALine(line) { | ||
line = line.replaceAll(' ', ''); | ||
line = line.replaceAll('\t', ''); | ||
line = line.replaceAll('\n', ''); | ||
return line; | ||
} | ||
|
||
function processCwd() { | ||
return process.cwd().replace('/.grunt', ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
module.exports = function(grunt) { | ||
|
||
require('jit-grunt')(grunt, { | ||
concat: 'grunt-contrib-concat', | ||
//compress: 'grunt-contrib-compress', | ||
clean: 'grunt-contrib-clean' | ||
}); | ||
|
||
// -- Load modules | ||
grunt.loadNpmTasks('grunt-contrib-cssmin'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-shell'); | ||
grunt.loadNpmTasks('grunt-run'); | ||
require('./.grunt/build_styles_task')(grunt); | ||
|
||
grunt.initConfig({ | ||
clean: { | ||
build: ['public/scripts/vanilla.min.js'], | ||
minified: ['public/scripts/api', 'public/scripts/controllers', 'public/scripts/views', 'public/scripts/app.min.js'] | ||
//minified: ['public/scripts/**/*.min.js', 'public/scripts/*', '!public/scripts/vanilla.min.js'] | ||
}, | ||
less: { | ||
development: { | ||
options: { | ||
compress: true, | ||
yuicompress: true, | ||
optimization: 2, | ||
strictImports: true | ||
}, | ||
files: { | ||
'public/styles/app.min.css' : 'assets/styles/less/admin_build.less' | ||
}, | ||
} | ||
}, | ||
watch: { | ||
options: { | ||
livereload: true | ||
}, | ||
styles: { | ||
files: [ | ||
'assets/styles/less/*.less', | ||
'assets/styles/less/**/*.less', | ||
'assets/styles/less/**/**/*.less', | ||
'!assets/styles/less/admin_build.less' | ||
], | ||
tasks: ['buildLess'], | ||
options: { | ||
nospawn: true | ||
} | ||
}, | ||
scripts: { | ||
files: [ | ||
'assets/pages/*.html', | ||
'assets/templates/**/*.html', | ||
'assets/templates/**/**/*.html', | ||
'external/view/*.js', | ||
'external/*.js', | ||
'framework/*.js' | ||
], | ||
tasks: ['shell:compileTemplates'] | ||
}, | ||
specificScripts: { | ||
files: ['assets/scripts/*.js', 'assets/scripts/**/*.js', 'assets/scripts/**/**/*.js'], | ||
tasks: ['uglify', 'clean:build', 'concat', 'clean:minified'] | ||
} | ||
}, | ||
uglify: { | ||
build: { | ||
options: { | ||
sourceMap: false, | ||
compress: { | ||
drop_console: false, | ||
sequences: true, | ||
dead_code: true, | ||
conditionals: true, | ||
booleans: true, | ||
unused: true, | ||
if_return: true, | ||
join_vars: true | ||
}, | ||
output: { | ||
ascii_only: true | ||
} | ||
}, | ||
files: [{ | ||
expand: true, | ||
src: [ | ||
'assets/scripts/*.js', | ||
'assets/scripts/**/*.js', | ||
'assets/scripts/**/**/*.js', | ||
'assets/scripts/**/**/**/*.js' | ||
], | ||
dest: 'public/', | ||
cwd: '', | ||
rename : function (dest, src) { | ||
|
||
var folder = src.substring(0, src.lastIndexOf('/')), | ||
filename = src.substring(src.lastIndexOf('/'), src.length); | ||
filename = filename.substring(0, filename.lastIndexOf('.')); | ||
folder = folder.replaceAll('assets', ''); | ||
return dest + folder + filename + '.min.js'; | ||
} | ||
}] | ||
} | ||
}, | ||
concat: { | ||
build: { | ||
src: [ | ||
// Order | ||
'public/scripts/controllers/**/*.min.js', | ||
'public/scripts/views/**/*.min.js', | ||
'public/scripts/api/**/*.min.js', | ||
'public/scripts/*.min.js', | ||
|
||
// Ignore files | ||
'!public/scripts/core/**', | ||
'!public/scripts/plugins/**', | ||
'!public/scripts/plugins/ui/**' | ||
], | ||
dest: 'public/scripts/vanilla.min.js' | ||
} | ||
}, | ||
compress: { | ||
main: { | ||
options: { | ||
mode: 'gzip' | ||
}, | ||
files: [{ | ||
expand: true, | ||
src: ['public/scripts/vanilla.min.js'], | ||
dest: '', | ||
ext: '.min.js.gz' | ||
}] | ||
} | ||
}, | ||
shell: { | ||
compileTemplates: { | ||
command: 'node .grunt/compile_html.js <%= grunt.option("env") %>' | ||
} | ||
} | ||
}); | ||
|
||
grunt.registerTask('default', ['buildLess', 'uglify', 'clean:build', 'concat', 'clean:minified', 'shell:compileTemplates', 'watch']); | ||
grunt.registerTask('build', ['buildLess', 'uglify', 'clean:build', 'concat', 'clean:minified', 'shell:compileTemplates']); | ||
grunt.registerTask('server', ['buildLess']); | ||
}; |
Oops, something went wrong.