@monkeyplus/flow 1.2.0 → 3.0.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/pages.js ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.definePage = void 0;
23
+ const flow_core_1 = require("@monkeyplus/flow-core");
24
+ const R = __importStar(require("ramda"));
25
+ const definePage = (pageOptions) => (levelOptions) => (configs) => {
26
+ //
27
+ const pages = [];
28
+ for (const locale in pageOptions.locales) {
29
+ if (configs.locales.find((_locale) => _locale === locale)) {
30
+ const singlePage = pageOptions.locales[locale];
31
+ pages.push({ url: singlePage.url, locale });
32
+ }
33
+ }
34
+ // R.mapObjIndexed((singlePage, locale) => {
35
+ // return { [locale]: singlePage.u };
36
+ // }, page.locales);
37
+ const infoPages = flow_core_1.definePages({
38
+ name: pageOptions.name,
39
+ view: pageOptions.view,
40
+ context: pageOptions.context,
41
+ level: pageOptions.level,
42
+ locales: pageOptions.locales
43
+ })({
44
+ language: configs.defaultLanguage,
45
+ ubication: configs.defaultUbication,
46
+ publicPath: configs.publicPath
47
+ })(levelOptions).pages(pages);
48
+ const { options: sharedOptions, rules: sharedRules, vhost: sharedVHost } = pageOptions;
49
+ // const = options || {};
50
+ const sharedPre = (sharedOptions === null || sharedOptions === void 0 ? void 0 : sharedOptions.pre) || [];
51
+ const routes = infoPages.map((page) => {
52
+ var _a;
53
+ const localPage = pageOptions.locales[page.locale];
54
+ const route = {
55
+ path: page.urlObject.path,
56
+ method: 'get',
57
+ options: {
58
+ app: {
59
+ // ...extensions,
60
+ flow: page
61
+ },
62
+ plugins: {
63
+ flow: {
64
+ extensions: pageOptions.extensions || {}
65
+ }
66
+ }
67
+ },
68
+ handler: {
69
+ flow: {
70
+ name: page.name,
71
+ locale: page.locale,
72
+ view: { template: page.template, bundle: page.bundle }
73
+ }
74
+ }
75
+ };
76
+ if (sharedRules || localPage.rules) {
77
+ route.rules = localPage.rules || sharedRules;
78
+ }
79
+ if (sharedVHost || localPage.vhost) {
80
+ route.vhost = localPage.vhost || sharedVHost;
81
+ }
82
+ if (sharedOptions || localPage.options) {
83
+ //
84
+ const localOptions = (localPage === null || localPage === void 0 ? void 0 : localPage.options) || {};
85
+ const localPre = ((_a = localPage === null || localPage === void 0 ? void 0 : localPage.options) === null || _a === void 0 ? void 0 : _a.pre) || [];
86
+ const pre = [...sharedPre, ...localPre];
87
+ const options = R.mergeDeepRight(sharedOptions || {}, localOptions);
88
+ route.options = R.mergeDeepRight(options, route.options);
89
+ if (route.options && pre.length) {
90
+ route.options.pre = pre;
91
+ }
92
+ }
93
+ return route;
94
+ });
95
+ return routes;
96
+ };
97
+ exports.definePage = definePage;
98
+ // definePages({
99
+ // name: 'test',
100
+ // view:
101
+ // })
102
+ //# sourceMappingURL=pages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pages.js","sourceRoot":"","sources":["../src/pages.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,qDAAgE;AAChE,yCAA2B;AAKpB,MAAM,UAAU,GAAe,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nB,YAAY,CACG,CAAC;YAElB,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,OAAQ,CAAiB,CAAC;YAC1E,IAAI,KAAK,CAAC,OAAO,IAAI,GAAG,CAAC,MAAM,EAAE;gBAC/B,KAAK,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;aACzB;SACF;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAzFW,QAAA,UAAU,cAyFrB;AAEF,gBAAgB;AAChB,gBAAgB;AAChB,QAAQ;AACR,KAAK"}
@@ -1,3 +1,4 @@
1
1
  import { Server } from '@hapi/hapi';
