diff --git a/MeshCentralServer.njsproj b/MeshCentralServer.njsproj index 3f50007e..e72e3d05 100644 --- a/MeshCentralServer.njsproj +++ b/MeshCentralServer.njsproj @@ -271,6 +271,8 @@ + + diff --git a/package.json b/package.json index 7e32f108..ec75e3d0 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,10 @@ "express": "^4.17.0", "express-handlebars": "^3.1.0", "express-ws": "^4.0.0", + "html-minifier": "^4.0.0", "ipcheck": "^0.1.0", "meshcentral": "*", + "minify-js": "0.0.4", "minimist": "^1.2.0", "multiparty": "^4.2.1", "nedb": "^1.8.0", diff --git a/public/compress.bat b/public/compress.bat index b6e55625..fba0f876 100644 --- a/public/compress.bat +++ b/public/compress.bat @@ -1,18 +1,4 @@ @ECHO OFF -CALL:CompressHandlebars default -CALL:CompressHandlebars default-mobile -CALL:CompressHandlebars login -CALL:CompressHandlebars login-mobile -CALL:CompressHandlebars messenger -PAUSE -GOTO:eof - -:CompressHandlebars -ECHO COMPRESS ..\views\%~1.handlebars TO ..\views\%~1-min.handlebars -DEL ..\views\%~1-min.handlebars -COPY ..\views\%~1.handlebars index.html -..\..\WebSiteCompiler\bin\Debug\WebSiteCompiler.exe compress.wcc -c -COPY compress.htm ..\views\%~1-min.handlebars -DEL compress.htm -DEL index.html -GOTO:eof +CD ..\translate +C:\Users\Default.DESKTOP-M9I88C9\AppData\Roaming\nvm\v12.13.0\node translate.js minifyall +C:\Users\Default.DESKTOP-M9I88C9\AppData\Roaming\nvm\v12.13.0\node translate.js translateall diff --git a/public/player-min.htm b/public/player-min.htm new file mode 100644 index 00000000..942a7b6e --- /dev/null +++ b/public/player-min.htm @@ -0,0 +1 @@ +
00:00:00
 
\ No newline at end of file diff --git a/public/translations/player-min_fr.htm b/public/translations/player-min_fr.htm new file mode 100644 index 00000000..92c93734 --- /dev/null +++ b/public/translations/player-min_fr.htm @@ -0,0 +1 @@ +
00:00:00
 
\ No newline at end of file diff --git a/public/translations/player.min_fr.htm b/public/translations/player.min_fr.htm new file mode 100644 index 00000000..02e7e779 --- /dev/null +++ b/public/translations/player.min_fr.htm @@ -0,0 +1 @@ +
00:00:00
 
\ No newline at end of file diff --git a/public/translations/player_fr.htm-min b/public/translations/player_fr.htm-min new file mode 100644 index 00000000..66dc9051 --- /dev/null +++ b/public/translations/player_fr.htm-min @@ -0,0 +1 @@ +undefined \ No newline at end of file diff --git a/public/translations/player_fr.htm-min2 b/public/translations/player_fr.htm-min2 new file mode 100644 index 00000000..02e7e779 --- /dev/null +++ b/public/translations/player_fr.htm-min2 @@ -0,0 +1 @@ +
00:00:00
 
\ No newline at end of file diff --git a/public/translations/player_fr.min.htm b/public/translations/player_fr.min.htm new file mode 100644 index 00000000..02e7e779 --- /dev/null +++ b/public/translations/player_fr.min.htm @@ -0,0 +1 @@ +
00:00:00
 
\ No newline at end of file diff --git a/public/translations/player_fr_fr.min.htm b/public/translations/player_fr_fr.min.htm new file mode 100644 index 00000000..02e7e779 --- /dev/null +++ b/public/translations/player_fr_fr.min.htm @@ -0,0 +1 @@ +
00:00:00
 
