@tixyel/cli 2.6.3 → 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.
Files changed (2) hide show
  1. package/dist/widget.js +30 -30
  2. package/package.json +1 -1
package/dist/widget.js CHANGED
@@ -278,17 +278,18 @@ 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.push(content);
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();
292
293
  /**
293
294
  * Build results processing
294
295
  * Find all files based on patterns and process them according to their type
@@ -298,7 +299,7 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
298
299
  */
299
300
  const results = Object.fromEntries(await Promise.all(Object.entries(findPatterns).map(async ([key, patterns]) => {
300
301
  let result = '';
301
- const list = normalizeList(patterns);
302
+ let list = normalizeList(patterns.filter((p) => !processedFile.has(p)));
302
303
  if (!list.length)
303
304
  return [key, ''];
304
305
  const check = (keys, formats) => {
@@ -316,27 +317,17 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
316
317
  if (!usedWatermarks.has('html'))
317
318
  result += watermark.html(widget) + '\n';
318
319
  usedWatermarks.add('html');
320
+ const fileList = list.filter((e) => e.endsWith('.html') && !processedFile.has(e));
319
321
  if (verbose)
320
- console.log(` - Processing HTML for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
321
- const files = findAndRead(entryDir, list);
322
+ console.log(` - Processing HTML for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
323
+ const files = findAndRead(entryDir, fileList);
322
324
  let mergedHTML = '';
323
- for await (const fileContent of files) {
325
+ for await (const [pattern, fileContent] of Object.entries(files)) {
324
326
  // Extract body content
325
327
  const bodyMatch = fileContent.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
326
328
  if (bodyMatch && bodyMatch[1]) {
327
329
  mergedHTML += bodyMatch[1].trim() + '\n';
328
- }
329
- // Extract and inline styles
330
- const styleMatches = fileContent.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/gi);
331
- for (const match of styleMatches) {
332
- mergedHTML += `<style>${match[1]}</style>\n`;
333
- }
334
- // Extract and inline <script> tags
335
- const scriptMatches = fileContent.matchAll(/<script[^>]*>([\s\S]*?)<\/script>/gi);
336
- for (const match of scriptMatches) {
337
- if (match[1]) {
338
- mergedHTML += `<script>${match[1]}</script>\n`;
339
- }
330
+ processedFile.add(pattern);
340
331
  }
341
332
  }
342
333
  const minified = await minifyHTML(mergedHTML, workspaceConfig.build?.obfuscation?.html);
@@ -347,11 +338,12 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
347
338
  if (!usedWatermarks.has('css'))
348
339
  result += watermark.css(widget) + '\n';
349
340
  usedWatermarks.add('css');
341
+ const fileList = list.filter((e) => e.endsWith('.css') && !processedFile.has(e));
350
342
  if (verbose)
351
- console.log(` - Processing CSS for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
352
- const files = findAndRead(entryDir, list);
343
+ console.log(` - Processing CSS for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
344
+ const files = findAndRead(entryDir, fileList);
353
345
  let mergedCSS = '';
354
- for await (const content of files) {
346
+ for await (const [pattern, content] of Object.entries(files)) {
355
347
  const plugin = [
356
348
  autoprefixer({
357
349
  overrideBrowserslist: ['Chrome 127'],
@@ -364,6 +356,7 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
364
356
  }
365
357
  const processed = await postcss(plugin).process(content, { from: undefined });
366
358
  mergedCSS += processed.css + '\n';
359
+ processedFile.add(pattern);
367
360
  }
368
361
  if (processed.has('html')) {
369
362
  result = result += `<style>${mergedCSS.trim()}</style>`;
@@ -376,11 +369,12 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
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 for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
381
- const files = findAndRead(entryDir, list);
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,6 +387,9 @@ 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);
@@ -407,13 +404,15 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
407
404
  if (!usedWatermarks.has('script'))
408
405
  result += watermark.script(widget) + '\n';
409
406
  usedWatermarks.add('script');
407
+ const fileList = list.filter((e) => e.endsWith('.js') && !processedFile.has(e));
410
408
  if (verbose)
411
- console.log(` - Processing JavaScript for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
412
- const files = findAndRead(entryDir, list);
409
+ console.log(` - Processing JavaScript for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
410
+ const files = findAndRead(entryDir, fileList);
413
411
  let mergedJS = '';
414
- for await (const content of files) {
412
+ for await (const [pattern, content] of Object.entries(files)) {
415
413
  const obfuscated = JavaScriptObfuscator.obfuscate(content, workspaceConfig.build?.obfuscation?.javascript);
416
414
  mergedJS += obfuscated.getObfuscatedCode() + '\n';
415
+ processedFile.add(pattern);
417
416
  }
418
417
  if (processed.has('html')) {
419
418
  result = result += `<script>${mergedJS.trim()}</script>`;
@@ -423,11 +422,12 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
423
422
  processed.add('script');
424
423
  }
425
424
  if (check(['fields', 'fielddata', 'fieldData', 'cf', 'customfields'], '.json')) {
425
+ const fileList = list.filter((e) => e.endsWith('.json') && !processedFile.has(e));
426
426
  if (verbose)
427
- console.log(` - Processing JSON for ${widget.config.name} [${key}, ${list.join(', ')}]...`);
428
- const files = findAndRead(entryDir, list);
427
+ console.log(` - Processing JSON for ${widget.config.name} [${key}, ${fileList.join(', ')}]...`);
428
+ const files = findAndRead(entryDir, fileList);
429
429
  let mergedFields = {};
430
- for await (const content of files) {
430
+ for await (const [pattern, content] of Object.entries(files)) {
431
431
  try {
432
432
  const noComments = parse(content);
433
433
  const parsed = JSON.parse(JSON.stringify(noComments));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tixyel/cli",
3
- "version": "2.6.3",
3
+ "version": "2.6.4",
4
4
  "description": "CLI tool for streamelements widgets",
5
5
  "keywords": [
6
6
  "cli",