@monkeyplus/flow 1.2.0 → 3.0.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.
@@ -0,0 +1,315 @@
1
+ "use strict";
2
+ // /* eslint-disable @typescript-eslint/no-var-requires */
3
+ // import { Lifecycle, Plugin, ServerRoute } from '@hapi/hapi';
4
+ // import { FULL_NAME_PLUGIN, DEPENDENCIES, FlowOptions } from './config';
5
+ // import {
6
+ // AppObject,
7
+ // RunDefinePage,
8
+ // Flow,
9
+ // FlowConfigs,
10
+ // OptionsHapiPage,
11
+ // OptionsInfo
12
+ // } from 'types';
13
+ // export { FlowOptions } from './config';
14
+ // import { PageInfo } from '@monkeyplus/flow-core';
15
+ // import * as R from 'ramda';
16
+ // export { definePage, defineSharedContext } from './lib';
17
+ // import { definePage } from './lib';
18
+ // export { defineImages, PageInfo } from '@monkeyplus/flow-core';
19
+ // import path from 'path';
20
+ // import { getConfigs } from './utils';
21
+ // import { registerGenerate } from './generate';
22
+ // const logger = require('consola').withScope('@monkeyplus/flow');
23
+ // export {
24
+ // AppObject,
25
+ // DefinePage,
26
+ // ResultPage,
27
+ // RunDefinePage,
28
+ // Flow,
29
+ // PreRunDefinePage,
30
+ // UrlPromise,
31
+ // RunContextHapi,
32
+ // CtxHapiBuildLocal,
33
+ // FlowConfigs
34
+ // } from 'types';
35
+ // export const plugin: Plugin<FlowOptions> = {
36
+ // pkg: require('../package.json'),
37
+ // name: FULL_NAME_PLUGIN,
38
+ // dependencies: DEPENDENCIES,
39
+ // register: async (server, options) => {
40
+ // const config = getConfigs(server, options.relativeTo);
41
+ // server.expose('configs', config);
42
+ // server.expose('getPath', (...paths: string[]) => {
43
+ // server.log(['warn'], 'This method is deprecated');
44
+ // return path.join(config.relativeTo, ...paths);
45
+ // });
46
+ // const locales = config.locales || ['es-ec'];
47
+ // const LOCALE = `${config.defaultLanguage}-${config.defaultUbication}`;
48
+ // server.app.flow = {
49
+ // images: {},
50
+ // locales,
51
+ // prevRoutes: new Map(),
52
+ // pages: new Map(),
53
+ // localePages: {},
54
+ // locale: LOCALE,
55
+ // domain: config.domain || 'http://localhost'
56
+ // };
57
+ // const logs = {
58
+ // pages: [] as string[],
59
+ // warns: [] as string[]
60
+ // };
61
+ // /**
62
+ // *
63
+ // */
64
+ // const inserPage = (pages: PageInfo[]) => {
65
+ // for (const page of pages) {
66
+ // if (server.app.flow.pages.has(page.name)) {
67
+ // // server.log(['warn', FULL_NAME_PLUGIN], {
68
+ // // error: 'insertPage',
69
+ // // message: `Duplicate name page, "${page.name}" already exists`,
70
+ // // details: page,
71
+ // // });
72
+ // // logger.error(
73
+ // // new Error(`Duplicate name page, "${page.name}" already exists`),
74
+ // // );
75
+ // // logs.warns.push(`Duplicate name page, "${page.name}" already exists`);
76
+ // } else {
77
+ // // server.log(['debug', FULL_NAME_PLUGIN], {
78
+ // // method: 'isertPage',
79
+ // // message: `Insert page`,
80
+ // // info: {
81
+ // // url: page.urlObject.path,
82
+ // // name: page.name,
83
+ // // locale: page.locale,
84
+ // // level: page.level,
85
+ // // },
86
+ // // });
87
+ // logs.pages.push(page.urlObject.path);
88
+ // server.app.flow.pages.set(page.name, page);
89
+ // server.app.flow.localePages = R.groupBy((f) => {
90
+ // return f.locale;
91
+ // }, Array.from(server.app.flow.pages.values()));
92
+ // }
93
+ // }
94
+ // };
95
+ // const addPage = async (_page: OptionsHapiPage | RunDefinePage) => {
96
+ // try {
97
+ // let page;
98
+ // if (typeof _page === 'function') {
99
+ // page = _page;
100
+ // } else {
101
+ // page = definePage(_page)();
102
+ // }
103
+ // const result = await page(
104
+ // server,
105
+ // {
106
+ // language: config.defaultLanguage,
107
+ // ubication: config.defaultUbication,
108
+ // publicPath: config.publicPath
109
+ // },
110
+ // locales,
111
+ // options.globals
112
+ // );
113
+ // // server.log(['debug', FULL_NAME_PLUGIN], {
114
+ // // method: 'addPage',
115
+ // // message: `Insert *${result.name}*`,
116
+ // // });
117
+ // const hasPage = server.app.flow.prevRoutes.has(result.name);
118
+ // if (hasPage) {
119
+ // // server.log(['warn', FULL_NAME_PLUGIN], {
120
+ // // error: 'addPage',
121
+ // // message: `The name of group pages '${result.name}' already exists`,
122
+ // // page: result,
123
+ // // });
124
+ // logger.warn(
125
+ // `The name of group pages '${result.name}' already exists`
126
+ // );
127
+ // } else {
128
+ // server.app.flow.prevRoutes.set(result.name, result);
129
+ // inserPage(result.pages);
130
+ // } // if(server.app.)
131
+ // } catch (details) {
132
+ // server.log(['error', FULL_NAME_PLUGIN], {
133
+ // error: 'addPage',
134
+ // message: 'Error addPage',
135
+ // details
136
+ // });
137
+ // }
138
+ // };
139
+ // const registerRoutes = (routes: ServerRoute[]) => {
140
+ // for (const route of routes) {
141
+ // const _routes = server.table();
142
+ // const _route = _routes.find((v) => v.path === route.path);
143
+ // if (_route) {
144
+ // logger.warn(
145
+ // `Duplicate route, the route ${route.path} already exists`
146
+ // );
147
+ // } else {
148
+ // if (route.path.includes('_context')) {
149
+ // server.route(route);
150
+ // } else {
151
+ // const r: ServerRoute = {
152
+ // ...route,
153
+ // options: R.hasPath(['options'], route)
154
+ // ? R.mergeDeepLeft(
155
+ // route.options as any,
156
+ // options.routeOptions || {}
157
+ // )
158
+ // : undefined
159
+ // };
160
+ // server.route(r);
161
+ // }
162
+ // }
163
+ // }
164
+ // };
165
+ // /**
166
+ // * Define info page to include in pages
167
+ // */
168
+ // const defineInfoPage = async (_opts: OptionsInfo) => {
169
+ // const info = await definePage({
170
+ // context: () => ({}),
171
+ // name: _opts.name,
172
+ // view: _opts.view ? _opts.view : { template: '' },
173
+ // locales: {
174
+ // [_opts.locale]: {
175
+ // url: _opts.path
176
+ // }
177
+ // }
178
+ // })()(
179
+ // server,
180
+ // {
181
+ // language: config.defaultLanguage,
182
+ // ubication: config.defaultUbication,
183
+ // publicPath: config.publicPath
184
+ // },
185
+ // locales,
186
+ // options.globals
187
+ // );
188
+ // const flow = info.pages[0];
189
+ // return {
190
+ // path: flow.urlObject.path,
191
+ // flow
192
+ // };
193
+ // };
194
+ // const visioHandler: Lifecycle.Method = (req, h) => {
195
+ // // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
196
+ // const { template } = req.route.settings.app!.flow!;
197
+ // return h.view(`${options.dirTemplates || ''}${template}`, {
198
+ // ...req.pre.context
199
+ // });
200
+ // };
201
+ // const init = async (proxy = false) => {
202
+ // const list = Array.from(server.app.flow.prevRoutes.values());
203
+ // const prePages = server
204
+ // .table()
205
+ // .filter((p) => p.settings.app?.flow)
206
+ // .map((p) => p.settings.app!.flow!);
207
+ // inserPage(prePages);
208
+ // for (const preRoute of list) {
209
+ // const routes = await preRoute.routes(
210
+ // {
211
+ // images: server.app.flow.images,
212
+ // globals: {},
213
+ // locale: '',
214
+ // name: '',
215
+ // shared: '',
216
+ // sharedLocale: '',
217
+ // originName: '',
218
+ // page: {} as any,
219
+ // defaultLocal: LOCALE,
220
+ // pages: server.app.flow.pages,
221
+ // server
222
+ // },
223
+ // visioHandler
224
+ // );
225
+ // if (proxy) {
226
+ // //
227
+ // const _r = routes
228
+ // .filter((route: any) => {
229
+ // if (route?.options?.plugins?.flow?.proxy) {
230
+ // return true;
231
+ // }
232
+ // return false;
233
+ // })
234
+ // .map<ServerRoute>((route) => {
235
+ // return {
236
+ // ...route,
237
+ // options: {
238
+ // ...route.options,
239
+ // pre: (route as any).options?.app?.pre || []
240
+ // },
241
+ // handler: {
242
+ // file: `${options.outputDir || 'build'}${route.path}.html`
243
+ // }
244
+ // };
245
+ // });
246
+ // const _redirects = _r.map<ServerRoute>((r) => {
247
+ // return {
248
+ // path: `${r.path}.html`,
249
+ // method: 'get',
250
+ // handler: (_, h) => h.redirect(r.path)
251
+ // };
252
+ // });
253
+ // const _routes = [..._r, ..._redirects];
254
+ // registerRoutes(_routes);
255
+ // } else {
256
+ // registerRoutes(routes);
257
+ // }
258
+ // }
259
+ // logger.info(`Flow ${logs.pages.length} pages registers`);
260
+ // // server.log(['info', FULL_NAME_PLUGIN], 'Init flow');
261
+ // };
262
+ // const flow = {
263
+ // init,
264
+ // addPage,
265
+ // defineInfoPage,
266
+ // getPath,
267
+ // runGenerate
268
+ // };
269
+ // server.decorate('server', 'flow', flow as any);
270
+ // // server.log(['debug', FULL_NAME_PLUGIN], { message: 'Registered plugin' });
271
+ // }
272
+ // };
273
+ // declare module '@hapi/hapi' {
274
+ // interface ServerApplicationState {
275
+ // flow: AppObject;
276
+ // }
277
+ // interface RouteOptionsApp {
278
+ // flow: PageInfo;
279
+ // }
280
+ // interface RequestApplicationState {
281
+ // local: any;
282
+ // global: any;
283
+ // }
284
+ // // interface ServerMethods {
285
+ // // addPage: (page: RunDefinePage | OptionsHapiPage) => Promise<void>;
286
+ // // }
287
+ // // interface PluginSpecificConfiguration {
288
+ // // flow: {
289
+ // // static?: {
290
+ // // ext: string;
291
+ // // };
292
+ // // };
293
+ // // }
294
+ // interface PluginSpecificConfiguration {
295
+ // flow?: {
296
+ // proxy?: boolean;
297
+ // };
298
+ // generate?:
299
+ // | boolean
300
+ // | {
301
+ // ext?: string;
302
+ // isAsset: boolean;
303
+ // };
304
+ // }
305
+ // interface Server {
306
+ // flow: Flow;
307
+ // }
308
+ // interface PluginProperties {
309
+ // flow: {
310
+ // configs: FlowConfigs;
311
+ // getPath: (...paths: string[]) => string;
312
+ // };
313
+ // }
314
+ // }
315
+ //# sourceMappingURL=index%20copy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index copy.js","sourceRoot":"","sources":["../src/index copy.ts"],"names":[],"mappings":";AAAA,0DAA0D;AAC1D,+DAA+D;AAC/D,0EAA0E;AAC1E,WAAW;AACX,eAAe;AACf,mBAAmB;AACnB,UAAU;AACV,iBAAiB;AACjB,qBAAqB;AACrB,gBAAgB;AAChB,kBAAkB;AAClB,0CAA0C;AAC1C,oDAAoD;AACpD,8BAA8B;AAC9B,2DAA2D;AAC3D,sCAAsC;AACtC,kEAAkE;AAClE,2BAA2B;AAC3B,wCAAwC;AACxC,iDAAiD;AAC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iC;AACjC,4EAA4E;AAC5E,SAAS;AACT,+CAA+C;AAC/C,iBAAiB;AACjB,sBAAsB;AACtB,0BAA0B;AAC1B,cAAc;AACd,YAAY;AACZ,SAAS;AACT,4CAA4C;AAC5C,eAAe;AACf,yBAAyB;AACzB,SAAS;AACT,iBAAiB;AACjB,kBAAkB;AAClB,YAAY;AACZ,0BAA0B;AAC1B,8BAA8B;AAC9B,aAAa;AACb,MAAM;AACN,uBAAuB;AACvB,kBAAkB;AAClB,MAAM;AACN,iCAAiC;AACjC,cAAc;AACd,8BAA8B;AAC9B,iDAAiD;AACjD,SAAS;AACT,MAAM;AACN,IAAI"}
package/dist/index.d.ts CHANGED
@@ -1,38 +1,43 @@
1
1
  import { Plugin } from '@hapi/hapi';
