fluxion-ts 0.3.1 → 0.3.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/index.cjs +68 -491
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +68 -491
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/index.cjs
CHANGED
|
@@ -7,483 +7,6 @@ var os = require('node:os');
|
|
|
7
7
|
var http = require('node:http');
|
|
8
8
|
var https = require('node:https');
|
|
9
9
|
|
|
10
|
-
const ANSI_BACKGROUND_OFFSET = 10;
|
|
11
|
-
|
|
12
|
-
const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
|
|
13
|
-
|
|
14
|
-
const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
|
|
15
|
-
|
|
16
|
-
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
17
|
-
|
|
18
|
-
const styles$1 = {
|
|
19
|
-
modifier: {
|
|
20
|
-
reset: [0, 0],
|
|
21
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
22
|
-
bold: [1, 22],
|
|
23
|
-
dim: [2, 22],
|
|
24
|
-
italic: [3, 23],
|
|
25
|
-
underline: [4, 24],
|
|
26
|
-
overline: [53, 55],
|
|
27
|
-
inverse: [7, 27],
|
|
28
|
-
hidden: [8, 28],
|
|
29
|
-
strikethrough: [9, 29],
|
|
30
|
-
},
|
|
31
|
-
color: {
|
|
32
|
-
black: [30, 39],
|
|
33
|
-
red: [31, 39],
|
|
34
|
-
green: [32, 39],
|
|
35
|
-
yellow: [33, 39],
|
|
36
|
-
blue: [34, 39],
|
|
37
|
-
magenta: [35, 39],
|
|
38
|
-
cyan: [36, 39],
|
|
39
|
-
white: [37, 39],
|
|
40
|
-
|
|
41
|
-
// Bright color
|
|
42
|
-
blackBright: [90, 39],
|
|
43
|
-
gray: [90, 39], // Alias of `blackBright`
|
|
44
|
-
grey: [90, 39], // Alias of `blackBright`
|
|
45
|
-
redBright: [91, 39],
|
|
46
|
-
greenBright: [92, 39],
|
|
47
|
-
yellowBright: [93, 39],
|
|
48
|
-
blueBright: [94, 39],
|
|
49
|
-
magentaBright: [95, 39],
|
|
50
|
-
cyanBright: [96, 39],
|
|
51
|
-
whiteBright: [97, 39],
|
|
52
|
-
},
|
|
53
|
-
bgColor: {
|
|
54
|
-
bgBlack: [40, 49],
|
|
55
|
-
bgRed: [41, 49],
|
|
56
|
-
bgGreen: [42, 49],
|
|
57
|
-
bgYellow: [43, 49],
|
|
58
|
-
bgBlue: [44, 49],
|
|
59
|
-
bgMagenta: [45, 49],
|
|
60
|
-
bgCyan: [46, 49],
|
|
61
|
-
bgWhite: [47, 49],
|
|
62
|
-
|
|
63
|
-
// Bright color
|
|
64
|
-
bgBlackBright: [100, 49],
|
|
65
|
-
bgGray: [100, 49], // Alias of `bgBlackBright`
|
|
66
|
-
bgGrey: [100, 49], // Alias of `bgBlackBright`
|
|
67
|
-
bgRedBright: [101, 49],
|
|
68
|
-
bgGreenBright: [102, 49],
|
|
69
|
-
bgYellowBright: [103, 49],
|
|
70
|
-
bgBlueBright: [104, 49],
|
|
71
|
-
bgMagentaBright: [105, 49],
|
|
72
|
-
bgCyanBright: [106, 49],
|
|
73
|
-
bgWhiteBright: [107, 49],
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
Object.keys(styles$1.modifier);
|
|
78
|
-
const foregroundColorNames = Object.keys(styles$1.color);
|
|
79
|
-
const backgroundColorNames = Object.keys(styles$1.bgColor);
|
|
80
|
-
[...foregroundColorNames, ...backgroundColorNames];
|
|
81
|
-
|
|
82
|
-
function assembleStyles() {
|
|
83
|
-
const codes = new Map();
|
|
84
|
-
|
|
85
|
-
for (const [groupName, group] of Object.entries(styles$1)) {
|
|
86
|
-
for (const [styleName, style] of Object.entries(group)) {
|
|
87
|
-
styles$1[styleName] = {
|
|
88
|
-
open: `\u001B[${style[0]}m`,
|
|
89
|
-
close: `\u001B[${style[1]}m`,
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
group[styleName] = styles$1[styleName];
|
|
93
|
-
|
|
94
|
-
codes.set(style[0], style[1]);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
Object.defineProperty(styles$1, groupName, {
|
|
98
|
-
value: group,
|
|
99
|
-
enumerable: false,
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
Object.defineProperty(styles$1, 'codes', {
|
|
104
|
-
value: codes,
|
|
105
|
-
enumerable: false,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
styles$1.color.close = '\u001B[39m';
|
|
109
|
-
styles$1.bgColor.close = '\u001B[49m';
|
|
110
|
-
|
|
111
|
-
styles$1.color.ansi = wrapAnsi16();
|
|
112
|
-
styles$1.color.ansi256 = wrapAnsi256();
|
|
113
|
-
styles$1.color.ansi16m = wrapAnsi16m();
|
|
114
|
-
styles$1.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
115
|
-
styles$1.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
116
|
-
styles$1.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
117
|
-
|
|
118
|
-
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
|
119
|
-
Object.defineProperties(styles$1, {
|
|
120
|
-
rgbToAnsi256: {
|
|
121
|
-
value(red, green, blue) {
|
|
122
|
-
// We use the extended greyscale palette here, with the exception of
|
|
123
|
-
// black and white. normal palette only has 4 greyscale shades.
|
|
124
|
-
if (red === green && green === blue) {
|
|
125
|
-
if (red < 8) {
|
|
126
|
-
return 16;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (red > 248) {
|
|
130
|
-
return 231;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return Math.round(((red - 8) / 247) * 24) + 232;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return 16
|
|
137
|
-
+ (36 * Math.round(red / 255 * 5))
|
|
138
|
-
+ (6 * Math.round(green / 255 * 5))
|
|
139
|
-
+ Math.round(blue / 255 * 5);
|
|
140
|
-
},
|
|
141
|
-
enumerable: false,
|
|
142
|
-
},
|
|
143
|
-
hexToRgb: {
|
|
144
|
-
value(hex) {
|
|
145
|
-
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
146
|
-
if (!matches) {
|
|
147
|
-
return [0, 0, 0];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
let [colorString] = matches;
|
|
151
|
-
|
|
152
|
-
if (colorString.length === 3) {
|
|
153
|
-
colorString = [...colorString].map(character => character + character).join('');
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const integer = Number.parseInt(colorString, 16);
|
|
157
|
-
|
|
158
|
-
return [
|
|
159
|
-
/* eslint-disable no-bitwise */
|
|
160
|
-
(integer >> 16) & 0xFF,
|
|
161
|
-
(integer >> 8) & 0xFF,
|
|
162
|
-
integer & 0xFF,
|
|
163
|
-
/* eslint-enable no-bitwise */
|
|
164
|
-
];
|
|
165
|
-
},
|
|
166
|
-
enumerable: false,
|
|
167
|
-
},
|
|
168
|
-
hexToAnsi256: {
|
|
169
|
-
value: hex => styles$1.rgbToAnsi256(...styles$1.hexToRgb(hex)),
|
|
170
|
-
enumerable: false,
|
|
171
|
-
},
|
|
172
|
-
ansi256ToAnsi: {
|
|
173
|
-
value(code) {
|
|
174
|
-
if (code < 8) {
|
|
175
|
-
return 30 + code;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
if (code < 16) {
|
|
179
|
-
return 90 + (code - 8);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
let red;
|
|
183
|
-
let green;
|
|
184
|
-
let blue;
|
|
185
|
-
|
|
186
|
-
if (code >= 232) {
|
|
187
|
-
red = (((code - 232) * 10) + 8) / 255;
|
|
188
|
-
green = red;
|
|
189
|
-
blue = red;
|
|
190
|
-
} else {
|
|
191
|
-
code -= 16;
|
|
192
|
-
|
|
193
|
-
const remainder = code % 36;
|
|
194
|
-
|
|
195
|
-
red = Math.floor(code / 36) / 5;
|
|
196
|
-
green = Math.floor(remainder / 6) / 5;
|
|
197
|
-
blue = (remainder % 6) / 5;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const value = Math.max(red, green, blue) * 2;
|
|
201
|
-
|
|
202
|
-
if (value === 0) {
|
|
203
|
-
return 30;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// eslint-disable-next-line no-bitwise
|
|
207
|
-
let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
|
|
208
|
-
|
|
209
|
-
if (value === 2) {
|
|
210
|
-
result += 60;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return result;
|
|
214
|
-
},
|
|
215
|
-
enumerable: false,
|
|
216
|
-
},
|
|
217
|
-
rgbToAnsi: {
|
|
218
|
-
value: (red, green, blue) => styles$1.ansi256ToAnsi(styles$1.rgbToAnsi256(red, green, blue)),
|
|
219
|
-
enumerable: false,
|
|
220
|
-
},
|
|
221
|
-
hexToAnsi: {
|
|
222
|
-
value: hex => styles$1.ansi256ToAnsi(styles$1.hexToAnsi256(hex)),
|
|
223
|
-
enumerable: false,
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
return styles$1;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const ansiStyles = assembleStyles();
|
|
231
|
-
|
|
232
|
-
/* eslint-env browser */
|
|
233
|
-
|
|
234
|
-
const level = (() => {
|
|
235
|
-
if (!('navigator' in globalThis)) {
|
|
236
|
-
return 0;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (globalThis.navigator.userAgentData) {
|
|
240
|
-
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
|
|
241
|
-
if (brand && brand.version > 93) {
|
|
242
|
-
return 3;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (/\b(Chrome|Chromium)\//.test(globalThis.navigator.userAgent)) {
|
|
247
|
-
return 1;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return 0;
|
|
251
|
-
})();
|
|
252
|
-
|
|
253
|
-
const colorSupport = level !== 0 && {
|
|
254
|
-
level};
|
|
255
|
-
|
|
256
|
-
const supportsColor = {
|
|
257
|
-
stdout: colorSupport,
|
|
258
|
-
stderr: colorSupport,
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
// TODO: When targeting Node.js 16, use `String.prototype.replaceAll`.
|
|
262
|
-
function stringReplaceAll(string, substring, replacer) {
|
|
263
|
-
let index = string.indexOf(substring);
|
|
264
|
-
if (index === -1) {
|
|
265
|
-
return string;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const substringLength = substring.length;
|
|
269
|
-
let endIndex = 0;
|
|
270
|
-
let returnValue = '';
|
|
271
|
-
do {
|
|
272
|
-
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
273
|
-
endIndex = index + substringLength;
|
|
274
|
-
index = string.indexOf(substring, endIndex);
|
|
275
|
-
} while (index !== -1);
|
|
276
|
-
|
|
277
|
-
returnValue += string.slice(endIndex);
|
|
278
|
-
return returnValue;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
282
|
-
let endIndex = 0;
|
|
283
|
-
let returnValue = '';
|
|
284
|
-
do {
|
|
285
|
-
const gotCR = string[index - 1] === '\r';
|
|
286
|
-
returnValue += string.slice(endIndex, (gotCR ? index - 1 : index)) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
|
287
|
-
endIndex = index + 1;
|
|
288
|
-
index = string.indexOf('\n', endIndex);
|
|
289
|
-
} while (index !== -1);
|
|
290
|
-
|
|
291
|
-
returnValue += string.slice(endIndex);
|
|
292
|
-
return returnValue;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
|
|
296
|
-
|
|
297
|
-
const GENERATOR = Symbol('GENERATOR');
|
|
298
|
-
const STYLER = Symbol('STYLER');
|
|
299
|
-
const IS_EMPTY = Symbol('IS_EMPTY');
|
|
300
|
-
|
|
301
|
-
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
|
302
|
-
const levelMapping = [
|
|
303
|
-
'ansi',
|
|
304
|
-
'ansi',
|
|
305
|
-
'ansi256',
|
|
306
|
-
'ansi16m',
|
|
307
|
-
];
|
|
308
|
-
|
|
309
|
-
const styles = Object.create(null);
|
|
310
|
-
|
|
311
|
-
const applyOptions = (object, options = {}) => {
|
|
312
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
313
|
-
throw new Error('The `level` option should be an integer from 0 to 3');
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Detect level if not set manually
|
|
317
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
318
|
-
object.level = options.level === undefined ? colorLevel : options.level;
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
const chalkFactory = options => {
|
|
322
|
-
const chalk = (...strings) => strings.join(' ');
|
|
323
|
-
applyOptions(chalk, options);
|
|
324
|
-
|
|
325
|
-
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
326
|
-
|
|
327
|
-
return chalk;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
function createChalk(options) {
|
|
331
|
-
return chalkFactory(options);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
335
|
-
|
|
336
|
-
for (const [styleName, style] of Object.entries(ansiStyles)) {
|
|
337
|
-
styles[styleName] = {
|
|
338
|
-
get() {
|
|
339
|
-
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
340
|
-
Object.defineProperty(this, styleName, {value: builder});
|
|
341
|
-
return builder;
|
|
342
|
-
},
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
styles.visible = {
|
|
347
|
-
get() {
|
|
348
|
-
const builder = createBuilder(this, this[STYLER], true);
|
|
349
|
-
Object.defineProperty(this, 'visible', {value: builder});
|
|
350
|
-
return builder;
|
|
351
|
-
},
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
const getModelAnsi = (model, level, type, ...arguments_) => {
|
|
355
|
-
if (model === 'rgb') {
|
|
356
|
-
if (level === 'ansi16m') {
|
|
357
|
-
return ansiStyles[type].ansi16m(...arguments_);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (level === 'ansi256') {
|
|
361
|
-
return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (model === 'hex') {
|
|
368
|
-
return getModelAnsi('rgb', level, type, ...ansiStyles.hexToRgb(...arguments_));
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return ansiStyles[type][model](...arguments_);
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
const usedModels = ['rgb', 'hex', 'ansi256'];
|
|
375
|
-
|
|
376
|
-
for (const model of usedModels) {
|
|
377
|
-
styles[model] = {
|
|
378
|
-
get() {
|
|
379
|
-
const {level} = this;
|
|
380
|
-
return function (...arguments_) {
|
|
381
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]);
|
|
382
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
383
|
-
};
|
|
384
|
-
},
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
|
388
|
-
styles[bgModel] = {
|
|
389
|
-
get() {
|
|
390
|
-
const {level} = this;
|
|
391
|
-
return function (...arguments_) {
|
|
392
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
|
|
393
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
394
|
-
};
|
|
395
|
-
},
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const proto = Object.defineProperties(() => {}, {
|
|
400
|
-
...styles,
|
|
401
|
-
level: {
|
|
402
|
-
enumerable: true,
|
|
403
|
-
get() {
|
|
404
|
-
return this[GENERATOR].level;
|
|
405
|
-
},
|
|
406
|
-
set(level) {
|
|
407
|
-
this[GENERATOR].level = level;
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
const createStyler = (open, close, parent) => {
|
|
413
|
-
let openAll;
|
|
414
|
-
let closeAll;
|
|
415
|
-
if (parent === undefined) {
|
|
416
|
-
openAll = open;
|
|
417
|
-
closeAll = close;
|
|
418
|
-
} else {
|
|
419
|
-
openAll = parent.openAll + open;
|
|
420
|
-
closeAll = close + parent.closeAll;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
return {
|
|
424
|
-
open,
|
|
425
|
-
close,
|
|
426
|
-
openAll,
|
|
427
|
-
closeAll,
|
|
428
|
-
parent,
|
|
429
|
-
};
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
const createBuilder = (self, _styler, _isEmpty) => {
|
|
433
|
-
// Single argument is hot path, implicit coercion is faster than anything
|
|
434
|
-
// eslint-disable-next-line no-implicit-coercion
|
|
435
|
-
const builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
|
|
436
|
-
|
|
437
|
-
// We alter the prototype because we must return a function, but there is
|
|
438
|
-
// no way to create a function with a different prototype
|
|
439
|
-
Object.setPrototypeOf(builder, proto);
|
|
440
|
-
|
|
441
|
-
builder[GENERATOR] = self;
|
|
442
|
-
builder[STYLER] = _styler;
|
|
443
|
-
builder[IS_EMPTY] = _isEmpty;
|
|
444
|
-
|
|
445
|
-
return builder;
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
const applyStyle = (self, string) => {
|
|
449
|
-
if (self.level <= 0 || !string) {
|
|
450
|
-
return self[IS_EMPTY] ? '' : string;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
let styler = self[STYLER];
|
|
454
|
-
|
|
455
|
-
if (styler === undefined) {
|
|
456
|
-
return string;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const {openAll, closeAll} = styler;
|
|
460
|
-
if (string.includes('\u001B')) {
|
|
461
|
-
while (styler !== undefined) {
|
|
462
|
-
// Replace any instances already present with a re-opening code
|
|
463
|
-
// otherwise only the part of the string until said closing code
|
|
464
|
-
// will be colored, and the rest will simply be 'plain'.
|
|
465
|
-
string = stringReplaceAll(string, styler.close, styler.open);
|
|
466
|
-
|
|
467
|
-
styler = styler.parent;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// We can move both next actions out of loop, because remaining actions in loop won't have
|
|
472
|
-
// any/visible effect on parts we add here. Close the styling before a linebreak and reopen
|
|
473
|
-
// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
|
|
474
|
-
const lfIndex = string.indexOf('\n');
|
|
475
|
-
if (lfIndex !== -1) {
|
|
476
|
-
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
return openAll + string + closeAll;
|
|
480
|
-
};
|
|
481
|
-
|
|
482
|
-
Object.defineProperties(createChalk.prototype, styles);
|
|
483
|
-
|
|
484
|
-
const chalk = createChalk();
|
|
485
|
-
createChalk({level: stderrColor ? stderrColor.level : 0});
|
|
486
|
-
|
|
487
10
|
function dtm(dt = new Date()) {
|
|
488
11
|
const y = dt.getFullYear();
|
|
489
12
|
const m = String(dt.getMonth() + 1).padStart(2, '0');
|
|
@@ -514,6 +37,61 @@ function loadFunction(injectionConfig) {
|
|
|
514
37
|
}
|
|
515
38
|
}
|
|
516
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
|
+
|
|
517
95
|
const safeStringify = (value) => {
|
|
518
96
|
try {
|
|
519
97
|
return $stringify(value);
|
|
@@ -523,20 +101,19 @@ const safeStringify = (value) => {
|
|
|
523
101
|
}
|
|
524
102
|
};
|
|
525
103
|
const ColoredLevels = {
|
|
526
|
-
INFO:
|
|
527
|
-
WARN:
|
|
528
|
-
ERROR:
|
|
529
|
-
SUCC:
|
|
530
|
-
DEBUG:
|
|
531
|
-
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}`,
|
|
532
110
|
};
|
|
533
|
-
const TimestampColor = chalk.hex('#166534');
|
|
534
111
|
const oneLineLogger = (entry) => {
|
|
535
112
|
const { level: rawLevel, timestamp: rawTimestamp, event: rawEvent, message: rawMessage, ...fields } = entry;
|
|
536
|
-
const timestamp =
|
|
113
|
+
const timestamp = `${cctl.darkGreen}[${rawTimestamp}]${cctl.reset}`;
|
|
537
114
|
const level = ColoredLevels[rawLevel] ?? rawLevel;
|
|
538
115
|
const body = rawMessage ?? rawEvent;
|
|
539
|
-
const fieldsText = $keys(fields).length > 0 ?
|
|
116
|
+
const fieldsText = $keys(fields).length > 0 ? `${cctl.dim}${safeStringify(fields)}${cctl.reset}` : '';
|
|
540
117
|
console.log(`${timestamp} ${level} ${body}${fieldsText}`);
|
|
541
118
|
};
|
|
542
119
|
/**
|
|
@@ -4010,7 +3587,7 @@ class FluxionRouter {
|
|
|
4010
3587
|
: path$1.join(process.cwd(), this.cx.options.dir, filepath);
|
|
4011
3588
|
if (!fs.existsSync(fullpath)) {
|
|
4012
3589
|
this.handlers.delete(filepath);
|
|
4013
|
-
this.cx.logger.info(
|
|
3590
|
+
this.cx.logger.info(`${cctl.red}Deleted ${cctl.reset} - ${filepath}`);
|
|
4014
3591
|
return;
|
|
4015
3592
|
}
|
|
4016
3593
|
delete require.cache[fullpath];
|
|
@@ -4019,7 +3596,7 @@ class FluxionRouter {
|
|
|
4019
3596
|
const matchesInclude = this.cx.options.include.some((pattern) => minimatch(filepath, pattern));
|
|
4020
3597
|
if (!matchesInclude) {
|
|
4021
3598
|
this.handlers.delete(filepath);
|
|
4022
|
-
this.cx.logger.info(
|
|
3599
|
+
this.cx.logger.info(`${cctl.yellow}Skipped ${cctl.reset} - ${filepath}`);
|
|
4023
3600
|
return;
|
|
4024
3601
|
}
|
|
4025
3602
|
// Step 3: Check if file matches exclude patterns
|
|
@@ -4027,7 +3604,7 @@ class FluxionRouter {
|
|
|
4027
3604
|
const matchesExclude = this.cx.options.exclude.some((pattern) => minimatch(filepath, pattern));
|
|
4028
3605
|
if (matchesExclude) {
|
|
4029
3606
|
this.handlers.delete(filepath);
|
|
4030
|
-
this.cx.logger.info(
|
|
3607
|
+
this.cx.logger.info(`${cctl.orange}Excluded${cctl.reset} - ${filepath}`);
|
|
4031
3608
|
return;
|
|
4032
3609
|
}
|
|
4033
3610
|
// Step 4 & 5: Check if file matches apiInclude patterns
|
|
@@ -4036,12 +3613,12 @@ class FluxionRouter {
|
|
|
4036
3613
|
if (matchesApiInclude) {
|
|
4037
3614
|
const handler = loadFunction({ modulePath: fullpath });
|
|
4038
3615
|
this.handlers.set(filepath, handler);
|
|
4039
|
-
this.cx.logger.info(
|
|
3616
|
+
this.cx.logger.info(`${cctl.green}Api ${cctl.reset} - ${filepath}`);
|
|
4040
3617
|
return;
|
|
4041
3618
|
}
|
|
4042
3619
|
// register as static resource
|
|
4043
3620
|
this.handlers.set(filepath, this.makeStaticResource(filepath));
|
|
4044
|
-
this.cx.logger.info(
|
|
3621
|
+
this.cx.logger.info(`${cctl.brightBlue}Static ${cctl.reset} - ${filepath}`);
|
|
4045
3622
|
}
|
|
4046
3623
|
getHandler(url) {
|
|
4047
3624
|
const relativePath = url.pathname.replace(/^[\/]+/, '').replace(/[\/]+$/, '');
|