@monkeyplus/flow 4.0.0-beta.9 → 5.0.0-beta.10
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/app.d.ts +1 -0
- package/bin/flow.mjs +2 -0
- package/build.config.ts +25 -0
- package/dist/app/composables/index.d.ts +4 -0
- package/dist/app/composables/index.mjs +12 -0
- package/dist/app/entry.d.ts +3 -0
- package/dist/app/entry.mjs +23 -0
- package/dist/app/flow.d.ts +73 -0
- package/dist/app/flow.mjs +85 -0
- package/dist/app/index.d.ts +3 -0
- package/dist/app/index.mjs +3 -0
- package/dist/core/runtime/nitro/flow.d.ts +3 -0
- package/dist/core/runtime/nitro/flow.mjs +32 -0
- package/dist/core/runtime/nitro/paths.d.ts +4 -0
- package/dist/core/runtime/nitro/paths.mjs +15 -0
- package/dist/core/runtime/nitro/renderer.d.ts +2 -0
- package/dist/core/runtime/nitro/renderer.mjs +59 -0
- package/dist/head/runtime/composables.d.ts +9 -0
- package/dist/head/runtime/composables.mjs +2 -0
- package/dist/head/runtime/index.d.ts +1 -0
- package/dist/head/runtime/index.mjs +1 -0
- package/dist/head/runtime/plugin.d.ts +2 -0
- package/dist/head/runtime/plugin.mjs +6 -0
- package/dist/index.d.ts +8 -61
- package/dist/index.mjs +1286 -954
- package/dist/pages/runtime/helpers/chunks.d.ts +0 -0
- package/dist/pages/runtime/helpers/chunks.mjs +0 -0
- package/dist/pages/runtime/helpers/index.d.ts +5 -0
- package/dist/pages/runtime/helpers/index.mjs +28 -0
- package/dist/pages/runtime/plugin.d.ts +2 -0
- package/dist/pages/runtime/plugin.mjs +51 -0
- package/dist/vite-client/runtime/injectManifest.d.ts +26 -0
- package/dist/vite-client/runtime/injectManifest.mjs +104 -0
- package/dist/vite-client/runtime/plugin.d.ts +2 -0
- package/dist/vite-client/runtime/plugin.mjs +27 -0
- package/package.json +54 -36
- package/src/app/composables/index.ts +20 -0
- package/src/app/entry.ts +36 -0
- package/src/app/flow.ts +157 -0
- package/src/app/index.ts +5 -0
- package/src/auto-imports/module.ts +143 -0
- package/src/auto-imports/presets.ts +49 -0
- package/src/auto-imports/transform.ts +48 -0
- package/src/core/app.ts +90 -0
- package/src/core/builder.ts +60 -0
- package/src/core/flow.ts +93 -0
- package/src/core/modules.ts +32 -0
- package/src/core/nitro.ts +206 -0
- package/src/core/plugins/import-protection.ts +49 -0
- package/src/core/plugins/unctx.ts +31 -0
- package/src/core/runtime/nitro/flow.ts +43 -0
- package/src/core/runtime/nitro/paths.ts +20 -0
- package/src/core/runtime/nitro/renderer.ts +74 -0
- package/src/core/templates.ts +119 -0
- package/src/core/vite/builder/css.ts +28 -0
- package/src/core/vite/builder/dev-bundler.ts +248 -0
- package/src/core/vite/builder/index.ts +96 -0
- package/src/core/vite/builder/manifest.ts +33 -0
- package/src/core/vite/builder/plugins/analyze.ts +32 -0
- package/src/core/vite/builder/plugins/cache-dir.ts +13 -0
- package/src/core/vite/builder/plugins/dynamic-base.ts +64 -0
- package/src/core/vite/builder/plugins/virtual.ts +45 -0
- package/src/core/vite/builder/server.ts +164 -0
- package/src/core/vite/builder/types/index.ts +13 -0
- package/src/core/vite/builder/utils/index.ts +53 -0
- package/src/core/vite/builder/utils/warmup.ts +27 -0
- package/src/core/vite/builder/utils/wpfs.ts +7 -0
- package/src/core/vite/builder/vite-node.ts +110 -0
- package/src/core/vite/client/index.ts +55 -0
- package/src/dirs.ts +8 -0
- package/src/head/module.ts +37 -0
- package/src/head/runtime/composables.ts +16 -0
- package/src/head/runtime/index.ts +1 -0
- package/src/head/runtime/plugin.ts +12 -0
- package/src/index.ts +2 -0
- package/src/pages/module.ts +55 -0
- package/src/pages/runtime/helpers/chunks.ts +0 -0
- package/src/pages/runtime/helpers/index.ts +33 -0
- package/src/pages/runtime/plugin.ts +58 -0
- package/src/pages/templates.ts +20 -0
- package/src/pages/utils.ts +49 -0
- package/src/vite-client/module.ts +81 -0
- package/src/vite-client/runtime/injectManifest.ts +188 -0
- package/src/vite-client/runtime/plugin.ts +33 -0
- package/types.d.ts +2 -0
- package/dist/index.cjs +0 -1061
- package/types/core.d.ts +0 -143
- package/types/flow.d.ts +0 -239
- package/types/index.d.ts +0 -38
- package/types/interfaces.d.ts +0 -61
package/dist/index.cjs
DELETED
|
@@ -1,1061 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const hoek = require('@hapi/hoek');
|
|
7
|
-
const consola = require('consola');
|
|
8
|
-
const R = require('ramda');
|
|
9
|
-
const boom = require('@hapi/boom');
|
|
10
|
-
const os = require('os');
|
|
11
|
-
const chalk = require('chalk');
|
|
12
|
-
const fs = require('fs-extra');
|
|
13
|
-
const fs$1 = require('fs');
|
|
14
|
-
const hookable = require('hookable');
|
|
15
|
-
const chokidar = require('chokidar');
|
|
16
|
-
|
|
17
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
18
|
-
|
|
19
|
-
function _interopNamespace(e) {
|
|
20
|
-
if (e && e.__esModule) return e;
|
|
21
|
-
const n = Object.create(null);
|
|
22
|
-
if (e) {
|
|
23
|
-
for (const k in e) {
|
|
24
|
-
n[k] = e[k];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
n["default"] = e;
|
|
28
|
-
return n;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
32
|
-
const consola__default = /*#__PURE__*/_interopDefaultLegacy(consola);
|
|
33
|
-
const R__namespace = /*#__PURE__*/_interopNamespace(R);
|
|
34
|
-
const os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
35
|
-
const chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
36
|
-
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
37
|
-
const fs__default$1 = /*#__PURE__*/_interopDefaultLegacy(fs$1);
|
|
38
|
-
const chokidar__default = /*#__PURE__*/_interopDefaultLegacy(chokidar);
|
|
39
|
-
|
|
40
|
-
const name = "@monkeyplus/flow";
|
|
41
|
-
const version = "4.0.0-beta.9";
|
|
42
|
-
const description = "Utils hapi";
|
|
43
|
-
const author = "Andres Navarrete";
|
|
44
|
-
const license = "MIT";
|
|
45
|
-
const main = "./dist/index.cjs";
|
|
46
|
-
const module$1 = "./dist/index.mjs";
|
|
47
|
-
const types = "./dist/index.d.ts";
|
|
48
|
-
const files = [
|
|
49
|
-
"dist/",
|
|
50
|
-
"types/"
|
|
51
|
-
];
|
|
52
|
-
const exports$1 = {
|
|
53
|
-
".": {
|
|
54
|
-
"import": "./dist/index.mjs",
|
|
55
|
-
require: "./dist/index.cjs"
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const scripts = {
|
|
59
|
-
build: "unbuild",
|
|
60
|
-
dev: "pnpm stub && pnpm types",
|
|
61
|
-
stub: "unbuild --stub",
|
|
62
|
-
types: "tsup ./src/index.ts --dts-only --external types && esno ../../scripts/replace",
|
|
63
|
-
lint: "eslint --ext .js,.ts .",
|
|
64
|
-
fix: "eslint --fix --ext .ts .",
|
|
65
|
-
prepublishOnly: "pnpm run build",
|
|
66
|
-
start: "esno src/index.ts",
|
|
67
|
-
test: "vitest"
|
|
68
|
-
};
|
|
69
|
-
const dependencies$1 = {
|
|
70
|
-
"@hapi/boom": "9.x.x",
|
|
71
|
-
"@hapi/hoek": "9.x.x",
|
|
72
|
-
consola: "^2.15.3",
|
|
73
|
-
chalk: "^4.1.2",
|
|
74
|
-
chokidar: "^3.5.3",
|
|
75
|
-
hookable: "^5.1.1",
|
|
76
|
-
"fs-extra": "^10.0.0",
|
|
77
|
-
ramda: "^0.28.0"
|
|
78
|
-
};
|
|
79
|
-
const devDependencies = {
|
|
80
|
-
"@types/fs-extra": "^9.0.13",
|
|
81
|
-
"@types/hapi__hapi": "^20.0.10",
|
|
82
|
-
"@types/hapi__nes": "^11.0.5",
|
|
83
|
-
"@types/hapi__vision": "^5.5.3",
|
|
84
|
-
"@types/ramda": "^0.27.64"
|
|
85
|
-
};
|
|
86
|
-
const peerDependencies = {
|
|
87
|
-
"@hapi/hapi": "^20.x"
|
|
88
|
-
};
|
|
89
|
-
const gitHead = "1d5387b9c77909019f36d360a0ac53ddaa40e4af";
|
|
90
|
-
const pkg = {
|
|
91
|
-
name: name,
|
|
92
|
-
version: version,
|
|
93
|
-
description: description,
|
|
94
|
-
author: author,
|
|
95
|
-
license: license,
|
|
96
|
-
main: main,
|
|
97
|
-
module: module$1,
|
|
98
|
-
types: types,
|
|
99
|
-
files: files,
|
|
100
|
-
exports: exports$1,
|
|
101
|
-
scripts: scripts,
|
|
102
|
-
dependencies: dependencies$1,
|
|
103
|
-
devDependencies: devDependencies,
|
|
104
|
-
peerDependencies: peerDependencies,
|
|
105
|
-
gitHead: gitHead
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const logger$1 = consola__default.withScope(pkg.name);
|
|
109
|
-
const dependencies = {
|
|
110
|
-
"@hapi/vision": "6.x.x",
|
|
111
|
-
"@hapi/inert": "6.x.x",
|
|
112
|
-
"@hapi/h2o2": "9.x.x",
|
|
113
|
-
"@hapi/nes": "12.x.x"
|
|
114
|
-
};
|
|
115
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
116
|
-
const isGenerate = process.env.GENERATE;
|
|
117
|
-
|
|
118
|
-
const LifeCircle = {
|
|
119
|
-
register: (server) => {
|
|
120
|
-
server.ext("onPreStart", async () => {
|
|
121
|
-
await server.methods.flow.pages();
|
|
122
|
-
});
|
|
123
|
-
server.ext("onRequest", async (req, h) => {
|
|
124
|
-
await server.methods.flow.pages();
|
|
125
|
-
const stateRequest = {
|
|
126
|
-
global: {},
|
|
127
|
-
local: {},
|
|
128
|
-
context: {},
|
|
129
|
-
utils: {},
|
|
130
|
-
extensions: {}
|
|
131
|
-
};
|
|
132
|
-
req.plugins.flow = stateRequest;
|
|
133
|
-
const { flow: state } = server.app;
|
|
134
|
-
const pathRedirect = state.pages.redirects[req.path];
|
|
135
|
-
if (state.truncates[req.path])
|
|
136
|
-
return h.redirect("/").takeover();
|
|
137
|
-
if (pathRedirect)
|
|
138
|
-
return h.redirect(pathRedirect).takeover();
|
|
139
|
-
return h.continue;
|
|
140
|
-
});
|
|
141
|
-
server.ext("onPreHandler", async (req, h) => {
|
|
142
|
-
const { dynamic } = req.route.settings.plugins?.flow || {};
|
|
143
|
-
const flow = req.route.settings.app?.flow;
|
|
144
|
-
if (!dynamic)
|
|
145
|
-
return h.continue;
|
|
146
|
-
const pages = await dynamic.pages({
|
|
147
|
-
server,
|
|
148
|
-
route: req.route,
|
|
149
|
-
locale: flow?.locale
|
|
150
|
-
});
|
|
151
|
-
if (!pages || !pages.length)
|
|
152
|
-
return h.continue;
|
|
153
|
-
const page = pages.find((_page) => _page.url === req.params.url);
|
|
154
|
-
if (!page)
|
|
155
|
-
return boom.notFound();
|
|
156
|
-
Object.assign(req.plugins.flow.local, {
|
|
157
|
-
[dynamic.assign || "dynamic"]: page.context ?? { a: "" }
|
|
158
|
-
});
|
|
159
|
-
req.app.dynamic = R__namespace.omit(["context"], page);
|
|
160
|
-
return h.continue;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const ServerInfo = {
|
|
166
|
-
register: (server) => {
|
|
167
|
-
const serverInfo = () => {
|
|
168
|
-
const interfaces = os__default.networkInterfaces();
|
|
169
|
-
const hostname = "localhost";
|
|
170
|
-
const protocol = "http";
|
|
171
|
-
console.log("");
|
|
172
|
-
logger$1.success(chalk__default.green(`Flow v${pkg.version} dev server running at:`));
|
|
173
|
-
console.log("");
|
|
174
|
-
Object.keys(interfaces).forEach((key) => (interfaces[key] || []).filter((details) => details.family === "IPv4").map((detail) => {
|
|
175
|
-
return {
|
|
176
|
-
type: detail.address.includes("127.0.0.1") ? "Local: " : "Network: ",
|
|
177
|
-
host: detail.address.replace("127.0.0.1", hostname)
|
|
178
|
-
};
|
|
179
|
-
}).forEach(({ type, host }) => {
|
|
180
|
-
const url = `${protocol}://${host}:${chalk__default.bold(server.info.port)}`;
|
|
181
|
-
console.log(` > ${type} ${chalk__default.cyan(url)}`);
|
|
182
|
-
}));
|
|
183
|
-
};
|
|
184
|
-
return { serverInfo };
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
function getLocalDefaults(loc, opts) {
|
|
189
|
-
const bundle = R__namespace.path(["locales", loc, "view", "bundle"], opts);
|
|
190
|
-
const view = R__namespace.path(["locales", loc, "view"], opts);
|
|
191
|
-
const runContext = R__namespace.path(["locales", loc, "context"], opts);
|
|
192
|
-
const seo = R__namespace.path(["locales", loc, "seo"], opts);
|
|
193
|
-
const blogInfo = R__namespace.path(["locales", loc, "blogInfo"], opts);
|
|
194
|
-
return {
|
|
195
|
-
bundle,
|
|
196
|
-
view,
|
|
197
|
-
runContext,
|
|
198
|
-
seo: seo || {},
|
|
199
|
-
blogInfo
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function getLevel(locale, defLevel) {
|
|
203
|
-
const level = typeof defLevel === "string" ? defLevel : typeof defLevel === "object" ? defLevel.locales[locale] || defLevel.default : "";
|
|
204
|
-
return level;
|
|
205
|
-
}
|
|
206
|
-
const definePages = (options) => (defaultLocale) => (levelOptions = {}) => {
|
|
207
|
-
const prefixName = levelOptions.prefixName || "";
|
|
208
|
-
const pages = (locales) => locales.map(({ locale, url, seo }) => {
|
|
209
|
-
const page = getLocalDefaults(locale, options);
|
|
210
|
-
const levelBase = getLevel(locale, levelOptions.level);
|
|
211
|
-
const level = getLevel(locale, options.level);
|
|
212
|
-
const [language, ubication] = locale.split("-");
|
|
213
|
-
const prefixLang = language === defaultLocale.language ? "" : language;
|
|
214
|
-
const prefixUbication = ubication === defaultLocale.ubication ? "" : ubication;
|
|
215
|
-
const prefixLevel = path__default.posix.join("/", prefixLang, prefixUbication, levelBase, level);
|
|
216
|
-
const publicPath = defaultLocale.publicPath || "/";
|
|
217
|
-
const fullPath = path__default.posix.join("/", publicPath, prefixLevel, url);
|
|
218
|
-
const redirect = R__namespace.last(fullPath) === "/" ? path__default.posix.join(fullPath, "index.html") : void 0;
|
|
219
|
-
const app = {
|
|
220
|
-
localeName: path__default.posix.join(prefixName, locale, options.name),
|
|
221
|
-
name: options.name,
|
|
222
|
-
locale,
|
|
223
|
-
language,
|
|
224
|
-
level,
|
|
225
|
-
redirect,
|
|
226
|
-
seo: R__namespace.mergeDeepLeft(seo || {}, page.seo),
|
|
227
|
-
blogInfo: page.blogInfo,
|
|
228
|
-
urlObject: {
|
|
229
|
-
publicPath,
|
|
230
|
-
level: prefixLevel,
|
|
231
|
-
url,
|
|
232
|
-
path: fullPath,
|
|
233
|
-
static: R__namespace.last(fullPath) === "/" ? `${fullPath}index.html` : `${fullPath}.html`
|
|
234
|
-
},
|
|
235
|
-
view: { ...options.view, ...page.view },
|
|
236
|
-
runSharedContext: options.context,
|
|
237
|
-
runLocalContext: page.runContext
|
|
238
|
-
};
|
|
239
|
-
return app;
|
|
240
|
-
});
|
|
241
|
-
return {
|
|
242
|
-
name: options.name,
|
|
243
|
-
pages
|
|
244
|
-
};
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const handlerPage = async (req, h) => {
|
|
248
|
-
const { configs } = req.server.plugins.flow;
|
|
249
|
-
const { flow } = req.route.settings.app;
|
|
250
|
-
const { dynamic } = req.app;
|
|
251
|
-
const local = {};
|
|
252
|
-
const global = {};
|
|
253
|
-
const page = R__namespace.clone({
|
|
254
|
-
...R__namespace.pick(["publicPath", "path"], flow.urlObject),
|
|
255
|
-
...R__namespace.pick([
|
|
256
|
-
"name",
|
|
257
|
-
"localeName",
|
|
258
|
-
"locale",
|
|
259
|
-
"level",
|
|
260
|
-
"template",
|
|
261
|
-
"bundle",
|
|
262
|
-
"language"
|
|
263
|
-
], flow)
|
|
264
|
-
});
|
|
265
|
-
if (dynamic) {
|
|
266
|
-
Object.assign(page, {
|
|
267
|
-
path: dynamic.url,
|
|
268
|
-
...R__namespace.omit(["url"], dynamic)
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
const utils = {
|
|
272
|
-
...req.plugins.flow.utils,
|
|
273
|
-
getLocalUrl: (name) => {
|
|
274
|
-
return h.getUrl(flow.locale, name);
|
|
275
|
-
},
|
|
276
|
-
getUrl: h.getUrl
|
|
277
|
-
};
|
|
278
|
-
const seo = {
|
|
279
|
-
...flow.seo,
|
|
280
|
-
...req.pre.seo,
|
|
281
|
-
url: configs.url,
|
|
282
|
-
pageUrl: `${configs.url}${req.url.pathname}`
|
|
283
|
-
};
|
|
284
|
-
const contextMethod = {
|
|
285
|
-
seo,
|
|
286
|
-
req,
|
|
287
|
-
h,
|
|
288
|
-
page,
|
|
289
|
-
extensions: req.plugins.flow.extensions,
|
|
290
|
-
global: req.plugins.flow.global,
|
|
291
|
-
utils
|
|
292
|
-
};
|
|
293
|
-
const extraContexts = req.plugins.flow.context;
|
|
294
|
-
for (const key in extraContexts) {
|
|
295
|
-
if (extraContexts[key]?.method) {
|
|
296
|
-
const assign = extraContexts[key].assign;
|
|
297
|
-
const data = await extraContexts[key].method(contextMethod);
|
|
298
|
-
const _context = { [key]: data };
|
|
299
|
-
if (assign === "global")
|
|
300
|
-
Object.assign(global, _context);
|
|
301
|
-
else if (assign === "local")
|
|
302
|
-
Object.assign(local, _context);
|
|
303
|
-
else
|
|
304
|
-
Object.assign(seo, _context);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
if (flow.runSharedContext) {
|
|
308
|
-
const _context = await flow.runSharedContext(contextMethod);
|
|
309
|
-
Object.assign(local, _context);
|
|
310
|
-
}
|
|
311
|
-
if (flow.runLocalContext) {
|
|
312
|
-
const _context = await flow.runLocalContext(contextMethod);
|
|
313
|
-
Object.assign(local, _context);
|
|
314
|
-
}
|
|
315
|
-
const context = {
|
|
316
|
-
view: flow.view,
|
|
317
|
-
context: Object.freeze({ ...local, ...req.plugins.flow.local }),
|
|
318
|
-
seo,
|
|
319
|
-
page,
|
|
320
|
-
utils: {},
|
|
321
|
-
hapi: { req, h },
|
|
322
|
-
global: Object.freeze({ ...global, ...req.plugins.flow.global })
|
|
323
|
-
};
|
|
324
|
-
if (req.query.context) {
|
|
325
|
-
context.utils = Object.keys(utils);
|
|
326
|
-
context.hapi = ["req", "h"];
|
|
327
|
-
return context;
|
|
328
|
-
}
|
|
329
|
-
context.utils = utils;
|
|
330
|
-
return h.view(`${configs.dirTemplates}${flow.view.layout || "default"}`, context);
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
const logger = consola__default.withScope("@monkeyplus/flow");
|
|
334
|
-
const defaults = {
|
|
335
|
-
locales: ["es-ec"],
|
|
336
|
-
defaultUbication: "ec",
|
|
337
|
-
defaultLanguage: "es",
|
|
338
|
-
staticDir: "static",
|
|
339
|
-
hmr: {
|
|
340
|
-
dirs: ["views"]
|
|
341
|
-
},
|
|
342
|
-
publicPath: "/",
|
|
343
|
-
locale: "es-ec",
|
|
344
|
-
relativeTo: "",
|
|
345
|
-
dirTemplates: "",
|
|
346
|
-
outputDir: "build",
|
|
347
|
-
url: process.env.CUSTOM_URL || process.env.URL,
|
|
348
|
-
engines: ["eta"],
|
|
349
|
-
plugins: {}
|
|
350
|
-
};
|
|
351
|
-
function getConfigs(server, options) {
|
|
352
|
-
const relativeTo = path__default.resolve(options.relativeTo);
|
|
353
|
-
const getObject = (object) => {
|
|
354
|
-
const config = hoek.applyToDefaults(defaults, { ...object, ...options });
|
|
355
|
-
return {
|
|
356
|
-
...config,
|
|
357
|
-
relativeTo,
|
|
358
|
-
locale: `${config.defaultLanguage}-${config.defaultUbication}`
|
|
359
|
-
};
|
|
360
|
-
};
|
|
361
|
-
try {
|
|
362
|
-
const pathWeb = path__default.resolve(options.relativeTo, "flow.config");
|
|
363
|
-
logger.info("Flow apply settings from file: flow.config");
|
|
364
|
-
const configBase = require(pathWeb);
|
|
365
|
-
const config = getObject(configBase);
|
|
366
|
-
return config;
|
|
367
|
-
} catch (error) {
|
|
368
|
-
logger.info("Flow no config file apply default settings");
|
|
369
|
-
return getObject({});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
const isDinamyc = (url) => /\{url?(.+)\}/.test(url);
|
|
373
|
-
|
|
374
|
-
const Decorators = {
|
|
375
|
-
register: (server) => {
|
|
376
|
-
const { flow: state } = server.app;
|
|
377
|
-
const { configs, helpers } = server.plugins.flow;
|
|
378
|
-
const flowDecorate = (route, options) => {
|
|
379
|
-
const { plugins, app } = route.settings;
|
|
380
|
-
Object.assign(plugins, { generate: ".html" });
|
|
381
|
-
const flow = app.flow;
|
|
382
|
-
const runCommons = (pageInfo) => {
|
|
383
|
-
helpers.addStaticPage(pageInfo.localeName, {
|
|
384
|
-
url: route.path,
|
|
385
|
-
locale: pageInfo.locale,
|
|
386
|
-
localeName: pageInfo.localeName,
|
|
387
|
-
name: pageInfo.name
|
|
388
|
-
});
|
|
389
|
-
if (pageInfo.redirect)
|
|
390
|
-
helpers.addRedirect(pageInfo.redirect, route.path);
|
|
391
|
-
};
|
|
392
|
-
if (flow) {
|
|
393
|
-
runCommons(flow);
|
|
394
|
-
} else {
|
|
395
|
-
const routes = definePages({
|
|
396
|
-
name: options.name,
|
|
397
|
-
view: options.view,
|
|
398
|
-
locales: {
|
|
399
|
-
[options.locale || configs.locale]: {}
|
|
400
|
-
},
|
|
401
|
-
context: options.context
|
|
402
|
-
})({
|
|
403
|
-
language: configs.defaultLanguage,
|
|
404
|
-
ubication: configs.defaultUbication,
|
|
405
|
-
publicPath: configs.publicPath
|
|
406
|
-
})().pages([
|
|
407
|
-
{ locale: options.locale || configs.locale, url: route.path }
|
|
408
|
-
]);
|
|
409
|
-
const pageInfo = routes[0];
|
|
410
|
-
runCommons(pageInfo);
|
|
411
|
-
Object.assign(app, { flow: pageInfo, content: options.content });
|
|
412
|
-
}
|
|
413
|
-
const extensions = plugins?.flow?.extensions || {};
|
|
414
|
-
if (isDinamyc(route.path)) {
|
|
415
|
-
if (!route.settings.plugins?.flow?.dynamic)
|
|
416
|
-
throw new Error("Dynamic pages require a method");
|
|
417
|
-
helpers.addDynamicPages(flow.localeName, ((options2) => async () => {
|
|
418
|
-
const _pages = await route.settings.plugins?.flow?.dynamic?.pages(options2);
|
|
419
|
-
const obj = {};
|
|
420
|
-
for (const sPage of _pages || []) {
|
|
421
|
-
const localeName = `${app?.flow.localeName}/${sPage.name}`;
|
|
422
|
-
obj[localeName] = {
|
|
423
|
-
locale: app?.flow.locale,
|
|
424
|
-
localeName,
|
|
425
|
-
name: localeName.replace(`${app?.flow.locale}/`, ""),
|
|
426
|
-
url: route.path.replace("{url*}", sPage.url),
|
|
427
|
-
context: sPage.context,
|
|
428
|
-
dynamicSlug: sPage.dynamicSlug
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
return obj;
|
|
432
|
-
})({
|
|
433
|
-
server,
|
|
434
|
-
route,
|
|
435
|
-
locale: app?.flow.locale
|
|
436
|
-
}));
|
|
437
|
-
}
|
|
438
|
-
for (const extension in extensions) {
|
|
439
|
-
const optionExtension = plugins?.flow?.extensions[extension];
|
|
440
|
-
const routeMethod = state.extensions[extension]?.routeMethod;
|
|
441
|
-
if (routeMethod)
|
|
442
|
-
routeMethod({ pageInfo: app.flow, route }, optionExtension);
|
|
443
|
-
}
|
|
444
|
-
return handlerPage;
|
|
445
|
-
};
|
|
446
|
-
const getUrl = (_locale, _name) => {
|
|
447
|
-
try {
|
|
448
|
-
const pageName = path__default.posix.join(_locale, _name);
|
|
449
|
-
const page = state.pages.all[pageName];
|
|
450
|
-
if (page) {
|
|
451
|
-
return page.url;
|
|
452
|
-
} else {
|
|
453
|
-
logger$1.warn("Not found link with name: %s", pageName);
|
|
454
|
-
return "/404";
|
|
455
|
-
}
|
|
456
|
-
} catch (error) {
|
|
457
|
-
logger$1.error(error);
|
|
458
|
-
return "/";
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
server.method("flow.getUrl", getUrl, {});
|
|
462
|
-
server.decorate("handler", "flow", flowDecorate);
|
|
463
|
-
server.decorate("toolkit", "getUrl", server.methods.flow.getUrl);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
const useGenerator = {
|
|
468
|
-
register: (server) => {
|
|
469
|
-
const { configs, helpers } = server.plugins.flow;
|
|
470
|
-
const getFlowPages = async () => {
|
|
471
|
-
const files = {};
|
|
472
|
-
const allPages = await server.methods.flow.pages();
|
|
473
|
-
const pages = Object.values(allPages);
|
|
474
|
-
logger.success("Read %i static pages", pages.length);
|
|
475
|
-
for (const page of pages)
|
|
476
|
-
files[page.url] = ".html";
|
|
477
|
-
const routes = server.table();
|
|
478
|
-
for (const route of routes) {
|
|
479
|
-
const isDynamic = /\{url?(.+)\}/.test(route.path);
|
|
480
|
-
const generate = route.settings.plugins?.generate;
|
|
481
|
-
if (!isDynamic && generate) {
|
|
482
|
-
if (!files[route.path])
|
|
483
|
-
files[route.path] = generate;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return files;
|
|
487
|
-
};
|
|
488
|
-
const writeFile = async (file, payload) => {
|
|
489
|
-
await fs__default.ensureFile(file);
|
|
490
|
-
await fs__default.writeFile(file, payload, "utf8");
|
|
491
|
-
};
|
|
492
|
-
const useCreateFile = (isVirtual = false) => async (dir, url, ext) => {
|
|
493
|
-
if (typeof ext === "object") {
|
|
494
|
-
if (!isVirtual) {
|
|
495
|
-
const dirFile = path__default.dirname(url);
|
|
496
|
-
await fs__default.ensureDir(path__default.join(dir, dirFile));
|
|
497
|
-
const file = await fs__default.readFile(ext.file);
|
|
498
|
-
await fs__default.writeFile(path__default.join(dir, url), file);
|
|
499
|
-
}
|
|
500
|
-
return { type: ext.type || "assets", url };
|
|
501
|
-
} else {
|
|
502
|
-
const r = await server.inject({
|
|
503
|
-
url,
|
|
504
|
-
method: "get"
|
|
505
|
-
});
|
|
506
|
-
let file = "";
|
|
507
|
-
if (typeof ext === "boolean") {
|
|
508
|
-
if (!isVirtual) {
|
|
509
|
-
file = path__default.join(dir, url);
|
|
510
|
-
await writeFile(file, r.payload);
|
|
511
|
-
}
|
|
512
|
-
return { type: "assets", url };
|
|
513
|
-
} else if (typeof ext === "string") {
|
|
514
|
-
if (ext === ".html") {
|
|
515
|
-
if (!isVirtual) {
|
|
516
|
-
const isIndex = R__namespace.last(url) === "/";
|
|
517
|
-
const nameFile = isIndex ? `${url}index.html` : `${url}.html`;
|
|
518
|
-
file = path__default.join(dir, nameFile);
|
|
519
|
-
await writeFile(file, r.payload);
|
|
520
|
-
}
|
|
521
|
-
return { type: "page", url };
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
return { type: "asset", url };
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
const injectAssets = (assets) => {
|
|
528
|
-
for (const asset of assets) {
|
|
529
|
-
const dirs = asset.dirs;
|
|
530
|
-
for (const dir of dirs) {
|
|
531
|
-
const dirFiles = fs__default.readdirSync(path__default.join(asset.relativeTo, dir));
|
|
532
|
-
for (const file of dirFiles) {
|
|
533
|
-
const pathFile = path__default.join(asset.relativeTo, dir, file);
|
|
534
|
-
const ext = path__default.extname(pathFile);
|
|
535
|
-
if (!!ext) {
|
|
536
|
-
const pathRoute = path__default.posix.join("/", asset.prefix, dir, file);
|
|
537
|
-
const pathRouteOverride = asset.override?.[pathRoute];
|
|
538
|
-
server.route({
|
|
539
|
-
path: pathRouteOverride || pathRoute,
|
|
540
|
-
method: "get",
|
|
541
|
-
options: {
|
|
542
|
-
plugins: {
|
|
543
|
-
generate: {
|
|
544
|
-
isAsset: true,
|
|
545
|
-
file: pathFile,
|
|
546
|
-
type: asset.type,
|
|
547
|
-
isRemane: !!pathRouteOverride
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
},
|
|
551
|
-
handler: {
|
|
552
|
-
file: {
|
|
553
|
-
path: pathFile,
|
|
554
|
-
confine: false
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
} else {
|
|
559
|
-
injectAssets([
|
|
560
|
-
{
|
|
561
|
-
dirs: [path__default.posix.join(dir, file)],
|
|
562
|
-
prefix: asset.prefix,
|
|
563
|
-
relativeTo: asset.relativeTo,
|
|
564
|
-
override: asset.override,
|
|
565
|
-
type: asset.type || file
|
|
566
|
-
}
|
|
567
|
-
]);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
const runGenerate = async ({
|
|
574
|
-
assets = [],
|
|
575
|
-
ommitAssets = [],
|
|
576
|
-
virtualGenerate = false
|
|
577
|
-
}) => {
|
|
578
|
-
await server.methods.flow.pages();
|
|
579
|
-
const _assetsApp = [...Object.values(server.app.flow.generate.folders)];
|
|
580
|
-
const _assets = [...assets, ..._assetsApp];
|
|
581
|
-
if (!virtualGenerate)
|
|
582
|
-
injectAssets(_assets);
|
|
583
|
-
const dirOutut = helpers.getPath(configs.outputDir ?? "build");
|
|
584
|
-
const staticDirs = Object.keys(server.app.flow.generate.staticFolders).map((dir) => helpers.getPath(dir));
|
|
585
|
-
const files = await getFlowPages();
|
|
586
|
-
const pairFiles = R__namespace.toPairs(files);
|
|
587
|
-
const ommit = ommitAssets;
|
|
588
|
-
try {
|
|
589
|
-
await fs__default.remove(dirOutut);
|
|
590
|
-
for (const dirStatic of staticDirs)
|
|
591
|
-
await fs__default.copy(dirStatic, dirOutut);
|
|
592
|
-
for (const omitFile of ommit)
|
|
593
|
-
await fs__default.remove(path__default.join(dirOutut, omitFile));
|
|
594
|
-
const createFile = useCreateFile(virtualGenerate);
|
|
595
|
-
const files2 = await Promise.all(pairFiles.map(async (v) => {
|
|
596
|
-
return await createFile(dirOutut, ...v);
|
|
597
|
-
}));
|
|
598
|
-
const groups = R__namespace.groupBy((file) => {
|
|
599
|
-
if (file.url.includes("images/"))
|
|
600
|
-
return "image";
|
|
601
|
-
else
|
|
602
|
-
return (path__default.extname(file.url) || file.type).toLowerCase();
|
|
603
|
-
}, files2);
|
|
604
|
-
const _groups = {
|
|
605
|
-
pages: 0,
|
|
606
|
-
js: 0,
|
|
607
|
-
css: 0,
|
|
608
|
-
images: 0,
|
|
609
|
-
fonts: 0,
|
|
610
|
-
others: 0
|
|
611
|
-
};
|
|
612
|
-
for (const type in groups) {
|
|
613
|
-
const cp = (ext) => ext === type;
|
|
614
|
-
const qty = groups[type].length;
|
|
615
|
-
if (type === "page")
|
|
616
|
-
_groups.pages += qty;
|
|
617
|
-
else if (type === ".js")
|
|
618
|
-
_groups.js += qty;
|
|
619
|
-
else if (type === ".css")
|
|
620
|
-
_groups.css += qty;
|
|
621
|
-
else if ([".gif", ".png", ".jpg", ".jpeg", "image"].find(cp))
|
|
622
|
-
_groups.images += qty;
|
|
623
|
-
else if ([".woff", ".eot", ".ttf"].find(cp))
|
|
624
|
-
_groups.fonts += qty;
|
|
625
|
-
else
|
|
626
|
-
_groups.others += qty;
|
|
627
|
-
}
|
|
628
|
-
for (const type in _groups)
|
|
629
|
-
logger.success("%i %s generated", _groups[type], type);
|
|
630
|
-
const bf = server.app.flow.generate.postGenerate;
|
|
631
|
-
if (Object.keys(bf).length) {
|
|
632
|
-
logger.info("Post generate");
|
|
633
|
-
}
|
|
634
|
-
for (const key in bf)
|
|
635
|
-
await bf[key]();
|
|
636
|
-
} catch (error) {
|
|
637
|
-
logger.error(error);
|
|
638
|
-
await fs__default.remove(dirOutut);
|
|
639
|
-
throw new Error(error);
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
return { runGenerate };
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
|
|
646
|
-
const definePage = (pageOptions) => (levelOptions) => (configs) => {
|
|
647
|
-
const pages = [];
|
|
648
|
-
for (const locale in pageOptions.locales) {
|
|
649
|
-
if (configs.locales.find((_locale) => _locale === locale)) {
|
|
650
|
-
const singlePage = pageOptions.locales[locale];
|
|
651
|
-
pages.push({ url: singlePage.url, locale });
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
const infoPages = definePages({
|
|
655
|
-
name: pageOptions.name,
|
|
656
|
-
view: pageOptions.view,
|
|
657
|
-
context: pageOptions.context,
|
|
658
|
-
level: pageOptions.level,
|
|
659
|
-
locales: pageOptions.locales
|
|
660
|
-
})({
|
|
661
|
-
language: configs.defaultLanguage,
|
|
662
|
-
ubication: configs.defaultUbication,
|
|
663
|
-
publicPath: configs.publicPath
|
|
664
|
-
})(levelOptions).pages(pages);
|
|
665
|
-
const {
|
|
666
|
-
options: sharedOptions,
|
|
667
|
-
rules: sharedRules,
|
|
668
|
-
vhost: sharedVHost
|
|
669
|
-
} = pageOptions;
|
|
670
|
-
const sharedPre = sharedOptions?.pre || [];
|
|
671
|
-
const routes = infoPages.map((page) => {
|
|
672
|
-
const localPage = pageOptions.locales[page.locale];
|
|
673
|
-
const route = {
|
|
674
|
-
path: page.urlObject.path,
|
|
675
|
-
method: "get",
|
|
676
|
-
options: {
|
|
677
|
-
app: {
|
|
678
|
-
flow: page
|
|
679
|
-
},
|
|
680
|
-
plugins: {
|
|
681
|
-
flow: {
|
|
682
|
-
extensions: pageOptions.extensions || {},
|
|
683
|
-
dynamic: localPage.dynamic
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
},
|
|
687
|
-
handler: {
|
|
688
|
-
flow: {
|
|
689
|
-
name: page.localeName,
|
|
690
|
-
locale: page.locale,
|
|
691
|
-
view: page.view
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
if (sharedRules || localPage.rules)
|
|
696
|
-
route.rules = localPage.rules || sharedRules;
|
|
697
|
-
if (sharedVHost || localPage.vhost)
|
|
698
|
-
route.vhost = localPage.vhost || sharedVHost;
|
|
699
|
-
if (sharedOptions || localPage.options) {
|
|
700
|
-
const localOptions = localPage?.options || {};
|
|
701
|
-
const localPre = localPage?.options?.pre || [];
|
|
702
|
-
const pre = [...sharedPre, ...localPre];
|
|
703
|
-
const options = R__namespace.mergeDeepRight(sharedOptions || {}, localOptions);
|
|
704
|
-
route.options = R__namespace.mergeDeepRight(options, route.options);
|
|
705
|
-
if (route.options && pre.length)
|
|
706
|
-
route.options.pre = pre;
|
|
707
|
-
}
|
|
708
|
-
return route;
|
|
709
|
-
});
|
|
710
|
-
return routes;
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
const readPagesDir = (pathDir, folder) => {
|
|
714
|
-
const p = fs__default$1.readdirSync(pathDir);
|
|
715
|
-
return R.flatten(p.filter((f) => !f.includes(".js.map") && !f.includes(" copy.js.map") && !f.includes(" copy.js") && !f.includes(".model")).map((e) => {
|
|
716
|
-
if (e.includes(".js") || e.includes(".ts")) {
|
|
717
|
-
return {
|
|
718
|
-
path: path__default.join(pathDir, e),
|
|
719
|
-
prefix: folder
|
|
720
|
-
};
|
|
721
|
-
} else {
|
|
722
|
-
return readPagesDir(path__default.join(pathDir, e), e);
|
|
723
|
-
}
|
|
724
|
-
}));
|
|
725
|
-
};
|
|
726
|
-
const registerPages = async (server, dir) => {
|
|
727
|
-
const dirPages = path__default.resolve(dir || "./pages");
|
|
728
|
-
const listFiles = readPagesDir(dirPages);
|
|
729
|
-
const listPrePages = [];
|
|
730
|
-
for (const item of listFiles) {
|
|
731
|
-
try {
|
|
732
|
-
const module = require(item.path)?.default;
|
|
733
|
-
if (typeof module === "function") {
|
|
734
|
-
listPrePages.push(module());
|
|
735
|
-
} else if (typeof module === "object") {
|
|
736
|
-
if (Array.isArray(module)) {
|
|
737
|
-
module.forEach((el) => listPrePages.push(el()));
|
|
738
|
-
} else {
|
|
739
|
-
const _pages = await module.pages({ server });
|
|
740
|
-
if (Array.isArray(_pages))
|
|
741
|
-
_pages.forEach((page) => listPrePages.push(definePage(page)()));
|
|
742
|
-
else
|
|
743
|
-
listPrePages.push(definePage(_pages)());
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
} catch (details) {
|
|
747
|
-
logger$1.error(details);
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
for (const page of listPrePages)
|
|
751
|
-
await server.flow.addPage(page);
|
|
752
|
-
};
|
|
753
|
-
|
|
754
|
-
const RunMethods = {
|
|
755
|
-
register: (server) => {
|
|
756
|
-
const { flow: state } = server.app;
|
|
757
|
-
const { configs: config } = server.plugins.flow;
|
|
758
|
-
const registerRoute = (route) => {
|
|
759
|
-
const _routes = server.table();
|
|
760
|
-
const _route = _routes.find((v) => v.path === route.path);
|
|
761
|
-
if (_route)
|
|
762
|
-
logger$1.warn(`Duplicate route, the route ${route.path} already exists`);
|
|
763
|
-
else
|
|
764
|
-
server.route(route);
|
|
765
|
-
};
|
|
766
|
-
const addPage = (_page, extra) => {
|
|
767
|
-
const registerPages2 = (_pages2) => {
|
|
768
|
-
for (const _route of _pages2) {
|
|
769
|
-
if (state.routes[_route.path])
|
|
770
|
-
logger$1.warn("The route %s alredy exist", _route.path);
|
|
771
|
-
else
|
|
772
|
-
state.routes[_route.path] = _route;
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
|
-
let _pages;
|
|
776
|
-
if (typeof _page === "function") {
|
|
777
|
-
_pages = _page(config);
|
|
778
|
-
registerPages2(_pages);
|
|
779
|
-
} else {
|
|
780
|
-
_pages = definePage(_page)()(config);
|
|
781
|
-
registerPages2(_pages);
|
|
782
|
-
}
|
|
783
|
-
};
|
|
784
|
-
const init = async () => {
|
|
785
|
-
await registerPages(server);
|
|
786
|
-
const pages = server.app.flow.routes;
|
|
787
|
-
for (const key in pages) {
|
|
788
|
-
const page = pages[key];
|
|
789
|
-
registerRoute(page);
|
|
790
|
-
}
|
|
791
|
-
for (const key in state.extensions) {
|
|
792
|
-
const ext = state.extensions[key];
|
|
793
|
-
if (ext.initMethod)
|
|
794
|
-
await ext.initMethod();
|
|
795
|
-
}
|
|
796
|
-
logger$1.debug("Register %s pages", `${Object.values(pages).length}`);
|
|
797
|
-
};
|
|
798
|
-
return { init, addPage };
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
|
|
802
|
-
const createHmr = (options) => {
|
|
803
|
-
const state = {
|
|
804
|
-
dir: options.relativeTo || "",
|
|
805
|
-
dirs: options.dirs || [],
|
|
806
|
-
extensions: options.extensions || ["eta"]
|
|
807
|
-
};
|
|
808
|
-
let watcher;
|
|
809
|
-
const hooks = hookable.createHooks();
|
|
810
|
-
const watch = () => {
|
|
811
|
-
watcher = chokidar__default.watch(state.dirs.map((d) => path__default.join(d, `**/*.(${state.extensions.join("|")})`)), {
|
|
812
|
-
cwd: state.dir,
|
|
813
|
-
ignoreInitial: true,
|
|
814
|
-
ignored: "node_modules/**/*"
|
|
815
|
-
}).on("change", (path2) => {
|
|
816
|
-
logger$1.info("Changed file", path2);
|
|
817
|
-
hooks.callHook("page:refresh");
|
|
818
|
-
});
|
|
819
|
-
};
|
|
820
|
-
watch();
|
|
821
|
-
return { watcher, hooks };
|
|
822
|
-
};
|
|
823
|
-
|
|
824
|
-
const RegisterCommon = async (server, configs) => {
|
|
825
|
-
server.route({
|
|
826
|
-
method: "GET",
|
|
827
|
-
path: "/{param*}",
|
|
828
|
-
options: {
|
|
829
|
-
ext: {
|
|
830
|
-
onPreResponse: {
|
|
831
|
-
method: (req, h) => {
|
|
832
|
-
return h.continue;
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
},
|
|
837
|
-
handler: {
|
|
838
|
-
directory: {
|
|
839
|
-
path: configs.staticDir,
|
|
840
|
-
listing: true
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
if (!isGenerate) {
|
|
845
|
-
const hmr = createHmr({
|
|
846
|
-
dirs: configs.hmr.dirs,
|
|
847
|
-
relativeTo: configs.relativeTo
|
|
848
|
-
});
|
|
849
|
-
hmr.hooks.hook("page:refresh", () => {
|
|
850
|
-
setTimeout(() => {
|
|
851
|
-
logger$1.info("Refresh page");
|
|
852
|
-
server.publish("/_flow/hmr", { reload: true });
|
|
853
|
-
}, 40);
|
|
854
|
-
});
|
|
855
|
-
server.subscription("/_flow/hmr");
|
|
856
|
-
server.route({
|
|
857
|
-
path: "/_flow/hmr/client.js",
|
|
858
|
-
method: "get",
|
|
859
|
-
handler: {
|
|
860
|
-
file: {
|
|
861
|
-
path: path.join(__dirname, "../resources/client"),
|
|
862
|
-
confine: false
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
});
|
|
866
|
-
server.route({
|
|
867
|
-
path: "/_flow/hmr/connect.js",
|
|
868
|
-
method: "get",
|
|
869
|
-
handler: {
|
|
870
|
-
file: {
|
|
871
|
-
path: path.join(__dirname, "../resources/ws.js"),
|
|
872
|
-
confine: false
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
});
|
|
876
|
-
logger$1.debug("Enable development routes");
|
|
877
|
-
server.route({
|
|
878
|
-
path: "/_flow/sitemap",
|
|
879
|
-
method: "get",
|
|
880
|
-
handler: async () => {
|
|
881
|
-
const { pages: getPages } = server.methods.flow;
|
|
882
|
-
const urls = await getPages();
|
|
883
|
-
const pages = Object.values(urls).map((p) => R.dissoc("context", p));
|
|
884
|
-
return {
|
|
885
|
-
total: pages.length,
|
|
886
|
-
pages
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
});
|
|
890
|
-
server.route({
|
|
891
|
-
path: "/_flow/locales",
|
|
892
|
-
method: "get",
|
|
893
|
-
handler: async (req) => {
|
|
894
|
-
const { pages: getPages } = server.methods.flow;
|
|
895
|
-
const urls = await getPages();
|
|
896
|
-
const pages = Object.values(urls).map((p) => R.dissoc("context", p));
|
|
897
|
-
const locales = R.groupBy((page) => page.locale, pages);
|
|
898
|
-
return {
|
|
899
|
-
locales: req.server.plugins.flow.configs.locales,
|
|
900
|
-
all: R.mapObjIndexed((l) => {
|
|
901
|
-
return {
|
|
902
|
-
total: l.length,
|
|
903
|
-
pages: l
|
|
904
|
-
};
|
|
905
|
-
}, locales)
|
|
906
|
-
};
|
|
907
|
-
}
|
|
908
|
-
});
|
|
909
|
-
server.route({
|
|
910
|
-
path: "/_flow/configs",
|
|
911
|
-
method: "get",
|
|
912
|
-
handler: (req) => {
|
|
913
|
-
return req.server.plugins.flow.configs;
|
|
914
|
-
}
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
|
-
const HMR = {
|
|
918
|
-
head: ' <script src="/_flow/hmr/client.js"><\/script>',
|
|
919
|
-
body: ' <script src="/_flow/hmr/connect.js"><\/script>'
|
|
920
|
-
};
|
|
921
|
-
server.ext("onPreHandler", async (req, h) => {
|
|
922
|
-
if (req.route.settings.plugins?.generate === ".html") {
|
|
923
|
-
const { global } = req.plugins.flow;
|
|
924
|
-
Object.assign(global, {
|
|
925
|
-
hmr: isProduction || isGenerate ? { head: "", body: "" } : HMR
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
return h.continue;
|
|
929
|
-
});
|
|
930
|
-
};
|
|
931
|
-
|
|
932
|
-
const plugin = {
|
|
933
|
-
pkg,
|
|
934
|
-
dependencies,
|
|
935
|
-
register: async (server, _options) => {
|
|
936
|
-
const config = getConfigs(server, _options);
|
|
937
|
-
server.expose("configs", config);
|
|
938
|
-
const state = {
|
|
939
|
-
pages: { statics: {}, redirects: {}, dynamics: {}, all: {} },
|
|
940
|
-
truncates: {},
|
|
941
|
-
extensions: {},
|
|
942
|
-
generate: {
|
|
943
|
-
folders: {},
|
|
944
|
-
staticFolders: {},
|
|
945
|
-
postGenerate: {},
|
|
946
|
-
beforePackage: {}
|
|
947
|
-
},
|
|
948
|
-
engines: {},
|
|
949
|
-
routes: {},
|
|
950
|
-
plugins: {}
|
|
951
|
-
};
|
|
952
|
-
server.app.flow = state;
|
|
953
|
-
const { serverInfo } = ServerInfo.register(server);
|
|
954
|
-
const serverDecorate = {
|
|
955
|
-
serverInfo
|
|
956
|
-
};
|
|
957
|
-
const helpers = {
|
|
958
|
-
getPath: (...paths) => path__default.join(config.relativeTo, ...paths),
|
|
959
|
-
addRedirect: (key, urlPath) => {
|
|
960
|
-
state.pages.redirects[key] = urlPath;
|
|
961
|
-
},
|
|
962
|
-
addStaticPage: (key, url) => {
|
|
963
|
-
if (isDinamyc(url.url))
|
|
964
|
-
return void 0;
|
|
965
|
-
if (state.pages.statics[key]) {
|
|
966
|
-
logger$1.warn("The namePage %s already exist", state.pages.statics[key]);
|
|
967
|
-
} else {
|
|
968
|
-
state.pages.statics[key] = url;
|
|
969
|
-
}
|
|
970
|
-
},
|
|
971
|
-
addDynamicPages: (key, method) => {
|
|
972
|
-
if (state.pages.dynamics[key])
|
|
973
|
-
logger$1.warn("The dynamdcPages %s already exist", key);
|
|
974
|
-
else
|
|
975
|
-
state.pages.dynamics[key] = method;
|
|
976
|
-
}
|
|
977
|
-
};
|
|
978
|
-
server.expose("helpers", helpers);
|
|
979
|
-
server.method("flow.pages", async () => {
|
|
980
|
-
const pages = {
|
|
981
|
-
...state.pages.statics
|
|
982
|
-
};
|
|
983
|
-
for (const key in state.pages.dynamics) {
|
|
984
|
-
if (Object.prototype.hasOwnProperty.call(state.pages.dynamics, key)) {
|
|
985
|
-
const element = state.pages.dynamics[key];
|
|
986
|
-
const dynamicPages = await element();
|
|
987
|
-
for (const keyPage in dynamicPages) {
|
|
988
|
-
if (Object.prototype.hasOwnProperty.call(dynamicPages, keyPage)) {
|
|
989
|
-
const page = dynamicPages[keyPage];
|
|
990
|
-
if (!pages[keyPage])
|
|
991
|
-
pages[keyPage] = page;
|
|
992
|
-
else
|
|
993
|
-
logger$1.warn("Duplicate page %s", keyPage);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
state.pages.all = pages;
|
|
999
|
-
return pages;
|
|
1000
|
-
}, {
|
|
1001
|
-
cache: { expiresIn: 3e3, generateTimeout: 8e3 }
|
|
1002
|
-
});
|
|
1003
|
-
server.expose("pages", () => {
|
|
1004
|
-
return state.pages.all;
|
|
1005
|
-
});
|
|
1006
|
-
server.decorate("server", "flow", serverDecorate);
|
|
1007
|
-
Decorators.register(server);
|
|
1008
|
-
LifeCircle.register(server);
|
|
1009
|
-
const { runGenerate } = useGenerator.register(server);
|
|
1010
|
-
serverDecorate.runGenerate = runGenerate;
|
|
1011
|
-
const { addPage, init } = RunMethods.register(server);
|
|
1012
|
-
serverDecorate.addPage = addPage;
|
|
1013
|
-
serverDecorate.init = init;
|
|
1014
|
-
serverDecorate.prepagePackage = async () => {
|
|
1015
|
-
for (const key in state.generate.beforePackage)
|
|
1016
|
-
await state.generate.beforePackage[key]();
|
|
1017
|
-
};
|
|
1018
|
-
serverDecorate.assignPluginOptions = (realm, options = {}, d = {}, _context) => {
|
|
1019
|
-
const key = realm.plugin.replace("@monkeyplus/", "").replace("flow-", "");
|
|
1020
|
-
const baseOptions = hoek.applyToDefaults(d, options);
|
|
1021
|
-
const { plugins } = config;
|
|
1022
|
-
if (plugins[key] && Object.values(plugins[key])) {
|
|
1023
|
-
if (typeof plugins[key] === "boolean") {
|
|
1024
|
-
try {
|
|
1025
|
-
const module = require(path__default.resolve("./extensions", key))?.default;
|
|
1026
|
-
if (typeof module === "function") {
|
|
1027
|
-
const promise = module({ server, ..._context });
|
|
1028
|
-
const isPromise = !!promise && typeof promise.then === "function";
|
|
1029
|
-
if (isPromise) {
|
|
1030
|
-
return promise.then((opts2) => {
|
|
1031
|
-
const _opts = hoek.applyToDefaults(baseOptions, opts2 || {});
|
|
1032
|
-
Object.assign(plugins, { [key]: _opts });
|
|
1033
|
-
return _opts;
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
|
-
Object.assign(plugins, { [key]: promise });
|
|
1037
|
-
return promise;
|
|
1038
|
-
}
|
|
1039
|
-
const opts = hoek.applyToDefaults(baseOptions, module || {});
|
|
1040
|
-
Object.assign(plugins, { [key]: opts });
|
|
1041
|
-
return opts;
|
|
1042
|
-
} catch (error) {
|
|
1043
|
-
logger$1.error("Error in load extension: %s", key);
|
|
1044
|
-
return baseOptions;
|
|
1045
|
-
}
|
|
1046
|
-
} else {
|
|
1047
|
-
const opts = hoek.applyToDefaults(baseOptions, plugins[key]);
|
|
1048
|
-
Object.assign(plugins, { [key]: opts });
|
|
1049
|
-
return opts;
|
|
1050
|
-
}
|
|
1051
|
-
} else {
|
|
1052
|
-
Object.assign(plugins, { [key]: baseOptions });
|
|
1053
|
-
return baseOptions;
|
|
1054
|
-
}
|
|
1055
|
-
};
|
|
1056
|
-
await RegisterCommon(server, config);
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
|
|
1060
|
-
exports.definePage = definePage;
|
|
1061
|
-
exports.plugin = plugin;
|