@monkeyplus/flow 4.0.0-beta.6 → 4.0.0-beta.7
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 +7 -465
- package/dist/index.mjs +3 -462
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const consola = require('consola');
|
|
|
8
8
|
const R = require('ramda');
|
|
9
9
|
const boom = require('@hapi/boom');
|
|
10
10
|
const os = require('os');
|
|
11
|
+
const chalk = require('chalk');
|
|
11
12
|
const fs = require('fs-extra');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
@@ -28,10 +29,11 @@ const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
|
28
29
|
const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
|
|
29
30
|
const R__namespace = /*#__PURE__*/_interopNamespace(R);
|
|
30
31
|
const os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
32
|
+
const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
31
33
|
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
32
34
|
|
|
33
35
|
const name = "@monkeyplus/flow";
|
|
34
|
-
const version = "4.0.0-beta.
|
|
36
|
+
const version = "4.0.0-beta.7";
|
|
35
37
|
const description = "Utils hapi";
|
|
36
38
|
const author = "Andres Navarrete";
|
|
37
39
|
const license = "MIT";
|
|
@@ -63,11 +65,11 @@ const dependencies$1 = {
|
|
|
63
65
|
"@hapi/boom": "9.x.x",
|
|
64
66
|
"@hapi/hoek": "9.x.x",
|
|
65
67
|
consola: "^2.15.3",
|
|
68
|
+
chalk: "^4.1.2",
|
|
66
69
|
"fs-extra": "^10.0.0",
|
|
67
70
|
ramda: "^0.28.0"
|
|
68
71
|
};
|
|
69
72
|
const devDependencies = {
|
|
70
|
-
chalk: "^5.0.0",
|
|
71
73
|
"@types/fs-extra": "^9.0.13",
|
|
72
74
|
"@types/hapi__hapi": "^20.0.10",
|
|
73
75
|
"@types/ramda": "^0.27.64"
|
|
@@ -146,466 +148,6 @@ const LifeCircle = {
|
|
|
146
148
|
}
|
|
147
149
|
};
|
|
148
150
|
|
|
149
|
-
const ANSI_BACKGROUND_OFFSET = 10;
|
|
150
|
-
|
|
151
|
-
const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
|
|
152
|
-
|
|
153
|
-
const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
|
|
154
|
-
|
|
155
|
-
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
156
|
-
|
|
157
|
-
function assembleStyles() {
|
|
158
|
-
const codes = new Map();
|
|
159
|
-
const styles = {
|
|
160
|
-
modifier: {
|
|
161
|
-
reset: [0, 0],
|
|
162
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
163
|
-
bold: [1, 22],
|
|
164
|
-
dim: [2, 22],
|
|
165
|
-
italic: [3, 23],
|
|
166
|
-
underline: [4, 24],
|
|
167
|
-
overline: [53, 55],
|
|
168
|
-
inverse: [7, 27],
|
|
169
|
-
hidden: [8, 28],
|
|
170
|
-
strikethrough: [9, 29],
|
|
171
|
-
},
|
|
172
|
-
color: {
|
|
173
|
-
black: [30, 39],
|
|
174
|
-
red: [31, 39],
|
|
175
|
-
green: [32, 39],
|
|
176
|
-
yellow: [33, 39],
|
|
177
|
-
blue: [34, 39],
|
|
178
|
-
magenta: [35, 39],
|
|
179
|
-
cyan: [36, 39],
|
|
180
|
-
white: [37, 39],
|
|
181
|
-
|
|
182
|
-
// Bright color
|
|
183
|
-
blackBright: [90, 39],
|
|
184
|
-
redBright: [91, 39],
|
|
185
|
-
greenBright: [92, 39],
|
|
186
|
-
yellowBright: [93, 39],
|
|
187
|
-
blueBright: [94, 39],
|
|
188
|
-
magentaBright: [95, 39],
|
|
189
|
-
cyanBright: [96, 39],
|
|
190
|
-
whiteBright: [97, 39],
|
|
191
|
-
},
|
|
192
|
-
bgColor: {
|
|
193
|
-
bgBlack: [40, 49],
|
|
194
|
-
bgRed: [41, 49],
|
|
195
|
-
bgGreen: [42, 49],
|
|
196
|
-
bgYellow: [43, 49],
|
|
197
|
-
bgBlue: [44, 49],
|
|
198
|
-
bgMagenta: [45, 49],
|
|
199
|
-
bgCyan: [46, 49],
|
|
200
|
-
bgWhite: [47, 49],
|
|
201
|
-
|
|
202
|
-
// Bright color
|
|
203
|
-
bgBlackBright: [100, 49],
|
|
204
|
-
bgRedBright: [101, 49],
|
|
205
|
-
bgGreenBright: [102, 49],
|
|
206
|
-
bgYellowBright: [103, 49],
|
|
207
|
-
bgBlueBright: [104, 49],
|
|
208
|
-
bgMagentaBright: [105, 49],
|
|
209
|
-
bgCyanBright: [106, 49],
|
|
210
|
-
bgWhiteBright: [107, 49],
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
// Alias bright black as gray (and grey)
|
|
215
|
-
styles.color.gray = styles.color.blackBright;
|
|
216
|
-
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
217
|
-
styles.color.grey = styles.color.blackBright;
|
|
218
|
-
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
219
|
-
|
|
220
|
-
for (const [groupName, group] of Object.entries(styles)) {
|
|
221
|
-
for (const [styleName, style] of Object.entries(group)) {
|
|
222
|
-
styles[styleName] = {
|
|
223
|
-
open: `\u001B[${style[0]}m`,
|
|
224
|
-
close: `\u001B[${style[1]}m`,
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
group[styleName] = styles[styleName];
|
|
228
|
-
|
|
229
|
-
codes.set(style[0], style[1]);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
Object.defineProperty(styles, groupName, {
|
|
233
|
-
value: group,
|
|
234
|
-
enumerable: false,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
Object.defineProperty(styles, 'codes', {
|
|
239
|
-
value: codes,
|
|
240
|
-
enumerable: false,
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
styles.color.close = '\u001B[39m';
|
|
244
|
-
styles.bgColor.close = '\u001B[49m';
|
|
245
|
-
|
|
246
|
-
styles.color.ansi = wrapAnsi16();
|
|
247
|
-
styles.color.ansi256 = wrapAnsi256();
|
|
248
|
-
styles.color.ansi16m = wrapAnsi16m();
|
|
249
|
-
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
250
|
-
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
251
|
-
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
252
|
-
|
|
253
|
-
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
|
254
|
-
Object.defineProperties(styles, {
|
|
255
|
-
rgbToAnsi256: {
|
|
256
|
-
value: (red, green, blue) => {
|
|
257
|
-
// We use the extended greyscale palette here, with the exception of
|
|
258
|
-
// black and white. normal palette only has 4 greyscale shades.
|
|
259
|
-
if (red === green && green === blue) {
|
|
260
|
-
if (red < 8) {
|
|
261
|
-
return 16;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (red > 248) {
|
|
265
|
-
return 231;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return Math.round(((red - 8) / 247) * 24) + 232;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return 16
|
|
272
|
-
+ (36 * Math.round(red / 255 * 5))
|
|
273
|
-
+ (6 * Math.round(green / 255 * 5))
|
|
274
|
-
+ Math.round(blue / 255 * 5);
|
|
275
|
-
},
|
|
276
|
-
enumerable: false,
|
|
277
|
-
},
|
|
278
|
-
hexToRgb: {
|
|
279
|
-
value: hex => {
|
|
280
|
-
const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
|
|
281
|
-
if (!matches) {
|
|
282
|
-
return [0, 0, 0];
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
let {colorString} = matches.groups;
|
|
286
|
-
|
|
287
|
-
if (colorString.length === 3) {
|
|
288
|
-
colorString = [...colorString].map(character => character + character).join('');
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const integer = Number.parseInt(colorString, 16);
|
|
292
|
-
|
|
293
|
-
return [
|
|
294
|
-
/* eslint-disable no-bitwise */
|
|
295
|
-
(integer >> 16) & 0xFF,
|
|
296
|
-
(integer >> 8) & 0xFF,
|
|
297
|
-
integer & 0xFF,
|
|
298
|
-
/* eslint-enable no-bitwise */
|
|
299
|
-
];
|
|
300
|
-
},
|
|
301
|
-
enumerable: false,
|
|
302
|
-
},
|
|
303
|
-
hexToAnsi256: {
|
|
304
|
-
value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
305
|
-
enumerable: false,
|
|
306
|
-
},
|
|
307
|
-
ansi256ToAnsi: {
|
|
308
|
-
value: code => {
|
|
309
|
-
if (code < 8) {
|
|
310
|
-
return 30 + code;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (code < 16) {
|
|
314
|
-
return 90 + (code - 8);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
let red;
|
|
318
|
-
let green;
|
|
319
|
-
let blue;
|
|
320
|
-
|
|
321
|
-
if (code >= 232) {
|
|
322
|
-
red = (((code - 232) * 10) + 8) / 255;
|
|
323
|
-
green = red;
|
|
324
|
-
blue = red;
|
|
325
|
-
} else {
|
|
326
|
-
code -= 16;
|
|
327
|
-
|
|
328
|
-
const remainder = code % 36;
|
|
329
|
-
|
|
330
|
-
red = Math.floor(code / 36) / 5;
|
|
331
|
-
green = Math.floor(remainder / 6) / 5;
|
|
332
|
-
blue = (remainder % 6) / 5;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const value = Math.max(red, green, blue) * 2;
|
|
336
|
-
|
|
337
|
-
if (value === 0) {
|
|
338
|
-
return 30;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
// eslint-disable-next-line no-bitwise
|
|
342
|
-
let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
|
|
343
|
-
|
|
344
|
-
if (value === 2) {
|
|
345
|
-
result += 60;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
return result;
|
|
349
|
-
},
|
|
350
|
-
enumerable: false,
|
|
351
|
-
},
|
|
352
|
-
rgbToAnsi: {
|
|
353
|
-
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
354
|
-
enumerable: false,
|
|
355
|
-
},
|
|
356
|
-
hexToAnsi: {
|
|
357
|
-
value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
358
|
-
enumerable: false,
|
|
359
|
-
},
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
return styles;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const ansiStyles = assembleStyles();
|
|
366
|
-
|
|
367
|
-
/* eslint-env browser */
|
|
368
|
-
|
|
369
|
-
const isBlinkBasedBrowser = /\b(Chrome|Chromium)\//.test(navigator.userAgent);
|
|
370
|
-
|
|
371
|
-
const colorSupport = isBlinkBasedBrowser ? {
|
|
372
|
-
level: 1,
|
|
373
|
-
hasBasic: true,
|
|
374
|
-
has256: false,
|
|
375
|
-
has16m: false,
|
|
376
|
-
} : false;
|
|
377
|
-
|
|
378
|
-
const supportsColor = {
|
|
379
|
-
stdout: colorSupport,
|
|
380
|
-
stderr: colorSupport,
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
// TODO: When targeting Node.js 16, use `String.prototype.replaceAll`.
|
|
384
|
-
function stringReplaceAll(string, substring, replacer) {
|
|
385
|
-
let index = string.indexOf(substring);
|
|
386
|
-
if (index === -1) {
|
|
387
|
-
return string;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const substringLength = substring.length;
|
|
391
|
-
let endIndex = 0;
|
|
392
|
-
let returnValue = '';
|
|
393
|
-
do {
|
|
394
|
-
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
|
395
|
-
endIndex = index + substringLength;
|
|
396
|
-
index = string.indexOf(substring, endIndex);
|
|
397
|
-
} while (index !== -1);
|
|
398
|
-
|
|
399
|
-
returnValue += string.slice(endIndex);
|
|
400
|
-
return returnValue;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
404
|
-
let endIndex = 0;
|
|
405
|
-
let returnValue = '';
|
|
406
|
-
do {
|
|
407
|
-
const gotCR = string[index - 1] === '\r';
|
|
408
|
-
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
|
409
|
-
endIndex = index + 1;
|
|
410
|
-
index = string.indexOf('\n', endIndex);
|
|
411
|
-
} while (index !== -1);
|
|
412
|
-
|
|
413
|
-
returnValue += string.slice(endIndex);
|
|
414
|
-
return returnValue;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
|
|
418
|
-
|
|
419
|
-
const GENERATOR = Symbol('GENERATOR');
|
|
420
|
-
const STYLER = Symbol('STYLER');
|
|
421
|
-
const IS_EMPTY = Symbol('IS_EMPTY');
|
|
422
|
-
|
|
423
|
-
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
|
424
|
-
const levelMapping = [
|
|
425
|
-
'ansi',
|
|
426
|
-
'ansi',
|
|
427
|
-
'ansi256',
|
|
428
|
-
'ansi16m',
|
|
429
|
-
];
|
|
430
|
-
|
|
431
|
-
const styles = Object.create(null);
|
|
432
|
-
|
|
433
|
-
const applyOptions = (object, options = {}) => {
|
|
434
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
435
|
-
throw new Error('The `level` option should be an integer from 0 to 3');
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
// Detect level if not set manually
|
|
439
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
440
|
-
object.level = options.level === undefined ? colorLevel : options.level;
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
const chalkFactory = options => {
|
|
444
|
-
const chalk = (...strings) => strings.join(' ');
|
|
445
|
-
applyOptions(chalk, options);
|
|
446
|
-
|
|
447
|
-
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
448
|
-
|
|
449
|
-
return chalk;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
function createChalk(options) {
|
|
453
|
-
return chalkFactory(options);
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
457
|
-
|
|
458
|
-
for (const [styleName, style] of Object.entries(ansiStyles)) {
|
|
459
|
-
styles[styleName] = {
|
|
460
|
-
get() {
|
|
461
|
-
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
462
|
-
Object.defineProperty(this, styleName, {value: builder});
|
|
463
|
-
return builder;
|
|
464
|
-
},
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
styles.visible = {
|
|
469
|
-
get() {
|
|
470
|
-
const builder = createBuilder(this, this[STYLER], true);
|
|
471
|
-
Object.defineProperty(this, 'visible', {value: builder});
|
|
472
|
-
return builder;
|
|
473
|
-
},
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
const getModelAnsi = (model, level, type, ...arguments_) => {
|
|
477
|
-
if (model === 'rgb') {
|
|
478
|
-
if (level === 'ansi16m') {
|
|
479
|
-
return ansiStyles[type].ansi16m(...arguments_);
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
if (level === 'ansi256') {
|
|
483
|
-
return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
if (model === 'hex') {
|
|
490
|
-
return getModelAnsi('rgb', level, type, ...ansiStyles.hexToRgb(...arguments_));
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
return ansiStyles[type][model](...arguments_);
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
const usedModels = ['rgb', 'hex', 'ansi256'];
|
|
497
|
-
|
|
498
|
-
for (const model of usedModels) {
|
|
499
|
-
styles[model] = {
|
|
500
|
-
get() {
|
|
501
|
-
const {level} = this;
|
|
502
|
-
return function (...arguments_) {
|
|
503
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]);
|
|
504
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
505
|
-
};
|
|
506
|
-
},
|
|
507
|
-
};
|
|
508
|
-
|
|
509
|
-
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
|
510
|
-
styles[bgModel] = {
|
|
511
|
-
get() {
|
|
512
|
-
const {level} = this;
|
|
513
|
-
return function (...arguments_) {
|
|
514
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
|
|
515
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
516
|
-
};
|
|
517
|
-
},
|
|
518
|
-
};
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const proto = Object.defineProperties(() => {}, {
|
|
522
|
-
...styles,
|
|
523
|
-
level: {
|
|
524
|
-
enumerable: true,
|
|
525
|
-
get() {
|
|
526
|
-
return this[GENERATOR].level;
|
|
527
|
-
},
|
|
528
|
-
set(level) {
|
|
529
|
-
this[GENERATOR].level = level;
|
|
530
|
-
},
|
|
531
|
-
},
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
const createStyler = (open, close, parent) => {
|
|
535
|
-
let openAll;
|
|
536
|
-
let closeAll;
|
|
537
|
-
if (parent === undefined) {
|
|
538
|
-
openAll = open;
|
|
539
|
-
closeAll = close;
|
|
540
|
-
} else {
|
|
541
|
-
openAll = parent.openAll + open;
|
|
542
|
-
closeAll = close + parent.closeAll;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
return {
|
|
546
|
-
open,
|
|
547
|
-
close,
|
|
548
|
-
openAll,
|
|
549
|
-
closeAll,
|
|
550
|
-
parent,
|
|
551
|
-
};
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
const createBuilder = (self, _styler, _isEmpty) => {
|
|
555
|
-
// Single argument is hot path, implicit coercion is faster than anything
|
|
556
|
-
// eslint-disable-next-line no-implicit-coercion
|
|
557
|
-
const builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
|
|
558
|
-
|
|
559
|
-
// We alter the prototype because we must return a function, but there is
|
|
560
|
-
// no way to create a function with a different prototype
|
|
561
|
-
Object.setPrototypeOf(builder, proto);
|
|
562
|
-
|
|
563
|
-
builder[GENERATOR] = self;
|
|
564
|
-
builder[STYLER] = _styler;
|
|
565
|
-
builder[IS_EMPTY] = _isEmpty;
|
|
566
|
-
|
|
567
|
-
return builder;
|
|
568
|
-
};
|
|
569
|
-
|
|
570
|
-
const applyStyle = (self, string) => {
|
|
571
|
-
if (self.level <= 0 || !string) {
|
|
572
|
-
return self[IS_EMPTY] ? '' : string;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
let styler = self[STYLER];
|
|
576
|
-
|
|
577
|
-
if (styler === undefined) {
|
|
578
|
-
return string;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
const {openAll, closeAll} = styler;
|
|
582
|
-
if (string.includes('\u001B')) {
|
|
583
|
-
while (styler !== undefined) {
|
|
584
|
-
// Replace any instances already present with a re-opening code
|
|
585
|
-
// otherwise only the part of the string until said closing code
|
|
586
|
-
// will be colored, and the rest will simply be 'plain'.
|
|
587
|
-
string = stringReplaceAll(string, styler.close, styler.open);
|
|
588
|
-
|
|
589
|
-
styler = styler.parent;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// We can move both next actions out of loop, because remaining actions in loop won't have
|
|
594
|
-
// any/visible effect on parts we add here. Close the styling before a linebreak and reopen
|
|
595
|
-
// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
|
|
596
|
-
const lfIndex = string.indexOf('\n');
|
|
597
|
-
if (lfIndex !== -1) {
|
|
598
|
-
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
return openAll + string + closeAll;
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
Object.defineProperties(createChalk.prototype, styles);
|
|
605
|
-
|
|
606
|
-
const chalk = createChalk();
|
|
607
|
-
createChalk({level: stderrColor ? stderrColor.level : 0});
|
|
608
|
-
|
|
609
151
|
const ServerInfo = {
|
|
610
152
|
register: (server) => {
|
|
611
153
|
const serverInfo = () => {
|
|
@@ -613,7 +155,7 @@ const ServerInfo = {
|
|
|
613
155
|
const hostname = "localhost";
|
|
614
156
|
const protocol = "http";
|
|
615
157
|
console.log("");
|
|
616
|
-
logger$1.success(
|
|
158
|
+
logger$1.success(chalk__default.green(`Flow v${pkg.version} dev server running at:`));
|
|
617
159
|
console.log("");
|
|
618
160
|
Object.keys(interfaces).forEach((key) => (interfaces[key] || []).filter((details) => details.family === "IPv4").map((detail) => {
|
|
619
161
|
return {
|
|
@@ -621,8 +163,8 @@ const ServerInfo = {
|
|
|
621
163
|
host: detail.address.replace("127.0.0.1", hostname)
|
|
622
164
|
};
|
|
623
165
|
}).forEach(({ type, host }) => {
|
|
624
|
-
const url = `${protocol}://${host}:${
|
|
625
|
-
console.log(` > ${type} ${
|
|
166
|
+
const url = `${protocol}://${host}:${chalk__default.bold(server.info.port)}`;
|
|
167
|
+
console.log(` > ${type} ${chalk__default.cyan(url)}`);
|
|
626
168
|
}));
|
|
627
169
|
};
|
|
628
170
|
return { serverInfo };
|
package/dist/index.mjs
CHANGED
|
@@ -4,10 +4,11 @@ import consola from 'consola';
|
|
|
4
4
|
import * as R from 'ramda';
|
|
5
5
|
import { notFound } from '@hapi/boom';
|
|
6
6
|
import os from 'os';
|
|
7
|
+
import chalk from 'chalk';
|
|
7
8
|
import fs from 'fs-extra';
|
|
8
9
|
|
|
9
10
|
const name = "@monkeyplus/flow";
|
|
10
|
-
const version = "4.0.0-beta.
|
|
11
|
+
const version = "4.0.0-beta.7";
|
|
11
12
|
const description = "Utils hapi";
|
|
12
13
|
const author = "Andres Navarrete";
|
|
13
14
|
const license = "MIT";
|
|
@@ -39,11 +40,11 @@ const dependencies$1 = {
|
|
|
39
40
|
"@hapi/boom": "9.x.x",
|
|
40
41
|
"@hapi/hoek": "9.x.x",
|
|
41
42
|
consola: "^2.15.3",
|
|
43
|
+
chalk: "^4.1.2",
|
|
42
44
|
"fs-extra": "^10.0.0",
|
|
43
45
|
ramda: "^0.28.0"
|
|
44
46
|
};
|
|
45
47
|
const devDependencies = {
|
|
46
|
-
chalk: "^5.0.0",
|
|
47
48
|
"@types/fs-extra": "^9.0.13",
|
|
48
49
|
"@types/hapi__hapi": "^20.0.10",
|
|
49
50
|
"@types/ramda": "^0.27.64"
|
|
@@ -122,466 +123,6 @@ const LifeCircle = {
|
|
|
122
123
|
}
|
|
123
124
|
};
|
|
124
125
|
|
|
125
|
-
const ANSI_BACKGROUND_OFFSET = 10;
|
|
126
|
-
|
|
127
|
-
const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
|
|
128
|
-
|
|
129
|
-
const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
|
|
130
|
-
|
|
131
|
-
const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
132
|
-
|
|
133
|
-
function assembleStyles() {
|
|
134
|
-
const codes = new Map();
|
|
135
|
-
const styles = {
|
|
136
|
-
modifier: {
|
|
137
|
-
reset: [0, 0],
|
|
138
|
-
// 21 isn't widely supported and 22 does the same thing
|
|
139
|
-
bold: [1, 22],
|
|
140
|
-
dim: [2, 22],
|
|
141
|
-
italic: [3, 23],
|
|
142
|
-
underline: [4, 24],
|
|
143
|
-
overline: [53, 55],
|
|
144
|
-
inverse: [7, 27],
|
|
145
|
-
hidden: [8, 28],
|
|
146
|
-
strikethrough: [9, 29],
|
|
147
|
-
},
|
|
148
|
-
color: {
|
|
149
|
-
black: [30, 39],
|
|
150
|
-
red: [31, 39],
|
|
151
|
-
green: [32, 39],
|
|
152
|
-
yellow: [33, 39],
|
|
153
|
-
blue: [34, 39],
|
|
154
|
-
magenta: [35, 39],
|
|
155
|
-
cyan: [36, 39],
|
|
156
|
-
white: [37, 39],
|
|
157
|
-
|
|
158
|
-
// Bright color
|
|
159
|
-
blackBright: [90, 39],
|
|
160
|
-
redBright: [91, 39],
|
|
161
|
-
greenBright: [92, 39],
|
|
162
|
-
yellowBright: [93, 39],
|
|
163
|
-
blueBright: [94, 39],
|
|
164
|
-
magentaBright: [95, 39],
|
|
165
|
-
cyanBright: [96, 39],
|
|
166
|
-
whiteBright: [97, 39],
|
|
167
|
-
},
|
|
168
|
-
bgColor: {
|
|
169
|
-
bgBlack: [40, 49],
|
|
170
|
-
bgRed: [41, 49],
|
|
171
|
-
bgGreen: [42, 49],
|
|
172
|
-
bgYellow: [43, 49],
|
|
173
|
-
bgBlue: [44, 49],
|
|
174
|
-
bgMagenta: [45, 49],
|
|
175
|
-
bgCyan: [46, 49],
|
|
176
|
-
bgWhite: [47, 49],
|
|
177
|
-
|
|
178
|
-
// Bright color
|
|
179
|
-
bgBlackBright: [100, 49],
|
|
180
|
-
bgRedBright: [101, 49],
|
|
181
|
-
bgGreenBright: [102, 49],
|
|
182
|
-
bgYellowBright: [103, 49],
|
|
183
|
-
bgBlueBright: [104, 49],
|
|
184
|
-
bgMagentaBright: [105, 49],
|
|
185
|
-
bgCyanBright: [106, 49],
|
|
186
|
-
bgWhiteBright: [107, 49],
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// Alias bright black as gray (and grey)
|
|
191
|
-
styles.color.gray = styles.color.blackBright;
|
|
192
|
-
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
193
|
-
styles.color.grey = styles.color.blackBright;
|
|
194
|
-
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
195
|
-
|
|
196
|
-
for (const [groupName, group] of Object.entries(styles)) {
|
|
197
|
-
for (const [styleName, style] of Object.entries(group)) {
|
|
198
|
-
styles[styleName] = {
|
|
199
|
-
open: `\u001B[${style[0]}m`,
|
|
200
|
-
close: `\u001B[${style[1]}m`,
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
group[styleName] = styles[styleName];
|
|
204
|
-
|
|
205
|
-
codes.set(style[0], style[1]);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
Object.defineProperty(styles, groupName, {
|
|
209
|
-
value: group,
|
|
210
|
-
enumerable: false,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
Object.defineProperty(styles, 'codes', {
|
|
215
|
-
value: codes,
|
|
216
|
-
enumerable: false,
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
styles.color.close = '\u001B[39m';
|
|
220
|
-
styles.bgColor.close = '\u001B[49m';
|
|
221
|
-
|
|
222
|
-
styles.color.ansi = wrapAnsi16();
|
|
223
|
-
styles.color.ansi256 = wrapAnsi256();
|
|
224
|
-
styles.color.ansi16m = wrapAnsi16m();
|
|
225
|
-
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
226
|
-
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
227
|
-
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
228
|
-
|
|
229
|
-
// From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
|
|
230
|
-
Object.defineProperties(styles, {
|
|
231
|
-
rgbToAnsi256: {
|
|
232
|
-
value: (red, green, blue) => {
|
|
233
|
-
// We use the extended greyscale palette here, with the exception of
|
|
234
|
-
// black and white. normal palette only has 4 greyscale shades.
|
|
235
|
-
if (red === green && green === blue) {
|
|
236
|
-
if (red < 8) {
|
|
237
|
-
return 16;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (red > 248) {
|
|
241
|
-
return 231;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return Math.round(((red - 8) / 247) * 24) + 232;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
return 16
|
|
248
|
-
+ (36 * Math.round(red / 255 * 5))
|
|
249
|
-
+ (6 * Math.round(green / 255 * 5))
|
|
250
|
-
+ Math.round(blue / 255 * 5);
|
|
251
|
-
},
|
|
252
|
-
enumerable: false,
|
|
253
|
-
},
|
|
254
|
-
hexToRgb: {
|
|
255
|
-
value: hex => {
|
|
256
|
-
const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
|
|
257
|
-
if (!matches) {
|
|
258
|
-
return [0, 0, 0];
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
let {colorString} = matches.groups;
|
|
262
|
-
|
|
263
|
-
if (colorString.length === 3) {
|
|
264
|
-
colorString = [...colorString].map(character => character + character).join('');
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const integer = Number.parseInt(colorString, 16);
|
|
268
|
-
|
|
269
|
-
return [
|
|
270
|
-
/* eslint-disable no-bitwise */
|
|
271
|
-
(integer >> 16) & 0xFF,
|
|
272
|
-
(integer >> 8) & 0xFF,
|
|
273
|
-
integer & 0xFF,
|
|
274
|
-
/* eslint-enable no-bitwise */
|
|
275
|
-
];
|
|
276
|
-
},
|
|
277
|
-
enumerable: false,
|
|
278
|
-
},
|
|
279
|
-
hexToAnsi256: {
|
|
280
|
-
value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
281
|
-
enumerable: false,
|
|
282
|
-
},
|
|
283
|
-
ansi256ToAnsi: {
|
|
284
|
-
value: code => {
|
|
285
|
-
if (code < 8) {
|
|
286
|
-
return 30 + code;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (code < 16) {
|
|
290
|
-
return 90 + (code - 8);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
let red;
|
|
294
|
-
let green;
|
|
295
|
-
let blue;
|
|
296
|
-
|
|
297
|
-
if (code >= 232) {
|
|
298
|
-
red = (((code - 232) * 10) + 8) / 255;
|
|
299
|
-
green = red;
|
|
300
|
-
blue = red;
|
|
301
|
-
} else {
|
|
302
|
-
code -= 16;
|
|
303
|
-
|
|
304
|
-
const remainder = code % 36;
|
|
305
|
-
|
|
306
|
-
red = Math.floor(code / 36) / 5;
|
|
307
|
-
green = Math.floor(remainder / 6) / 5;
|
|
308
|
-
blue = (remainder % 6) / 5;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const value = Math.max(red, green, blue) * 2;
|
|
312
|
-
|
|
313
|
-
if (value === 0) {
|
|
314
|
-
return 30;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// eslint-disable-next-line no-bitwise
|
|
318
|
-
let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
|
|
319
|
-
|
|
320
|
-
if (value === 2) {
|
|
321
|
-
result += 60;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
return result;
|
|
325
|
-
},
|
|
326
|
-
enumerable: false,
|
|
327
|
-
},
|
|
328
|
-
rgbToAnsi: {
|
|
329
|
-
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
330
|
-
enumerable: false,
|
|
331
|
-
},
|
|
332
|
-
hexToAnsi: {
|
|
333
|
-
value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
334
|
-
enumerable: false,
|
|
335
|
-
},
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
return styles;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const ansiStyles = assembleStyles();
|
|
342
|
-
|
|
343
|
-
/* eslint-env browser */
|
|
344
|
-
|
|
345
|
-
const isBlinkBasedBrowser = /\b(Chrome|Chromium)\//.test(navigator.userAgent);
|
|
346
|
-
|
|
347
|
-
const colorSupport = isBlinkBasedBrowser ? {
|
|
348
|
-
level: 1,
|
|
349
|
-
hasBasic: true,
|
|
350
|
-
has256: false,
|
|
351
|
-
has16m: false,
|
|
352
|
-
} : false;
|
|
353
|
-
|
|
354
|
-
const supportsColor = {
|
|
355
|
-
stdout: colorSupport,
|
|
356
|
-
stderr: colorSupport,
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
// TODO: When targeting Node.js 16, use `String.prototype.replaceAll`.
|
|
360
|
-
function stringReplaceAll(string, substring, replacer) {
|
|
361
|
-
let index = string.indexOf(substring);
|
|
362
|
-
if (index === -1) {
|
|
363
|
-
return string;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const substringLength = substring.length;
|
|
367
|
-
let endIndex = 0;
|
|
368
|
-
let returnValue = '';
|
|
369
|
-
do {
|
|
370
|
-
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
|
371
|
-
endIndex = index + substringLength;
|
|
372
|
-
index = string.indexOf(substring, endIndex);
|
|
373
|
-
} while (index !== -1);
|
|
374
|
-
|
|
375
|
-
returnValue += string.slice(endIndex);
|
|
376
|
-
return returnValue;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
380
|
-
let endIndex = 0;
|
|
381
|
-
let returnValue = '';
|
|
382
|
-
do {
|
|
383
|
-
const gotCR = string[index - 1] === '\r';
|
|
384
|
-
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
|
385
|
-
endIndex = index + 1;
|
|
386
|
-
index = string.indexOf('\n', endIndex);
|
|
387
|
-
} while (index !== -1);
|
|
388
|
-
|
|
389
|
-
returnValue += string.slice(endIndex);
|
|
390
|
-
return returnValue;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
const {stdout: stdoutColor, stderr: stderrColor} = supportsColor;
|
|
394
|
-
|
|
395
|
-
const GENERATOR = Symbol('GENERATOR');
|
|
396
|
-
const STYLER = Symbol('STYLER');
|
|
397
|
-
const IS_EMPTY = Symbol('IS_EMPTY');
|
|
398
|
-
|
|
399
|
-
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
|
400
|
-
const levelMapping = [
|
|
401
|
-
'ansi',
|
|
402
|
-
'ansi',
|
|
403
|
-
'ansi256',
|
|
404
|
-
'ansi16m',
|
|
405
|
-
];
|
|
406
|
-
|
|
407
|
-
const styles = Object.create(null);
|
|
408
|
-
|
|
409
|
-
const applyOptions = (object, options = {}) => {
|
|
410
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
411
|
-
throw new Error('The `level` option should be an integer from 0 to 3');
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
// Detect level if not set manually
|
|
415
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
416
|
-
object.level = options.level === undefined ? colorLevel : options.level;
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
const chalkFactory = options => {
|
|
420
|
-
const chalk = (...strings) => strings.join(' ');
|
|
421
|
-
applyOptions(chalk, options);
|
|
422
|
-
|
|
423
|
-
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
424
|
-
|
|
425
|
-
return chalk;
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
function createChalk(options) {
|
|
429
|
-
return chalkFactory(options);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
433
|
-
|
|
434
|
-
for (const [styleName, style] of Object.entries(ansiStyles)) {
|
|
435
|
-
styles[styleName] = {
|
|
436
|
-
get() {
|
|
437
|
-
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
438
|
-
Object.defineProperty(this, styleName, {value: builder});
|
|
439
|
-
return builder;
|
|
440
|
-
},
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
styles.visible = {
|
|
445
|
-
get() {
|
|
446
|
-
const builder = createBuilder(this, this[STYLER], true);
|
|
447
|
-
Object.defineProperty(this, 'visible', {value: builder});
|
|
448
|
-
return builder;
|
|
449
|
-
},
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
const getModelAnsi = (model, level, type, ...arguments_) => {
|
|
453
|
-
if (model === 'rgb') {
|
|
454
|
-
if (level === 'ansi16m') {
|
|
455
|
-
return ansiStyles[type].ansi16m(...arguments_);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
if (level === 'ansi256') {
|
|
459
|
-
return ansiStyles[type].ansi256(ansiStyles.rgbToAnsi256(...arguments_));
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
return ansiStyles[type].ansi(ansiStyles.rgbToAnsi(...arguments_));
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (model === 'hex') {
|
|
466
|
-
return getModelAnsi('rgb', level, type, ...ansiStyles.hexToRgb(...arguments_));
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return ansiStyles[type][model](...arguments_);
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
const usedModels = ['rgb', 'hex', 'ansi256'];
|
|
473
|
-
|
|
474
|
-
for (const model of usedModels) {
|
|
475
|
-
styles[model] = {
|
|
476
|
-
get() {
|
|
477
|
-
const {level} = this;
|
|
478
|
-
return function (...arguments_) {
|
|
479
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]);
|
|
480
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
481
|
-
};
|
|
482
|
-
},
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
|
486
|
-
styles[bgModel] = {
|
|
487
|
-
get() {
|
|
488
|
-
const {level} = this;
|
|
489
|
-
return function (...arguments_) {
|
|
490
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]);
|
|
491
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
492
|
-
};
|
|
493
|
-
},
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
const proto = Object.defineProperties(() => {}, {
|
|
498
|
-
...styles,
|
|
499
|
-
level: {
|
|
500
|
-
enumerable: true,
|
|
501
|
-
get() {
|
|
502
|
-
return this[GENERATOR].level;
|
|
503
|
-
},
|
|
504
|
-
set(level) {
|
|
505
|
-
this[GENERATOR].level = level;
|
|
506
|
-
},
|
|
507
|
-
},
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
const createStyler = (open, close, parent) => {
|
|
511
|
-
let openAll;
|
|
512
|
-
let closeAll;
|
|
513
|
-
if (parent === undefined) {
|
|
514
|
-
openAll = open;
|
|
515
|
-
closeAll = close;
|
|
516
|
-
} else {
|
|
517
|
-
openAll = parent.openAll + open;
|
|
518
|
-
closeAll = close + parent.closeAll;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
return {
|
|
522
|
-
open,
|
|
523
|
-
close,
|
|
524
|
-
openAll,
|
|
525
|
-
closeAll,
|
|
526
|
-
parent,
|
|
527
|
-
};
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
const createBuilder = (self, _styler, _isEmpty) => {
|
|
531
|
-
// Single argument is hot path, implicit coercion is faster than anything
|
|
532
|
-
// eslint-disable-next-line no-implicit-coercion
|
|
533
|
-
const builder = (...arguments_) => applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
|
|
534
|
-
|
|
535
|
-
// We alter the prototype because we must return a function, but there is
|
|
536
|
-
// no way to create a function with a different prototype
|
|
537
|
-
Object.setPrototypeOf(builder, proto);
|
|
538
|
-
|
|
539
|
-
builder[GENERATOR] = self;
|
|
540
|
-
builder[STYLER] = _styler;
|
|
541
|
-
builder[IS_EMPTY] = _isEmpty;
|
|
542
|
-
|
|
543
|
-
return builder;
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
const applyStyle = (self, string) => {
|
|
547
|
-
if (self.level <= 0 || !string) {
|
|
548
|
-
return self[IS_EMPTY] ? '' : string;
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
let styler = self[STYLER];
|
|
552
|
-
|
|
553
|
-
if (styler === undefined) {
|
|
554
|
-
return string;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
const {openAll, closeAll} = styler;
|
|
558
|
-
if (string.includes('\u001B')) {
|
|
559
|
-
while (styler !== undefined) {
|
|
560
|
-
// Replace any instances already present with a re-opening code
|
|
561
|
-
// otherwise only the part of the string until said closing code
|
|
562
|
-
// will be colored, and the rest will simply be 'plain'.
|
|
563
|
-
string = stringReplaceAll(string, styler.close, styler.open);
|
|
564
|
-
|
|
565
|
-
styler = styler.parent;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
// We can move both next actions out of loop, because remaining actions in loop won't have
|
|
570
|
-
// any/visible effect on parts we add here. Close the styling before a linebreak and reopen
|
|
571
|
-
// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
|
|
572
|
-
const lfIndex = string.indexOf('\n');
|
|
573
|
-
if (lfIndex !== -1) {
|
|
574
|
-
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
return openAll + string + closeAll;
|
|
578
|
-
};
|
|
579
|
-
|
|
580
|
-
Object.defineProperties(createChalk.prototype, styles);
|
|
581
|
-
|
|
582
|
-
const chalk = createChalk();
|
|
583
|
-
createChalk({level: stderrColor ? stderrColor.level : 0});
|
|
584
|
-
|
|
585
126
|
const ServerInfo = {
|
|
586
127
|
register: (server) => {
|
|
587
128
|
const serverInfo = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkeyplus/flow",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.7",
|
|
4
4
|
"description": "Utils hapi",
|
|
5
5
|
"author": "Andres Navarrete",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"@hapi/boom": "9.x.x",
|
|
22
22
|
"@hapi/hoek": "9.x.x",
|
|
23
23
|
"consola": "^2.15.3",
|
|
24
|
+
"chalk": "^4.1.2",
|
|
24
25
|
"fs-extra": "^10.0.0",
|
|
25
26
|
"ramda": "^0.28.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"chalk": "^5.0.0",
|
|
29
29
|
"@types/fs-extra": "^9.0.13",
|
|
30
30
|
"@types/hapi__hapi": "^20.0.10",
|
|
31
31
|
"@types/ramda": "^0.27.64"
|