@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.mjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import path from 'path';
|
|
1
|
+
import path, { join } from 'path';
|
|
2
2
|
import { applyToDefaults } from '@hapi/hoek';
|
|
3
3
|
import consola from 'consola';
|
|
4
4
|
import * as R from 'ramda';
|
|
5
|
+
import { flatten, dissoc, groupBy, mapObjIndexed } from 'ramda';
|
|
5
6
|
import { notFound } from '@hapi/boom';
|
|
6
7
|
import os from 'os';
|
|
8
|
+
import chalk from 'chalk';
|
|
7
9
|
import fs from 'fs-extra';
|
|
10
|
+
import fs$1 from 'fs';
|
|
11
|
+
import { createHooks } from 'hookable';
|
|
12
|
+
import chokidar from 'chokidar';
|
|
8
13
|
|
|
9
14
|
const name = "@monkeyplus/flow";
|
|
10
|
-
const version = "4.0.0-beta.
|
|
15
|
+
const version = "4.0.0-beta.8";
|
|
11
16
|
const description = "Utils hapi";
|
|
12
17
|
const author = "Andres Navarrete";
|
|
13
18
|
const license = "MIT";
|
|
@@ -39,13 +44,17 @@ const dependencies$1 = {
|
|
|
39
44
|
"@hapi/boom": "9.x.x",
|
|
40
45
|
"@hapi/hoek": "9.x.x",
|
|
41
46
|
consola: "^2.15.3",
|
|
47
|
+
chalk: "^4.1.2",
|
|
48
|
+
chokidar: "^3.5.3",
|
|
49
|
+
hookable: "^5.1.1",
|
|
42
50
|
"fs-extra": "^10.0.0",
|
|
43
51
|
ramda: "^0.28.0"
|
|
44
52
|
};
|
|
45
53
|
const devDependencies = {
|
|
46
|
-
chalk: "^5.0.0",
|
|
47
54
|
"@types/fs-extra": "^9.0.13",
|
|
48
55
|
"@types/hapi__hapi": "^20.0.10",
|
|
56
|
+
"@types/hapi__nes": "^11.0.5",
|
|
57
|
+
"@types/hapi__vision": "^5.5.3",
|
|
49
58
|
"@types/ramda": "^0.27.64"
|
|
50
59
|
};
|
|
51
60
|
const peerDependencies = {
|
|
@@ -72,8 +81,13 @@ const pkg = {
|
|
|
72
81
|
|
|
73
82
|
const logger$1 = consola.withScope(pkg.name);
|
|
74
83
|
const dependencies = {
|
|
75
|
-
"@hapi/vision": "6.x.x"
|
|
84
|
+
"@hapi/vision": "6.x.x",
|
|
85
|
+
"@hapi/inert": "6.x.x",
|
|
86
|
+
"@hapi/h2o2": "9.x.x",
|
|
87
|
+
"@hapi/nes": "12.x.x"
|
|
76
88
|
};
|
|
89
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
90
|
+
const isGenerate = process.env.GENERATE;
|
|
77
91
|
|
|
78
92
|
const LifeCircle = {
|
|
79
93
|
register: (server) => {
|
|
@@ -122,466 +136,6 @@ const LifeCircle = {
|
|
|
122
136
|
}
|
|
123
137
|
};
|
|
124
138
|
|
|
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
139
|
const ServerInfo = {
|
|
586
140
|
register: (server) => {
|
|
587
141
|
const serverInfo = () => {
|
|
@@ -747,7 +301,7 @@ const handlerPage = async (req, h) => {
|
|
|
747
301
|
return context;
|
|
748
302
|
}
|
|
749
303
|
context.utils = utils;
|
|
750
|
-
return h.view(`${configs.dirTemplates}${flow.view.
|
|
304
|
+
return h.view(`${configs.dirTemplates}${flow.view.layout || "default"}`, context);
|
|
751
305
|
};
|
|
752
306
|
|
|
753
307
|
const logger = consola.withScope("@monkeyplus/flow");
|
|
@@ -755,6 +309,10 @@ const defaults = {
|
|
|
755
309
|
locales: ["es-ec"],
|
|
756
310
|
defaultUbication: "ec",
|
|
757
311
|
defaultLanguage: "es",
|
|
312
|
+
staticDir: "static",
|
|
313
|
+
hmr: {
|
|
314
|
+
dirs: ["views"]
|
|
315
|
+
},
|
|
758
316
|
publicPath: "/",
|
|
759
317
|
locale: "es-ec",
|
|
760
318
|
relativeTo: "",
|
|
@@ -1126,6 +684,47 @@ const definePage = (pageOptions) => (levelOptions) => (configs) => {
|
|
|
1126
684
|
return routes;
|
|
1127
685
|
};
|
|
1128
686
|
|
|
687
|
+
const readPagesDir = (pathDir, folder) => {
|
|
688
|
+
const p = fs$1.readdirSync(pathDir);
|
|
689
|
+
return flatten(p.filter((f) => !f.includes(".js.map") && !f.includes(" copy.js.map") && !f.includes(" copy.js") && !f.includes(".model")).map((e) => {
|
|
690
|
+
if (e.includes(".js") || e.includes(".ts")) {
|
|
691
|
+
return {
|
|
692
|
+
path: path.join(pathDir, e),
|
|
693
|
+
prefix: folder
|
|
694
|
+
};
|
|
695
|
+
} else {
|
|
696
|
+
return readPagesDir(path.join(pathDir, e), e);
|
|
697
|
+
}
|
|
698
|
+
}));
|
|
699
|
+
};
|
|
700
|
+
const registerPages = async (server, dir) => {
|
|
701
|
+
const dirPages = path.resolve(dir || "./pages");
|
|
702
|
+
const listFiles = readPagesDir(dirPages);
|
|
703
|
+
const listPrePages = [];
|
|
704
|
+
for (const item of listFiles) {
|
|
705
|
+
try {
|
|
706
|
+
const module = require(item.path)?.default;
|
|
707
|
+
if (typeof module === "function") {
|
|
708
|
+
listPrePages.push(module());
|
|
709
|
+
} else if (typeof module === "object") {
|
|
710
|
+
if (Array.isArray(module)) {
|
|
711
|
+
module.forEach((el) => listPrePages.push(el()));
|
|
712
|
+
} else {
|
|
713
|
+
const _pages = await module.pages({ server });
|
|
714
|
+
if (Array.isArray(_pages))
|
|
715
|
+
_pages.forEach((page) => listPrePages.push(definePage(page)()));
|
|
716
|
+
else
|
|
717
|
+
listPrePages.push(definePage(_pages)());
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
} catch (details) {
|
|
721
|
+
logger$1.error(details);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
for (const page of listPrePages)
|
|
725
|
+
await server.flow.addPage(page);
|
|
726
|
+
};
|
|
727
|
+
|
|
1129
728
|
const RunMethods = {
|
|
1130
729
|
register: (server) => {
|
|
1131
730
|
const { flow: state } = server.app;
|
|
@@ -1139,7 +738,7 @@ const RunMethods = {
|
|
|
1139
738
|
server.route(route);
|
|
1140
739
|
};
|
|
1141
740
|
const addPage = (_page, extra) => {
|
|
1142
|
-
const
|
|
741
|
+
const registerPages2 = (_pages2) => {
|
|
1143
742
|
for (const _route of _pages2) {
|
|
1144
743
|
if (state.routes[_route.path])
|
|
1145
744
|
logger$1.warn("The route %s alredy exist", _route.path);
|
|
@@ -1150,13 +749,14 @@ const RunMethods = {
|
|
|
1150
749
|
let _pages;
|
|
1151
750
|
if (typeof _page === "function") {
|
|
1152
751
|
_pages = _page(config);
|
|
1153
|
-
|
|
752
|
+
registerPages2(_pages);
|
|
1154
753
|
} else {
|
|
1155
754
|
_pages = definePage(_page)()(config);
|
|
1156
|
-
|
|
755
|
+
registerPages2(_pages);
|
|
1157
756
|
}
|
|
1158
757
|
};
|
|
1159
758
|
const init = async () => {
|
|
759
|
+
await registerPages(server);
|
|
1160
760
|
const pages = server.app.flow.routes;
|
|
1161
761
|
for (const key in pages) {
|
|
1162
762
|
const page = pages[key];
|
|
@@ -1173,6 +773,136 @@ const RunMethods = {
|
|
|
1173
773
|
}
|
|
1174
774
|
};
|
|
1175
775
|
|
|
776
|
+
const createHmr = (options) => {
|
|
777
|
+
const state = {
|
|
778
|
+
dir: options.relativeTo || "",
|
|
779
|
+
dirs: options.dirs || [],
|
|
780
|
+
extensions: options.extensions || ["eta"]
|
|
781
|
+
};
|
|
782
|
+
let watcher;
|
|
783
|
+
const hooks = createHooks();
|
|
784
|
+
const watch = () => {
|
|
785
|
+
watcher = chokidar.watch(state.dirs.map((d) => path.join(d, `**/*.(${state.extensions.join("|")})`)), {
|
|
786
|
+
cwd: state.dir,
|
|
787
|
+
ignoreInitial: true,
|
|
788
|
+
ignored: "node_modules/**/*"
|
|
789
|
+
}).on("change", (path2) => {
|
|
790
|
+
logger$1.info("Changed file", path2);
|
|
791
|
+
hooks.callHook("page:refresh");
|
|
792
|
+
});
|
|
793
|
+
};
|
|
794
|
+
watch();
|
|
795
|
+
return { watcher, hooks };
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
const RegisterCommon = async (server, configs) => {
|
|
799
|
+
server.route({
|
|
800
|
+
method: "GET",
|
|
801
|
+
path: "/{param*}",
|
|
802
|
+
options: {
|
|
803
|
+
ext: {
|
|
804
|
+
onPreResponse: {
|
|
805
|
+
method: (req, h) => {
|
|
806
|
+
return h.continue;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
},
|
|
811
|
+
handler: {
|
|
812
|
+
directory: {
|
|
813
|
+
path: configs.staticDir,
|
|
814
|
+
listing: true
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
if (!isGenerate) {
|
|
819
|
+
const hmr = createHmr({
|
|
820
|
+
dirs: configs.hmr.dirs,
|
|
821
|
+
relativeTo: configs.relativeTo
|
|
822
|
+
});
|
|
823
|
+
hmr.hooks.hook("page:refresh", () => {
|
|
824
|
+
setTimeout(() => {
|
|
825
|
+
logger$1.info("Refresh page");
|
|
826
|
+
server.publish("/_flow/hmr", { reload: true });
|
|
827
|
+
}, 40);
|
|
828
|
+
});
|
|
829
|
+
server.subscription("/_flow/hmr");
|
|
830
|
+
server.route({
|
|
831
|
+
path: "/_flow/hmr/client.js",
|
|
832
|
+
method: "get",
|
|
833
|
+
handler: {
|
|
834
|
+
file: {
|
|
835
|
+
path: join(__dirname, "../resources/client"),
|
|
836
|
+
confine: false
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
server.route({
|
|
841
|
+
path: "/_flow/hmr/connect.js",
|
|
842
|
+
method: "get",
|
|
843
|
+
handler: {
|
|
844
|
+
file: {
|
|
845
|
+
path: join(__dirname, "../resources/ws.js"),
|
|
846
|
+
confine: false
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
logger$1.debug("Enable development routes");
|
|
851
|
+
server.route({
|
|
852
|
+
path: "/_flow/sitemap",
|
|
853
|
+
method: "get",
|
|
854
|
+
handler: async () => {
|
|
855
|
+
const { pages: getPages } = server.methods.flow;
|
|
856
|
+
const urls = await getPages();
|
|
857
|
+
const pages = Object.values(urls).map((p) => dissoc("context", p));
|
|
858
|
+
return {
|
|
859
|
+
total: pages.length,
|
|
860
|
+
pages
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
server.route({
|
|
865
|
+
path: "/_flow/locales",
|
|
866
|
+
method: "get",
|
|
867
|
+
handler: async (req) => {
|
|
868
|
+
const { pages: getPages } = server.methods.flow;
|
|
869
|
+
const urls = await getPages();
|
|
870
|
+
const pages = Object.values(urls).map((p) => dissoc("context", p));
|
|
871
|
+
const locales = groupBy((page) => page.locale, pages);
|
|
872
|
+
return {
|
|
873
|
+
locales: req.server.plugins.flow.configs.locales,
|
|
874
|
+
all: mapObjIndexed((l) => {
|
|
875
|
+
return {
|
|
876
|
+
total: l.length,
|
|
877
|
+
pages: l
|
|
878
|
+
};
|
|
879
|
+
}, locales)
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
});
|
|
883
|
+
server.route({
|
|
884
|
+
path: "/_flow/configs",
|
|
885
|
+
method: "get",
|
|
886
|
+
handler: (req) => {
|
|
887
|
+
return req.server.plugins.flow.configs;
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
const HMR = {
|
|
892
|
+
head: ' <script src="/_flow/hmr/client.js"><\/script>',
|
|
893
|
+
body: ' <script src="/_flow/hmr/connect.js"><\/script>'
|
|
894
|
+
};
|
|
895
|
+
server.ext("onPreHandler", async (req, h) => {
|
|
896
|
+
if (req.route.settings.plugins?.generate === ".html") {
|
|
897
|
+
const { global } = req.plugins.flow;
|
|
898
|
+
Object.assign(global, {
|
|
899
|
+
hmr: isProduction || isGenerate ? { head: "", body: "" } : HMR
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
return h.continue;
|
|
903
|
+
});
|
|
904
|
+
};
|
|
905
|
+
|
|
1176
906
|
const plugin = {
|
|
1177
907
|
pkg,
|
|
1178
908
|
dependencies,
|
|
@@ -1297,6 +1027,7 @@ const plugin = {
|
|
|
1297
1027
|
return baseOptions;
|
|
1298
1028
|
}
|
|
1299
1029
|
};
|
|
1030
|
+
await RegisterCommon(server, config);
|
|
1300
1031
|
}
|
|
1301
1032
|
};
|
|
1302
1033
|
|