@tixyel/cli 2.6.2 → 2.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/widget.js +55 -24
- package/package.json +1 -1
package/dist/widget.js
CHANGED
|
@@ -289,6 +289,13 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
289
289
|
return contents;
|
|
290
290
|
};
|
|
291
291
|
const usedWatermarks = new Set();
|
|
292
|
+
/**
|
|
293
|
+
* Build results processing
|
|
294
|
+
* Find all files based on patterns and process them according to their type
|
|
295
|
+
* (html, css, script, fields)
|
|
296
|
+
* Group results based on resultMapping and compactedMapping
|
|
297
|
+
* Compact/minify where applicable
|
|
298
|
+
*/
|
|
292
299
|
const results = Object.fromEntries(await Promise.all(Object.entries(findPatterns).map(async ([key, patterns]) => {
|
|
293
300
|
let result = '';
|
|
294
301
|
const list = normalizeList(patterns);
|
|
@@ -303,13 +310,14 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
303
310
|
// check formats
|
|
304
311
|
list.some((p) => formats.some((f) => p.toLowerCase().endsWith(f.toLowerCase()))));
|
|
305
312
|
};
|
|
313
|
+
const processed = new Set();
|
|
306
314
|
// Process HTML
|
|
307
315
|
if (check('html', '.html')) {
|
|
308
316
|
if (!usedWatermarks.has('html'))
|
|
309
317
|
result += watermark.html(widget) + '\n';
|
|
310
318
|
usedWatermarks.add('html');
|
|
311
319
|
if (verbose)
|
|
312
|
-
console.log(` - Processing HTML...`);
|
|
320
|
+
console.log(` - Processing HTML for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
|
|
313
321
|
const files = findAndRead(entryDir, list);
|
|
314
322
|
let mergedHTML = '';
|
|
315
323
|
for await (const fileContent of files) {
|
|
@@ -333,13 +341,14 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
333
341
|
}
|
|
334
342
|
const minified = await minifyHTML(mergedHTML, workspaceConfig.build?.obfuscation?.html);
|
|
335
343
|
result += minified.trim();
|
|
344
|
+
processed.add('html');
|
|
336
345
|
}
|
|
337
|
-
|
|
346
|
+
if (check(['css', 'style', 'styles'], '.css')) {
|
|
338
347
|
if (!usedWatermarks.has('css'))
|
|
339
348
|
result += watermark.css(widget) + '\n';
|
|
340
349
|
usedWatermarks.add('css');
|
|
341
350
|
if (verbose)
|
|
342
|
-
console.log(` - Processing CSS...`);
|
|
351
|
+
console.log(` - Processing CSS for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
|
|
343
352
|
const files = findAndRead(entryDir, list);
|
|
344
353
|
let mergedCSS = '';
|
|
345
354
|
for await (const content of files) {
|
|
@@ -356,28 +365,19 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
356
365
|
const processed = await postcss(plugin).process(content, { from: undefined });
|
|
357
366
|
mergedCSS += processed.css + '\n';
|
|
358
367
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
else if (check(['script', 'js', 'javascript'], '.js')) {
|
|
362
|
-
if (!usedWatermarks.has('script'))
|
|
363
|
-
result += watermark.script(widget) + '\n';
|
|
364
|
-
usedWatermarks.add('script');
|
|
365
|
-
if (verbose)
|
|
366
|
-
console.log(` - Processing JavaScript...`);
|
|
367
|
-
const files = findAndRead(entryDir, list);
|
|
368
|
-
let mergedJS = '';
|
|
369
|
-
for await (const content of files) {
|
|
370
|
-
const obfuscated = JavaScriptObfuscator.obfuscate(content, workspaceConfig.build?.obfuscation?.javascript);
|
|
371
|
-
mergedJS += obfuscated.getObfuscatedCode() + '\n';
|
|
368
|
+
if (processed.has('html')) {
|
|
369
|
+
result = result += `<style>${mergedCSS.trim()}</style>`;
|
|
372
370
|
}
|
|
373
|
-
|
|
371
|
+
else
|
|
372
|
+
result += mergedCSS.trim();
|
|
373
|
+
processed.add('css');
|
|
374
374
|
}
|
|
375
|
-
|
|
375
|
+
if (check(['typescript', 'ts'], '.ts')) {
|
|
376
376
|
if (!usedWatermarks.has('script'))
|
|
377
377
|
result += watermark.script(widget) + '\n';
|
|
378
378
|
usedWatermarks.add('script');
|
|
379
379
|
if (verbose)
|
|
380
|
-
console.log(` - Processing TypeScript...`);
|
|
380
|
+
console.log(` - Processing TypeScript for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
|
|
381
381
|
const files = findAndRead(entryDir, list);
|
|
382
382
|
let mergedTS = '';
|
|
383
383
|
for await (const content of files) {
|
|
@@ -396,11 +396,35 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
396
396
|
}
|
|
397
397
|
// Obfuscate the compiled JavaScript
|
|
398
398
|
const obfuscated = JavaScriptObfuscator.obfuscate(mergedTS.trim(), workspaceConfig.build?.obfuscation?.javascript);
|
|
399
|
-
|
|
399
|
+
if (processed.has('html')) {
|
|
400
|
+
result = result += `<script>${obfuscated.getObfuscatedCode()}</script>`;
|
|
401
|
+
}
|
|
402
|
+
else
|
|
403
|
+
result += obfuscated.getObfuscatedCode();
|
|
404
|
+
processed.add('typescript');
|
|
400
405
|
}
|
|
401
|
-
|
|
406
|
+
if (check(['script', 'js', 'javascript'], '.js')) {
|
|
407
|
+
if (!usedWatermarks.has('script'))
|
|
408
|
+
result += watermark.script(widget) + '\n';
|
|
409
|
+
usedWatermarks.add('script');
|
|
410
|
+
if (verbose)
|
|
411
|
+
console.log(` - Processing JavaScript for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
|
|
412
|
+
const files = findAndRead(entryDir, list);
|
|
413
|
+
let mergedJS = '';
|
|
414
|
+
for await (const content of files) {
|
|
415
|
+
const obfuscated = JavaScriptObfuscator.obfuscate(content, workspaceConfig.build?.obfuscation?.javascript);
|
|
416
|
+
mergedJS += obfuscated.getObfuscatedCode() + '\n';
|
|
417
|
+
}
|
|
418
|
+
if (processed.has('html')) {
|
|
419
|
+
result = result += `<script>${mergedJS.trim()}</script>`;
|
|
420
|
+
}
|
|
421
|
+
else
|
|
422
|
+
result += mergedJS.trim();
|
|
423
|
+
processed.add('script');
|
|
424
|
+
}
|
|
425
|
+
if (check(['fields', 'fielddata', 'fieldData', 'cf', 'customfields'], '.json')) {
|
|
402
426
|
if (verbose)
|
|
403
|
-
console.log(` - Processing
|
|
427
|
+
console.log(` - Processing JSON for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
|
|
404
428
|
const files = findAndRead(entryDir, list);
|
|
405
429
|
let mergedFields = {};
|
|
406
430
|
for await (const content of files) {
|
|
@@ -414,15 +438,22 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
414
438
|
throw error;
|
|
415
439
|
}
|
|
416
440
|
}
|
|
417
|
-
|
|
441
|
+
if (!processed.size)
|
|
442
|
+
result += JSON.stringify(mergedFields, null, 2);
|
|
443
|
+
processed.add('fields');
|
|
418
444
|
}
|
|
419
|
-
|
|
445
|
+
if (!result.length) {
|
|
420
446
|
if (verbose)
|
|
421
447
|
console.log(` - Unknown build key: ${key}, the available keys are html, css, script and fields.`);
|
|
422
448
|
result += '';
|
|
423
449
|
}
|
|
424
450
|
return [key, result];
|
|
425
451
|
})));
|
|
452
|
+
if (verbose) {
|
|
453
|
+
console.log(` - Build results:`, Object.keys(results)
|
|
454
|
+
.map((k) => `${k}: ${results[k].length} bytes`)
|
|
455
|
+
.join(', '));
|
|
456
|
+
}
|
|
426
457
|
for await (const [filename, key] of Object.entries(resultMapping)) {
|
|
427
458
|
let content = '';
|
|
428
459
|
if (typeof key === 'string')
|