\ No newline at end of file diff --git a/translate/translate.js b/translate/translate.js index a994eb13..98f5258d 100644 --- a/translate/translate.js +++ b/translate/translate.js @@ -13,7 +13,8 @@ var translationTable = null; var sourceStrings = null; var jsdom = null; //require('jsdom'); var esprima = null; //require('esprima'); // https://www.npmjs.com/package/esprima -//var { JSDOM } = jsdom; +var minifyLib = 2; // 0 = None, 1 = minify-js, 2 = HTMLMinifier +var minify = null; var meshCentralSourceFiles = [ "../views/agentinvite.handlebars", @@ -21,6 +22,7 @@ var meshCentralSourceFiles = [ "../views/default-mobile.handlebars", "../views/download.handlebars", "../views/error404.handlebars", + "../views/error404-mobile.handlebars", "../views/login.handlebars", "../views/login-mobile.handlebars", "../views/message.handlebars", @@ -32,15 +34,20 @@ var meshCentralSourceFiles = [ // node translate.json EXTRACT bob.json ../meshcentral/views/default.handlebars // node translate.js TRANSLATE fr test2.json ../meshcentral/views/default.handlebars -InstallModules(['jsdom', 'esprima'], start); +var libs = ['jsdom', 'esprima', 'minify-js']; +if (minifyLib == 1) { libs.push('minify-js'); } +if (minifyLib == 2) { libs.push('html-minifier'); } +InstallModules(libs, start); function start() { jsdom = require('jsdom'); esprima = require('esprima'); // https://www.npmjs.com/package/esprima + if (minifyLib == 1) { minify = require('minify-js'); } + if (minifyLib == 2) { minify = require('html-minifier').minify; } var command = null; if (process.argv.length > 2) { command = process.argv[2].toLowerCase(); } - if (['check', 'extract', 'extractall', 'translate', 'translateall'].indexOf(command) == -1) { command = null; } + if (['check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall'].indexOf(command) == -1) { command = null; } console.log('MeshCentral web site translator'); if (command == null) { @@ -61,6 +68,9 @@ function start() { console.log(''); console.log(' TRANSLATEALL'); console.log(' Translate all MeshCentral strings using the languages.json file.'); + console.log(''); + console.log(' MINIFYALL'); + console.log(' Minify the main MeshCentral english web pages.'); process.exit(); return; } @@ -111,6 +121,44 @@ function start() { translate(lang, langFile, sources, false); } + + if (command == 'minifyall') { + for (var i in meshCentralSourceFiles) { + var outname = meshCentralSourceFiles[i]; + 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'); + } + console.log('Generating ' + outnamemin + '...'); + + // Minify the file + if (minifyLib = 2) { + var minifiedOut = minify(fs.readFileSync(outname).toString(), { + collapseBooleanAttributes: true, + collapseInlineTagWhitespace: true, + 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+' }); + } + } + } } function translate(lang, langFile, sources, createSubDir) { @@ -129,7 +177,7 @@ function translate(lang, langFile, sources, createSubDir) { for (var i in langs) { translateEx(i, langFileData, sources, createSubDir); } } - process.exit(); + //process.exit(); return; } @@ -252,14 +300,59 @@ function translateFromHtml(lang, file, createSubDir) { var out = dom.serialize(); var outname = file; + var outnamemin = null; if (createSubDir != null) { outname = path.join(path.dirname(file), createSubDir, path.basename(file)); } - if (outname.endsWith('.handlebars')) { outname = (outname.substring(0, outname.length - 11) + '_' + lang + '.handlebars'); } - else if (outname.endsWith('.html')) { outname = (outname.substring(0, outname.length - 5) + '_' + lang + '.html'); } - else if (outname.endsWith('.htm')) { outname = (outname.substring(0, outname.length - 4) + '_' + lang + '.htm'); } - else { outname = (outname + '_' + lang); } + if (outname.endsWith('.handlebars')) { + outnamemin = (outname.substring(0, outname.length - 11) + '-min_' + lang + '.handlebars'); + outname = (outname.substring(0, outname.length - 11) + '_' + lang + '.handlebars'); + } else if (outname.endsWith('.html')) { + outnamemin = (outname.substring(0, outname.length - 5) + '-min_' + lang + '.html'); + outname = (outname.substring(0, outname.length - 5) + '_' + lang + '.html'); + } else if (outname.endsWith('.htm')) { + outnamemin = (outname.substring(0, outname.length - 4) + '-min_' + lang + '.htm'); + outname = (outname.substring(0, outname.length - 4) + '_' + lang + '.htm'); + } else { + outnamemin = (outname + '_' + lang + '.min'); + outname = (outname + '_' + lang); + } fs.writeFileSync(outname, out, { flag: 'w+' }); + + // Minify the file + if (minifyLib == 1) { + minify.file({ + file: outname, + dist: outnamemin + }, (e, compress) => { + if (e) { console.log('ERROR ', e); return done(); } + compress.run((e) => { e ? console.log('Minification fail', e) : console.log('Minification sucess'); minifyDone(); }); + } + ); + } + + // Minify the file + if (minifyLib = 2) { + var minifiedOut = minify(out, { + collapseBooleanAttributes: true, + collapseInlineTagWhitespace: true, + 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+' }); + } } +function minifyDone() { console.log('Completed minification.'); } + function translateStrings(name, node) { for (var i = 0; i < node.childNodes.length; i++) { var subnode = node.childNodes[i]; diff --git a/views/agentinvite-min.handlebars b/views/agentinvite-min.handlebars new file mode 100644 index 00000000..621bfcd4 --- /dev/null +++ b/views/agentinvite-min.handlebars @@ -0,0 +1 @@ +MeshCentral - Agent Installation
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

