Improved --translate feature.

This commit is contained in:
Ylian Saint-Hilaire 2020-02-06 11:33:21 -08:00
parent ffb61443ec
commit 21162cab72
2 changed files with 47 additions and 2 deletions

View File

@ -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();

View File

@ -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;
}