Improved --translate feature.
Ylian Saint-Hilaire committed
Feb 6, 2020 at 11:33 UTC
21162cab72b6f8b85760e7997e3284eb52403177
2 files changed
+47
-2
meshcentral.js
+9
@@ -183,10 +183,18 @@ function CreateMeshCentralServer(config, args) {
183
for (var i in files) {
184
var file = obj.path.join(obj.webViewsOverridePath, files[i]);
185
if (file.endsWith('.handlebars') && !file.endsWith('-min.handlebars')) {
186
+ translateEngine.startEx(['', '', 'minify', file]);
187
+ }
188
+ }
189
+ files = obj.fs.readdirSync(obj.webViewsOverridePath);
190
+ for (var i in files) {
191
+ var file = obj.path.join(obj.webViewsOverridePath, files[i]);
192
+ if (file.endsWith('.handlebars') || file.endsWith('-min.handlebars')) {
193
translateEngine.startEx(['', '', 'translate', '*', translationFile, file, '--subdir:translations']);
194
}
195
}
196
}
197
+ /*
198
if (obj.webPublicOverridePath != null) {
199
didSomething = true;
200
var files = obj.fs.readdirSync(obj.webPublicOverridePath);
@@ -197,6 +205,7 @@ function CreateMeshCentralServer(config, args) {
205
}
206
}
207
}
208
+ */
209
210
if (didSomething == false) { console.log("Nothing to do."); }
211
process.exit();
translate/translate.js
+38
-2
@@ -99,7 +99,7 @@ function startEx(argv) {
99
100
var command = null;
101
if (argv.length > 2) { command = argv[2].toLowerCase(); }
102
- if (['check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall', 'merge', 'totext', 'fromtext'].indexOf(command) == -1) { command = null; }
102
+ if (['minify', 'check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall', 'merge', 'totext', 'fromtext'].indexOf(command) == -1) { command = null; }
103
104
if (directRun) { log('MeshCentral web site translator'); }
105
if (command == null) {
@@ -283,6 +283,42 @@ function startEx(argv) {
283
}
284
}
285
}
286
+
287
+ if (command == 'minify') {
288
+ var outname = argv[3];
289
+ var outnamemin = null;
290
+ if (outname.endsWith('.handlebars')) {
291
+ outnamemin = (outname.substring(0, outname.length - 11) + '-min.handlebars');
292
+ } else if (outname.endsWith('.html')) {
293
+ outnamemin = (outname.substring(0, outname.length - 5) + '-min.html');
294
+ } else if (outname.endsWith('.htm')) {
295
+ outnamemin = (outname.substring(0, outname.length - 4) + '-min.htm');
296
+ } else {
297
+ outnamemin = (outname, outname + '.min');
298
+ }
299
+ log('Generating ' + path.basename(outnamemin) + '...');
300
+
301
+ // Minify the file
302
+ if (minifyLib = 2) {
303
+ var minifiedOut = minify(fs.readFileSync(outname).toString(), {
304
+ collapseBooleanAttributes: true,
305
+ collapseInlineTagWhitespace: false, // This is not good.
306
+ collapseWhitespace: true,
307
+ minifyCSS: true,
308
+ minifyJS: true,
309
+ removeComments: true,
310
+ removeOptionalTags: true,
311
+ removeEmptyAttributes: true,
312
+ removeAttributeQuotes: true,
313
+ removeRedundantAttributes: true,
314
+ removeScriptTypeAttributes: true,
315
+ removeTagWhitespace: true,
316
+ preserveLineBreaks: false,
317
+ useShortDoctype: true
318
+ });
319
+ fs.writeFileSync(outnamemin, minifiedOut, { flag: 'w+' });
320
+ }
321
+ }
322
}
323
324
@@ -474,7 +510,7 @@ function extract(langFile, sources) {
510
}
511
fs.writeFileSync(langFile, translationsToJson({ strings: output }), { flag: 'w+' });
512
log(format("{0} strings in output file.", count));
477
- process.exit();
513
+ //process.exit();
514
return;
515
}
516