Remote Agent Installation

You have been invited to install a software that will allow a remote operator to fully access your computer remotely including the desktop and files. Only follow the instructions below if this invitation was expected and you know who will be accessing your computer. Selecting your operation system and follow the instructions below.

Microsoft™ Windows 64bit

Download the software here, run it and press "Install" or "Connect".

Microsoft™ Windows 32bit

Download the software here, run it and press "Install" or "Connect".

Linux

To install, cut and paste the following command in a root terminal.

To uninstall, cut and paste the following command as root.



Apple™ MacOS

Download the installer here, right click on it or press "control" and click on the file. Then select "Open" and follow the instructions.

\ No newline at end of file diff --git a/views/default-min.handlebars b/views/default-min.handlebars index ec459cbb..6d42ef46 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1,7023 +1,15 @@ - {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

{{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + function addDetailItem(title, value, state) { return '
' + value + '' + title + '
'; } + function format(format) { var args = Array.prototype.slice.call(arguments, 1); return format.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); }; + function nobreak(x) { return x.split(' ').join(' '); } \ No newline at end of file diff --git a/views/default-mobile-min.handlebars b/views/default-mobile-min.handlebars index eecf06f5..f590c545 100644 --- a/views/default-mobile-min.handlebars +++ b/views/default-mobile-min.handlebars @@ -1 +1 @@ - {{{title}}}
{{{title}}}
{{{title2}}}
\ No newline at end of file +{{{title}}}
{{{title}}}
{{{title2}}}
\ No newline at end of file diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars index 75c0abd6..7f5e7183 100644 --- a/views/default-mobile.handlebars +++ b/views/default-mobile.handlebars @@ -568,8 +568,8 @@
- -
Other
diff --git a/views/download-min.handlebars b/views/download-min.handlebars new file mode 100644 index 00000000..d4f2c1e7 --- /dev/null +++ b/views/download-min.handlebars @@ -0,0 +1 @@ +MeshCentral - Download
{{{title}}}
{{{title2}}}

Download

{{{message}}}


\ No newline at end of file diff --git a/views/error404-min.handlebars b/views/error404-min.handlebars new file mode 100644 index 00000000..8e2b960c --- /dev/null +++ b/views/error404-min.handlebars @@ -0,0 +1 @@ +MeshCentral - Terms of use
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

404
This page does not exist
\ No newline at end of file diff --git a/views/error404-mobile-min.handlebars b/views/error404-mobile-min.handlebars new file mode 100644 index 00000000..12f6dc9f --- /dev/null +++ b/views/error404-mobile-min.handlebars @@ -0,0 +1 @@ +MeshCentral - Terms of use
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

404
This page does not exist
\ No newline at end of file diff --git a/views/login-min.handlebars b/views/login-min.handlebars index f57ebd75..08876e88 100644 --- a/views/login-min.handlebars +++ b/views/login-min.handlebars @@ -1 +1 @@ - {{{title}}} - Login
{{{title}}}
{{{title2}}}

Welcome


\ No newline at end of file +{{{title}}} - Login
{{{title}}}
{{{title2}}}

Welcome


\ No newline at end of file diff --git a/views/login-mobile-min.handlebars b/views/login-mobile-min.handlebars index 8d374e1d..ddbe028e 100644 --- a/views/login-mobile-min.handlebars +++ b/views/login-mobile-min.handlebars @@ -1 +1 @@ - MeshCentral - Login
{{{title}}}
{{{title2}}}
\ No newline at end of file +MeshCentral - Login
{{{title}}}
{{{title2}}}
\ No newline at end of file diff --git a/views/message-min.handlebars b/views/message-min.handlebars new file mode 100644 index 00000000..5a96f1d6 --- /dev/null +++ b/views/message-min.handlebars @@ -0,0 +1 @@ +MeshCentral - {{{title3}}}
{{{title}}}
{{{title2}}}

{{{title3}}}

{{{message}}}


\ No newline at end of file diff --git a/views/messenger-min.handlebars b/views/messenger-min.handlebars index a7d98d4f..5efd3707 100644 --- a/views/messenger-min.handlebars +++ b/views/messenger-min.handlebars @@ -1 +1 @@ - MeshMessenger
MeshMessenger
\ No newline at end of file +MeshMessenger
MeshMessenger
\ No newline at end of file diff --git a/views/translations/agentinvite-min_fr.handlebars b/views/translations/agentinvite-min_fr.handlebars new file mode 100644 index 00000000..01590ed4 --- /dev/null +++ b/views/translations/agentinvite-min_fr.handlebars @@ -0,0 +1 @@ +MeshCentral - Agent Installation
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

Remote Agent Installation

You have been invited to install a software that will allow a remote operator to fully access your computer remotely including the desktop and files. Only follow the instructions below if this invitation was expected and you know who will be accessing your computer. Selecting your operation system and follow the instructions below.

Microsoft™ Windows 64bit

Download the software here, run it and press "Install" or "Connect".

Microsoft™ Windows 32bit

Download the software here, run it and press "Install" or "Connect".

Linux

To install, cut and paste the following command in a root terminal.

To uninstall, cut and paste the following command as root.



Apple™ MacOS

Download the installer here, right click on it or press "control" and click on the file. Then select "Open" and follow the instructions.

\ No newline at end of file diff --git a/views/translations/default-min_fr.handlebars b/views/translations/default-min_fr.handlebars new file mode 100644 index 00000000..98094639 --- /dev/null +++ b/views/translations/default-min_fr.handlebars @@ -0,0 +1,8339 @@ +{{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/translations/default-mobile-min_fr.handlebars b/views/translations/default-mobile-min_fr.handlebars new file mode 100644 index 00000000..031c56be --- /dev/null +++ b/views/translations/default-mobile-min_fr.handlebars @@ -0,0 +1 @@ +{{{title}}}
{{{title}}}
{{{title2}}}
\ No newline at end of file diff --git a/views/translations/default-mobile_fr.handlebars b/views/translations/default-mobile_fr.handlebars index 746cdd8c..d0cbb50f 100644 --- a/views/translations/default-mobile_fr.handlebars +++ b/views/translations/default-mobile_fr.handlebars @@ -566,9 +566,9 @@
- -
+
+
+
Autre
diff --git a/views/translations/download-min_fr.handlebars b/views/translations/download-min_fr.handlebars new file mode 100644 index 00000000..31c57152 --- /dev/null +++ b/views/translations/download-min_fr.handlebars @@ -0,0 +1 @@ +MeshCentral - Download
{{{title}}}
{{{title2}}}

Download

{{{message}}}


\ No newline at end of file diff --git a/views/translations/error404-min_fr.handlebars b/views/translations/error404-min_fr.handlebars new file mode 100644 index 00000000..2f64dcb7 --- /dev/null +++ b/views/translations/error404-min_fr.handlebars @@ -0,0 +1 @@ +MeshCentral - Terms of use
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

404
This page does not exist
\ No newline at end of file diff --git a/views/translations/error404-mobile-min_fr.handlebars b/views/translations/error404-mobile-min_fr.handlebars new file mode 100644 index 00000000..80ed0505 --- /dev/null +++ b/views/translations/error404-mobile-min_fr.handlebars @@ -0,0 +1 @@ +MeshCentral - Terms of use
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

404
This page does not exist
\ No newline at end of file diff --git a/views/translations/error404-mobile_fr.handlebars b/views/translations/error404-mobile_fr.handlebars new file mode 100644 index 00000000..ec40a31e --- /dev/null +++ b/views/translations/error404-mobile_fr.handlebars @@ -0,0 +1,55 @@ + + + + + + + MeshCentral - Terms of use + + + +
+ +
+
+ {{{title}}} +
+
+ {{{title2}}} +
+

{{{logoutControl}}}

+
+
+
+
404
+
This page does not exist
+ +
+
+ +
+ + + \ No newline at end of file diff --git a/views/translations/login-min_fr.handlebars b/views/translations/login-min_fr.handlebars new file mode 100644 index 00000000..54ec8fe4 --- /dev/null +++ b/views/translations/login-min_fr.handlebars @@ -0,0 +1 @@ +{{{title}}} - Login
{{{title}}}
{{{title2}}}

Bienvenue


\ No newline at end of file diff --git a/views/translations/login-mobile-min_fr.handlebars b/views/translations/login-mobile-min_fr.handlebars new file mode 100644 index 00000000..68a5c00d --- /dev/null +++ b/views/translations/login-mobile-min_fr.handlebars @@ -0,0 +1 @@ +MeshCentral - Login
{{{title}}}
{{{title2}}}
\ No newline at end of file diff --git a/views/translations/message-min_fr.handlebars b/views/translations/message-min_fr.handlebars new file mode 100644 index 00000000..7a75c669 --- /dev/null +++ b/views/translations/message-min_fr.handlebars @@ -0,0 +1 @@ +MeshCentral - {{{title3}}}
{{{title}}}
{{{title2}}}

{{{title3}}}

{{{message}}}


\ No newline at end of file diff --git a/views/translations/messenger-min_fr.handlebars b/views/translations/messenger-min_fr.handlebars new file mode 100644 index 00000000..0832659f --- /dev/null +++ b/views/translations/messenger-min_fr.handlebars @@ -0,0 +1 @@ +MeshMessenger
MeshMessenger
\ No newline at end of file