@monkeyplus/flow 4.0.0-beta.19 → 4.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -10,9 +10,6 @@ const boom = require('@hapi/boom');
10
10
  const os = require('os');
11
11
  const chalk = require('chalk');
12
12
  const fs = require('fs-extra');
13
- const fs$1 = require('fs');
14
- const hookable = require('hookable');
15
- const chokidar = require('chokidar');
16
13
 
17
14
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
18
15
 
@@ -34,11 +31,9 @@ const R__namespace = /*#__PURE__*/_interopNamespace(R);
34
31
  const os__default = /*#__PURE__*/_interopDefaultLegacy(os);
35
32
  const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
36
33
  const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
37
- const fs__default$1 = /*#__PURE__*/_interopDefaultLegacy(fs$1);
38
- const chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
39
34
 
40
35
  const name = "@monkeyplus/flow";
41
- const version = "4.0.0-beta.19";
36
+ const version = "4.0.0-beta.3";
42
37
  const description = "Utils hapi";
43
38
  const author = "Andres Navarrete";
44
39
  const license = "MIT";
@@ -47,8 +42,7 @@ const module$1 = "./dist/index.mjs";
47
42
  const types = "./dist/index.d.ts";
48
43
  const files = [
49
44
  "dist/",
50
- "types/",
51
- "resources/"
45
+ "types/"
52
46
  ];
