fluxion-ts 0.3.2 → 0.3.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/README.md CHANGED
@@ -79,6 +79,8 @@ In this repository, `pnpm dev` runs `src/index.ts` directly and starts Fluxion u
79
79
  Default development options:
80
80
 
81
81
  ```ts
82
+ // if process.env.FLUXION_COLORS === '0', colors will be disabled in logs
83
+
82
84
  fluxion({
83
85
  dir: process.env.DYNAMIC_DIRECTORY ?? 'dynamicDirectory',
84
86
  host: process.env.HOST ?? 'localhost',
package/dist/index.cjs CHANGED
@@ -37,6 +37,61 @@ function loadFunction(injectionConfig) {
37
37
  }
38
38
  }
39
39
 
40
+ const useColor = process.env.FLUXION_COLORS !== '0';
41
+ /**
42
+ * Color Control Characters for Terminal (cctl)
43
+ */
44
+ var cctl;
45
+ (function (cctl) {
46
+ cctl.reset = useColor ? '\x1b[0m' : '';
47
+ cctl.bold = useColor ? '\x1b[1m' : '';
48
+ cctl.dim = useColor ? '\x1b[2m' : '';
49
+ cctl.italic = useColor ? '\x1b[3m' : '';
50
+ cctl.underline = useColor ? '\x1b[4m' : '';
51
+ cctl.blink = useColor ? '\x1b[5m' : '';
52
+ cctl.inverse = useColor ? '\x1b[7m' : '';
53
+ cctl.black = useColor ? '\x1b[30m' : '';
54
+ cctl.red = useColor ? '\x1b[31m' : '';
55
+ cctl.green = useColor ? '\x1b[32m' : '';
56
+ cctl.yellow = useColor ? '\x1b[33m' : '';
57
+ cctl.blue = useColor ? '\x1b[34m' : '';
58
+ cctl.magenta = useColor ? '\x1b[35m' : '';
59
+ cctl.cyan = useColor ? '\x1b[36m' : '';
60
+ cctl.white = useColor ? '\x1b[37m' : '';
61
+ cctl.brightBlack = useColor ? '\x1b[90m' : '';
62
+ cctl.brightRed = useColor ? '\x1b[91m' : '';
63
+ cctl.brightGreen = useColor ? '\x1b[92m' : '';
64
+ cctl.brightYellow = useColor ? '\x1b[93m' : '';
65
+ cctl.brightBlue = useColor ? '\x1b[94m' : '';
66
+ cctl.brightMagenta = useColor ? '\x1b[95m' : '';
67
+ cctl.brightCyan = useColor ? '\x1b[96m' : '';
68
+ cctl.brightWhite = useColor ? '\x1b[97m' : '';
69
+ cctl.bgBlack = useColor ? '\x1b[40m' : '';
70
+ cctl.bgRed = useColor ? '\x1b[41m' : '';
71
+ cctl.bgGreen = useColor ? '\x1b[42m' : '';
72
+ cctl.bgYellow = useColor ? '\x1b[43m' : '';
73
+ cctl.bgBlue = useColor ? '\x1b[44m' : '';
74
+ cctl.bgMagenta = useColor ? '\x1b[45m' : '';
75
+ cctl.bgCyan = useColor ? '\x1b[46m' : '';
76
+ cctl.bgWhite = useColor ? '\x1b[47m' : '';
77
+ cctl.bgBrightBlack = useColor ? '\x1b[100m' : '';
78
+ cctl.bgBrightRed = useColor ? '\x1b[101m' : '';
79
+ cctl.bgBrightGreen = useColor ? '\x1b[102m' : '';
80
+ cctl.bgBrightYellow = useColor ? '\x1b[103m' : '';
81
+ cctl.bgBrightBlue = useColor ? '\x1b[104m' : '';
82
+ cctl.bgBrightMagenta = useColor ? '\x1b[105m' : '';
83
+ cctl.bgBrightCyan = useColor ? '\x1b[106m' : '';
84
+ cctl.bgBrightWhite = useColor ? '\x1b[107m' : '';
85
+ // 'rgb(225, 16, 248)';
86
+ cctl.purple = useColor ? '\x1b[38;2;225;16;248m' : '';
87
+ // 'rgb(248, 147, 16)';
88
+ cctl.orange = useColor ? '\x1b[38;2;248;147;16m' : '';
89
+ cctl.darkGreen = useColor ? '\x1b[38;2;22;101;52m' : '';
90
+ cctl.claude = useColor ? '\x1b[38;2;217;119;87m' : '';
91
+ cctl.deepseek = useColor ? '\x1b[38;2;57;100;254m' : '';
92
+ cctl.gpt = useColor ? '\x1b[38;2;41;60;77m' : '';
93
+ })(cctl || (cctl = {}));
94
+
40
95
  const safeStringify = (value) => {
41
96
  try {
42
97
  return $stringify(value);
@@ -46,19 +101,19 @@ const safeStringify = (value) => {
46
101
  }
47
102
  };
48
103
  const ColoredLevels = {
49
- INFO: 'INFO',
50
- WARN: 'WARN',
51
- ERROR: 'ERROR',
52
- SUCC: 'SUCC',
53
- DEBUG: 'DEBUG',
54
- VERBOSE: 'VERBOSE',
104
+ INFO: `${cctl.cyan}INFO${cctl.reset}`,
105
+ WARN: `${cctl.orange}WARN${cctl.reset}`,
106
+ ERROR: `${cctl.red}ERROR${cctl.reset}`,
107
+ SUCC: `${cctl.green}SUCC${cctl.reset}`,
108
+ DEBUG: `${cctl.blue}DEBUG${cctl.reset}`,
109
+ VERBOSE: `${cctl.purple}VERBOSE${cctl.reset}`,
55
110
  };
56
111
  const oneLineLogger = (entry) => {
57
112
  const { level: rawLevel, timestamp: rawTimestamp, event: rawEvent, message: rawMessage, ...fields } = entry;
58
- const timestamp = `[${rawTimestamp}]`;
113
+ const timestamp = `${cctl.darkGreen}[${rawTimestamp}]${cctl.reset}`;
59
114
  const level = ColoredLevels[rawLevel] ?? rawLevel;
60
115
  const body = rawMessage ?? rawEvent;
61
- const fieldsText = $keys(fields).length > 0 ? ` ${safeStringify(fields)}` : '';
116
+ const fieldsText = $keys(fields).length > 0 ? `${cctl.dim}${safeStringify(fields)}${cctl.reset}` : '';
62
117
  console.log(`${timestamp} ${level} ${body}${fieldsText}`);
63
118
  };
64
119
  /**
@@ -3532,7 +3587,7 @@ class FluxionRouter {
3532
3587
  : path$1.join(process.cwd(), this.cx.options.dir, filepath);
3533
3588
  if (!fs.existsSync(fullpath)) {
3534
3589
  this.handlers.delete(filepath);
3535
- this.cx.logger.info(`[${filepath}] deleted`);
3590
+ this.cx.logger.info(`${cctl.red}Deleted ${cctl.reset} - ${filepath}`);
3536
3591
  return;
3537
3592
  }
3538
3593
  delete require.cache[fullpath];
@@ -3541,7 +3596,7 @@ class FluxionRouter {
3541
3596
  const matchesInclude = this.cx.options.include.some((pattern) => minimatch(filepath, pattern));
3542
3597
  if (!matchesInclude) {
3543
3598
  this.handlers.delete(filepath);
3544
- this.cx.logger.info(`[${filepath}] skipped (not in include)`);
3599
+ this.cx.logger.info(`${cctl.yellow}Skipped ${cctl.reset} - ${filepath}`);
3545
3600
  return;
3546
3601
  }
3547
3602
  // Step 3: Check if file matches exclude patterns
@@ -3549,7 +3604,7 @@ class FluxionRouter {
3549
3604
  const matchesExclude = this.cx.options.exclude.some((pattern) => minimatch(filepath, pattern));
3550
3605
  if (matchesExclude) {
3551
3606
  this.handlers.delete(filepath);
3552
- this.cx.logger.info(`[${filepath}] excluded`);
3607
+ this.cx.logger.info(`${cctl.orange}Excluded${cctl.reset} - ${filepath}`);
3553
3608
  return;
3554
3609
  }
3555
3610
  // Step 4 & 5: Check if file matches apiInclude patterns
@@ -3558,12 +3613,12 @@ class FluxionRouter {
3558
3613
  if (matchesApiInclude) {
3559
3614
  const handler = loadFunction({ modulePath: fullpath });
3560
3615
  this.handlers.set(filepath, handler);
3561
- this.cx.logger.info(`[${filepath}] handler registered`);
3616
+ this.cx.logger.info(`${cctl.green}Api ${cctl.reset} - ${filepath}`);
3562
3617
  return;
3563
3618
  }
3564
3619
  // register as static resource
3565
3620
  this.handlers.set(filepath, this.makeStaticResource(filepath));
3566
- this.cx.logger.info(`[${filepath}] static resource registered`);
3621
+ this.cx.logger.info(`${cctl.brightBlue}Static ${cctl.reset} - ${filepath}`);
3567
3622
  }
3568
3623
  getHandler(url) {
3569
3624
  const relativePath = url.pathname.replace(/^[\/]+/, '').replace(/[\/]+$/, '');