2
- import { FlowOptions } from "./config";
3
- import { AppObject, Flow, FlowConfigs } from "../types/index";
4
- export { FlowOptions } from "./config";
5
2
  import { PageInfo } from '@monkeyplus/flow-core';
6
- export { definePage, defineSharedContext } from "./lib/index";
7
- export { defineImages, PageInfo } from '@monkeyplus/flow-core';
8
- export { AppObject, DefinePage, ResultPage, RunDefinePage, Flow, PreRunDefinePage, UrlPromise, RunContextHapi, CtxHapiBuildLocal, FlowConfigs } from "../types/index";
3
+ import { Flow, FlowOptions, GenerateOptions, GenerateFolder } from "../types/index";
4
+ export { definePage } from "./pages";
5
+ export { DefinePage, RunDefinePage, OptionsHapiPage, RunPreDefinePage, FlowOptions, GenerateFolder } from "../types/index";
9
6
  export declare const plugin: Plugin<FlowOptions>;
10
7
  declare module '@hapi/hapi' {
11
8
  interface ServerApplicationState {
12
- flow: AppObject;
9
+ flow: Flow.AppState;
10
+ generate: {
11
+ folders: Record<string, GenerateFolder>;
12
+ };
13
13
  }
14
14
  interface RouteOptionsApp {
15
15
  flow: PageInfo;
16
+ content?: string;
17
+ }
18
+ interface HandlerDecorations {
19
+ flow?: Flow.HandlerOptions;
16
20
  }
17
21
  interface RequestApplicationState {
18
22
  local: any;
19
23
  global: any;
24
+ utils: any;
25
+ }
26
+ interface ResponseToolkit {
27
+ getUrl: (locale: string, name: string) => string;
20
28
  }
21
29
  interface PluginSpecificConfiguration {
22
30
  flow?: {
23
31
  proxy?: boolean;
24
32
  };
25
- generate?: boolean | {
26
- ext?: string;
27
- isAsset: boolean;
28
- };
33
+ generate?: GenerateOptions;
29
34
  }
30
35
  interface Server {
31
- flow: Flow;
36
+ flow: Flow.Decorate;
32
37
  }
33
38
  interface PluginProperties {
34
39
  flow: {
35
- configs: FlowConfigs;
40
+ configs: Flow.Configs;
36
41
  getPath: (...paths: string[]) => string;
37
42
  };
38
43
  }