2
- import { FlowConfigs } from "../../types/index";
3
- export declare function getConfigs(server: Server, _relativeTo: string): FlowConfigs;
2
+ import { Flow, FlowOptions } from "../../types/index";
3
+ export declare const logger: import("consola").Consola;
4
+ export declare function getConfigs(server: Server, options: FlowOptions): Flow.Configs;
@@ -3,17 +3,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConfigs = void 0;
6
+ exports.getConfigs = exports.logger = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
- function getConfigs(server, _relativeTo) {
8
+ const consola_1 = __importDefault(require("consola"));
9
+ exports.logger = consola_1.default.withScope('@monkeyplus/flow');
10
+ const hoek_1 = require("@hapi/hoek");
11
+ const defaults = {
12
+ locales: ['es-ec'],
13
+ defaultUbication: 'ec',
14
+ defaultLanguage: 'es',
15
+ publicPath: '/',
16
+ locale: 'es-ec',
17
+ relativeTo: '',
18
+ dirTemplates: '',
19
+ outputDir: 'build',
20
+ url: process.env.URL
21
+ };
22
+ function getConfigs(server, options) {
23
+ const relativeTo = path_1.default.resolve(options.relativeTo);
24
+ const getObject = (object) => {
25
+ const config = hoek_1.applyToDefaults(defaults, { ...object, ...options });
26
+ return {
27
+ ...config,
28
+ relativeTo,
29
+ locale: `${config.defaultLanguage}-${config.defaultUbication}`
30
+ };
31
+ };
9
32
  try {
10
- const pathWeb = path_1.default.resolve(_relativeTo, 'flow.config');
11
- const relativeTo = path_1.default.resolve(_relativeTo);
12
- return { ...require(pathWeb), relativeTo };
33
+ const pathWeb = path_1.default.resolve(options.relativeTo, 'flow.config');
34
+ exports.logger.info('Flow apply settings from file: flow.config');
35
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
36
+ const configBase = require(pathWeb);
37
+ const config = getObject(configBase);
38
+ return config;
13
39
  }
14
40
  catch (error) {
15
- server.log(['error'], error);
16
- return {};
41
+ // server.log(['error'], error);
42
+ exports.logger.info('Flow no config file apply default settings');
43
+ return getObject({});
17
44
  }
18
45
  }
19
46
  exports.getConfigs = getConfigs;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAEA,gDAAwB;AAExB,SAAgB,UAAU,CAAC,MAAc,EAAE,WAAmB;IAC5D,IAAI;QACF,MAAM,OAAO,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QACzD,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAE7C,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;KAC5C;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;QAC7B,OAAO,EAAS,CAAC;KAClB;AACH,CAAC;AAVD,gCAUC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;AAEA,gDAAwB;AACxB,sDAA8B;AACjB,QAAA,MAAM,GAAG,iBAAO,CAAC,SAAS,CAAC,kB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@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "1.2.0",
3
+ "version": "3.0.3",
4
4
  "description": "Utils hapi",
5
5
  "author": "Andres Navarrete",
6
6
  "license": "MIT",
@@ -11,18 +11,20 @@
11
11
  "types/"
12
12
  ],
13
13
  "scripts": {
14
- "build": "ttsc -p tsconfig.build.json",
14
+ "build:ts": "ttsc -p tsconfig.build.json",
15
15
  "watch": "ttsc -p tsconfig.build.json -w",
16
16
  "test": "jest",
17
- "prepare": "yarn build"
17
+ "prepare": "yarn build:ts"
18
18
  },
19
19
  "devDependencies": {
20
- "@types/ramda": "^0.27.14"
20
+ "@types/fs-extra": "^9.0.8",
21
+ "@types/ramda": "^0.27.38"
21
22
  },
