diff --git a/meshcentral.js b/meshcentral.js index a34c07ad..648a300a 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -183,10 +183,18 @@ function CreateMeshCentralServer(config, args) { for (var i in files) { var file = obj.path.join(obj.webViewsOverridePath, files[i]); if (file.endsWith('.handlebars') && !file.endsWith('-min.handlebars')) { + translateEngine.startEx(['', '', 'minify', file]); + } + } + files = obj.fs.readdirSync(obj.webViewsOverridePath); + for (var i in files) { + var file = obj.path.join(obj.webViewsOverridePath, files[i]); + if (file.endsWith('.handlebars') || file.endsWith('-min.handlebars')) { translateEngine.startEx(['', '', 'translate', '*', translationFile, file, '--subdir:translations']); } } } + /* if (obj.webPublicOverridePath != null) { didSomething = true; var files = obj.fs.readdirSync(obj.webPublicOverridePath); @@ -197,6 +205,7 @@ function CreateMeshCentralServer(config, args) { } } } + */ if (didSomething == false) { console.log("Nothing to do."); } process.exit(); diff --git a/translate/translate.js b/translate/translate.js index db202971..e231a95b 100644 --- a/translate/translate.js +++ b/translate/translate.js @@ -99,7 +99,7 @@ function startEx(argv) { var command = null; if (argv.length > 2) { command = argv[2].toLowerCase(); } - if (['check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall', 'merge', 'totext', 'fromtext'].indexOf(command) == -1) { command = null; } + if (['minify', 'check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall', 'merge', 'totext', 'fromtext'].indexOf(command) == -1) { command = null; } if (directRun) { log('MeshCentral web site translator'); } if (command == null) { @@ -283,6 +283,42 @@ function startEx(argv) { } } } + + if (command == 'minify') { + var outname = argv[3]; + var outnamemin = null; + if (outname.endsWith('.handlebars')) { + outnamemin = (outname.substring(0, outname.length - 11) + '-min.handlebars'); + } else if (outname.endsWith('.html')) { + outnamemin = (outname.substring(0, outname.length - 5) + '-min.html'); + } else if (outname.endsWith('.htm')) { + outnamemin = (outname.substring(0, outname.length - 4) + '-min.htm'); + } else { + outnamemin = (outname, outname + '.min'); + } + log('Generating ' + path.basename(outnamemin) + '...'); + + // Minify the file + if (minifyLib = 2) { + var minifiedOut = minify(fs.readFileSync(outname).toString(), { + collapseBooleanAttributes: true, + collapseInlineTagWhitespace: false, // This is not good. + collapseWhitespace: true, + minifyCSS: true, + minifyJS: true, + removeComments: true, + removeOptionalTags: true, + removeEmptyAttributes: true, + removeAttributeQuotes: true, + removeRedundantAttributes: true, + removeScriptTypeAttributes: true, + removeTagWhitespace: true, + preserveLineBreaks: false, + useShortDoctype: true + }); + fs.writeFileSync(outnamemin, minifiedOut, { flag: 'w+' }); + } + } } @@ -474,7 +510,7 @@ function extract(langFile, sources) { } fs.writeFileSync(langFile, translationsToJson({ strings: output }), { flag: 'w+' }); log(format("{0} strings in output file.", count)); - process.exit(); + //process.exit(); return; }