53
47
  const exports$1 = {
54
48
  ".": {
@@ -70,18 +64,14 @@ const scripts = {
70
64
  const dependencies$1 = {
71
65
  "@hapi/boom": "9.x.x",
72
66
  "@hapi/hoek": "9.x.x",
67
+ chalk: "^5.0.0",
73
68
  consola: "^2.15.3",
74
- chalk: "^4.1.2",
75
- chokidar: "^3.5.3",
76
- hookable: "^5.1.1",
77
69
  "fs-extra": "^10.0.0",
78
70
  ramda: "^0.28.0"
79
71
  };
80
72
  const devDependencies = {
81
73
  "@types/fs-extra": "^9.0.13",
82
74
  "@types/hapi__hapi": "^20.0.10",
83
- "@types/hapi__nes": "^11.0.5",
84
- "@types/hapi__vision": "^5.5.3",
85
75
  "@types/ramda": "^0.27.64"
86
76
  };
87
77
  const peerDependencies = {
@@ -108,13 +98,8 @@ const pkg = {
108
98
 
109
99
  const logger$1 = consola__default.withScope(pkg.name);
110
100
  const dependencies = {
111
- "@hapi/vision": "6.x.x",
112
- "@hapi/inert": "6.x.x",
113
- "@hapi/h2o2": "9.x.x",
114
- "@hapi/nes": "12.x.x"
101
+ "@hapi/vision": "6.x.x"
115
102
  };
116
- const isProduction = process.env.NODE_ENV === "production";
117
- const isGenerate = process.env.GENERATE;
118
103
 
119
104
  const LifeCircle = {
120
105
  register: (server) => {
@@ -328,7 +313,7 @@ const handlerPage = async (req, h) => {
328
313
  return context;
329
314
  }
330
315
  context.utils = utils;
331
- return h.view(`${configs.dirTemplates}${flow.view.layout || "default"}`, context);
316
+ return h.view(`${configs.dirTemplates}${flow.view.template}`, context);
332
317
  };
333
318
 
334
319
  const logger = consola__default.withScope("@monkeyplus/flow");
@@ -336,10 +321,6 @@ const defaults = {
336
321
  locales: ["es-ec"],
337
322
  defaultUbication: "ec",
338
323
  defaultLanguage: "es",
339
- staticDir: "static",
340
- hmr: {
341
- dirs: ["views"]
342
- },
343
324
  publicPath: "/",
344
325
  locale: "es-ec",
345
326
  relativeTo: "",
@@ -582,7 +563,7 @@ const useGenerator = {
582
563
  if (!virtualGenerate)
583
564
  injectAssets(_assets);
584
565
  const dirOutut = helpers.getPath(configs.outputDir ?? "build");
585
- const staticDirs = [configs.staticDir].map((dir) => helpers.getPath(dir));
566
+ const staticDirs = Object.keys(server.app.flow.generate.staticFolders).map((dir) => helpers.getPath(dir));
586
567
  const files = await getFlowPages();
587
568
  const pairFiles = R__namespace.toPairs(files);
588
569
  const ommit = ommitAssets;
@@ -711,47 +692,6 @@ const definePage = (pageOptions) => (levelOptions) => (configs) => {
711
692
  return routes;
712
693
  };
713
694
 
714
- const readPagesDir = (pathDir, folder) => {
715
- const p = fs__default$1.readdirSync(pathDir);
716
- return R.flatten(p.filter((f) => !f.includes(".js.map") && !f.includes(" copy.js.map") && !f.includes(" copy.js") && !f.includes(".model")).map((e) => {
717
- if (e.includes(".js") || e.includes(".ts")) {
718
- return {
719
- path: path__default.join(pathDir, e),
720
- prefix: folder
721
- };
722
- } else {
723
- return readPagesDir(path__default.join(pathDir, e), e);
724
- }
725
- }));
726
- };
727
- const registerPages = async (server, dir) => {
728
- const dirPages = path__default.resolve(dir || "./pages");
729
- const listFiles = readPagesDir(dirPages);
730
- const listPrePages = [];
731
- for (const item of listFiles) {
732
- try {
733
- const module = require(item.path)?.default;
734
- if (typeof module === "function") {
735
- listPrePages.push(module());
736
- } else if (typeof module === "object") {
737
- if (Array.isArray(module)) {
738
- module.forEach((el) => listPrePages.push(el()));
739
- } else {
740
- const _pages = await module.pages({ server });
741
- if (Array.isArray(_pages))
742
- _pages.forEach((page) => listPrePages.push(definePage(page)()));
743
- else
744
- listPrePages.push(definePage(_pages)());
745
- }
746
- }
747
- } catch (details) {
748
- logger$1.error(details);
749
- }
750
- }
751
- for (const page of listPrePages)
752
- await server.flow.addPage(page);
753
- };
754
-
755
695
  const RunMethods = {
756
696
  register: (server) => {
757
697
  const { flow: state } = server.app;
@@ -765,7 +705,7 @@ const RunMethods = {
765
705
  server.route(route);
766
706
  };
767
707
  const addPage = (_page, extra) => {
768
- const registerPages2 = (_pages2) => {
708
+ const registerPages = (_pages2) => {
769
709
  for (const _route of _pages2) {
770
710
  if (state.routes[_route.path])
771
711
  logger$1.warn("The route %s alredy exist", _route.path);
@@ -776,14 +716,13 @@ const RunMethods = {
776
716
  let _pages;
777
717
  if (typeof _page === "function") {
778
718
  _pages = _page(config);
779
- registerPages2(_pages);
719
+ registerPages(_pages);
780
720
  } else {
781
721
  _pages = definePage(_page)()(config);
782
- registerPages2(_pages);
722
+ registerPages(_pages);
783
723
  }
784
724
  };
785
725
  const init = async () => {
786
- await registerPages(server, config.pagesDir);
787
726
  const pages = server.app.flow.routes;
788
727
  for (const key in pages) {
789
728
  const page = pages[key];
@@ -800,137 +739,6 @@ const RunMethods = {
800
739
  }
801
740
  };
802
741
 
803
- const createHmr = (options) => {
804
- const state = {
805
- dir: options.relativeTo || "",
806
- dirs: options.dirs || [],
807
- extensions: options.extensions || ["eta"]
808
- };
809
- let watcher;
810
- const hooks = hookable.createHooks();
811
- const watch = () => {
812
- watcher = chokidar__default.watch(state.dirs.map((d) => path__default.join(d, `**/*.(${state.extensions.join("|")})`)), {
813
- cwd: state.dir,
814
- ignoreInitial: true,
815
- ignored: "node_modules/**/*"
816
- }).on("change", (path2) => {
817
- logger$1.info("Changed file", path2);
818
- hooks.callHook("page:refresh");
819
- });
820
- };
821
- watch();
822
- return { watcher, hooks };
823
- };
824
-
825
- const RegisterCommon = async (server, configs) => {
826
- server.route({
827
- method: "GET",
828
- path: "/{param*}",
829
- options: {
830
- ext: {
831
- onPreResponse: {
832
- method: (req, h) => {
833
- return h.continue;
834
- }
835
- }
836
- }
837
- },
838
- handler: {
839
- directory: {
840
- path: configs.staticDir,
841
- listing: true
842
- }
843
- }
844
- });
845
- if (!isGenerate) {
846
- const hmr = createHmr({
847
- dirs: configs.hmr.dirs,
848
- relativeTo: configs.relativeTo,
849
- extensions: configs.hmr.extensions
850
- });
851
- hmr.hooks.hook("page:refresh", () => {
852
- setTimeout(() => {
853
- logger$1.info("Refresh page");
854
- server.publish("/_flow/hmr", { reload: true });
855
- }, 40);
856
- });
857
- server.subscription("/_flow/hmr");
858
- server.route({
859
- path: "/_flow/hmr/client.js",
860
- method: "get",
861
- handler: {
862
- file: {
863
- path: path.join(__dirname, "../resources/client"),
864
- confine: false
865
- }
866
- }
867
- });
868
- server.route({
869
- path: "/_flow/hmr/connect.js",
870
- method: "get",
871
- handler: {
872
- file: {
873
- path: path.join(__dirname, "../resources/ws.js"),
874
- confine: false
875
- }
876
- }
877
- });
878
- logger$1.debug("Enable development routes");
879
- server.route({
880
- path: "/_flow/sitemap",
881
- method: "get",
882
- handler: async () => {
883
- const { pages: getPages } = server.methods.flow;
884
- const urls = await getPages();
885
- const pages = Object.values(urls).map((p) => R.dissoc("context", p));
886
- return {
887
- total: pages.length,
888
- pages
889
- };
890
- }
891
- });
892
- server.route({
893
- path: "/_flow/locales",
894
- method: "get",
895
- handler: async (req) => {
896
- const { pages: getPages } = server.methods.flow;
897
- const urls = await getPages();
898
- const pages = Object.values(urls).map((p) => R.dissoc("context", p));
899
- const locales = R.groupBy((page) => page.locale, pages);
900
- return {
901
- locales: req.server.plugins.flow.configs.locales,
902
- all: R.mapObjIndexed((l) => {
903
- return {
904
- total: l.length,
905
- pages: l
906
- };
907
- }, locales)
908
- };
909
- }
910
- });
911
- server.route({
912
- path: "/_flow/configs",
913
- method: "get",
914
- handler: (req) => {
915
- return req.server.plugins.flow.configs;
916
- }
917
- });
918
- }
919
- const HMR = {
920
- head: ' <script src="/_flow/hmr/client.js"><\/script>',
921
- body: ' <script src="/_flow/hmr/connect.js"><\/script>'
922
- };
923
- server.ext("onPreHandler", async (req, h) => {
924
- if (req.route.settings.plugins?.generate === ".html") {
925
- const { global } = req.plugins.flow;
926
- Object.assign(global, {
927
- hmr: isProduction || isGenerate ? { head: "", body: "" } : HMR
928
- });
929
- }
930
- return h.continue;
931
- });
932
- };
933
-
934
742
  const plugin = {
935
743
  pkg,
936
744
  dependencies,
@@ -1055,7 +863,6 @@ const plugin = {
1055
863
  return baseOptions;
1056
864
  }
1057
865
  };
1058
- await RegisterCommon(server, config);
1059
866
  }
1060
867
  };
1061
868
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Server, Plugin } from '@hapi/hapi';
1
+ import { Plugin } from '@hapi/hapi';
2
2
  import { PageInfo } from '../types/core';
3
3
  import { OptionsHapiPage, RunPreDefinePage, Flow, FlowExtensions, OptionDynamicLocalePages, GenerateOptions, FlowServerMethods, FlowOptions } from '../types';
4
4
  export { ContextHandler, Contexts, Extension, Flow, FlowContextPage, FlowContextSeo, FlowContextView, FlowEngines, FlowExtensions, FlowOptionPlugins, FlowOptions, FlowPluginExtension, FlowPluginGlobal, FlowPluginLocal, FlowPluginUtils, FlowServerMethods, FlowStatePlugins, GenerateFolder, OptionDynamicLocalePages, OptionsDynamicPages, OptionsHapiPage, RunDefinePage, RunPreDefinePage } from '../types';
@@ -6,14 +6,7 @@ export { ContextHandler, Contexts, Extension, Flow, FlowContextPage, FlowContext
6
6
  declare type DefinePage = (page: OptionsHapiPage) => RunPreDefinePage;
7
7
  declare const definePage: DefinePage;
8
8
 
9
- declare type HapiPages = OptionsHapiPage | OptionsHapiPage[];
10
- interface Context {
11
- server: Server;
12
- }
13
- declare type Pages = (ctx: Context) => Promise<HapiPages>;
14
-
15
9
  declare const plugin: Plugin<FlowOptions>;
16
-
17
10
  declare module '@hapi/hapi' {
18
11
  interface ServerApplicationState {
19
12
  flow: Flow.AppState;
@@ -61,4 +54,4 @@ declare module '@hapi/hapi' {
61
54
  }
62
55
  }
63
56
 
64
- export { Pages, definePage, plugin };
57
+ export { definePage, plugin };
package/dist/index.mjs CHANGED
@@ -1,18 +1,14 @@
1
- import path, { join } from 'path';
1
+ import path 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';
6
5
  import { notFound } from '@hapi/boom';
7
6
  import os from 'os';
8
7
  import chalk from 'chalk';
9
8
  import fs from 'fs-extra';
10
- import fs$1 from 'fs';
11
- import { createHooks } from 'hookable';
12
- import chokidar from 'chokidar';
13
9
 
14
10
  const name = "@monkeyplus/flow";
15
- const version = "4.0.0-beta.19";
11
+ const version = "4.0.0-beta.3";
16
12
  const description = "Utils hapi";
17
13
  const author = "Andres Navarrete";
18
14
  const license = "MIT";
@@ -21,8 +17,7 @@ const module = "./dist/index.mjs";
21
17
  const types = "./dist/index.d.ts";
22
18
  const files = [
23
19
  "dist/",
24
- "types/",
25
- "resources/"
20
+ "types/"
26
21
  ];
27
22
  const exports = {
28
23
  ".": {
@@ -44,18 +39,14 @@ const scripts = {
44
39
  const dependencies$1 = {
45
40
  "@hapi/boom": "9.x.x",
46
41
  "@hapi/hoek": "9.x.x",
42
+ chalk: "^5.0.0",
47
43
  consola: "^2.15.3",
48
- chalk: "^4.1.2",
49
- chokidar: "^3.5.3",
50
- hookable: "^5.1.1",
51
44
  "fs-extra": "^10.0.0",
52
45
  ramda: "^0.28.0"
53
46
  };
54
47
  const devDependencies = {
55
48
  "@types/fs-extra": "^9.0.13",
56
49
  "@types/hapi__hapi": "^20.0.10",
57
- "@types/hapi__nes": "^11.0.5",
58
- "@types/hapi__vision": "^5.5.3",
59
50
  "@types/ramda": "^0.27.64"
60
51
  };
61
52
  const peerDependencies = {
@@ -82,13 +73,8 @@ const pkg = {
82
73
 
83
74
  const logger$1 = consola.withScope(pkg.name);
84
75
  const dependencies = {
85
- "@hapi/vision": "6.x.x",
86
- "@hapi/inert": "6.x.x",
87
- "@hapi/h2o2": "9.x.x",
88
- "@hapi/nes": "12.x.x"
76
+ "@hapi/vision": "6.x.x"
89
77
  };
90
- const isProduction = process.env.NODE_ENV === "production";
91
- const isGenerate = process.env.GENERATE;
92
78
 
93
79
  const LifeCircle = {
94
80
  register: (server) => {
@@ -302,7 +288,7 @@ const handlerPage = async (req, h) => {
302
288
  return context;
303
289
  }
304
290
  context.utils = utils;
305
- return h.view(`${configs.dirTemplates}${flow.view.layout || "default"}`, context);
291
+ return h.view(`${configs.dirTemplates}${flow.view.template}`, context);
306
292
  };
307
293
 
308
294
  const logger = consola.withScope("@monkeyplus/flow");
@@ -310,10 +296,6 @@ const defaults = {
310
296
  locales: ["es-ec"],
311
297
  defaultUbication: "ec",
312
298
  defaultLanguage: "es",
313
- staticDir: "static",
314
- hmr: {
315
- dirs: ["views"]
316
- },
317
299
  publicPath: "/",
318
300
  locale: "es-ec",
319
301
  relativeTo: "",
@@ -556,7 +538,7 @@ const useGenerator = {
556
538
  if (!virtualGenerate)
557
539
  injectAssets(_assets);
558
540
  const dirOutut = helpers.getPath(configs.outputDir ?? "build");
559
- const staticDirs = [configs.staticDir].map((dir) => helpers.getPath(dir));
541
+ const staticDirs = Object.keys(server.app.flow.generate.staticFolders).map((dir) => helpers.getPath(dir));
560
542
  const files = await getFlowPages();
561
543
  const pairFiles = R.toPairs(files);
562
544
  const ommit = ommitAssets;
@@ -685,47 +667,6 @@ const definePage = (pageOptions) => (levelOptions) => (configs) => {
685
667
  return routes;
686
668
  };
687
669
 
688
- const readPagesDir = (pathDir, folder) => {
689
- const p = fs$1.readdirSync(pathDir);
690
- return flatten(p.filter((f) => !f.includes(".js.map") && !f.includes(" copy.js.map") && !f.includes(" copy.js") && !f.includes(".model")).map((e) => {
691
- if (e.includes(".js") || e.includes(".ts")) {
692
- return {
693
- path: path.join(pathDir, e),
694
- prefix: folder
695
- };
696
- } else {
697
- return readPagesDir(path.join(pathDir, e), e);
698
- }
699
- }));
700
- };
701
- const registerPages = async (server, dir) => {
702
- const dirPages = path.resolve(dir || "./pages");
703
- const listFiles = readPagesDir(dirPages);
704
- const listPrePages = [];
705
- for (const item of listFiles) {
706
- try {
707
- const module = require(item.path)?.default;
708
- if (typeof module === "function") {
709
- listPrePages.push(module());
710
- } else if (typeof module === "object") {
711
- if (Array.isArray(module)) {
712
- module.forEach((el) => listPrePages.push(el()));
713
- } else {
714
- const _pages = await module.pages({ server });
715
- if (Array.isArray(_pages))
716
- _pages.forEach((page) => listPrePages.push(definePage(page)()));
717
- else
718
- listPrePages.push(definePage(_pages)());
719
- }
720
- }
721
- } catch (details) {
722
- logger$1.error(details);
723
- }
724
- }
725
- for (const page of listPrePages)
726
- await server.flow.addPage(page);
727
- };
728
-
729
670
  const RunMethods = {
730
671
  register: (server) => {
731
672
  const { flow: state } = server.app;
@@ -739,7 +680,7 @@ const RunMethods = {
739
680
  server.route(route);
740
681
  };
741
682
  const addPage = (_page, extra) => {
742
- const registerPages2 = (_pages2) => {
683
+ const registerPages = (_pages2) => {
743
684
  for (const _route of _pages2) {
744
685
  if (state.routes[_route.path])
745
686
  logger$1.warn("The route %s alredy exist", _route.path);
@@ -750,14 +691,13 @@ const RunMethods = {
750
691
  let _pages;
751
692
  if (typeof _page === "function") {
752
693
  _pages = _page(config);
753
- registerPages2(_pages);
694
+ registerPages(_pages);
754
695
  } else {
755
696
  _pages = definePage(_page)()(config);
756
- registerPages2(_pages);
697
+ registerPages(_pages);
757
698
  }
758
699
  };
759
700
  const init = async () => {
760
- await registerPages(server, config.pagesDir);
761
701
  const pages = server.app.flow.routes;
762
702
  for (const key in pages) {
763
703
  const page = pages[key];
@@ -774,137 +714,6 @@ const RunMethods = {
774
714
  }
775
715
  };
776
716
 
777
- const createHmr = (options) => {
778
- const state = {
779
- dir: options.relativeTo || "",
780
- dirs: options.dirs || [],
781
- extensions: options.extensions || ["eta"]
782
- };
783
- let watcher;
784
- const hooks = createHooks();
785
- const watch = () => {
786
- watcher = chokidar.watch(state.dirs.map((d) => path.join(d, `**/*.(${state.extensions.join("|")})`)), {
787
- cwd: state.dir,
788
- ignoreInitial: true,
789
- ignored: "node_modules/**/*"
790
- }).on("change", (path2) => {
791
- logger$1.info("Changed file", path2);
792
- hooks.callHook("page:refresh");
793
- });
794
- };
795
- watch();
796
- return { watcher, hooks };
797
- };
798
-
799
- const RegisterCommon = async (server, configs) => {
800
- server.route({
801
- method: "GET",
802
- path: "/{param*}",
803
- options: {
804
- ext: {
805
- onPreResponse: {
806
- method: (req, h) => {
807
- return h.continue;
808
- }
809
- }
810
- }
811
- },
812
- handler: {
813
- directory: {
814
- path: configs.staticDir,
815
- listing: true
816
- }
817
- }
818
- });
819
- if (!isGenerate) {
820
- const hmr = createHmr({
821
- dirs: configs.hmr.dirs,
822
- relativeTo: configs.relativeTo,
823
- extensions: configs.hmr.extensions
824
- });
825
- hmr.hooks.hook("page:refresh", () => {
826
- setTimeout(() => {
827
- logger$1.info("Refresh page");
828
- server.publish("/_flow/hmr", { reload: true });
829
- }, 40);
830
- });
831
- server.subscription("/_flow/hmr");
832
- server.route({
833
- path: "/_flow/hmr/client.js",
834
- method: "get",
835
- handler: {
836
- file: {
837
- path: join(__dirname, "../resources/client"),
838
- confine: false
839
- }
840
- }
841
- });
842
- server.route({
843
- path: "/_flow/hmr/connect.js",
844
- method: "get",
845
- handler: {
846
- file: {
847
- path: join(__dirname, "../resources/ws.js"),
848
- confine: false
849
- }
850
- }
851
- });
852
- logger$1.debug("Enable development routes");
853
- server.route({
854
- path: "/_flow/sitemap",
855
- method: "get",
856
- handler: async () => {
857
- const { pages: getPages } = server.methods.flow;
858
- const urls = await getPages();
859
- const pages = Object.values(urls).map((p) => dissoc("context", p));
860
- return {
861
- total: pages.length,
862
- pages
863
- };
864
- }
865
- });
866
- server.route({
867
- path: "/_flow/locales",
868
- method: "get",
869
- handler: async (req) => {
870
- const { pages: getPages } = server.methods.flow;
871
- const urls = await getPages();
872
- const pages = Object.values(urls).map((p) => dissoc("context", p));
873
- const locales = groupBy((page) => page.locale, pages);
874
- return {
875
- locales: req.server.plugins.flow.configs.locales,
876
- all: mapObjIndexed((l) => {
877
- return {
878
- total: l.length,
879
- pages: l
880
- };
881
- }, locales)
882
- };
883
- }
884
- });
885
- server.route({
886
- path: "/_flow/configs",
887
- method: "get",
888
- handler: (req) => {
889
- return req.server.plugins.flow.configs;
890
- }
891
- });
892
- }
893
- const HMR = {
894
- head: ' <script src="/_flow/hmr/client.js"><\/script>',
895
- body: ' <script src="/_flow/hmr/connect.js"><\/script>'
896
- };
897
- server.ext("onPreHandler", async (req, h) => {
898
- if (req.route.settings.plugins?.generate === ".html") {
899
- const { global } = req.plugins.flow;
900
- Object.assign(global, {
901
- hmr: isProduction || isGenerate ? { head: "", body: "" } : HMR
902
- });
903
- }
904
- return h.continue;
905
- });
906
- };
907
-
908
717
  const plugin = {
909
718
  pkg,
910
719
  dependencies,
@@ -1029,7 +838,6 @@ const plugin = {
1029
838
  return baseOptions;
1030
839
  }
1031
840
  };
1032
- await RegisterCommon(server, config);
1033
841
  }
1034
842
  };
1035
843
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "4.0.0-beta.19",
3
+ "version": "4.0.0-beta.3",
4
4
  "description": "Utils hapi",
5
5
  "author": "Andres Navarrete",
6
6
  "license": "MIT",
@@ -9,8 +9,7 @@
9
9
  "types": "./dist/index.d.ts",
10
10
  "files": [
11
11
  "dist/",
12
- "types/",
13
- "resources/"
12
+ "types/"
14
13
  ],
15
14
  "exports": {
16
15
  ".": {
@@ -21,18 +20,14 @@
21
20
  "dependencies": {
22
21
  "@hapi/boom": "9.x.x",
23
22
  "@hapi/hoek": "9.x.x",
23
+ "chalk": "^5.0.0",
24
24
  "consola": "^2.15.3",
25
- "chalk": "^4.1.2",
26
- "chokidar": "^3.5.3",
27
- "hookable": "^5.1.1",
28
25
  "fs-extra": "^10.0.0",
29
26
  "ramda": "^0.28.0"
30
27
  },
31
28
  "devDependencies": {
32
29
  "@types/fs-extra": "^9.0.13",
33
30
  "@types/hapi__hapi": "^20.0.10",
34
- "@types/hapi__nes": "^11.0.5",
35
- "@types/hapi__vision": "^5.5.3",
36
31
  "@types/ramda": "^0.27.64"
37
32
  },
38
33
  "peerDependencies": {
package/types/flow.d.ts CHANGED
@@ -33,12 +33,6 @@ export interface FlowOptions {
33
33
  routeOptions?: RouteOptions
34
34
  dirTemplates?: string
35
35
  plugins: FlowOptionPlugins
36
- staticDir: string
37
- pagesDir?: string
38
- hmr: {
39
- dirs: string[]
40
- extensions?: string[]
41
- }
42
36
  engines?: ('eta' | 'nunjucks')[]
43
37
  }
44
38
 
package/resources/client DELETED
@@ -1 +0,0 @@
1
- 'use strict';var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a};(function(a,b){'object'===('undefined'==typeof exports?'undefined':_typeof(exports))&&'object'===('undefined'==typeof module?'undefined':_typeof(module))?module.exports=b():'function'==typeof define&&define.amd?define(b):'object'===('undefined'==typeof exports?'undefined':_typeof(exports))?exports.nes=b():a.nes=b()})('undefined'==typeof window?global:window,function(){var a=function(){},b=function(a){try{return JSON.stringify(a)}catch(a){throw new e(a,d.USER)}},c=function(a){return function(b){setTimeout(function(){return a(b)},0)}},d={TIMEOUT:'timeout',DISCONNECT:'disconnect',SERVER:'server',PROTOCOL:'protocol',WS:'ws',USER:'user'},e=function(a,b){'string'==typeof a&&(a=new Error(a)),a.type=b,a.isNes=!0;try{throw a}catch(a){return a}},f={1000:'Normal closure',1001:'Going away',1002:'Protocol error',1003:'Unsupported data',1004:'Reserved',1005:'No status received',1006:'Abnormal closure',1007:'Invalid frame payload data',1008:'Policy violation',1009:'Message too big',1010:'Mandatory extension',1011:'Internal server error',1015:'TLS handshake'},g=function(b,c){c=c||{},this._isBrowser='undefined'!=typeof WebSocket,this._isBrowser||(c.ws=c.ws||{},void 0===c.ws.maxPayload&&(c.ws.maxPayload=0)),this._url=b,this._settings=c,this._heartbeatTimeout=!1,this._ws=null,this._reconnection=null,this._reconnectionTimer=null,this._ids=0,this._requests={},this._subscriptions={},this._heartbeat=null,this._packets=[],this._disconnectListeners=null,this._disconnectRequested=!1,this.onError=function(a){return console.error(a)},this.onConnect=a,this.onDisconnect=a,this.onHeartbeatTimeout=a,this.onUpdate=a,this.id=null};return g.WebSocket='undefined'==typeof WebSocket?null:WebSocket,g.prototype.connect=function(a){var b=this;return(a=a||{},this._reconnection)?Promise.reject(new e('Cannot connect while client attempts to reconnect',d.USER)):this._ws?Promise.reject(new e('Already connected',d.USER)):(this._reconnection=!1===a.reconnect?null:{wait:0,delay:a.delay||1e3,maxDelay:a.maxDelay||5e3,retries:a.retries||Infinity,settings:{auth:a.auth,timeout:a.timeout}},new Promise(function(c,d){b._connect(a,!0,function(a){return a?d(a):c()})}))},g.prototype._connect=function(a,b,h){var i=this,j=this._isBrowser?new g.WebSocket(this._url):new g.WebSocket(this._url,this._settings.ws);this._ws=j,clearTimeout(this._reconnectionTimer),this._reconnectionTimer=null;var k=function(a){j.onopen&&l(new e('Connection terminated while waiting to connect',d.WS));var b=i._disconnectRequested;i._cleanup();var c={code:a.code,explanation:f[a.code]||'Unknown',reason:a.reason,wasClean:a.wasClean,willReconnect:i._willReconnect(),wasRequested:b};i.onDisconnect(c.willReconnect,c),i._reconnect()},l=function(a){if(h){var b=h;return h=null,b(a)}return i.onError(a)},m=a.timeout?setTimeout(function timeoutHandler(){if(i._cleanup(),l(new e('Connection timed out',d.TIMEOUT)),b)return i._reconnect()},a.timeout):null;j.onopen=function(){clearTimeout(m),j.onopen=null,i._hello(a.auth).then(function(){i.onConnect(),l()}).catch(function(a){a.path&&delete i._subscriptions[a.path],i._disconnect(function(){return c(l)(a)},!0)})},j.onerror=function(a){if(clearTimeout(m),i._willReconnect())return k(a);i._cleanup();var b=new e('Socket error',d.WS);return l(b)},j.onclose=k,j.onmessage=function(a){return i._onMessage(a)}},g.prototype.overrideReconnectionAuth=function(a){return!!this._reconnection&&(this._reconnection.settings.auth=a,!0)},g.prototype.reauthenticate=function(a){this.overrideReconnectionAuth(a);return this._send({type:'reauth',auth:a},!0)},g.prototype.disconnect=function(){var a=this;return new Promise(function(b){return a._disconnect(b,!1)})},g.prototype._disconnect=function(a,b){this._reconnection=null,clearTimeout(this._reconnectionTimer),this._reconnectionTimer=null;var c=this._disconnectRequested||!b;return this._disconnectListeners?(this._disconnectRequested=c,void this._disconnectListeners.push(a)):this._ws&&(this._ws.readyState===g.WebSocket.OPEN||this._ws.readyState===g.WebSocket.CONNECTING)?void(this._disconnectRequested=c,this._disconnectListeners=[a],this._ws.close()):a()},g.prototype._cleanup=function(){if(this._ws){var k=this._ws;this._ws=null,k.readyState!==g.WebSocket.CLOSED&&k.readyState!==g.WebSocket.CLOSING&&k.close(),k.onopen=null,k.onclose=null,k.onerror=a,k.onmessage=null}this._packets=[],this.id=null,clearTimeout(this._heartbeat),this._heartbeat=null;var b=new e('Request failed - server disconnected',d.DISCONNECT),c=this._requests;this._requests={};for(var f=Object.keys(c),h=0;h<f.length;++h){var i=f[h],j=c[i];clearTimeout(j.timeout),j.reject(b)}if(this._disconnectListeners){var l=this._disconnectListeners;this._disconnectListeners=null,this._disconnectRequested=!1,l.forEach(function(a){return a()})}},g.prototype._reconnect=function(){var b=this,c=this._reconnection;if(c){if(1>c.retries)return this._disconnect(a,!0);--c.retries,c.wait+=c.delay;var d=Math.min(c.wait,c.maxDelay);this._reconnectionTimer=setTimeout(function(){b._connect(c.settings,!1,function(a){if(a)return b.onError(a),b._reconnect()})},d)}},g.prototype.request=function(a){'string'==typeof a&&(a={method:'GET',path:a});var b={type:'request',method:a.method||'GET',path:a.path,headers:a.headers,payload:a.payload};return this._send(b,!0)},g.prototype.message=function(a){return this._send({type:'message',message:a},!0)},g.prototype._isReady=function(){return this._ws&&this._ws.readyState===g.WebSocket.OPEN},g.prototype._send=function(a,c){if(!this._isReady())return Promise.reject(new e('Failed to send message - server disconnected',d.DISCONNECT));a.id=++this._ids;try{var f=b(a)}catch(a){return Promise.reject(a)}if(!c)try{return this._ws.send(f),Promise.resolve()}catch(a){return Promise.reject(new e(a,d.WS))}var g={resolve:null,reject:null,timeout:null},h=new Promise(function(a,b){g.resolve=a,g.reject=b});this._settings.timeout&&(g.timeout=setTimeout(function(){return g.timeout=null,g.reject(new e('Request timed out',d.TIMEOUT))},this._settings.timeout)),this._requests[a.id]=g;try{this._ws.send(f)}catch(b){return clearTimeout(this._requests[a.id].timeout),delete this._requests[a.id],Promise.reject(new e(b,d.WS))}return h},g.prototype._hello=function(a){var b={type:'hello',version:'2'};a&&(b.auth=a);var c=this.subscriptions();return c.length&&(b.subs=c),this._send(b,!0)},g.prototype.subscriptions=function(){return Object.keys(this._subscriptions)},g.prototype.subscribe=function(a,b){var c=this;if(!a||'/'!==a[0])return Promise.reject(new e('Invalid path',d.USER));var f=this._subscriptions[a];if(f)return-1===f.indexOf(b)&&f.push(b),Promise.resolve();if(this._subscriptions[a]=[b],!this._isReady())return Promise.resolve();var g=this._send({type:'sub',path:a},!0);return g.catch(function(){delete c._subscriptions[a]}),g},g.prototype.unsubscribe=function(b,c){if(!b||'/'!==b[0])return Promise.reject(new e('Invalid path',d.USER));var f=this._subscriptions[b];if(!f)return Promise.resolve();var g=!1;if(!c)delete this._subscriptions[b],g=!0;else{var i=f.indexOf(c);if(-1===i)return Promise.resolve();f.splice(i,1),f.length||(delete this._subscriptions[b],g=!0)}if(!g||!this._isReady())return Promise.resolve();var h=this._send({type:'unsub',path:b},!0);return h.catch(a),h},g.prototype._onMessage=function(b){this._beat();var c=b.data,f=c[0];if('{'!==f){if(this._packets.push(c.slice(1)),'!'!==f)return;c=this._packets.join(''),this._packets=[]}this._packets.length&&(this._packets=[],this.onError(new e('Received an incomplete message',d.PROTOCOL)));try{var g=JSON.parse(c)}catch(a){return this.onError(new e(a,d.PROTOCOL))}var h=null;if(g.statusCode&&400<=g.statusCode&&(h=new e(g.payload.message||g.payload.error||'Error',d.SERVER),h.statusCode=g.statusCode,h.data=g.payload,h.headers=g.headers,h.path=g.path),'ping'===g.type)return this._send({type:'ping'},!1).catch(a);if('update'===g.type)return this.onUpdate(g.message);if('pub'===g.type||'revoke'===g.type){var l=this._subscriptions[g.path];if('revoke'===g.type&&delete this._subscriptions[g.path],l&&void 0!==g.message){var m={};'revoke'===g.type&&(m.revoked=!0);for(var n=0;n<l.length;++n)l[n](g.message,m)}return}var j=this._requests[g.id];if(!j)return this.onError(new e('Received response for unknown request',d.PROTOCOL));clearTimeout(j.timeout),delete this._requests[g.id];var k=function(a,b){return a?j.reject(a):j.resolve(b)};return'request'===g.type?k(h,{payload:g.payload,statusCode:g.statusCode,headers:g.headers}):'message'===g.type?k(h,{payload:g.message}):'hello'===g.type?(this.id=g.socket,g.heartbeat&&(this._heartbeatTimeout=g.heartbeat.interval+g.heartbeat.timeout,this._beat()),k(h)):'reauth'===g.type?k(h,!0):'sub'===g.type||'unsub'===g.type?k(h):(k(new e('Received invalid response',d.PROTOCOL)),this.onError(new e('Received unknown response type: '+g.type,d.PROTOCOL)))},g.prototype._beat=function(){var a=this;this._heartbeatTimeout&&(clearTimeout(this._heartbeat),this._heartbeat=setTimeout(function(){a.onError(new e('Disconnecting due to heartbeat timeout',d.TIMEOUT)),a.onHeartbeatTimeout(a._willReconnect()),a._ws.close()},this._heartbeatTimeout))},g.prototype._willReconnect=function(){return!!(this._reconnection&&1<=this._reconnection.retries)},{Client:g}});
package/resources/ws.js DELETED
@@ -1,15 +0,0 @@
1
- /* eslint-disable no-undef */
2
- const client = new nes.Client("ws://" + location.host, {
3
- timeout: 5000,
4
- });
5
- console.log("[flow] connecting...");
6
- const start = async () => {
7
- await client.connect({ delay: 5000 });
8
- console.log("[flow] connected.");
9
- const handler = (update, flags) => {
10
- location.reload();
11
- };
12
- client.subscribe("/_flow/hmr", handler);
13
- };
14
-
15
- start();