22
23
  "dependencies": {
23
- "@monkeyplus/flow-core": "^2.0.7",
24
+ "@monkeyplus/flow-core": "^3.0.3",
24
25
  "consola": "^2.15.2",
26
+ "fs-extra": "^9.1.0",
25
27
  "ramda": "^0.27.1"
26
28
  },
27
- "gitHead": "264f9730da965d9faa0899f3a6c22bd0e7a73cdb"
29
+ "gitHead": "917c281fd6e0c0b3253a9206f41846a46a76938a"
28
30
  }
@@ -0,0 +1,164 @@
1
+ import {
2
+ OptionsPage,
3
+ OptionsLocalPage,
4
+ BlogInfo,
5
+ LevelOptions,
6
+ PageInfo
7
+ } from '@monkeyplus/flow-core';
8
+ import {
9
+ RouteOptions,
10
+ ServerRoute,
11
+ Request,
12
+ ResponseToolkit,
13
+ RequestRoute
14
+ } from '@hapi/hapi';
15
+ import {
16
+ FlowPluginExtension,
17
+ FlowPluginGlobal,
18
+ FlowPluginLocal,
19
+ FlowPluginUtils,
20
+ FlowExtensions
21
+ } from './interfaces';
22
+
23
+ export interface FlowOptions {
24
+ relativeTo: string;
25
+ outputDir?: string;
26
+ routeOptions?: RouteOptions;
27
+ dirTemplates?: string;
28
+ }
29
+
30
+ export interface GenerateFolder {
31
+ prefix: string;
32
+ relativeTo: string;
33
+ dirs: string[];
34
+ override?: Record<string, string>;
35
+ type?: string;
36
+ }
37
+ export namespace Extension {
38
+ export interface RouteContext {
39
+ pageInfo: PageInfo;
40
+ route: RequestRoute;
41
+ }
42
+ export type RouteMethod<T = any> = (
43
+ context: RouteContext,
44
+ options: T
45
+ ) => void;
46
+ export interface InitContext {
47
+ helpers: Flow.Helpers;
48
+ }
49
+ export type InitMethod = (context: InitContext) => Promise<void>;
50
+ export interface Extension {
51
+ state: any;
52
+ initMethod?: InitMethod;
53
+ routeMethod?: RouteMethod;
54
+ }
55
+ }
56
+ export namespace Flow {
57
+ interface Url {
58
+ url: string;
59
+ locale: string;
60
+ name: string;
61
+ originalName: string;
62
+ }
63
+ export type Urls = Record<string, Url>;
64
+ export type Pages = Record<string, ServerRoute>;
65
+ export type Redirects = Record<string, string>;
66
+ export type Truncates = Record<string, string>;
67
+ export type DynamicContent = Record<string, { path: string; page: PageInfo }>;
68
+ export type DynamicPages = Record<string, string[]>;
69
+
70
+ export interface PluginState {
71
+ local: FlowPluginLocal;
72
+ global: FlowPluginGlobal;
73
+ utils: FlowPluginUtils;
74
+ extensions: FlowPluginExtension;
75
+ }
76
+ export interface Helpers {
77
+ addRedirect: (key: string, urlPath: string) => void;
78
+ addUrl: (key: string, url: Url) => undefined;
79
+ }
80
+ export interface AppState {
81
+ redirects: Redirects;
82
+ urls: Urls;
83
+ pages: Pages;
84
+ truncates: Truncates;
85
+ extensions: Record<string, Extension.Extension>;
86
+ dynamicPages: DynamicPages;
87
+ generate: {
88
+ folders: Record<string, GenerateFolder>;
89
+ };
90
+ }
91
+ export interface Configs extends FlowOptions {
92
+ relativeTo: string;
93
+ locales: string[];
94
+ defaultUbication: string;
95
+ defaultLanguage: string;
96
+ publicPath: string;
97
+ locale: string;
98
+ url: string;
99
+ // redirects: {};
100
+ }
101
+ export interface GenerateOptions {
102
+ assets?: GenerateFolder[];
103
+ ommitAssets?: string[];
104
+ }
105
+
106
+ export interface Decorate {
107
+ init: (proxy?: boolean) => Promise<void>;
108
+ addPage: (page: RunDefinePage | OptionsHapiPage) => Promise<void>;
109
+ getPath: (...path: string[]) => string;
110
+ runGenerate: (options?: GenerateOptions) => Promise<void>;
111
+ }
112
+ export interface HandlerOptions {
113
+ name: string;
114
+ locale?: string;
115
+ view: {
116
+ template: string;
117
+ bundle?: string;
118
+ };
119
+ context?: RunContextHapi;
120
+ content?: string;
121
+ }
122
+ }
123
+
124
+ export interface OptionsHapiLocalPage extends OptionsLocalPage {
125
+ url: string;
126
+ blogInfo?: BlogInfo;
127
+ options?: RouteOptions;
128
+ rules?: Record<string, unknown>;
129
+ context?: RunContextHapi;
130
+ vhost?: string | string[];
131
+ }
132
+ interface Context {
133
+ req: Request;
134
+ h: ResponseToolkit;
135
+ page: {
136
+ level: string;
137
+ name: string;
138
+ locale: string;
139
+ template: string;
140
+ bundle: string;
141
+ publicPath: string;
142
+ path: string;
143
+ };
144
+ /**
145
+ * Si la genoracion de paginas es dinamica este es el contenido
146
+ */
147
+ global: FlowPluginGlobal;
148
+ extensions: FlowPluginExtension;
149
+ utils: FlowPluginUtils;
150
+ }
151
+
152
+ export type RunContextHapi = (ctx: Context) => Promise<any>;
153
+
154
+ export interface OptionsHapiPage extends OptionsPage {
155
+ options?: RouteOptions;
156
+ context?: RunContextHapi;
157
+ locales: Record<string, OptionsHapiLocalPage>;
158
+ rules?: Record<string, unknown>;
159
+ vhost?: string | string[];
160
+ extensions?: FlowExtensions;
161
+ }
162
+ // import {} from '..'
163
+ export type RunDefinePage = (configs: Flow.Configs) => ServerRoute[];
164
+ export type RunPreDefinePage = (level?: LevelOptions) => RunDefinePage;
package/types/index.d.ts CHANGED
@@ -1,176 +1,26 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import {
3
- PageInfo,
4
- OptionsPage,
5
- OptionsLocalPage,
6
- CtxBuildLocal,
7
- CtxBuildGlobal,
8
- RunContext,
9
- DictionaryImagesSeo,
10
- ExtraOptions,
11
- BlogInfo,
12
- LocalesUrl
13
- } from '@monkeyplus/flow-core';
14
- import { Dictionary } from 'ramda';
15
- import { Lifecycle, RouteOptions, Server, ServerRoute } from '@hapi/hapi';
16
- import { Options } from 'prettier';
17
- export interface AppObject {
18
- images: DictionaryImagesSeo;
19
- // defaultUbication: string;
20
- // defaultLanguage: string;
21
- // publicPath: string;
22
- domain: string;
23
- locale: string;
24
- locales: string[];
25
- pages: Map<string, PageInfo>;
26
- // routes: Dictionary<any>;
27
- localePages: Dictionary<any>;
28
- // globalData: Dictionary<any>;
29
- // pathImages: string;
30
- // pathAssets: string;
31
- // // robots: {
32
- // // dissallowPaths?: string[];
33
- // // allowPaths?: string[];
34
- // // };
35
- prevRoutes: Map<string, ResultPage>;
36
- }
37
2
 
