@monkeyplus/flow 4.0.0-beta.6 → 4.0.0-beta.8
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 +203 -470
- package/dist/index.d.ts +9 -2
- package/dist/index.mjs +199 -468
- package/package.json +6 -2
- package/types/flow.d.ts +5 -0
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,11 @@ 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');
|
|
13
|
+
const fs$1 = require('fs');
|
|
14
|
+
const hookable = require('hookable');
|
|
15
|
+
const chokidar = require('chokidar');
|
|
12
16
|
|
|
13
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
14
18
|
|
|
@@ -28,10 +32,13 @@ const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
|
28
32
|
const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
|
|
29
33
|
const R__namespace = /*#__PURE__*/_interopNamespace(R);
|
|
30
34
|
const os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
35
|
+
const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
31
36
|
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
37
|
+
const fs__default$1 = /*#__PURE__*/_interopDefaultLegacy(fs$1);
|
|
38
|
+
const chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
|
|
32
39
|
|
|
33
40
|
const name = "@monkeyplus/flow";
|
|
34
|
-
const version = "4.0.0-beta.
|
|
41
|
+
const version = "4.0.0-beta.8";
|
|
35
42
|
const description = "Utils hapi";
|
|
36
43
|
const author = "Andres Navarrete";
|
|
37
44
|
const license = "MIT";
|
|
@@ -63,13 +70,17 @@ const dependencies$1 = {
|
|
|
63
70
|
"@hapi/boom": "9.x.x",
|
|
64
71
|
"@hapi/hoek": "9.x.x",
|
|
65
72
|
consola: "^2.15.3",
|
|
73
|
+
chalk: "^4.1.2",
|
|
74
|
+
chokidar: "^3.5.3",
|
|
75
|
+
hookable: "^5.1.1",
|
|
66
76
|
"fs-extra": "^10.0.0",
|
|
67
77
|
ramda: "^0.28.0"
|
|
68
78
|
};
|
|
69
79
|
const devDependencies = {
|
|
70
|
-
chalk: "^5.0.0",
|
|
71
80
|
"@types/fs-extra": "^9.0.13",
|
|
72
81
|
"@types/hapi__hapi": "^20.0.10",
|
|
82
|
+
"@types/hapi__nes": "^11.0.5",
|
|
83
|
+
"@types/hapi__vision": "^5.5.3",
|
|
73
84
|
"@types/ramda": "^0.27.64"
|
|
74
85
|
};
|
|
75
86
|
const peerDependencies = {
|
|
@@ -96,8 +107,13 @@ const pkg = {
|
|
|
96
107
|
|
|
97
108
|
const logger$1 = consola__default.withScope(pkg.name);
|
|
98
109
|
const dependencies = {
|
|
99
|
-
"@hapi/vision": "6.x.x"
|
|
110
|
+
"@hapi/vision": "6.x.x",
|
|
111
|
+
"@hapi/inert": "6.x.x",
|
|
112
|
+
"@hapi/h2o2": "9.x.x",
|
|
113
|
+
"@hapi/nes": "12.x.x"
|
|
100
114
|
};
|
|
115
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
116
|
+
const isGenerate = process.env.GENERATE;
|
|
101
117
|
|
|
102
118
|
const LifeCircle = {
|
|
103
119
|
register: (server) => {
|
|
@@ -146,466 +162,6 @@ const LifeCircle = {
|
|
|
146
162
|
}
|
|
147
163
|
};
|
|
148
164
|
|
|
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
165
|
const ServerInfo = {
|
|
610
166
|
register: (server) => {
|
|
611
167
|
const serverInfo = () => {
|
|
@@ -613,7 +169,7 @@ const ServerInfo = {
|
|
|
613
169
|
const hostname = "localhost";
|
|
614
170
|
const protocol = "http";
|
|
615
171
|
console.log("");
|
|
616
|
-
logger$1.success(
|
|
172
|
+
logger$1.success(chalk__default.green(`Flow v${pkg.version} dev server running at:`));
|
|
617
173
|
console.log("");
|
|
618
174
|
Object.keys(interfaces).forEach((key) => (interfaces[key] || []).filter((details) => details.family === "IPv4").map((detail) => {
|
|
619
175
|
return {
|
|
@@ -621,8 +177,8 @@ const ServerInfo = {
|
|
|
621
177
|
host: detail.address.replace("127.0.0.1", hostname)
|
|
622
178
|
};
|
|
623
179
|
}).forEach(({ type, host }) => {
|
|
624
|
-
const url = `${protocol}://${host}:${
|
|
625
|
-
console.log(` > ${type} ${
|
|
180
|
+
const url = `${protocol}://${host}:${chalk__default.bold(server.info.port)}`;
|
|
181
|
+
console.log(` > ${type} ${chalk__default.cyan(url)}`);
|
|
626
182
|
}));
|
|
627
183
|
};
|
|
628
184
|
return { serverInfo };
|
|
@@ -771,7 +327,7 @@ const handlerPage = async (req, h) => {
|
|
|
771
327
|
return context;
|
|
772
328
|
}
|
|
773
329
|
context.utils = utils;
|
|
774
|
-
return h.view(`${configs.dirTemplates}${flow.view.
|
|
330
|
+
return h.view(`${configs.dirTemplates}${flow.view.layout || "default"}`, context);
|
|
775
331
|
};
|
|
776
332
|
|
|
777
333
|
const logger = consola__default.withScope("@monkeyplus/flow");
|
|
@@ -779,6 +335,10 @@ const defaults = {
|
|
|
779
335
|
locales: ["es-ec"],
|
|
780
336
|
defaultUbication: "ec",
|
|
781
337
|
defaultLanguage: "es",
|
|
338
|
+
staticDir: "static",
|
|
339
|
+
hmr: {
|
|
340
|
+
dirs: ["views"]
|
|
341
|
+
},
|
|
782
342
|
publicPath: "/",
|
|
783
343
|
locale: "es-ec",
|
|
784
344
|
relativeTo: "",
|
|
@@ -1150,6 +710,47 @@ const definePage = (pageOptions) => (levelOptions) => (configs) => {
|
|
|
1150
710
|
return routes;
|
|
1151
711
|
};
|
|
1152
712
|
|
|
713
|
+
const readPagesDir = (pathDir, folder) => {
|
|
714
|
+
const p = fs__default$1.readdirSync(pathDir);
|
|
715
|
+
return R.flatten(p.filter((f) => !f.includes(".js.map") && !f.includes(" copy.js.map") && !f.includes(" copy.js") && !f.includes(".model")).map((e) => {
|
|
716
|
+
if (e.includes(".js") || e.includes(".ts")) {
|
|
717
|
+
return {
|
|
718
|
+
path: path__default.join(pathDir, e),
|
|
719
|
+
prefix: folder
|
|
720
|
+
};
|
|
721
|
+
} else {
|
|
722
|
+
return readPagesDir(path__default.join(pathDir, e), e);
|
|
723
|
+
}
|
|
724
|
+
}));
|
|
725
|
+
};
|
|
726
|
+
const registerPages = async (server, dir) => {
|
|
727
|
+
const dirPages = path__default.resolve(dir || "./pages");
|
|
728
|
+
const listFiles = readPagesDir(dirPages);
|
|
729
|
+
const listPrePages = [];
|
|
730
|
+
for (const item of listFiles) {
|
|
731
|
+
try {
|
|
732
|
+
const module = require(item.path)?.default;
|
|
733
|
+
if (typeof module === "function") {
|
|
734
|
+
listPrePages.push(module());
|
|
735
|
+
} else if (typeof module === "object") {
|
|
736
|
+
if (Array.isArray(module)) {
|
|
737
|
+
module.forEach((el) => listPrePages.push(el()));
|
|
738
|
+
} else {
|
|
739
|
+
const _pages = await module.pages({ server });
|
|
740
|
+
if (Array.isArray(_pages))
|
|
741
|
+
_pages.forEach((page) => listPrePages.push(definePage(page)()));
|
|
742
|
+
else
|
|
743
|
+
listPrePages.push(definePage(_pages)());
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
} catch (details) {
|
|
747
|
+
logger$1.error(details);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
for (const page of listPrePages)
|
|
751
|
+
await server.flow.addPage(page);
|
|
752
|
+
};
|
|
753
|
+
|
|
1153
754
|
const RunMethods = {
|
|
1154
755
|
register: (server) => {
|
|
1155
756
|
const { flow: state } = server.app;
|
|
@@ -1163,7 +764,7 @@ const RunMethods = {
|
|
|
1163
764
|
server.route(route);
|
|
1164
765
|
};
|
|
1165
766
|
const addPage = (_page, extra) => {
|
|
1166
|
-
const
|
|
767
|
+
const registerPages2 = (_pages2) => {
|
|
1167
768
|
for (const _route of _pages2) {
|
|
1168
769
|
if (state.routes[_route.path])
|
|
1169
770
|
logger$1.warn("The route %s alredy exist", _route.path);
|
|
@@ -1174,13 +775,14 @@ const RunMethods = {
|
|
|
1174
775
|
let _pages;
|
|
1175
776
|
if (typeof _page === "function") {
|
|
1176
777
|
_pages = _page(config);
|
|
1177
|
-
|
|
778
|
+
registerPages2(_pages);
|
|
1178
779
|
} else {
|
|
1179
780
|
_pages = definePage(_page)()(config);
|
|
1180
|
-
|
|
781
|
+
registerPages2(_pages);
|
|
1181
782
|
}
|
|
1182
783
|
};
|
|
1183
784
|
const init = async () => {
|
|
785
|
+
await registerPages(server);
|
|
1184
786
|
const pages = server.app.flow.routes;
|
|
1185
787
|
for (const key in pages) {
|
|
1186
788
|
const page = pages[key];
|
|
@@ -1197,6 +799,136 @@ const RunMethods = {
|
|
|
1197
799
|
}
|
|
1198
800
|
};
|
|
1199
801
|
|
|
802
|
+
const createHmr = (options) => {
|
|
803
|
+
const state = {
|
|
804
|
+
dir: options.relativeTo || "",
|
|
805
|
+
dirs: options.dirs || [],
|
|
806
|
+
extensions: options.extensions || ["eta"]
|
|
807
|
+
};
|
|
808
|
+
let watcher;
|
|
809
|
+
const hooks = hookable.createHooks();
|
|
810
|
+
const watch = () => {
|
|
811
|
+
watcher = chokidar__default.watch(state.dirs.map((d) => path__default.join(d, `**/*.(${state.extensions.join("|")})`)), {
|
|
812
|
+
cwd: state.dir,
|
|
813
|
+
ignoreInitial: true,
|
|
814
|
+
ignored: "node_modules/**/*"
|
|
815
|
+
}).on("change", (path2) => {
|
|
816
|
+
logger$1.info("Changed file", path2);
|
|
817
|
+
hooks.callHook("page:refresh");
|
|
818
|
+
});
|
|
819
|
+
};
|
|
820
|
+
watch();
|
|
821
|
+
return { watcher, hooks };
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
const RegisterCommon = async (server, configs) => {
|
|
825
|
+
server.route({
|
|
826
|
+
method: "GET",
|
|
827
|
+
path: "/{param*}",
|
|
828
|
+
options: {
|
|
829
|
+
ext: {
|
|
830
|
+
onPreResponse: {
|
|
831
|
+
method: (req, h) => {
|
|
832
|
+
return h.continue;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
},
|
|
837
|
+
handler: {
|
|
838
|
+
directory: {
|
|
839
|
+
path: configs.staticDir,
|
|
840
|
+
listing: true
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
});
|
|
844
|
+
if (!isGenerate) {
|
|
845
|
+
const hmr = createHmr({
|
|
846
|
+
dirs: configs.hmr.dirs,
|
|
847
|
+
relativeTo: configs.relativeTo
|
|
848
|
+
});
|
|
849
|
+
hmr.hooks.hook("page:refresh", () => {
|
|
850
|
+
setTimeout(() => {
|
|
851
|
+
logger$1.info("Refresh page");
|
|
852
|
+
server.publish("/_flow/hmr", { reload: true });
|
|
853
|
+
}, 40);
|
|
854
|
+
});
|
|
855
|
+
server.subscription("/_flow/hmr");
|
|
856
|
+
server.route({
|
|
857
|
+
path: "/_flow/hmr/client.js",
|
|
858
|
+
method: "get",
|
|
859
|
+
handler: {
|
|
860
|
+
file: {
|
|
861
|
+
path: path.join(__dirname, "../resources/client"),
|
|
862
|
+
confine: false
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
server.route({
|
|
867
|
+
path: "/_flow/hmr/connect.js",
|
|
868
|
+
method: "get",
|
|
869
|
+
handler: {
|
|
870
|
+
file: {
|
|
871
|
+
path: path.join(__dirname, "../resources/ws.js"),
|
|
872
|
+
confine: false
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
logger$1.debug("Enable development routes");
|
|
877
|
+
server.route({
|
|
878
|
+
path: "/_flow/sitemap",
|
|
879
|
+
method: "get",
|
|
880
|
+
handler: async () => {
|
|
881
|
+
const { pages: getPages } = server.methods.flow;
|
|
882
|
+
const urls = await getPages();
|
|
883
|
+
const pages = Object.values(urls).map((p) => R.dissoc("context", p));
|
|
884
|
+
return {
|
|
885
|
+
total: pages.length,
|
|
886
|
+
pages
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
server.route({
|
|
891
|
+
path: "/_flow/locales",
|
|
892
|
+
method: "get",
|
|
893
|
+
handler: async (req) => {
|
|
894
|
+
const { pages: getPages } = server.methods.flow;
|
|
895
|
+
const urls = await getPages();
|
|
896
|
+
const pages = Object.values(urls).map((p) => R.dissoc("context", p));
|
|
897
|
+
const locales = R.groupBy((page) => page.locale, pages);
|
|
898
|
+
return {
|
|
899
|
+
locales: req.server.plugins.flow.configs.locales,
|
|
900
|
+
all: R.mapObjIndexed((l) => {
|
|
901
|
+
return {
|
|
902
|
+
total: l.length,
|
|
903
|
+
pages: l
|
|
904
|
+
};
|
|
905
|
+
}, locales)
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
server.route({
|
|
910
|
+
path: "/_flow/configs",
|
|
911
|
+
method: "get",
|
|
912
|
+
handler: (req) => {
|
|
913
|
+
return req.server.plugins.flow.configs;
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
const HMR = {
|
|
918
|
+
head: ' <script src="/_flow/hmr/client.js"><\/script>',
|
|
919
|
+
body: ' <script src="/_flow/hmr/connect.js"><\/script>'
|
|
920
|
+
};
|
|
921
|
+
server.ext("onPreHandler", async (req, h) => {
|
|
922
|
+
if (req.route.settings.plugins?.generate === ".html") {
|
|
923
|
+
const { global } = req.plugins.flow;
|
|
924
|
+
Object.assign(global, {
|
|
925
|
+
hmr: isProduction || isGenerate ? { head: "", body: "" } : HMR
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
return h.continue;
|
|
929
|
+
});
|
|
930
|
+
};
|
|
931
|
+
|
|
1200
932
|
const plugin = {
|
|
1201
933
|
pkg,
|
|
1202
934
|
dependencies,
|
|
@@ -1321,6 +1053,7 @@ const plugin = {
|
|
|
1321
1053
|
return baseOptions;
|
|
1322
1054
|
}
|
|
1323
1055
|
};
|
|
1056
|
+
await RegisterCommon(server, config);
|
|
1324
1057
|
}
|
|
1325
1058
|
};
|
|
1326
1059
|
|