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

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.2";
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
  ".": {
@@ -64,24 +58,21 @@ const scripts = {
64
58
  lint: "eslint --ext .js,.ts .",
65
59
  fix: "eslint --fix --ext .ts .",
66
60
  prepublishOnly: "pnpm run build",
61
+ publish: "pnpm publish",
67
62
  start: "esno src/index.ts",
68
63
  test: "vitest"
69
64
  };
70
65
  const dependencies$1 = {
71
66
  "@hapi/boom": "9.x.x",
72
67
  "@hapi/hoek": "9.x.x",
68
+ chalk: "^5.0.0",
73
69
  consola: "^2.15.3",
74
- chalk: "^4.1.2",
75
- chokidar: "^3.5.3",
76
- hookable: "^5.1.1",
77
70
  "fs-extra": "^10.0.0",
78
71
  ramda: "^0.28.0"
79
72
  };
80
73
  const devDependencies = {
81
74
  "@types/fs-extra": "^9.0.13",
82
75
  "@types/hapi__hapi": "^20.0.10",
83
- "@types/hapi__nes": "^11.0.5",
84
- "@types/hapi__vision": "^5.5.3",
85
76
  "@types/ramda": "^0.27.64"
86
77
  };
87
78
  const peerDependencies = {
@@ -108,13 +99,8 @@ const pkg = {
108
99
 
109
100
  const logger$1 = consola__default.withScope(pkg.name);
110
101
  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"
102
+ "@hapi/vision": "6.x.x"
115
103
  };
116
- const isProduction = process.env.NODE_ENV === "production";
117
- const isGenerate = process.env.GENERATE;
118
104
 
119
105
  const LifeCircle = {
120
106
  register: (server) => {
@@ -328,7 +314,7 @@ const handlerPage = async (req, h) => {
328
314
  return context;
329
315
  }
330
316
  context.utils = utils;
331
- return h.view(`${configs.dirTemplates}${flow.view.layout || "default"}`, context);
317
+ return h.view(`${configs.dirTemplates}${flow.view.template}`, context);
332
318
  };
333
319
 
334
320
  const logger = consola__default.withScope("@monkeyplus/flow");
@@ -336,10 +322,6 @@ const defaults = {
336
322
  locales: ["es-ec"],
337
323
  defaultUbication: "ec",
338
324
  defaultLanguage: "es",
339
- staticDir: "static",
340
- hmr: {
341
- dirs: ["views"]
342
- },
343
325
  publicPath: "/",
344
326
  locale: "es-ec",
345
327
  relativeTo: "",
@@ -582,7 +564,7 @@ const useGenerator = {
582
564
  if (!virtualGenerate)
583
565
  injectAssets(_assets);
584
566
  const dirOutut = helpers.getPath(configs.outputDir ?? "build");
585
- const staticDirs = [configs.staticDir].map((dir) => helpers.getPath(dir));
567
+ const staticDirs = Object.keys(server.app.flow.generate.staticFolders).map((dir) => helpers.getPath(dir));
586
568
  const files = await getFlowPages();
587
569
  const pairFiles = R__namespace.toPairs(files);
588
570
  const ommit = ommitAssets;
@@ -711,47 +693,6 @@ const definePage = (pageOptions) => (levelOptions) => (configs) => {
711
693
  return routes;
712
694
  };
713
695
 
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
696
  const RunMethods = {
756
697
  register: (server) => {
757
698
  const { flow: state } = server.app;
@@ -765,7 +706,7 @@ const RunMethods = {
765
706
  server.route(route);
766
707
  };
767
708
  const addPage = (_page, extra) => {
768
- const registerPages2 = (_pages2) => {
709
+ const registerPages = (_pages2) => {
769
710
  for (const _route of _pages2) {
770
711
  if (state.routes[_route.path])
771
712
  logger$1.warn("The route %s alredy exist", _route.path);
@@ -776,14 +717,13 @@ const RunMethods = {
776
717
  let _pages;
777
718
  if (typeof _page === "function") {
778
719
  _pages = _page(config);
779
- registerPages2(_pages);
720
+ registerPages(_pages);
780
721
  } else {
781
722
  _pages = definePage(_page)()(config);
782
- registerPages2(_pages);
723
+ registerPages(_pages);
783
724
  }
784
725
  };
785
726
  const init = async () => {
786
- await registerPages(server, config.pagesDir);
787
727
  const pages = server.app.flow.routes;
788
728
  for (const key in pages) {
789
729
  const page = pages[key];
@@ -800,137 +740,6 @@ const RunMethods = {
800
740
  }
801
741
  };
802
742
 
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
743
  const plugin = {
935
744
  pkg,
936
745
  dependencies,
@@ -1055,7 +864,6 @@ const plugin = {
1055
864
  return baseOptions;
1056
865
  }
1057
866
  };
1058
- await RegisterCommon(server, config);
1059
867
  }
1060
868
  };
1061
869
 
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.2";
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
  ".": {
@@ -38,24 +33,21 @@ const scripts = {
38
33
  lint: "eslint --ext .js,.ts .",
39
34
  fix: "eslint --fix --ext .ts .",
40
35
  prepublishOnly: "pnpm run build",
36
+ publish: "pnpm publish",
41
37
  start: "esno src/index.ts",
42
38
  test: "vitest"
43
39
  };
44
40
  const dependencies$1 = {
45
41
  "@hapi/boom": "9.x.x",
46
42
  "@hapi/hoek": "9.x.x",
43
+ chalk: "^5.0.0",
47
44
  consola: "^2.15.3",
48
- chalk: "^4.1.2",
49
- chokidar: "^3.5.3",
50
- hookable: "^5.1.1",
51
45
  "fs-extra": "^10.0.0",
52
46
  ramda: "^0.28.0"
53
47
  };
54
48
  const devDependencies = {
55
49
  "@types/fs-extra": "^9.0.13",
56
50
  "@types/hapi__hapi": "^20.0.10",
57
- "@types/hapi__nes": "^11.0.5",
58
- "@types/hapi__vision": "^5.5.3",
59
51
  "@types/ramda": "^0.27.64"
60
52
  };
61
53
  const peerDependencies = {
@@ -82,13 +74,8 @@ const pkg = {
82
74
 
83
75
  const logger$1 = consola.withScope(pkg.name);
84
76
  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"
77
+ "@hapi/vision": "6.x.x"
89
78
  };
90
- const isProduction = process.env.NODE_ENV === "production";
91
- const isGenerate = process.env.GENERATE;
92
79
 
93
80
  const LifeCircle = {
94
81
  register: (server) => {
@@ -302,7 +289,7 @@ const handlerPage = async (req, h) => {
302
289
  return context;
303
290
  }
304
291
  context.utils = utils;
305
- return h.view(`${configs.dirTemplates}${flow.view.layout || "default"}`, context);
292
+ return h.view(`${configs.dirTemplates}${flow.view.template}`, context);
306
293
  };
307
294
 
308
295
  const logger = consola.withScope("@monkeyplus/flow");
@@ -310,10 +297,6 @@ const defaults = {
310
297
  locales: ["es-ec"],
311
298
  defaultUbication: "ec",
312
299
  defaultLanguage: "es",
313
- staticDir: "static",
314
- hmr: {
315
- dirs: ["views"]
316
- },
317
300
  publicPath: "/",
318
301
  locale: "es-ec",
319
302
  relativeTo: "",
@@ -556,7 +539,7 @@ const useGenerator = {
556
539
  if (!virtualGenerate)
557
540
  injectAssets(_assets);
558
541
  const dirOutut = helpers.getPath(configs.outputDir ?? "build");
559
- const staticDirs = [configs.staticDir].map((dir) => helpers.getPath(dir));
542
+ const staticDirs = Object.keys(server.app.flow.generate.staticFolders).map((dir) => helpers.getPath(dir));
560
543
  const files = await getFlowPages();
561
544
  const pairFiles = R.toPairs(files);
562
545
  const ommit = ommitAssets;
@@ -685,47 +668,6 @@ const definePage = (pageOptions) => (levelOptions) => (configs) => {
685
668
  return routes;
686
669
  };
687
670
 
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
671
  const RunMethods = {
730
672
  register: (server) => {
731
673
  const { flow: state } = server.app;
@@ -739,7 +681,7 @@ const RunMethods = {
739
681
  server.route(route);
740
682
  };
741
683
  const addPage = (_page, extra) => {
742
- const registerPages2 = (_pages2) => {
684
+ const registerPages = (_pages2) => {
743
685
  for (const _route of _pages2) {
744
686
  if (state.routes[_route.path])
745
687
  logger$1.warn("The route %s alredy exist", _route.path);
@@ -750,14 +692,13 @@ const RunMethods = {
750
692
  let _pages;
751
693
  if (typeof _page === "function") {
752
694
  _pages = _page(config);
753
- registerPages2(_pages);
695
+ registerPages(_pages);
754
696
  } else {
755
697
  _pages = definePage(_page)()(config);
756
- registerPages2(_pages);
698
+ registerPages(_pages);
757
699
  }
758
700
  };
759
701
  const init = async () => {
760
- await registerPages(server, config.pagesDir);
761
702
  const pages = server.app.flow.routes;
762
703
  for (const key in pages) {
763
704
  const page = pages[key];
@@ -774,137 +715,6 @@ const RunMethods = {
774
715
  }
775
716
  };
776
717
 
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
718
  const plugin = {
909
719
  pkg,
910
720
  dependencies,
@@ -1029,7 +839,6 @@ const plugin = {
1029
839
  return baseOptions;
1030
840
  }
1031
841
  };
1032
- await RegisterCommon(server, config);
1033
842
  }
1034
843
  };
1035
844
 
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.2",
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();