38
- export interface OptionsHapiLocalPage extends OptionsLocalPage {
39
- url: string;
40
- blogInfo?: BlogInfo;
41
- routeOptions?: RouteOptions;
42
- rules?: Record<string, unknown>;
43
- context?: RunContextHapi;
44
-
45
- vhost?: string | string[];
46
- }
47
- export interface CtxHapiBuildLocal extends CtxBuildLocal {
48
- server: Server;
49
- isStatic?: boolean;
50
- shared: any;
51
- sharedLocale: any;
52
- page: PageInfo;
53
- }
54
- export interface CtxHapiBuilGlobal extends CtxBuildGlobal {
55
- server: Server;
56
- isStatic?: boolean;
57
- }
58
-
59
- export type RunContextHapi<CTX = any> = RunContext<CtxHapiBuildLocal, CTX>;
60
- export interface OptionsHapiPage extends OptionsPage {
61
- routeOptions?: RouteOptions;
62
- context: RunContextHapi;
63
- locales: Dictionary<OptionsHapiLocalPage>;
64
- rules?: Record<string, unknown>;
65
- vhost?: string | string[];
66
- }
67
-
68
- /**
69
- *
70
- */
71
- interface DefaultLocale {
72
- language: string;
73
- ubication: string;
74
- publicPath?: string;
75
- }
76
- export interface ResultPage {
77
- name: string;
78
- routes: (
79
- ctx: CtxHapiBuildLocal,
80
- handler: Lifecycle.Method
81
- ) => Promise<ServerRoute[]>;
82
- pages: PageInfo[];
83
- }
84
-
85
- export type RunDefinePage = (
86
- server: Server,
87
- defs: DefaultLocale,
88
- locales: string[],
89
- runGlobal?: RunDefineGlobalContext
90
- ) => Promise<ResultPage>;
91
-
92
- export type PreRunDefinePage<T = RunDefinePage> = (
93
- extOpts?: ExtraOptions,
94
- prefixName?: string
95
- ) => T;
96
- export type DefinePage = (options: OptionsHapiPage) => PreRunDefinePage;
97
-
98
- export interface ResultPage2 {
99
- name: string;
100
- options: OptionsHapiPage;
101
- pages: PageInfo[];
102
- }
103
-
104
- export type RunDefinePage2 = (
105
- server: Server,
106
- defs: DefaultLocale,
107
- locales: string[]
108
- ) => Promise<ResultPage2>;
109
-
110
- export type DefinePage2 = (
111
- options: OptionsHapiPage
112
- ) => PreRunDefinePage<RunDefinePage2>;
3
+ export {
4
+ Flow,
5
+ FlowOptions,
6
+ RunDefinePage,
7
+ RunPreDefinePage,
8
+ OptionsHapiPage,
9
+ GenerateFolder,
10
+ Extension
11
+ } from './flow';
12
+ export {
13
+ FlowExtensions,
14
+ FlowPluginExtension,
15
+ FlowPluginUtils,
16
+ FlowPluginGlobal,
17
+ FlowPluginLocal
18
+ } from './interfaces';
19
+ export type GenerateOptions =
20
+ | boolean
21
+ | string
22
+ | { isAsset: boolean; file: string; type?: string; isRemane?: boolean };
113
23
 
