@tixyel/cli 2.6.2 → 2.6.4
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 +78 -47
- package/package.json +1 -1
package/dist/widget.js
CHANGED
|
@@ -278,20 +278,28 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
278
278
|
// const results: Record<string, string> = {};
|
|
279
279
|
const normalizeList = (value) => (Array.isArray(value) ? value.filter(Boolean) : []);
|
|
280
280
|
const findAndRead = (baseDir, patterns) => {
|
|
281
|
-
const contents =
|
|
281
|
+
const contents = {};
|
|
282
282
|
for (const pattern of patterns) {
|
|
283
283
|
const fullPath = join(baseDir, pattern);
|
|
284
284
|
if (existsSync(fullPath)) {
|
|
285
285
|
const content = readFileSync(fullPath, 'utf-8');
|
|
286
|
-
contents
|
|
286
|
+
contents[pattern] = content;
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
return contents;
|
|
290
290
|
};
|
|
291
291
|
const usedWatermarks = new Set();
|
|
292
|
+
const processedFile = new Set();
|
|
293
|
+
/**
|
|
294
|
+
* Build results processing
|
|
295
|
+
* Find all files based on patterns and process them according to their type
|
|
296
|
+
* (html, css, script, fields)
|
|
297
|
+
* Group results based on resultMapping and compactedMapping
|
|
298
|
+
* Compact/minify where applicable
|
|
299
|
+
*/
|
|
292
300
|
const results = Object.fromEntries(await Promise.all(Object.entries(findPatterns).map(async ([key, patterns]) => {
|
|
293
301
|
let result = '';
|
|
294
|
-
|
|
302
|
+
let list = normalizeList(patterns.filter((p) => !processedFile.has(p)));
|
|
295
303
|
if (!list.length)
|
|
296
304
|
return [key, ''];
|
|
297
305
|
const check = (keys, formats) => {
|
|
@@ -303,46 +311,39 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
303
311
|
// check formats
|
|
304
312
|
list.some((p) => formats.some((f) => p.toLowerCase().endsWith(f.toLowerCase()))));
|
|
305
313
|
};
|
|
314
|
+
const processed = new Set();
|
|
306
315
|
// Process HTML
|
|
307
316
|
if (check('html', '.html')) {
|
|
308
317
|
if (!usedWatermarks.has('html'))
|
|
309
318
|
result += watermark.html(widget) + '\n';
|
|
310
319
|
usedWatermarks.add('html');
|
|
320
|
+
const fileList = list.filter((e) => e.endsWith('.html') && !processedFile.has(e));
|
|
311
321
|
if (verbose)
|
|
312
|
-
console.log(` - Processing HTML...`);
|
|
313
|
-
const files = findAndRead(entryDir,
|
|
322
|
+
console.log(` - Processing HTML for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
|
|
323
|
+
const files = findAndRead(entryDir, fileList);
|
|
314
324
|
let mergedHTML = '';
|
|
315
|
-
for await (const fileContent of files) {
|
|
325
|
+
for await (const [pattern, fileContent] of Object.entries(files)) {
|
|
316
326
|
// Extract body content
|
|
317
327
|
const bodyMatch = fileContent.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
|
|
318
328
|
if (bodyMatch && bodyMatch[1]) {
|
|
319
329
|
mergedHTML += bodyMatch[1].trim() + '\n';
|
|
320
|
-
|
|
321
|
-
// Extract and inline styles
|
|
322
|
-
const styleMatches = fileContent.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/gi);
|
|
323
|
-
for (const match of styleMatches) {
|
|
324
|
-
mergedHTML += `<style>${match[1]}</style>\n`;
|
|
325
|
-
}
|
|
326
|
-
// Extract and inline <script> tags
|
|
327
|
-
const scriptMatches = fileContent.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/gi);
|
|
328
|
-
for (const match of scriptMatches) {
|
|
329
|
-
if (match[1]) {
|
|
330
|
-
mergedHTML += `<script>${match[1]}</script>\n`;
|
|
331
|
-
}
|
|
330
|
+
processedFile.add(pattern);
|
|
332
331
|
}
|
|
333
332
|
}
|
|
334
333
|
const minified = await minifyHTML(mergedHTML, workspaceConfig.build?.obfuscation?.html);
|
|
335
334
|
result += minified.trim();
|
|
335
|
+
processed.add('html');
|
|
336
336
|
}
|
|
337
|
-
|
|
337
|
+
if (check(['css', 'style', 'styles'], '.css')) {
|
|
338
338
|
if (!usedWatermarks.has('css'))
|
|
339
339
|
result += watermark.css(widget) + '\n';
|
|
340
340
|
usedWatermarks.add('css');
|
|
341
|
+
const fileList = list.filter((e) => e.endsWith('.css') && !processedFile.has(e));
|
|
341
342
|
if (verbose)
|
|
342
|
-
console.log(` - Processing CSS...`);
|
|
343
|
-
const files = findAndRead(entryDir,
|
|
343
|
+
console.log(` - Processing CSS for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
|
|
344
|
+
const files = findAndRead(entryDir, fileList);
|
|
344
345
|
let mergedCSS = '';
|
|
345
|
-
for await (const content of files) {
|
|
346
|
+
for await (const [pattern, content] of Object.entries(files)) {
|
|
346
347
|
const plugin = [
|
|
347
348
|
autoprefixer({
|
|
348
349
|
overrideBrowserslist: ['Chrome 127'],
|
|
@@ -355,32 +356,25 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
355
356
|
}
|
|
356
357
|
const processed = await postcss(plugin).process(content, { from: undefined });
|
|
357
358
|
mergedCSS += processed.css + '\n';
|
|
359
|
+
processedFile.add(pattern);
|
|
358
360
|
}
|
|
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';
|
|
361
|
+
if (processed.has('html')) {
|
|
362
|
+
result = result += `<style>${mergedCSS.trim()}</style>`;
|
|
372
363
|
}
|
|
373
|
-
|
|
364
|
+
else
|
|
365
|
+
result += mergedCSS.trim();
|
|
366
|
+
processed.add('css');
|
|
374
367
|
}
|
|
375
|
-
|
|
368
|
+
if (check(['typescript', 'ts'], '.ts')) {
|
|
376
369
|
if (!usedWatermarks.has('script'))
|
|
377
370
|
result += watermark.script(widget) + '\n';
|
|
378
371
|
usedWatermarks.add('script');
|
|
372
|
+
const fileList = list.filter((e) => e.endsWith('.ts') && !processedFile.has(e));
|
|
379
373
|
if (verbose)
|
|
380
|
-
console.log(` - Processing TypeScript...`);
|
|
381
|
-
const files = findAndRead(entryDir,
|
|
374
|
+
console.log(` - Processing TypeScript for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
|
|
375
|
+
const files = findAndRead(entryDir, fileList);
|
|
382
376
|
let mergedTS = '';
|
|
383
|
-
for await (const content of files) {
|
|
377
|
+
for await (const [pattern, content] of Object.entries(files)) {
|
|
384
378
|
try {
|
|
385
379
|
const transpiled = transformSync(content, {
|
|
386
380
|
loader: 'ts',
|
|
@@ -393,17 +387,47 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
393
387
|
console.warn(` ⚠️ Failed to compile TypeScript: ${error}`);
|
|
394
388
|
throw error;
|
|
395
389
|
}
|
|
390
|
+
finally {
|
|
391
|
+
processedFile.add(pattern);
|
|
392
|
+
}
|
|
396
393
|
}
|
|
397
394
|
// Obfuscate the compiled JavaScript
|
|
398
395
|
const obfuscated = JavaScriptObfuscator.obfuscate(mergedTS.trim(), workspaceConfig.build?.obfuscation?.javascript);
|
|
399
|
-
|
|
396
|
+
if (processed.has('html')) {
|
|
397
|
+
result = result += `<script>${obfuscated.getObfuscatedCode()}</script>`;
|
|
398
|
+
}
|
|
399
|
+
else
|
|
400
|
+
result += obfuscated.getObfuscatedCode();
|
|
401
|
+
processed.add('typescript');
|
|
400
402
|
}
|
|
401
|
-
|
|
403
|
+
if (check(['script', 'js', 'javascript'], '.js')) {
|
|
404
|
+
if (!usedWatermarks.has('script'))
|
|
405
|
+
result += watermark.script(widget) + '\n';
|
|
406
|
+
usedWatermarks.add('script');
|
|
407
|
+
const fileList = list.filter((e) => e.endsWith('.js') && !processedFile.has(e));
|
|
408
|
+
if (verbose)
|
|
409
|
+
console.log(` - Processing JavaScript for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
|
|
410
|
+
const files = findAndRead(entryDir, fileList);
|
|
411
|
+
let mergedJS = '';
|
|
412
|
+
for await (const [pattern, content] of Object.entries(files)) {
|
|
413
|
+
const obfuscated = JavaScriptObfuscator.obfuscate(content, workspaceConfig.build?.obfuscation?.javascript);
|
|
414
|
+
mergedJS += obfuscated.getObfuscatedCode() + '\n';
|
|
415
|
+
processedFile.add(pattern);
|
|
416
|
+
}
|
|
417
|
+
if (processed.has('html')) {
|
|
418
|
+
result = result += `<script>${mergedJS.trim()}</script>`;
|
|
419
|
+
}
|
|
420
|
+
else
|
|
421
|
+
result += mergedJS.trim();
|
|
422
|
+
processed.add('script');
|
|
423
|
+
}
|
|
424
|
+
if (check(['fields', 'fielddata', 'fieldData', 'cf', 'customfields'], '.json')) {
|
|
425
|
+
const fileList = list.filter((e) => e.endsWith('.json') && !processedFile.has(e));
|
|
402
426
|
if (verbose)
|
|
403
|
-
console.log(` - Processing
|
|
404
|
-
const files = findAndRead(entryDir,
|
|
427
|
+
console.log(` - Processing JSON for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
|
|
428
|
+
const files = findAndRead(entryDir, fileList);
|
|
405
429
|
let mergedFields = {};
|
|
406
|
-
for await (const content of files) {
|
|
430
|
+
for await (const [pattern, content] of Object.entries(files)) {
|
|
407
431
|
try {
|
|
408
432
|
const noComments = parse(content);
|
|
409
433
|
const parsed = JSON.parse(JSON.stringify(noComments));
|
|
@@ -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')
|