@tixyel/cli 2.1.0 → 2.2.0
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 +26 -0
- package/package.json +1 -1
package/dist/widget.js
CHANGED
|
@@ -14,6 +14,7 @@ import inquirer from 'inquirer';
|
|
|
14
14
|
import postcss from 'postcss';
|
|
15
15
|
import cssnano from 'cssnano';
|
|
16
16
|
import JSZip from 'jszip';
|
|
17
|
+
import { transformSync } from 'esbuild';
|
|
17
18
|
export async function createWidget(path, metadata, config, root) {
|
|
18
19
|
try {
|
|
19
20
|
console.log(`📁 Creating ${metadata?.name} at: ${path}`);
|
|
@@ -257,6 +258,7 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
257
258
|
const findPatterns = workspaceConfig.build?.find || {
|
|
258
259
|
html: ['index.html'],
|
|
259
260
|
script: ['script.js'],
|
|
261
|
+
typescript: ['script.ts'],
|
|
260
262
|
css: ['styles.css'],
|
|
261
263
|
fields: ['fields.json'],
|
|
262
264
|
};
|
|
@@ -411,6 +413,30 @@ export async function processBuild(widget, workspaceConfig, verbose = false) {
|
|
|
411
413
|
}
|
|
412
414
|
result += mergedJS.trim();
|
|
413
415
|
}
|
|
416
|
+
else if (['typescript', 'ts'].some((k) => key === k)) {
|
|
417
|
+
result += watermark.script + '\n';
|
|
418
|
+
if (verbose)
|
|
419
|
+
console.log(` - Processing TypeScript...`);
|
|
420
|
+
const files = findAndRead(entryDir, list);
|
|
421
|
+
let mergedTS = '';
|
|
422
|
+
for await (const content of files) {
|
|
423
|
+
try {
|
|
424
|
+
const transpiled = transformSync(content, {
|
|
425
|
+
loader: 'ts',
|
|
426
|
+
target: 'es2021',
|
|
427
|
+
format: 'iife',
|
|
428
|
+
});
|
|
429
|
+
mergedTS += transpiled.code + '\n';
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
console.warn(` ⚠️ Failed to compile TypeScript: ${error}`);
|
|
433
|
+
throw error;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
// Obfuscate the compiled JavaScript
|
|
437
|
+
const obfuscated = JavaScriptObfuscator.obfuscate(mergedTS.trim(), workspaceConfig.build?.obfuscation?.javascript);
|
|
438
|
+
result += obfuscated.getObfuscatedCode();
|
|
439
|
+
}
|
|
414
440
|
else if (['fields', 'FIELDS', 'fielddata', 'fieldData'].some((k) => key === k)) {
|
|
415
441
|
if (verbose)
|
|
416
442
|
console.log(` - Processing Json...`);
|