114
24
  /**
115
- *
25
+ * Extension method
116
26
  */
117
- export interface OptionsInfo {
118
- locale: string;
119
- name: string;
120
- path: string;
121
- view?: {
122
- template: string;
123
- bundle?: string;
124
- };
125
- }
126
- export interface Flow {
127
- init: (proxy?: boolean) => Promise<void>;
128
- addPage: (page: RunDefinePage | OptionsHapiPage) => Promise<void>;
129
- defineInfoPage: (
130
- options: OptionsInfo
131
- ) => Promise<{ path: string; flow: PageInfo }>;
132
- getPath: (...path: string[]) => string;
133
- runGenerate: () => Promise<void>;
134
- }
135
-
136
- export type GetUrl = (
137
- server: Server,
138
- options: R.Dictionary<OptionsHapiLocalPage>,
139
- def: string
140
- ) => (locale: string) => Promise<LocalesUrl>;
141
- export type UrlPromise = (
142
- locale: string,
143
- name: string
144
- ) => Promise<{ url: string; seo: any; [key: string]: any }>;
145
- /**
146
- *
147
- */
148
- export type RunDefineGlobalContext = (ctx: CtxHapiBuildLocal) => Promise<any>;
149
- export type DefineGlobalContext = (options: {
150
- shared: RunContextHapi;
151
- locales?: Dictionary<RunContextHapi>;
152
- }) => RunDefineGlobalContext;
153
-
154
- export interface FlowConfigs {
155
- relativeTo: string;
156
- locales: string[];
157
- defaultUbication: string;
158
- defaultLanguage: string;
159
- domain: string;
160
- publicPath: string;
161
- sourceImagesDir: string;
162
- dictionaryImages: string;
163
- assetsDir: string;
164
- assetsImagesDir: string;
165
- sourceRename: string;
166
- images: {
167
- sources: string;
168
- dirJsons: string;
169
- };
170
- server: {
171
- watch: number;
172
- dev: number;
173
- };
174
- vue: Record<string, string>;
175
- // redirects: {};
176
- }
@@ -0,0 +1,16 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
+ export interface FlowExtensions {}
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
4
+ export interface FlowPluginExtension {}
5
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
6
+ export interface FlowPluginUtils {}
7
+
8
+ export interface FlowPluginUtils {
9
+ getLocalUrl: (name: string) => string;
10
+ getUrl: (locale: string, name: string) => string;
11
+ }
12
+
13
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
14
+ export interface FlowPluginLocal {}
15
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
16
+ export interface FlowPluginGlobal {}
@@ -1,3 +0,0 @@
1
- import { DefineGlobalContext } from "../../types/index";
2
- export { definePage } from "./pages/index";
3
- export declare const defineSharedContext: DefineGlobalContext;
package/dist/lib/index.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineSharedContext = exports.definePage = void 0;
4
- var pages_1 = require("./pages/index");
5
- Object.defineProperty(exports, "definePage", { enumerable: true, get: function () { return pages_1.definePage; } });
6
- const defineSharedContext = (options) => async (ctx) => {
7
- const SHARED = await options.shared({ ...ctx });
8
- const locales = options.locales || {};
9
- const obj = {};
10
- for (const key in locales) {
11
- obj[key.toUpperCase().replace('-', '_')] = await locales[key]({
12
- ...ctx,
13
- locale: key,
14
- });
15
- }
16
- return {
17
- ...obj,
18
- SHARED_LOCALE: obj[ctx.locale.toUpperCase().replace('-', '_')],
19
- $_: obj[ctx.locale.toUpperCase().replace('-', '_')],
20
- SHARED,
21
- $: SHARED,
22
- };
23
- };
24
- exports.defineSharedContext = defineSharedContext;
25
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;AACA,uCAAqC;AAA5B,mGAAA,UAAU,OAAA;AAEZ,MAAM,mBAAmB,GAAwB,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,EACxE,GAAG,EACH,EAAE;IACF,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;IACtC,MAAM,GAAG,GAAQ,EAAE,CAAC;IACpB,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;QACzB,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5D,GAAG,GAAG;YACN,MAAM,EAAE,GAAG;SACZ,CAAC,CAAC;KACJ;IACD,OAAO;QACL,GAAG,GAAG;QACN,aAAa,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC9D,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACnD,MAAM;QACN,CAAC,EAAE,MAAM;KACV,CAAC;AACJ,CAAC,CAAC;AAnBW,QAAA,mBAAmB,uBAmB9B"}
@@ -1,2 +0,0 @@
1
- import { DefinePage } from "../../../types/index";
2
- export declare const definePage: DefinePage;